if (result.isValid()) updateRemoteIssueLinkPrivate(result.getRemoteIssueLink(), request); final URI self = RemoteIssueLinkBeanBuilder.createSelfLink(result.getRemoteIssueLink(), issue, contextUriInfo); final RemoteIssueLinkCreateOrUpdateResponse response = newCreateOrUpdateResponse(result.getRemoteIssueLink(), self); return status(OK).entity(response).build(); throw new RESTException(ErrorCollection.of(result.getErrorCollection()));
@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); }
if (remoteIssueLinkResult.getErrorCollection().hasAnyErrors()) addErrorMessages(remoteIssueLinkResult.getErrorCollection().getErrorMessages()); remoteIssueLink = remoteIssueLinkResult.getRemoteIssueLink();
if (!result.isValid()) throw new RESTException(ErrorCollection.of(result.getErrorCollection())); entity = convertToBean(result.getRemoteIssueLink());
/** * Creates a remote issue link. * * @param issue the issue to create the link with * @param request the request, containing the values of the remote issue link to be created * @param contextUriInfo uri context, for building the self link * @return a Response containing a RemoteIssueLinkCreateOrUpdateResponse, or the error details if something went wrong */ private Response createRemoteIssueLink(final Issue issue, final RemoteIssueLinkCreateOrUpdateRequest request, final ContextUriInfo contextUriInfo) { final RemoteIssueLink remoteIssueLink = buildRemoteIssueLink(issue.getId(), request); final ApplicationUser user = callingUser(); final CreateValidationResult validationResult = remoteIssueLinkService.validateCreate(user, remoteIssueLink); if (!validationResult.isValid()) { throw new RESTException(ErrorCollection.of(validationResult.getErrorCollection())); } final RemoteIssueLinkResult result = remoteIssueLinkService.create(user, validationResult); if (!result.isValid()) { throw new RESTException(ErrorCollection.of(validationResult.getErrorCollection())); } final URI self = RemoteIssueLinkBeanBuilder.createSelfLink(result.getRemoteIssueLink(), issue, contextUriInfo); final RemoteIssueLinkCreateOrUpdateResponse response = newCreateOrUpdateResponse(result.getRemoteIssueLink(), self); return status(CREATED).location(self).entity(response).build(); }
/** * Gets the remote issue link with the given id, and performs some error checking. An exception will be thrown if the id * is invalid, the remote issue link does not exist, or the remote issue link does not belong to the given issue. * * @param issue the issue * @param idString the remote issue link id * @return a RemoteIssueLink */ private RemoteIssueLink getRemoteIssueLinkPrivate(final Issue issue, final String idString) { final Long remoteIssueLinkId = getRemoteIssueLinkId(idString); final RemoteIssueLinkResult result = remoteIssueLinkService.getRemoteIssueLink(callingUser(), remoteIssueLinkId); if (!result.isValid()) { throw new RESTException(ErrorCollection.of(result.getErrorCollection())); } // Check if remote issue link exists final RemoteIssueLink remoteIssueLink = result.getRemoteIssueLink(); if (remoteIssueLink == null) { throw new RESTException(Response.Status.NOT_FOUND, ErrorCollection.of(i18n.getText("rest.issue.remotelink.with.id.not.found", idString))); } // Check that the remote issue link belongs to this issue if (!issue.getId().equals(remoteIssueLink.getIssueId())) { throw new RESTException(Response.Status.BAD_REQUEST, ErrorCollection.of(i18n.getText("rest.issue.remotelink.not.for.issue", idString, issue.getKey()))); } return remoteIssueLink; }
@Override public RemoteIssueLinkResult create(final ApplicationUser user, final CreateValidationResult createValidationResult) { if (createValidationResult == null) { throw new IllegalArgumentException("You cannot create a remote issue link with a null validation result."); } if (!createValidationResult.isValid()) { throw new IllegalStateException("You cannot create a remote issue link with an invalid validation result."); } final RemoteIssueLink remoteIssueLink = createValidationResult.getRemoteIssueLink(); if (remoteIssueLink == null) { throw new IllegalArgumentException("You cannot create a null remote issue link."); } final ErrorCollection errors = new SimpleErrorCollection(); RemoteIssueLink createdRemoteIssueLink = null; try { createdRemoteIssueLink = remoteIssueLinkManager.createRemoteIssueLink(remoteIssueLink, user); } catch (final CreateException e) { handleCreateException(getI18n(user), errors, e); } return new RemoteIssueLinkResult(createdRemoteIssueLink, 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())); } }
@Override public RemoteIssueLinkResult getRemoteIssueLink(final ApplicationUser user, final Long remoteIssueLinkId) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); RemoteIssueLink remoteIssueLink = null; if (!errors.hasAnyErrors()) { remoteIssueLink = remoteIssueLinkManager.getRemoteIssueLink(remoteIssueLinkId); if (remoteIssueLink == null) { errors.addErrorMessage(i18n.getText("remotelink.service.does.not.exist"), Reason.NOT_FOUND); } } if (!errors.hasAnyErrors()) { validatePermissionToView(user, remoteIssueLink, errors, i18n); } return new RemoteIssueLinkResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
@Override public RemoteIssueLinkResult getRemoteIssueLinkByGlobalId(final ApplicationUser user, final Issue issue, final String globalId) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); if (!errors.hasAnyErrors()) { validatePermissionToView(user, issue, errors, i18n); } RemoteIssueLink remoteIssueLink = null; if (!errors.hasAnyErrors()) { remoteIssueLink = remoteIssueLinkManager.getRemoteIssueLinkByGlobalId(issue, globalId); if (remoteIssueLink == null) { errors.addErrorMessage(i18n.getText("remotelink.service.does.not.exist"), Reason.NOT_FOUND); } } return new RemoteIssueLinkResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
private boolean isValidForCreate(final RemoteIssueLinkResult result) { // The result is still valid if there is only a NOT_FOUND error, as the remote issue link not existing is not an error in this case if (!result.isValid()) { if (result.getErrorCollection().getReasons().contains(Reason.NOT_FOUND) && result.getErrorCollection().getReasons().size() == 1) { return true; } // Errors other than NOT_FOUND return false; } // No errors return true; }
/** * Creates the link and publishes an event for the creation * * @param validationResult the CreateValidationResult to be used to create the link * @return create result */ public RemoteIssueLinkService.RemoteIssueLinkResult createLink(final CreateValidationResult validationResult) { final RemoteIssueLinkService.RemoteIssueLinkResult result = remoteIssueLinkService.create(getLoggedInUser(), validationResult); final RemoteIssueLink link = result.getRemoteIssueLink(); eventPublisher.publish(new RemoteIssueLinkUICreateEvent(link)); return result; }
@RequiresXsrfCheck protected String doExecute() { final RemoteIssueLinkService.RemoteIssueLinkResult result = createLink(); if (!result.isValid()) { addErrorCollection(result.getErrorCollection()); return ERROR; } createComment(); return returnComplete(getRedirectUrl()); }
private void createRemoteLinks() { for (final CreateValidationResult validationResult : validationResults) { final RemoteIssueLinkResult result = createLink(validationResult); if (!result.isValid()) { mapErrors(result.getErrorCollection()); addErrorCollection(result.getErrorCollection()); } } }