Пример #1
0
 /**
  * validate the field value
  *
  * @param operationContext OperationContext
  * @param errorCollectionToAddTo ErrorCollection
  * @param i18n I18nHelper
  * @param issue Issue
  * @param fieldScreenRenderLayoutItem FieldScreenRenderLayoutItem
  */
 public void validateParams(
     OperationContext operationContext,
     ErrorCollection errorCollectionToAddTo,
     I18nHelper i18n,
     Issue issue,
     FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem) {
   Map fieldValuesHolder = operationContext.getFieldValuesHolder();
   String summary = (String) getValueFromParams(fieldValuesHolder);
   if (summary == null) {
     errorCollectionToAddTo.addError(getId(), i18n.getText("createissue.error.specify.a.summary"));
     return;
   }
   // JRADEV-1867 User can create summary with "  "
   summary = summary.trim();
   if (!TextUtils.stringSet(summary)) {
     errorCollectionToAddTo.addError(getId(), i18n.getText("createissue.error.specify.a.summary"));
   }
   if (summary.contains("\n") || summary.contains("\r")) {
     errorCollectionToAddTo.addError(getId(), i18n.getText("createissue.invalidsummary.newlines"));
   }
   if (summary.length() > MAX_LEN) {
     errorCollectionToAddTo.addError(
         getId(), i18n.getText("createissue.error.summary.less.than", MAX_LEN.toString()));
   }
 }
  @Override
  public void validateFromParams(
      CustomFieldParams cfParams, ErrorCollection errorCollection, FieldConfig fieldConfig) {
    @SuppressWarnings("unchecked")
    final Collection<String> params = cfParams.getAllValues();
    CustomField cf = fieldConfig.getCustomField();
    JiraAuthenticationContext authCtx =
        ComponentManager.getInstance().getJiraAuthenticationContext();
    I18nHelper i18n = authCtx.getI18nHelper();
    UserProjectHistoryManager userProjectHistoryManager =
        ComponentManager.getComponentInstanceOfType(UserProjectHistoryManager.class);
    Project currentProject =
        userProjectHistoryManager.getCurrentProject(Permissions.BROWSE, authCtx.getLoggedInUser());

    boolean isAutocompleteView;
    if (cf.isAllProjects()) {
      isAutocompleteView =
          qfMgr.isAutocompleteView(cf.getIdAsLong(), Consts.PROJECT_ID_FOR_GLOBAL_CF);
    } else {
      isAutocompleteView = qfMgr.isAutocompleteView(cf.getIdAsLong(), currentProject.getId());
    }

    if (isAutocompleteView) {
      if ((params == null) || params.isEmpty()) {
        boolean addNull;
        if (cf.isAllProjects()) {
          addNull = qfMgr.getAddNull(cf.getIdAsLong(), Consts.PROJECT_ID_FOR_GLOBAL_CF);
        } else {
          addNull = qfMgr.getAddNull(cf.getIdAsLong(), currentProject.getId());
        }

        if (!addNull) {
          errorCollection.addError(
              fieldConfig.getFieldId(), i18n.getText("queryfields.error.isnotnull"));
        }
      } else {
        if (params.size() > 1) {
          errorCollection.addError(
              fieldConfig.getFieldId(), i18n.getText("queryfields.error.invalid.params"));
        } else {
          for (String param : params) {
            Issue issue = issueMgr.getIssueObject(param);
            if (issue == null) {
              errorCollection.addError(
                  fieldConfig.getFieldId(), i18n.getText("queryfields.error.notissue", param));
            }
          }
        }
      }
    }
  }
Пример #3
0
 private void validateRemoveComment(
     ErrorCollection errorCollectionToAddTo,
     Map<String, Object> commentParams,
     ApplicationUser user) {
   Object commentIdObj = commentParams.get(PARAM_COMMENT_ID);
   if (commentIdObj != null) {
     try {
       Long commentId = Long.valueOf((String) commentIdObj);
       commentService.hasPermissionToDelete(
           new JiraServiceContextImpl(user, errorCollectionToAddTo), commentId);
     } catch (NumberFormatException ex) {
       errorCollectionToAddTo.addError(
           IssueFieldConstants.COMMENT, "invalid comment id specified.");
     }
   } else {
     errorCollectionToAddTo.addError(IssueFieldConstants.COMMENT, "no comment id specified.");
   }
 }
