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; }
if (result.isValid())
/** * 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(); }
if (!result.isValid())
/** * 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; }
/** * 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())); } }
@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()); } } }