예제 #1
0
  public void addProjectProxyUser(Project project, String proxyName, User modifier)
      throws ProjectManagerException {
    logger.info(
        "User "
            + modifier.getUserId()
            + " adding proxy user "
            + proxyName
            + " to project "
            + project.getName());
    project.addProxyUser(proxyName);

    projectLoader.postEvent(
        project,
        EventType.PROXY_USER,
        modifier.getUserId(),
        "Proxy user " + proxyName + " is added to project.");
    updateProjectSetting(project);
  }
예제 #2
0
  public Project createProject(String projectName, String description, User creator)
      throws ProjectManagerException {
    if (projectName == null || projectName.trim().isEmpty()) {
      throw new ProjectManagerException("Project name cannot be empty.");
    } else if (description == null || description.trim().isEmpty()) {
      throw new ProjectManagerException("Description cannot be empty.");
    } else if (creator == null) {
      throw new ProjectManagerException("Valid creator user must be set.");
    } else if (!projectName.matches("[a-zA-Z][a-zA-Z_0-9|-]*")) {
      throw new ProjectManagerException(
          "Project names must start with a letter, followed by any number of letters, digits, '-' or '_'.");
    }

    if (projectsByName.containsKey(projectName)) {
      throw new ProjectManagerException("Project already exists.");
    }

    logger.info("Trying to create " + projectName + " by user " + creator.getUserId());
    Project newProject = projectLoader.createNewProject(projectName, description, creator);
    projectsByName.put(newProject.getName(), newProject);
    projectsById.put(newProject.getId(), newProject);

    if (creatorDefaultPermissions) {
      // Add permission to project
      projectLoader.updatePermission(
          newProject, creator.getUserId(), new Permission(Permission.Type.ADMIN), false);

      // Add proxy user
      newProject.addProxyUser(creator.getUserId());
      try {
        updateProjectSetting(newProject);
      } catch (ProjectManagerException e) {
        e.printStackTrace();
        throw e;
      }
    }

    projectLoader.postEvent(newProject, EventType.CREATED, creator.getUserId(), null);

    return newProject;
  }