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; }
throw new RESTException(ErrorCollection.of(result.getErrorCollection()));
if (!result.isValid()) throw new RESTException(ErrorCollection.of(result.getErrorCollection()));
if (remoteIssueLinkResult.getErrorCollection().hasAnyErrors()) addErrorMessages(remoteIssueLinkResult.getErrorCollection().getErrorMessages());
/** * 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; }
@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()); } } }