@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); }
private void validatePermissionToCreate(final ApplicationUser user, final Issue issue, final ErrorCollection errors, final I18nHelper i18n) { hasLinkIssuePermission(user, issue, errors, i18n); }
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 DeleteByGlobalIdValidationResult validateDeleteByGlobalId(final ApplicationUser user, final Issue issue, final String globalId) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); RemoteIssueLink remoteIssueLink = null; if (!errors.hasAnyErrors()) { remoteIssueLink = validateExistsByGlobalId(issue, globalId, i18n, errors); } if (!errors.hasAnyErrors()) { validatePermissionToDelete(user, remoteIssueLink, errors, i18n); } return new DeleteByGlobalIdValidationResult(issue, globalId, errors); }
@Override public UpdateValidationResult validateUpdate(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()) { validatePermissionToUpdate(user, issue, errors, i18n); } RemoteIssueLink found = null; if (!errors.hasAnyErrors()) { found = validateExists(remoteIssueLink.getId(), i18n, errors); } if (!errors.hasAnyErrors()) { validateMandatoryFields(remoteIssueLink, i18n, errors); validateFieldLengths(remoteIssueLink, i18n, errors); validateUrls(remoteIssueLink, i18n, errors); validateGlobalIdForUpdate(issue, found, remoteIssueLink, errors, i18n); } return new UpdateValidationResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
@Override public DeleteValidationResult validateDelete(final ApplicationUser user, final Long remoteIssueLinkId) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); RemoteIssueLink remoteIssueLink = null; if (!errors.hasAnyErrors()) { remoteIssueLink = validateExists(remoteIssueLinkId, i18n, errors); } if (!errors.hasAnyErrors()) { validatePermissionToDelete(user, remoteIssueLink, errors, i18n); } return new DeleteValidationResult((errors.hasAnyErrors() ? null : remoteIssueLinkId), errors); }
@Override public RemoteIssueLinkListResult getRemoteIssueLinksForIssue(final ApplicationUser user, final Issue issue) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); if (!errors.hasAnyErrors()) { validatePermissionToView(user, issue, errors, i18n); } List<RemoteIssueLink> remoteIssueLinks = null; if (!errors.hasAnyErrors()) { remoteIssueLinks = remoteIssueLinkManager.getRemoteIssueLinksForIssue(issue); } return new RemoteIssueLinkListResult((errors.hasAnyErrors() ? null : remoteIssueLinks), errors); }
@Override public RemoteIssueLinkResult update(final ApplicationUser user, final UpdateValidationResult updateValidationResult) { if (updateValidationResult == null) { throw new IllegalArgumentException("You cannot update a remote issue link with a null validation result."); } if (!updateValidationResult.isValid()) { throw new IllegalStateException("You cannot update a remote issue link with an invalid validation result."); } final RemoteIssueLink remoteIssueLink = updateValidationResult.getRemoteIssueLink(); if (remoteIssueLink == null) { throw new IllegalArgumentException("You cannot update a null remote issue link."); } final ErrorCollection errors = new SimpleErrorCollection(); RemoteIssueLink updatedRemoteIssueLink = null; try { remoteIssueLinkManager.updateRemoteIssueLink(remoteIssueLink, user); updatedRemoteIssueLink = remoteIssueLink; } catch (final UpdateException e) { handleUpdateException(getI18n(user), errors, e); } return new RemoteIssueLinkResult(updatedRemoteIssueLink, errors); }
@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); }
final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors);
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); } }
private void validateUrls(final RemoteIssueLink remoteIssueLink, final I18nHelper i18n, final ErrorCollection errors) { if (!isValidUrl(remoteIssueLink.getUrl())) { errors.addError("url", i18n.getText("remotelink.service.invalid.uri", i18n.getText("remotelink.service.url")), Reason.VALIDATION_FAILED); } if (!isValidUrl(remoteIssueLink.getIconUrl())) { errors.addError("iconUrl", i18n.getText("remotelink.service.invalid.uri", "iconUrl"), Reason.VALIDATION_FAILED); } if (!isValidUrl(remoteIssueLink.getStatusIconUrl())) { errors.addError("statusIconUrl", i18n.getText("remotelink.service.invalid.uri", "statusIconUrl"), Reason.VALIDATION_FAILED); } if (!isValidUrl(remoteIssueLink.getStatusIconLink())) { errors.addError("statusIconLink", i18n.getText("remotelink.service.invalid.uri", "statusIconLink"), Reason.VALIDATION_FAILED); } }
@Override public RemoteIssueLinkResult getRemoteIssueLink(final ApplicationUser user, final Long remoteIssueLinkId) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); RemoteIssueLink remoteIssueLink = null; if (!errors.hasAnyErrors()) { remoteIssueLink = remoteIssueLinkManager.getRemoteIssueLink(remoteIssueLinkId); if (remoteIssueLink == null) { errors.addErrorMessage(i18n.getText("remotelink.service.does.not.exist"), Reason.NOT_FOUND); } } if (!errors.hasAnyErrors()) { validatePermissionToView(user, remoteIssueLink, errors, i18n); } return new RemoteIssueLinkResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
@Override public RemoteIssueLinkResult getRemoteIssueLinkByGlobalId(final ApplicationUser user, final Issue issue, final String globalId) { final ErrorCollection errors = new SimpleErrorCollection(); final I18nHelper i18n = getI18n(user); validateLinkingEnabled(i18n, errors); if (!errors.hasAnyErrors()) { validatePermissionToView(user, issue, errors, i18n); } RemoteIssueLink remoteIssueLink = null; if (!errors.hasAnyErrors()) { remoteIssueLink = remoteIssueLinkManager.getRemoteIssueLinkByGlobalId(issue, globalId); if (remoteIssueLink == null) { errors.addErrorMessage(i18n.getText("remotelink.service.does.not.exist"), Reason.NOT_FOUND); } } return new RemoteIssueLinkResult((errors.hasAnyErrors() ? null : remoteIssueLink), errors); }
private void validatePermissionToUpdate(final ApplicationUser user, final Issue issue, final ErrorCollection errors, final I18nHelper i18n) { hasLinkIssuePermission(user, issue, errors, i18n); }
private void validatePermissionToDelete(final ApplicationUser user, final RemoteIssueLink remoteIssueLink, final ErrorCollection errors, final I18nHelper i18n) { final IssueService.IssueResult result = issueService.getIssue(user, remoteIssueLink.getIssueId()); if (result.isValid()) { final Issue issue = result.getIssue(); hasLinkIssuePermission(user, issue, errors, i18n); } }