@Override public void updateRemoteIssueLink(RemoteIssueLink remoteIssueLink) { remoteIssueLinks.put(remoteIssueLink.getId(), remoteIssueLink); }
public AbstractRemoteIssueLinkEvent(RemoteIssueLink remoteIssueLink) { this.remoteIssueLinkId = remoteIssueLink.getId(); this.globalId = remoteIssueLink.getGlobalId(); }
static URI createSelfLink(final RemoteIssueLink remoteIssueLink, final Issue issue, final ContextUriInfo contextUriInfo) { return contextUriInfo.getBaseUriBuilder() .path(IssueResource.class) .path(issue.getKey()) .path("remotelink") .path(remoteIssueLink.getId().toString()) .build(); } }
private void createChangeItemForUpdate(final RemoteIssueLink oldLink, final RemoteIssueLink newLink, final Issue issue, final ApplicationUser remoteUser) { final ChangeItemBean changeItemBean = new ChangeItemBean( ChangeItemBean.STATIC_FIELD, "RemoteIssueLink", oldLink.getId().toString(), getChangeItemDescription(oldLink, remoteUser), newLink.getId().toString(), getChangeItemDescription(newLink, remoteUser)); createChangeItem(changeItemBean, issue, remoteUser); }
private void createChangeItemForRemove(final RemoteIssueLink remoteIssueLink, final Issue issue, final ApplicationUser remoteUser) { final ChangeItemBean changeItemBean = new ChangeItemBean( ChangeItemBean.STATIC_FIELD, "RemoteIssueLink", remoteIssueLink.getId().toString(), getChangeItemDescription(remoteIssueLink, remoteUser), null, null); createChangeItem(changeItemBean, issue, remoteUser); }
private RemoteIssueLinkCreateOrUpdateResponse newCreateOrUpdateResponse(final RemoteIssueLink remoteIssueLink, final URI self) { return new RemoteIssueLinkCreateOrUpdateResponse() .id(remoteIssueLink.getId()) .self(self.toString()); }
private void createChangeItemForCreate(final RemoteIssueLink remoteIssueLink, final Issue issue, final ApplicationUser remoteUser) { final ChangeItemBean changeItemBean = new ChangeItemBean( ChangeItemBean.STATIC_FIELD, "RemoteIssueLink", null, null, remoteIssueLink.getId().toString(), getChangeItemDescription(remoteIssueLink, remoteUser)); createChangeItem(changeItemBean, issue, remoteUser); }
@Override public RemoteIssueLink createRemoteIssueLink(RemoteIssueLink remoteIssueLink) { final RemoteIssueLink linkToStore = createBuilder(remoteIssueLink).id(getNextId()).build(); remoteIssueLinks.put(linkToStore.getId(), linkToStore); return linkToStore; }
private void removeRemoteIssueLink(RemoteIssueLink remoteIssueLink, ApplicationUser user) { remoteIssueLinkStore.removeRemoteIssueLink(remoteIssueLink.getId()); final Issue issue = issueManager.getIssueObject(remoteIssueLink.getIssueId()); createChangeItemForRemove(remoteIssueLink, issue, user); eventPublisher.publish(new RemoteIssueLinkDeleteEvent(remoteIssueLink)); }
/** * Deletes a remote issue link. * * @param issue the issue * @param idString the id of the remote issue link * @return a Response with no content, or the error details if something went wrong */ public Response deleteRemoteIssueLinkById(final Issue issue, final String idString) { // Get the remote issue link to validate that it exists and belongs to the given issue final RemoteIssueLink remoteIssueLink = getRemoteIssueLinkPrivate(issue, idString); final ApplicationUser user = callingUser(); final DeleteValidationResult validationResult = remoteIssueLinkService.validateDelete(user, remoteIssueLink.getId()); if (!validationResult.isValid()) { throw new RESTException(ErrorCollection.of(validationResult.getErrorCollection())); } remoteIssueLinkService.delete(user, validationResult); return Response.noContent().cacheControl(never()).build(); }
/** * Mandatory fields are: * - id (the remote issue link must exist) * - issueId * - title * - url * * @param remoteIssueLink * @throws UpdateException */ private void validateMandatoryFieldsForUpdate(final RemoteIssueLink remoteIssueLink) throws UpdateException { if (remoteIssueLink.getId() == null) { throw new UpdateException(missingMandatoryFieldMessage("id")); } final Result result = validateMandatoryFields(remoteIssueLink); if (!result.isValid()) { throw new UpdateException(result.getMessage()); } }
private void removeIssueLinks(ApplicationUser user, Issue issue) { // test if the issue is a sub-task // NOTE: This has to be done BEFORE removing the issue link as the sub-task issue link is // used to determine if the issue is a sub-task if (issue.isSubTask()) { // Get the parent issue before removing the links, as we need the link to determine the parent issue Issue parentIssue = issue.getParentObject(); // Remove the links issueLinkManager.removeIssueLinksNoChangeItems(issue); // We need to reorder the parent's links as the its sub-task link for this issue has been removed subTaskManager.resetSequences(parentIssue); } else { // If there are no sub-tasks so all we need to do is delete the issue's links issueLinkManager.removeIssueLinksNoChangeItems(issue); } for (RemoteIssueLink remoteIssueLink : remoteIssueLinkManager.getRemoteIssueLinksForIssue(issue)) { remoteIssueLinkManager.removeRemoteIssueLink(remoteIssueLink.getId(), user); } }
@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."); } // Make sure remote issue link exists 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)); }
} finally { final RemoteIssueLinkService.DeleteValidationResult deleteValidationResult = remoteIssueLinkService.validateDelete(user, remoteIssueLink.getId()); if (deleteValidationResult.isValid()) { remoteIssueLinkService.delete(user, deleteValidationResult);
/** * 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())); } }
public RemoteIssueLinkBean build() { final URI self = createSelfLink(remoteIssueLink); return new RemoteIssueLinkBean( remoteIssueLink.getId(), self, remoteIssueLink.getGlobalId(), remoteIssueLink.getApplicationType(), remoteIssueLink.getApplicationName(), remoteIssueLink.getRelationship(), remoteIssueLink.getUrl(), remoteIssueLink.getTitle(), remoteIssueLink.getSummary(), remoteIssueLink.getIconUrl(), remoteIssueLink.getIconTitle(), remoteIssueLink.isResolved(), remoteIssueLink.getStatusIconUrl(), remoteIssueLink.getStatusIconTitle(), remoteIssueLink.getStatusIconLink() ); }
@Override public RemoteIssueLink createRemoteIssueLink(final RemoteIssueLink remoteIssueLink, final ApplicationUser user) throws CreateException { validateMandatoryFieldsForCreate(remoteIssueLink); validateFieldLengthsForCreate(remoteIssueLink); validateUrlsForCreate(remoteIssueLink); final Issue issue = issueManager.getIssueObject(remoteIssueLink.getIssueId()); if (issue == null) { throw new CreateException("Issue with id '" + remoteIssueLink.getIssueId() + "' does not exist."); } validateGlobalIdForCreate(issue, remoteIssueLink.getGlobalId()); final RemoteIssueLink created = remoteIssueLinkStore.createRemoteIssueLink(remoteIssueLink); if (hasDuplicateGlobalId(issue, created)) { remoteIssueLinkStore.removeRemoteIssueLink(created.getId()); throw new CreateException("A remote issue link already exists on this issue with the globalId '" + created.getGlobalId() + "'"); } createChangeItemForCreate(created, issue, user); eventPublisher.publish(new RemoteIssueLinkCreateEvent(remoteIssueLink)); return created; }
@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); }
public RemoteIssueLinkBuilder(final RemoteIssueLink remoteIssueLink) { id(remoteIssueLink.getId()); issueId(remoteIssueLink.getIssueId()); globalId(remoteIssueLink.getGlobalId()); title(remoteIssueLink.getTitle()); summary(remoteIssueLink.getSummary()); url(remoteIssueLink.getUrl()); iconUrl(remoteIssueLink.getIconUrl()); iconTitle(remoteIssueLink.getIconTitle()); relationship(remoteIssueLink.getRelationship()); resolved(remoteIssueLink.isResolved()); statusName(remoteIssueLink.getStatusName()); statusDescription(remoteIssueLink.getStatusDescription()); statusIconUrl(remoteIssueLink.getStatusIconUrl()); statusIconTitle(remoteIssueLink.getStatusIconTitle()); statusIconLink(remoteIssueLink.getStatusIconLink()); statusCategoryKey(remoteIssueLink.getStatusCategoryKey()); statusCategoryColorName(remoteIssueLink.getStatusCategoryColorName()); applicationType(remoteIssueLink.getApplicationType()); applicationName(remoteIssueLink.getApplicationName()); }
@Override public FieldMap fieldMapFrom(final RemoteIssueLink value) { return new FieldMap("id", value.getId()) .add("issueid", value.getIssueId()) .add("globalid", value.getGlobalId()) .add("title", value.getTitle()) .add("summary", value.getSummary()) .add("url", value.getUrl()) .add("iconurl", value.getIconUrl()) .add("icontitle", value.getIconTitle()) .add("relationship", value.getRelationship()) .add("resolved", booleanToString(value.isResolved())) .add("statusname", value.getStatusName()) .add("statusdescription", value.getStatusDescription()) .add("statusiconurl", value.getStatusIconUrl()) .add("statusicontitle", value.getStatusIconTitle()) .add("statusiconlink", value.getStatusIconLink()) .add("statuscategorykey", value.getStatusCategoryKey()) .add("statuscategorycolorname", value.getStatusCategoryColorName()) .add("applicationtype", value.getApplicationType()) .add("applicationname", value.getApplicationName()); }