@Override
public void updateRemoteIssueLink(final RemoteIssueLink remoteIssueLink, final ApplicationUser user) throws UpdateException
{
validateMandatoryFieldsForUpdate(remoteIssueLink);
validateFieldLengthsForUpdate(remoteIssueLink);
validateUrlsForUpdate(remoteIssueLink);
final Issue issue = issueManager.getIssueObject(remoteIssueLink.getIssueId());
if (issue == null)
{
throw new UpdateException("Issue with id '" + remoteIssueLink.getIssueId() + "' does not exist.");
}
final RemoteIssueLink found = getRemoteIssueLink(remoteIssueLink.getId());
if (found == null)
{
throw new UpdateException("Remote link with id '" + remoteIssueLink.getId() + "' does not exist.");
}
else
{
validateGlobalIdForUpdate(issue, found.getGlobalId(), remoteIssueLink.getGlobalId());
}
remoteIssueLinkStore.updateRemoteIssueLink(remoteIssueLink);
if (found.getGlobalId() != null && !found.getGlobalId().equals(remoteIssueLink.getGlobalId()) && hasDuplicateGlobalId(issue, remoteIssueLink))
{
remoteIssueLinkStore.updateRemoteIssueLink(found);
throw new UpdateException("A remote issue link already exists on this issue with the globalId '" + remoteIssueLink.getGlobalId() + "'");
}
createChangeItemForUpdate(found, remoteIssueLink, issue, user);
eventPublisher.publish(new RemoteIssueLinkUpdateEvent(remoteIssueLink));
}