@Override public RemoteIssueLinkResult update(final ApplicationUser user, final UpdateValidationResult updateValidationResult) { if (updateValidationResult == null) { throw new IllegalArgumentException("You cannot update a remote issue link with a null validation result."); } if (!updateValidationResult.isValid()) { throw new IllegalStateException("You cannot update a remote issue link with an invalid validation result."); } final RemoteIssueLink remoteIssueLink = updateValidationResult.getRemoteIssueLink(); if (remoteIssueLink == null) { throw new IllegalArgumentException("You cannot update a null remote issue link."); } final ErrorCollection errors = new SimpleErrorCollection(); RemoteIssueLink updatedRemoteIssueLink = null; try { remoteIssueLinkManager.updateRemoteIssueLink(remoteIssueLink, user); updatedRemoteIssueLink = remoteIssueLink; } catch (final UpdateException e) { handleUpdateException(getI18n(user), errors, e); } return new RemoteIssueLinkResult(updatedRemoteIssueLink, errors); }
@Override public UpdateValidationResult validateUpdate(final ApplicationUser user, final RemoteIssueLink remoteIssueLink) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); Issue issue = null; if (!errors.hasAnyErrors()) { issue = validateIssueExists(remoteIssueLink, errors, i18n); } if (!errors.hasAnyErrors()) { validatePermissionToUpdate(user, issue, errors, i18n); } RemoteIssueLink found = null; if (!errors.hasAnyErrors()) { found = validateExists(remoteIssueLink.getId(), i18n, errors); } if (!errors.hasAnyErrors()) { validateMandatoryFields(remoteIssueLink, i18n, errors); validateFieldLengths(remoteIssueLink, i18n, errors); validateUrls(remoteIssueLink, i18n, errors); validateGlobalIdForUpdate(issue, found, remoteIssueLink, errors, i18n); } return new UpdateValidationResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
/** * Updates a remote issue link. * * @param oldRemoteIssueLink the remote issue link to update * @param request the request, containing the values of the remote issue link to be updated */ private void updateRemoteIssueLinkPrivate(final RemoteIssueLink oldRemoteIssueLink, final RemoteIssueLinkCreateOrUpdateRequest request) { final RemoteIssueLink remoteIssueLink = buildRemoteIssueLink(oldRemoteIssueLink.getIssueId(), request, oldRemoteIssueLink.getId()); final ApplicationUser user = callingUser(); final RemoteIssueLinkService.UpdateValidationResult validationResult = remoteIssueLinkService.validateUpdate(user, remoteIssueLink); if (!validationResult.isValid()) { throw new RESTException(ErrorCollection.of(validationResult.getErrorCollection())); } final RemoteIssueLinkResult result = remoteIssueLinkService.update(user, validationResult); if (!result.isValid()) { throw new RESTException(ErrorCollection.of(validationResult.getErrorCollection())); } }