/** * 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; }
/** * 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(); }
@RequiresXsrfCheck protected String doExecute() throws Exception { if (confirm) { remoteIssueLinkService.delete(getLoggedInUser(), deleteValidationResult); eventPublisher.publish(new RemoteIssueLinkUIDeleteEvent(deleteValidationResult.getRemoteIssueLinkId())); boolean hasRemoteIssueLinks = remoteIssueLinkService.getRemoteIssueLinksForIssue(getLoggedInUser(), getIssueObject()).getRemoteIssueLinks().iterator().hasNext(); String targetID = hasRemoteIssueLinks ? "#linkingmodule" : ""; final String redirectUrl = "/browse/" + getIssueObject().getKey() + targetID; if (isInlineDialogMode()) { return returnCompleteWithInlineRedirect(redirectUrl); } return returnComplete(redirectUrl); } else { // No confirmation supplied - ask for one return INPUT; } }
public Response deleteRemoteIssueLinkByGlobalId(final Issue issue, final String globalId) { final ApplicationUser user = callingUser(); final DeleteByGlobalIdValidationResult validationResult = remoteIssueLinkService.validateDeleteByGlobalId(user, issue, globalId); if (!validationResult.isValid()) { throw new RESTException(ErrorCollection.of(validationResult.getErrorCollection())); } remoteIssueLinkService.deleteByGlobalId(user, validationResult); return Response.noContent().cacheControl(never()).build(); }
final RemoteIssueLinkService.RemoteIssueLinkListResult linksResult = remoteIssueLinkService.getRemoteIssueLinksForIssue(user, issue); if (!linksResult.isValid()) { throw new RemoteLinksNotFoundException(linksResult.getErrorCollection()); } finally { final RemoteIssueLinkService.DeleteValidationResult deleteValidationResult = remoteIssueLinkService.validateDelete(user, remoteIssueLink.getId()); if (deleteValidationResult.isValid()) { remoteIssueLinkService.delete(user, deleteValidationResult);
/** * 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(); }
deleteValidationResult = remoteIssueLinkService.validateDelete(getLoggedInUser(), remoteIssueLinkId); if (!deleteValidationResult.isValid()) RemoteIssueLinkService.RemoteIssueLinkResult remoteIssueLinkResult = remoteIssueLinkService.getRemoteIssueLink(getLoggedInUser(), remoteIssueLinkId); if (remoteIssueLinkResult.getErrorCollection().hasAnyErrors())
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()); } } }
final RemoteIssueLinkResult result = remoteIssueLinkService.getRemoteIssueLinkByGlobalId(user, issue, globalId); if (!result.isValid()) final RemoteIssueLinkListResult result = remoteIssueLinkService.getRemoteIssueLinksForIssue(user, issue); 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; }
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()); } }
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; }