コード例 #1
0
  /**
   * Executes the action.
   *
   * <p>Create the project based on the input parameters.
   *
   * <p>Validation: not present, already completely done by the annotations in the setters.
   *
   * <p>
   *
   * @throws IllegalStateException if the project service facade is not set.
   * @throws Exception if any other error occurs
   * @see ProjectServiceFacade#createProject(com.topcoder.security.TCSubject, ProjectData)
   */
  protected void executeAction() throws Exception {
    ProjectServiceFacade projectServiceFacade = getProjectServiceFacade();

    if (null == projectServiceFacade) {
      throw new IllegalStateException("The project service facade is not initialized");
    }

    // create the project data with the input parameters.
    ProjectData projectData = new ProjectData();
    projectData.setName(getProjectName());
    projectData.setDescription(getProjectDescription());

    // delegate to ProjectServiceFacade to create the project.
    projectData =
        projectServiceFacade.createProject(
            DirectStrutsActionsHelper.getTCSubjectFromSession(), projectData);

    setResult(projectData);
  }
コード例 #2
0
  /**
   * The main logic to create the new project and assign permissions to the new project.
   *
   * @throws Exception if there is any error.
   */
  @Override
  protected void executeAction() throws Exception {
    TCSubject currentUser = DirectStrutsActionsHelper.getTCSubjectFromSession();

    Map<String, String> result = new HashMap<String, String>();

    // create new project first
    ProjectServiceFacade projectServiceFacade = getProjectServiceFacade();

    if (null == projectServiceFacade) {
      throw new IllegalStateException("The project service facade is not initialized");
    }

    // create the project data with the input parameters.
    ProjectData projectData = new ProjectData();
    projectData.setName(getProjectName());
    projectData.setDescription(getProjectDescription());
    // prepare the project answer.
    for (ProjectAnswer answer : getProjectData().getProjectAnswers()) {
      if (answer.getOptionAnswers() != null) {
        for (ProjectAnswerOption answerOption : answer.getOptionAnswers()) {
          answerOption.setProjectAnswer(answer);
        }
      }
      // replace XWorkList by ArrayList.
      if (answer.getMultipleAnswers() != null) {
        List<String> s = new ArrayList<String>();
        for (String mAnswer : answer.getMultipleAnswers()) {
          s.add(mAnswer);
        }
        answer.setMultipleAnswers(s);
      }
    }
    projectData.setProjectAnswers(getProjectData().getProjectAnswers());

    // set project billing account id if exists
    if (getProjectData().getProjectBillingAccountId() > 0) {

      // check if user has access to the billing account
      if (!canAccessBillingAccount(getProjectData().getProjectBillingAccountId())) {
        throw new IllegalArgumentException(
            "You don't have permission to access the billing account you set");
      }
      projectData.setProjectBillingAccountId(getProjectData().getProjectBillingAccountId());
    }

    if (forums != null) {
      Map<String, String> forumsMap = new HashMap<String, String>();
      for (ProjectForumTemplateDTO forum : forums) {
        forumsMap.put(forum.getForumName(), forum.getForumDescription());
      }
      // delegate to ProjectServiceFacade to create the project.
      projectData =
          projectServiceFacade.createTCDirectProject(
              currentUser, projectData, getPermissions(), forumsMap);
    } else {
      // delegate to ProjectServiceFacade to create the project.
      projectData =
          projectServiceFacade.createTCDirectProject(currentUser, projectData, getPermissions());
    }

    if (getProjectData().getProjectBillingAccountId() > 0) {
      DirectUtils.updateDirectProjectBugContestFee(
          DirectUtils.getTCSubjectFromSession(),
          projectData.getProjectId(),
          getProjectServiceFacade(),
          getProjectContestFeeService(),
          getProjectContestFeePercentageService());
    }

    // put data into result
    result.put("projectName", projectData.getName());
    result.put("projectId", String.valueOf(projectData.getProjectId()));

    if (!isCreateCopilotPosting()) {
      // check whether has copilots to add
      if (getCopilotIds() != null && getCopilotIds().length > 0) {
        // add the copilot into the new project
        List<CopilotProject> copilotProjects = new ArrayList<CopilotProject>();
        List<Boolean> removeFlags = new ArrayList<Boolean>();

        for (long id : getCopilotIds()) {
          removeFlags.add(false);

          CopilotProject copilotProject = new CopilotProject();
          copilotProject.setTcDirectProjectId(projectData.getProjectId());
          copilotProject.setCopilotProfileId(id);
          copilotProject.setId(0);
          copilotProjects.add(copilotProject);
        }

        // update copilots projects
        getContestServiceFacade().updateCopilotProjects(currentUser, copilotProjects, removeFlags);
      }

      if (presentationProject) {
        // create the draft copilot contest
        createPPTCopilotDraftPosting(projectData);
        // create JIRA issue
        Map<String, Object> conetstResult = (Map<String, Object>) getResult();
        String description =
            "Copilot Opportunities: " + copilotURLPrefix + conetstResult.get("projectId");
        JiraRpcServiceWrapper.createIssue(
            pptJIRAProject, pptJIRAIssueTypeId, projectName, description, pptJIRAIssueReporter);
      }
    } else {
      createCopilotDraftPosting(projectData);
    }

    setResult(result);
  }