Пример #1
0
 public void doValidation(
     String key, Map<String, String> parameters, JiraServiceContext jiraServiceContext) {
   // JRA-13808: Need to check whether or not the user CF has a searcher set.
   String customFieldOption = parameters.get(getType());
   if (StringUtils.isEmpty(customFieldOption)) {
     String localisedMessage =
         jiraServiceContext
             .getI18nBean()
             .getText("admin.permissions.errors.please.select.user.customfield");
     jiraServiceContext.getErrorCollection().addErrorMessage(localisedMessage);
   } else {
     // passed in parameters names a Custom Field - lets investigate.
     CustomField customField = customFieldManager.getCustomFieldObject(customFieldOption);
     if (customField != null && customField.getCustomFieldSearcher() == null) {
       // In order to use a Custom Field it must be indexed in Lucene Index. Currently we only
       // index custom fields if they have a Searcher.
       // Message: "Custom field '{0}' is not indexed for searching - please add a searcher to this
       // Custom Field."
       String localisedMessage =
           jiraServiceContext
               .getI18nBean()
               .getText("admin.permissions.errors.customfieldnotindexed", customField.getName());
       jiraServiceContext.getErrorCollection().addErrorMessage(localisedMessage);
     }
   }
 }
 @EventListener
 public void issueEvent(IssueEvent issueEvent) {
   if (priorityCustomField == null) priorityCustomField = getSortingCustomField();
   if (priorityCustomField == null) return;
   Issue issue = issueEvent.getIssue();
   User initiator = issueEvent.getUser();
   // if priority not changed stringNewPriority is null
   if (issueEvent.getEventTypeId().equals(EventType.ISSUE_CREATED_ID)) {
     Object priorityObject = issue.getCustomFieldValue(priorityCustomField);
     if (priorityObject == null) return;
     Double priority = (Double) priorityObject;
     User assignee = issue.getAssignee();
     updatePriorities(initiator, assignee, issue, priority);
   } else {
     String stringNewPriority =
         getChangedField(issueEvent.getChangeLog(), priorityCustomField.getName(), false);
     String stringNewAssignee = getChangedField(issueEvent.getChangeLog(), "Assignee", false);
     if (stringNewAssignee != null || stringNewPriority != null) {
       Double priority = (Double) issue.getCustomFieldValue(priorityCustomField);
       if (priority == null) return;
       User assignee = issue.getAssignee();
       if (assignee == null) return;
       updatePriorities(initiator, assignee, issue, priority);
     }
   }
 }
 public Collection getCustomFieldObjectsByName(final String customFieldName) {
   Collection objectsByName = new ArrayList();
   for (Iterator iterator = customFields.iterator(); iterator.hasNext(); ) {
     CustomField customField = (CustomField) iterator.next();
     if (customField.getName().equals(customFieldName)) {
       objectsByName.add(customField);
     }
   }
   return objectsByName;
 }
  @Test
  public void testGetClauseFromParamsValuesGetFiltered() throws Exception {
    final String clauseName = "clauseName";

    final CustomField customField = mockController.getMock(CustomField.class);
    EasyMock.expect(customField.getName()).andStubReturn("ABC");
    EasyMock.expect(customFieldInputHelper.getUniqueClauseName(theUser, clauseName, "ABC"))
        .andStubReturn(clauseName);

    final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl();
    customFieldParams.addValue(CollectionBuilder.newBuilder("55", "-1", "").asMutableSet());

    final Set<String> expectedFilteredValues = CollectionBuilder.newBuilder("55").asMutableSet();

    final Clause expectedClause = mockController.getMock(Clause.class);

    final IndexedInputHelper indexedInputHelper = mockController.getMock(IndexedInputHelper.class);
    indexedInputHelper.getClauseForNavigatorValues(clauseName, expectedFilteredValues);
    mockController.setReturnValue(expectedClause);

    transformer =
        new VersionCustomFieldSearchInputTransformer(
            clauseName,
            new ClauseNames(clauseName),
            customField,
            indexInfoResolver,
            operandResolver,
            fieldFlagOperandRegistry,
            searchContextVisibilityChecker,
            versionResolver,
            customFieldInputHelper,
            versionManager) {
          @Override
          IndexedInputHelper getIndexedInputHelper() {
            return indexedInputHelper;
          }

          @Override
          boolean isVersionsNotRelatedToProjects(
              final Set<String> versionIdsFromHolder, final FieldValuesHolder fieldValuesHolder) {
            return false;
          }
        };

    mockController.replay();

    FieldValuesHolder holderValues =
        new FieldValuesHolderImpl(MapBuilder.singletonMap(urlParameterName, customFieldParams));
    assertEquals(
        expectedClause, transformer.getClauseFromParams(theUser, customFieldParams, holderValues));

    mockController.verify();
  }
  @Override
  protected void getVelocityParamsForView(
      Map<String, Object> velocityParams, AbstractDescriptor descriptor) {
    String lCf = getParam(descriptor, Consts.LATEST_START_FIELD);
    String cCf = getParam(descriptor, Consts.CALCULATED_FIELD);
    CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager();

    if (lCf != null && lCf.length() > 0) {
      velocityParams.put("nolCf", Boolean.FALSE);

      CustomField lCfObj = cfMgr.getCustomFieldObject(lCf);
      if (lCfObj != null) {
        velocityParams.put("nolCfObj", Boolean.FALSE);
        velocityParams.put("lCfName", lCfObj.getName());
      } else {
        velocityParams.put("nolCfObj", Boolean.TRUE);
      }
    } else {
      velocityParams.put("nolCf", Boolean.TRUE);
    }

    if (cCf != null && cCf.length() > 0) {
      velocityParams.put("nocCf", Boolean.FALSE);

      CustomField cCfObj = cfMgr.getCustomFieldObject(cCf);
      if (cCfObj != null) {
        velocityParams.put("nocCfObj", Boolean.FALSE);
        velocityParams.put("cCfName", cCfObj.getName());
      } else {
        velocityParams.put("nocCfObj", Boolean.TRUE);
      }
    } else {
      velocityParams.put("nocCf", Boolean.TRUE);
    }

    velocityParams.put(Consts.LATEST_START_FIELD, getParam(descriptor, Consts.LATEST_START_FIELD));
    velocityParams.put(Consts.CALCULATED_FIELD, getParam(descriptor, Consts.CALCULATED_FIELD));
  }
  /** Get custom fields by type. */
  private Map<String, String> getFieldsByType(String type) {
    Map<String, String> params = new TreeMap<String, String>();

    List<CustomField> fields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects();
    if (fields != null) {
      for (CustomField cf : fields) {
        if (cf.getCustomFieldType().getKey().equals(type)) {
          params.put(cf.getId(), cf.getName());
        }
      }
    }

    return params;
  }
 public boolean isFieldLocked() {
   CustomField customField = getCustomField();
   ManagedConfigurationItem managedConfigurationItem =
       managedConfigurationItemService.getManagedCustomField(customField);
   boolean locked =
       !managedConfigurationItemService.doesUserHavePermission(
           getLoggedInUser(), managedConfigurationItem);
   if (locked) {
     addErrorMessage(
         getText(
             "admin.managed.configuration.items.customfield.error.cannot.alter.context.locked",
             customField.getName()),
         Reason.FORBIDDEN);
   }
   return locked;
 }
Пример #8
0
 public String getArgumentDisplay(String argument) {
   CustomField field = fieldManager.getCustomField(argument);
   return field.getName();
 }
Пример #9
0
 @Override
 public String getArgumentDisplay(String argument) {
   CustomFieldManager fieldManager = ComponentAccessor.getCustomFieldManager();
   CustomField field = fieldManager.getCustomFieldObject(argument);
   return (field != null) ? field.getName() : argument;
 }