Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update Summary/Description/Priority not always works but UpdateValidation don't have errors

Heinz Wittig March 22, 2018

Hi, 

I work on a plugin that has to update the linked Issues (Dependency on) of one issue with the Summary/Description/Priority. The linkedIssue are on N others projects. The code I wrote work only partially and I can't understand why. Because there is no logic behind them that works and them that not works. I have scenarios where when I update the main Issue, all linked issues are updated. Other scenarios where only some linked Issues are updated, and other scenarios where nothing is updated. I perform this in a for loop:

 

      IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setSummary(summary);
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser currentUser = jiraAuthenticationContext.getLoggedInUser();
UpdateValidationResult result =issueService.validateUpdate(currentUser, issueId, issueInputParameters);

if(result.isValid()){
IssueResult updateRes =issueService.update(currentUser, result,
com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false);
logErrorAndWarnings(UPDATE, updateRes, true);
}else {
logErrorAndWarnings(VALIDATION_UPDATE, result, true);
}

and the helper method logErrorWarnings:

private void logErrorAndWarnings(String action, ServiceResultImpl results, boolean throwException) throws Exception {
Collection<String> errorMessages = results.getErrorCollection().getErrorMessages();
Collection<String> warningsMessages =results.getWarningCollection().getWarnings();
log.info("RESULT of " + action+ ": " + results.isValid() +" and has "+ errorMessages.size()+" ERRORS, and "+ warningsMessages.size()+ " WARNINGS" );
if(!errorMessages.isEmpty()){
String exceptionMessage = "ERROR: ";
for (String error: errorMessages){
exceptionMessage.concat("Can't "+action+" Issue while errors: "+ error);
log.error("Can't "+action+" Issue while errors: {}", error);
}
if(throwException){
throw new Exception(exceptionMessage);
}
}
if(!warningsMessages.isEmpty()){
String exceptionMessage = "WARNING: ";
for (String error: errorMessages){
exceptionMessage.concat("Can't "+action+" Issue while errors: "+ error);
log.warn("Can't "+action+" Issue while warnings: {}", error);
}
if(throwException){
throw new Exception(exceptionMessage);
}
}

So by debugging locally I have trouble. But in test environment yes (There I have replicated the production Data). 

What I can read out from the logs is that when the update fails,  then I have as result that the update validation is false, but no warnings and no errors are present, and this don't helps me out to find why I can't update the issue.  I can't start the test environment in debug mode to attach me and debug it. 

How I sayed: in some scenarios it works in other no, but I have no Idea how I could figure out why. Some tips or tricks?

 

Thanks in advance. 

 

1 answer

0 votes
Heinz Wittig March 26, 2018

Hi I found the problem.  The problem is not in the code I wrote, but more a consistency problem. The plugin was released in a first version with some custom_fields in a issue. This custom_field was not mandatory. In a second release this field become mandatory. Now when I run in my code with issues that where created after the second release, then all is fine. Whenn I run in my code whit issues that where created before and the field was not populated then the validation is false (that is correct). But why the code, or why the 

UpdateValidationResult

 don't shows or list the errors/warnings?

Suggest an answer

Log in or Sign up to answer