@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); }
public void createLinkToRemoteIssue(final Issue localIssue, final ApplicationLink applicationLink, final String remoteIssueKey, final Long remoteIssueId, final String relationship) { final String globalId = encodeGlobalId(applicationLink.getId(), remoteIssueId); final String url = buildIssueUrl(applicationLink.getDisplayUrl().toASCIIString(), remoteIssueKey); final RemoteIssueLink remoteIssueLink = new RemoteIssueLinkBuilder() .globalId(globalId) .applicationType(RemoteIssueLink.APPLICATION_TYPE_JIRA) .relationship(relationship) .url(url) .applicationName(applicationLink.getName()) .issueId(localIssue.getId()) .title(remoteIssueKey) .build(); final ApplicationUser user = callingUser(); final RemoteIssueLinkService.CreateValidationResult issueLinkValidationResult = remoteIssueLinkService.validateCreate(user, remoteIssueLink); if (issueLinkValidationResult.isValid()) { final RemoteIssueLinkService.RemoteIssueLinkResult remoteIssueLinkResult = remoteIssueLinkService.create(user, issueLinkValidationResult); } else { log.error("Failed to create issue link to remote JIRA issue with key '" + remoteIssueKey + "' Error(s): " + issueLinkValidationResult.getErrorCollection()); } }
protected void doValidation() { super.doValidation(); validateUrl(pageUrl); if (hasAnyErrors()) { return; } pageUrl = ConfluencePageUrl.build(pageUrl, appLink).getUrlRebasedToRpcUrl(); String pageId = getPageId(pageUrl, appLink); if (!hasAnyErrors()) { if (pageId == null) { addErrorMessage(getText("addconfluencelink.error.pageid.notfound")); } } if (!hasAnyErrors()) { RemoteIssueLink remoteIssueLink = new ConfluenceRemoteIssueLinkBuilder().build(appLink, pageId, getIssue().getLong("id")); validationResult = remoteIssueLinkService.validateCreate(getLoggedInUser(), remoteIssueLink); if (!validationResult.isValid()) { mapErrors(validationResult.getErrorCollection()); addErrorCollection(validationResult.getErrorCollection()); } } }
@Override public CreateValidationResult validateCreate(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()) { validatePermissionToCreate(user, issue, errors, i18n); } if (!errors.hasAnyErrors()) { validateMandatoryFields(remoteIssueLink, i18n, errors); validateFieldLengths(remoteIssueLink, i18n, errors); validateUrls(remoteIssueLink, i18n, errors); validateGlobalId(remoteIssueLink, issue, errors, i18n); } return new CreateValidationResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
/** * 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(); }
private CreateValidationResult validateCreateRemote(final RemoteJiraIssue remoteJiraIssue) { final String globalId = RemoteJiraGlobalIdFactoryImpl.encode(new RemoteJiraGlobalId(getJiraAppLink(), remoteJiraIssue.getId())); // Only store the bare minimum information, the rest will be shown using the renderer plugin final RemoteIssueLink remoteIssueLink = new RemoteIssueLinkBuilder() .url(remoteJiraIssue.getBrowseUrl()) .title(remoteJiraIssue.getKey()) .globalId(globalId) .issueId(id) .relationship(linkDesc) .applicationName(getJiraAppLink().getName()) .applicationType(RemoteIssueLink.APPLICATION_TYPE_JIRA) .build(); final CreateValidationResult validationResult = remoteIssueLinkService.validateCreate(getLoggedInUser(), remoteIssueLink); if (!validationResult.isValid()) { mapErrors(validationResult.getErrorCollection()); addErrorCollection(validationResult.getErrorCollection()); } return validationResult; }