@Override public boolean apply(@Nullable final RemoteIssueLink ril) { return ril.getGlobalId() == null; } })));
@Override public boolean apply(@Nullable final RemoteIssueLink ril) { return globalId.equals(ril.getGlobalId()); } })));
private boolean hasDuplicateGlobalId(Issue issue, RemoteIssueLink link) { if (link.getGlobalId() == null) { return false; } final List<RemoteIssueLink> links = remoteIssueLinkStore.getRemoteIssueLinksByGlobalId(issue, link.getGlobalId()); return links.size() > 1; }
public AbstractRemoteIssueLinkEvent(RemoteIssueLink remoteIssueLink) { this.remoteIssueLinkId = remoteIssueLink.getId(); this.globalId = remoteIssueLink.getGlobalId(); }
private void validateGlobalIdForUpdate(final Issue issue, final RemoteIssueLink found, final RemoteIssueLink remoteIssueLink, final ErrorCollection errors, final I18nHelper i18n) { // Validate only if it has changed if (!isEqual(found.getGlobalId(), remoteIssueLink.getGlobalId())) { validateGlobalId(remoteIssueLink, issue, errors, i18n); } }
@Override public List<RemoteIssueLink> getRemoteIssueLinksByGlobalId(Issue issue, String globalId) { final List<RemoteIssueLink> result = new ArrayList<RemoteIssueLink>(); for (final RemoteIssueLink remoteIssueLink : getRemoteIssueLinksForIssue(issue)) { if (globalId.equals(remoteIssueLink.getGlobalId())) { result.add(remoteIssueLink); } } return result; }
@Override public List<RemoteIssueLink> findRemoteIssueLinksByGlobalIds(final Collection<String> globalIds) { if (globalIds == null) { return ImmutableList.of(); } final List<RemoteIssueLink> result = Lists.newArrayListWithExpectedSize(globalIds.size()); final Set<String> globalIdSet = ImmutableSet.copyOf(globalIds); for (final RemoteIssueLink remoteIssueLink : remoteIssueLinks.values()) { if (globalIdSet.contains(remoteIssueLink.getGlobalId())) { result.add(remoteIssueLink); } } return result; }
private void validateGlobalId(final RemoteIssueLink remoteIssueLink, final Issue issue, final ErrorCollection errors, final I18nHelper i18n) { if (remoteIssueLink.getGlobalId() == null) { // No need to check for duplicates if it is null return; } // Check for duplicate globalId final RemoteIssueLink found = remoteIssueLinkManager.getRemoteIssueLinkByGlobalId(issue, remoteIssueLink.getGlobalId()); if (found != null) { errors.addError("globalId", i18n.getText("remotelink.service.globalid.duplicate", remoteIssueLink.getTitle()), Reason.VALIDATION_FAILED); } }
@Override public ConfluenceGlobalId create(final RemoteIssueLink link) { final Map<String, String> values = GlobalIdFactory.decode(link.getGlobalId(), KEYS); // Get application link final String appId = values.get(APP_ID_KEY); final ApplicationLink appLink = getApplicationLink(appId, link.getUrl()); if (appLink == null) { throw new IllegalArgumentException("No Application Link found for the given Application Id: " + appId + " or URL: " + link.getUrl()); } // Get issue id final String pageId = values.get(PAGE_ID_KEY); return new ConfluenceGlobalId(appLink, pageId); }
@Override public RemoteIssueLink decorate(final RemoteIssueLink remoteIssueLink) throws CredentialsRequiredException, IOException, PermissionException { if (!RemoteIssueLink.APPLICATION_TYPE_JIRA.equals(remoteIssueLink.getApplicationType())) { throw new IllegalArgumentException("Remote link is not to JIRA"); } final RemoteJiraGlobalId remoteJiraGlobalId = remoteJiraGlobalIdFactory.decode(remoteIssueLink.getGlobalId()); final ApplicationLink jiraAppLink = remoteJiraGlobalId.getApplicationLink(); final String remoteIssueID = String.valueOf(remoteJiraGlobalId.getRemoteIssueId()); try { final RemoteResponse<RemoteJiraIssue> response = remoteJiraRestService.getIssue(jiraAppLink, remoteIssueID, RemoteJiraRestService.RestVersion.VERSION_2); return handleJiraResponse(response, remoteIssueLink, jiraAppLink); } catch (final ResponseException exception) { throw new IOException("Failed to load JIRA issue from remote server", exception); } // TODO: Retrieval of non-AppLinked issues was here. See r163408. }
@Override public void updateRemoteIssueLink(final RemoteIssueLink remoteIssueLink, final ApplicationUser user) throws UpdateException { validateMandatoryFieldsForUpdate(remoteIssueLink); validateFieldLengthsForUpdate(remoteIssueLink); validateUrlsForUpdate(remoteIssueLink); final Issue issue = issueManager.getIssueObject(remoteIssueLink.getIssueId()); if (issue == null) { throw new UpdateException("Issue with id '" + remoteIssueLink.getIssueId() + "' does not exist."); } // Make sure remote issue link exists final RemoteIssueLink found = getRemoteIssueLink(remoteIssueLink.getId()); if (found == null) { throw new UpdateException("Remote link with id '" + remoteIssueLink.getId() + "' does not exist."); } else { validateGlobalIdForUpdate(issue, found.getGlobalId(), remoteIssueLink.getGlobalId()); } remoteIssueLinkStore.updateRemoteIssueLink(remoteIssueLink); if (found.getGlobalId() != null && !found.getGlobalId().equals(remoteIssueLink.getGlobalId()) && hasDuplicateGlobalId(issue, remoteIssueLink)) { remoteIssueLinkStore.updateRemoteIssueLink(found); throw new UpdateException("A remote issue link already exists on this issue with the globalId '" + remoteIssueLink.getGlobalId() + "'"); } createChangeItemForUpdate(found, remoteIssueLink, issue, user); eventPublisher.publish(new RemoteIssueLinkUpdateEvent(remoteIssueLink)); }
@Override public RemoteIssueLink createRemoteIssueLink(final RemoteIssueLink remoteIssueLink, final ApplicationUser user) throws CreateException { validateMandatoryFieldsForCreate(remoteIssueLink); validateFieldLengthsForCreate(remoteIssueLink); validateUrlsForCreate(remoteIssueLink); final Issue issue = issueManager.getIssueObject(remoteIssueLink.getIssueId()); if (issue == null) { throw new CreateException("Issue with id '" + remoteIssueLink.getIssueId() + "' does not exist."); } validateGlobalIdForCreate(issue, remoteIssueLink.getGlobalId()); final RemoteIssueLink created = remoteIssueLinkStore.createRemoteIssueLink(remoteIssueLink); if (hasDuplicateGlobalId(issue, created)) { remoteIssueLinkStore.removeRemoteIssueLink(created.getId()); throw new CreateException("A remote issue link already exists on this issue with the globalId '" + created.getGlobalId() + "'"); } createChangeItemForCreate(created, issue, user); eventPublisher.publish(new RemoteIssueLinkCreateEvent(remoteIssueLink)); return created; }
private void validateFieldLengths(RemoteIssueLink remoteIssueLink, I18nHelper i18n, ErrorCollection errors) { if (isLongerThan(remoteIssueLink.getGlobalId(), MAX_LONG_VARCHAR_LENGTH)) { errors.addError("globalId", i18n.getText("remotelink.service.field.too.long", i18n.getText("remotelink.service.globalid"), String.valueOf(MAX_LONG_VARCHAR_LENGTH)), Reason.VALIDATION_FAILED); } if (isLongerThan(remoteIssueLink.getTitle(), MAX_LONG_VARCHAR_LENGTH)) { errors.addError("title", i18n.getText("remotelink.service.field.too.long", i18n.getText("remotelink.service.title"), String.valueOf(MAX_LONG_VARCHAR_LENGTH)), Reason.VALIDATION_FAILED); } if (isLongerThan(remoteIssueLink.getRelationship(), MAX_LONG_VARCHAR_LENGTH)) { errors.addError("relationship", i18n.getText("remotelink.service.field.too.long", i18n.getText("remotelink.service.relationship"), String.valueOf(MAX_LONG_VARCHAR_LENGTH)), Reason.VALIDATION_FAILED); } if (isLongerThan(remoteIssueLink.getApplicationType(), MAX_LONG_VARCHAR_LENGTH)) { errors.addError("applicationType", i18n.getText("remotelink.service.field.too.long", i18n.getText("remotelink.service.applicationtype"), String.valueOf(MAX_LONG_VARCHAR_LENGTH)), Reason.VALIDATION_FAILED); } if (isLongerThan(remoteIssueLink.getApplicationName(), MAX_LONG_VARCHAR_LENGTH)) { errors.addError("applicationName", i18n.getText("remotelink.service.field.too.long", i18n.getText("remotelink.service.applicationname"), String.valueOf(MAX_LONG_VARCHAR_LENGTH)), Reason.VALIDATION_FAILED); } }
final Map<String, String> values = GlobalIdFactory.decode(remoteIssueLink.getGlobalId(), GLOBAL_ID_KEYS); if (internalHostApplication.getId().get().equals(values.get("appId"))) {
public RemoteIssueLinkBean build() { final URI self = createSelfLink(remoteIssueLink); return new RemoteIssueLinkBean( remoteIssueLink.getId(), self, remoteIssueLink.getGlobalId(), remoteIssueLink.getApplicationType(), remoteIssueLink.getApplicationName(), remoteIssueLink.getRelationship(), remoteIssueLink.getUrl(), remoteIssueLink.getTitle(), remoteIssueLink.getSummary(), remoteIssueLink.getIconUrl(), remoteIssueLink.getIconTitle(), remoteIssueLink.isResolved(), remoteIssueLink.getStatusIconUrl(), remoteIssueLink.getStatusIconTitle(), remoteIssueLink.getStatusIconLink() ); }
private Result validateFieldLengths(final RemoteIssueLink remoteIssueLink) { if (isLongerThan(remoteIssueLink.getGlobalId(), MAX_LONG_VARCHAR_LENGTH)) { return new Result(false, tooLongFieldMessage("globalId", MAX_LONG_VARCHAR_LENGTH)); } if (isLongerThan(remoteIssueLink.getTitle(), MAX_LONG_VARCHAR_LENGTH)) { return new Result(false, tooLongFieldMessage("title", MAX_LONG_VARCHAR_LENGTH)); } if (isLongerThan(remoteIssueLink.getRelationship(), MAX_LONG_VARCHAR_LENGTH)) { return new Result(false, tooLongFieldMessage("relationship", MAX_LONG_VARCHAR_LENGTH)); } if (isLongerThan(remoteIssueLink.getApplicationType(), MAX_LONG_VARCHAR_LENGTH)) { return new Result(false, tooLongFieldMessage("applicationType", MAX_LONG_VARCHAR_LENGTH)); } if (isLongerThan(remoteIssueLink.getApplicationName(), MAX_LONG_VARCHAR_LENGTH)) { return new Result(false, tooLongFieldMessage("applicationName", MAX_LONG_VARCHAR_LENGTH)); } return TRUE; }
json.put("globalId", remoteIssueLink.getGlobalId());
@Override public FieldMap fieldMapFrom(final RemoteIssueLink value) { return new FieldMap("id", value.getId()) .add("issueid", value.getIssueId()) .add("globalid", value.getGlobalId()) .add("title", value.getTitle()) .add("summary", value.getSummary()) .add("url", value.getUrl()) .add("iconurl", value.getIconUrl()) .add("icontitle", value.getIconTitle()) .add("relationship", value.getRelationship()) .add("resolved", booleanToString(value.isResolved())) .add("statusname", value.getStatusName()) .add("statusdescription", value.getStatusDescription()) .add("statusiconurl", value.getStatusIconUrl()) .add("statusicontitle", value.getStatusIconTitle()) .add("statusiconlink", value.getStatusIconLink()) .add("statuscategorykey", value.getStatusCategoryKey()) .add("statuscategorycolorname", value.getStatusCategoryColorName()) .add("applicationtype", value.getApplicationType()) .add("applicationname", value.getApplicationName()); }
public RemoteIssueLinkBuilder(final RemoteIssueLink remoteIssueLink) { id(remoteIssueLink.getId()); issueId(remoteIssueLink.getIssueId()); globalId(remoteIssueLink.getGlobalId()); title(remoteIssueLink.getTitle()); summary(remoteIssueLink.getSummary()); url(remoteIssueLink.getUrl()); iconUrl(remoteIssueLink.getIconUrl()); iconTitle(remoteIssueLink.getIconTitle()); relationship(remoteIssueLink.getRelationship()); resolved(remoteIssueLink.isResolved()); statusName(remoteIssueLink.getStatusName()); statusDescription(remoteIssueLink.getStatusDescription()); statusIconUrl(remoteIssueLink.getStatusIconUrl()); statusIconTitle(remoteIssueLink.getStatusIconTitle()); statusIconLink(remoteIssueLink.getStatusIconLink()); statusCategoryKey(remoteIssueLink.getStatusCategoryKey()); statusCategoryColorName(remoteIssueLink.getStatusCategoryColorName()); applicationType(remoteIssueLink.getApplicationType()); applicationName(remoteIssueLink.getApplicationName()); }
remoteIssueLink.getId(), remoteIssueLink.getIssueId(), remoteIssueLink.getGlobalId(), remoteJiraIssue.getKey(), remoteJiraIssue.getSummary(),