Пример #4
0
 private void validateEditComment(
     ErrorCollection errorCollection,
     Issue issue,
     Map<String, Object> commentParams,
     String body,
     Visibility visibility,
     ApplicationUser user) {
   if (commentParams.get(PARAM_COMMENT_ID) != null) {
     try {
       commentService.isValidCommentBody(body, errorCollection);
       final Long commentIdAsLong = Long.valueOf((String) commentParams.get(PARAM_COMMENT_ID));
       commentService.hasPermissionToEdit(
           new JiraServiceContextImpl(user, errorCollection), commentIdAsLong);
       commentService.isValidCommentVisibility(user, issue, visibility, errorCollection);
       validateCommentProperties(commentParams, errorCollection);
     } catch (NumberFormatException ex) {
       errorCollection.addError(IssueFieldConstants.COMMENT, "invalid comment id specified.");
     }
   } else {
     errorCollection.addError(IssueFieldConstants.COMMENT, "no comment id specified.");
   }
 }
 public void addError(String name, String error) {
   errorCollection.addError(name, error);
 }
  public void validateGetBackupOverview(
      final JiraServiceContext jiraServiceContext,
      final ProjectImportOptions projectImportOptions) {
    Null.not("projectImportOptions", projectImportOptions);
    validateJiraServiceContext(jiraServiceContext);

    final ErrorCollection errorCollection = jiraServiceContext.getErrorCollection();
    final I18nHelper i18n = jiraServiceContext.getI18nBean();

    // The user must have the system administrator permission to perform a project import
    if (!userHasSysAdminPermission(jiraServiceContext.getUser())) {
      errorCollection.addErrorMessage(getText(i18n, "admin.errors.project.import.must.be.admin"));
      // Don't care to check any more validity
      return;
    }

    if (StringUtils.isEmpty(projectImportOptions.getPathToBackupXml())) {
      errorCollection.addError(
          "backupXmlPath", getText(i18n, "admin.errors.project.import.provide.backup.path"));
    } else if (!pathExists(projectImportOptions.getPathToBackupXml(), true)) {
      errorCollection.addError(
          "backupXmlPath", getText(i18n, "admin.errors.project.import.invalid.backup.path"));
    }

    // Check if the user has supplied an attachment path
    if (!StringUtils.isEmpty(projectImportOptions.getAttachmentPath())) {
      // Check that attachments are enabled for the current JIRA
      if (!attachmentManager.attachmentsEnabled()) {
        errorCollection.addError(
            "backupAttachmentPath",
            getText(i18n, "admin.errors.project.import.attachments.not.enabled"));
      }
      // Now check if the path exists
      else if (pathExists(projectImportOptions.getAttachmentPath(), false)) {
        // Path Exists, but it is not allowed to be the current system's Attachment Path.
        // Get the configured attachment path for this JIRA instance.
        final String attachmentPathString = attachmentPathManager.getAttachmentPath();
        // Create a File object with it.
        final File attachmentPathFile = new File(attachmentPathString);
        // Create a File object with the attachment path
        final File backupAttachmentPathFile = new File(projectImportOptions.getAttachmentPath());
        // Compare the canonical paths to see if the directories are the same.
        try {
          if (attachmentPathFile
              .getCanonicalPath()
              .equals(backupAttachmentPathFile.getCanonicalPath())) {
            errorCollection.addError(
                "backupAttachmentPath",
                getText(i18n, "admin.errors.project.import.attachment.backup.path.same.as.system"));
          }
        } catch (final IOException e) {
          // This would be rather strange, but see the javadoc for getCanonicalFile():
          // "If an I/O error occurs, which is possible because the construction of the canonical
          // pathname may require filesystem queries"
          errorCollection.addErrorMessage(
              getText(i18n, "admin.errors.project.import.attachment.ioexception", e.getMessage()));
        }
      } else {
        // Path doesn't exist
        errorCollection.addError(
            "backupAttachmentPath",
            getText(i18n, "admin.errors.project.import.invalid.attachment.backup.path"));
      }
    }
  }
 private void transferErrorMessages(
     ErrorCollection errorCollection, Collection<String> errorMessages) {
   for (String errMsg : errorMessages) {
     errorCollection.addError(getId(), errMsg);
   }
 }