コード例 #1
0
 public Object getValueFromLuceneField(String documentValue) {
   if (StringUtils.isBlank(documentValue)) {
     return null;
   } else {
     return projectManager.getProject(new Long(documentValue));
   }
 }
コード例 #2
0
  public MessageSet validateBackupProjectImportableSystemLevel(
      final JiraServiceContext jiraServiceContext,
      final BackupProject backupProject,
      final BackupSystemInformation backupSystemInformation) {
    validateJiraServiceContext(jiraServiceContext);
    // No need to check if backupProject has null members, we will never create backup project like
    // that.
    Null.not("backupSystemInformation", backupSystemInformation);

    final MessageSet messageSet = new MessageSetImpl();
    final I18nHelper i18n = jiraServiceContext.getI18nBean();

    // Need to provide a backupProject
    if (backupProject == null) {
      messageSet.addErrorMessage(getText(i18n, "admin.error.project.import.null.project"));
      jiraServiceContext
          .getErrorCollection()
          .addErrorMessage(getText(i18n, "admin.error.project.import.null.project"));
      return messageSet;
    }

    // The user must have the system administrator permission to perform a project import
    if (!userHasSysAdminPermission(jiraServiceContext.getUser())) {
      messageSet.addErrorMessage(getText(i18n, "admin.errors.project.import.must.be.admin"));
    } else {
      // Verify that if the backup projects custom field plugins exist that they are of the right
      // version in this JIRA instance
      // NOTE: warnings, such as the plugin not existing or the custom field being not importable or
      // out of context
      // are not checked here, that is handled by the next phase of the import.
      validateCustomFieldPluginVersions(
          backupProject, backupSystemInformation.getPluginVersions(), messageSet, i18n);

      final String projectKey = backupProject.getProject().getKey();
      final Project existingProject = projectManager.getProjectObjByKey(projectKey);
      if (existingProject == null) {
        // It does not really make sense to warn that we will create a project for them if there are
        // already errors.
        if (!messageSet.hasAnyErrors()) {
          messageSet.addWarningMessage(
              getText(i18n, "admin.warning.project.import.no.existing.project", projectKey));
        }
      } else {
        // We need to make sure that the project does not contain issues, versions, components,
        // etc...
        validateExistingProjectHasValidStateForImport(
            backupProject, backupSystemInformation, existingProject, i18n, messageSet);
      }
    }

    // Copy the errors into the service context error collection
    jiraServiceContext.getErrorCollection().addErrorMessages(messageSet.getErrorMessages());
    return messageSet;
  }
  public void testGetProjectIdsWithUnknownCategory() {
    expect(ctx.getLoggedInUser()).andReturn(mockUser);
    expect(proj.getProjectObjectsFromProjectCategory(555L))
        .andReturn(Collections.<Project>emptyList());
    EasyMock.replay(ctx, prms, proj);

    ProjectsAndCategoriesHelper helper = new DefaultProjectsAndCategoriesHelper(proj, prms, ctx);

    Set<Long> ids = helper.getProjectIds("cat555");
    assertEquals(0, ids.size());
  }
  public Map<String, String> getAllProjects() {
    Map<String, String> allProjs = new TreeMap<String, String>();

    List<Project> projs = prMgr.getProjectObjects();
    if (projs != null) {
      for (Project proj : projs) {
        allProjs.put(proj.getId().toString(), getProjView(proj.getName(), proj.getDescription()));
      }
    }

    return allProjs;
  }
  public void testGetProjectIds() {
    expect(ctx.getLoggedInUser()).andReturn(mockUser);
    Project project = createNiceMock(Project.class);
    expect(project.getId()).andReturn(666L);
    Project project2 = createNiceMock(Project.class);
    expect(project2.getId()).andReturn(323L);
    expect(proj.getProjectObj(666L)).andReturn(project);
    expect(proj.getProjectObj(323L)).andReturn(project2);
    expect(prms.hasPermission(Permissions.BROWSE, project, mockUser)).andReturn(true);
    expect(prms.hasPermission(Permissions.BROWSE, project2, mockUser)).andReturn(true);

    expect(proj.getProjectObjectsFromProjectCategory(555L)).andReturn(Arrays.asList(project2));

    EasyMock.replay(ctx, prms, proj, project, project2);

    ProjectsAndCategoriesHelper helper = new DefaultProjectsAndCategoriesHelper(proj, prms, ctx);

    Set<Long> ids = helper.getProjectIds("666|cat555");
    assertNotNull(ids);
    assertEquals(1, ids.size());
  }
  public void testValidateNullProject() {
    Project project = createNiceMock(Project.class);
    expect(ctx.getLoggedInUser()).andReturn(mockUser);
    expect(proj.getProjectObj(666L)).andReturn(project);
    EasyMock.replay(ctx, prms, proj);

    ProjectsAndCategoriesHelper helper = new DefaultProjectsAndCategoriesHelper(proj, prms, ctx);

    List<ValidationError> errors = new ArrayList<ValidationError>();
    helper.validate(null, errors, "somefield");
    assertErrors(errors, "gadget.common.projects.and.categories.none.selected");
  }
  public void testValidate() {
    Project project = createNiceMock(Project.class);
    expect(ctx.getLoggedInUser()).andReturn(mockUser);
    expect(proj.getProjectObj(666L)).andReturn(project);
    EasyMock.replay(ctx, prms, proj);

    ProjectsAndCategoriesHelper helper = new DefaultProjectsAndCategoriesHelper(proj, prms, ctx);

    List<ValidationError> errors = new ArrayList<ValidationError>();
    helper.validate("666", errors, "somefield");
    assertEquals(0, errors.size());
  }
コード例 #8
0
  public Collection getAllProjects() throws Exception {
    Collection availableProjects = Collections.EMPTY_LIST;

    final Collection projects = projectManager.getProjects();

    if (projects != null) {
      availableProjects = new ArrayList(projects);
      availableProjects =
          CollectionUtils.subtract(availableProjects, getCustomField().getAssociatedProjects());
      final FieldConfigScheme fieldConfigScheme = getFieldConfigScheme();
      if (fieldConfigScheme != null) {
        final List currentlySlectedProjects = fieldConfigScheme.getAssociatedProjects();
        if (currentlySlectedProjects != null) {
          availableProjects.addAll(currentlySlectedProjects);
        }
      }
    }

    return availableProjects;
  }
コード例 #9
0
 public Collection getAllProjectCategories() throws Exception {
   return projectManager.getProjectCategories();
 }