List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:org.cgiar.ccafs.ap.action.projects.ProjectBudgetByMOGAction.java
@Override public void prepare() throws Exception { projectID = Integer/*from w w w . jav a 2s .co m*/ .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); // Getting the project information project = projectManager.getProject(projectID); project.setOutputs(ipElementManager.getProjectOutputs(projectID)); // Remove the outputs duplicated Set<IPElement> outputsTemp = new HashSet<>(project.getOutputs()); project.getOutputs().clear(); project.getOutputs().addAll(outputsTemp); allYears = project.getAllYears(); if (!allYears.isEmpty()) { // Getting the year from the URL parameters. try { String parameter = this.getRequest().getParameter(APConstants.YEAR_REQUEST); year = (parameter != null) ? Integer.parseInt(StringUtils.trim(parameter)) : config.getPlanningCurrentYear(); } catch (NumberFormatException e) { LOG.warn("-- prepare() > There was an error parsing the year '{}'.", year); year = config.getPlanningCurrentYear(); } bilateralBudgetType = BudgetType.W3_BILATERAL.getValue(); ccafsBudgetType = BudgetType.W1_W2.getValue(); List<OutputBudget> budgets = new ArrayList<>(); budgets.addAll( budgetByMogManager.getProjectOutputsBudgetByTypeAndYear(projectID, ccafsBudgetType, year)); budgets.addAll( budgetByMogManager.getProjectOutputsBudgetByTypeAndYear(projectID, bilateralBudgetType, year)); project.setOutputsBudgets(budgets); ccafsBudgetByYear = budgetManager.calculateProjectBudgetByTypeAndYear(projectID, ccafsBudgetType, year); bilateralBudgetByYear = budgetManager.calculateProjectBudgetByTypeAndYear(projectID, bilateralBudgetType, year); ccafsGenderPercentage = budgetManager.calculateTotalGenderPercentageByYearAndType(projectID, year, ccafsBudgetType, project.isCoFundedProject() || project.isCoreProject()); bilateralGenderPercentage = budgetManager.calculateTotalGenderPercentageByYearAndType(projectID, year, bilateralBudgetType, project.isCoFundedProject() || project.isCoreProject()); if (!allYears.contains(new Integer(year))) { year = allYears.get(0); } } // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); // Getting the history for this section this.setHistory(historyManager.getProjectBudgetByMogHistory(projectID)); }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectBudgetsAction.java
@Override public void prepare() throws Exception { previousProject = new Project(); // Getting the project id from the URL parameter // It's assumed that the project parameter is ok. (@See ValidateProjectParameterInterceptor) projectID = Integer/* w w w. ja v a2 s . c o m*/ .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); // Getting the project identified with the id parameter. project = projectManager.getProject(projectID); // If project is CCAFS cofounded, we should load the core projects linked to it. if (!project.isBilateralProject()) { project.setLinkedProjects(linkedProjectManager.getLinkedBilateralProjects(projectID)); } else { project.setLinkedProjects(linkedProjectManager.getLinkedCoreProjects(projectID)); project.setOverhead(overheadManager.getProjectBudgetOverhead(projectID)); } if (project.getLinkedProjects() != null) { List<Project> linkedProjects = new ArrayList<>(); for (Project p : project.getLinkedProjects()) { linkedProjects.add(new Project(p.getId())); } previousProject.setLinkedProjects(linkedProjects); } if (this.isReportingCycle()) { year = config.getReportingCurrentYear(); } else { year = config.getPlanningCurrentYear(); } project.setProjectPartners(projectPartnerManager.getProjectPartners(project, year)); projectPPAPartners = new HashSet<Institution>(); // If the project is bilateral only ask budget for the lead institution if (project.isBilateralProject()) { if (project.getLeader() != null) { projectPPAPartners.add(project.getLeader().getInstitution()); } } else { for (ProjectPartner partner : project.getProjectPartners()) { if (partner.getInstitution().isPPA()) { projectPPAPartners.add(partner.getInstitution()); } } } totalCCAFSBudget = budgetManager.calculateTotalProjectBudgetByType(projectID, BudgetType.W1_W2.getValue()); totalBilateralBudget = budgetManager.calculateTotalProjectBudgetByType(projectID, BudgetType.W3_BILATERAL.getValue()); allYears = project.getAllYears(); invalidYear = allYears.isEmpty(); if (!allYears.isEmpty()) { // Getting the year from the URL parameters. try { String parameter = this.getRequest().getParameter(APConstants.YEAR_REQUEST); year = (parameter != null) ? Integer.parseInt(StringUtils.trim(parameter)) : config.getPlanningCurrentYear(); } catch (NumberFormatException e) { LOG.warn("-- prepare() > There was an error parsing the year '{}'.", year); // Set the current year as default year = config.getPlanningCurrentYear(); } totalCCAFSBudgetbyYear = budgetManager.calculateTotalProjectBudgetByTypeYear(projectID, BudgetType.W1_W2.getValue(), year); totalBilateralBudgetbyYear = budgetManager.calculateTotalProjectBudgetByTypeYear(projectID, BudgetType.W3_BILATERAL.getValue(), year); if (!allYears.contains(new Integer(year))) { year = config.getPlanningCurrentYear(); } if (project.getLeader() != null) { // Getting the list of budgets. project.setBudgets(budgetManager.getBudgetsByYear(project.getId(), year)); List<Budget> budgetsPrevious = new ArrayList<Budget>(); budgetsPrevious.addAll(project.getBudgets()); previousProject.setBudgets(budgetsPrevious); } else { hasLeader = false; } // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); // Getting the history for this section super.setHistory(historyManager.getProjectBudgetHistory(projectID)); } else { invalidYear = true; } for (Project contribution : project.getLinkedProjects()) { contribution.setAnualContribution(this.getCofinancingBudget(projectID, contribution.getId(), year)); } if (this.getRequest().getMethod().equalsIgnoreCase("post")) { // Clear out the list if it has some element if (project.getBudgets() != null) { project.getBudgets().clear(); } if (project.getLinkedProjects() != null) { project.getLinkedProjects().clear(); } } }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectCaseStudiesAction.java
@Override public void prepare() throws Exception { super.prepare(); projectID = Integer//from w w w . j a v a 2s . c o m .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); project = projectManager.getProject(projectID); // Getting all years from project allYears = project.getAllYears(); // Getting the Project lessons for this section. int evaluatingYear = 0; if (this.getCycleName().equals(APConstants.REPORTING_SECTION)) { evaluatingYear = this.getCurrentReportingYear(); } else { evaluatingYear = this.getCurrentPlanningYear(); } project.setCaseStudies(caseStudieManager.getCaseStudysByProject(projectID)); List<String> idsIndicators; Iterator<CaseStudieIndicators> iteratorIndicators; CaseStudieIndicators caseStudyIndicator; List<IPIndicator> indicators; for (CasesStudies caseStudy : project.getCaseStudies()) { idsIndicators = new ArrayList<>(); indicators = new ArrayList<>(); iteratorIndicators = caseStudy.getCaseStudieIndicatorses().iterator(); while (iteratorIndicators.hasNext()) { caseStudyIndicator = iteratorIndicators.next(); idsIndicators.add(String.valueOf(caseStudyIndicator.getIdIndicator())); indicators.add(ipIndicatorMamager.getIndicator(caseStudyIndicator.getIdIndicator())); } caseStudy.setCaseStudyIndicatorsIds(idsIndicators); caseStudy.setCaseStudyIndicators(indicators); } // Getting the Project lessons for this section. this.setProjectLessons(lessonManager.getProjectComponentLesson(projectID, this.getActionName(), evaluatingYear, this.getCycleName())); // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); List<IPIndicator> listIndicators = ipIndicatorMamager.getIndicatorsFlagShips(); caseStudyIndicators = new HashMap(); for (IPIndicator ipIndicator : listIndicators) { caseStudyIndicators.put(String.valueOf(ipIndicator.getId()), ipIndicator.getDescription()); } super.setHistory(historyManager.getProjectCaseStudyHistory(project.getId())); if (this.getRequest().getMethod().equalsIgnoreCase("post")) { // Clear out the list if it has some element if (project.getCaseStudies() != null) { project.getCaseStudies().clear(); } } // Getting the last history }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectCCAFSOutcomesAction.java
@Override public void prepare() throws Exception { super.prepare(); midOutcomes = new ArrayList<>(); midOutcomesSelected = new ArrayList<>(); projectID = Integer//w w w .j a va 2s . c om .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); project = projectManager.getProject(projectID); // Get all years allYears = project.getAllYears(); allYears.add(this.getMidOutcomeYear()); // Load the project impact pathway // Get the programs to which the project contributes projectFocusList = new ArrayList<>(); projectFocusList.addAll(programManager.getProjectFocuses(projectID, APConstants.FLAGSHIP_PROGRAM_TYPE)); projectFocusList.addAll(programManager.getProjectFocuses(projectID, APConstants.REGION_PROGRAM_TYPE)); // Get the project outputs from database project.setOutputs(ipElementManager.getProjectOutputsCcafs(projectID)); // Get the project indicators from database project.setIndicators(indicatorManager.getProjectIndicators(projectID)); // Then, we have to get all the midOutcomes that belongs to the project focuses this.getMidOutcomesByProjectFocuses(); // Get all the midOutcomes selected this.getMidOutcomesByOutputs(); // Get all the midOutcomes selected through the indicators this.getMidOutcomesByIndicators(); this.removeOutcomesAlreadySelected(); // Keep the activity outputs brought from the database previousOutputs = new ArrayList<>(); previousOutputs.addAll(project.getOutputs()); // Save the activity indicators brought from the database previousIndicators = new ArrayList<>(); previousIndicators.addAll(project.getIndicators()); // Getting the Project lessons for this section. int evaluatingYear = 0; if (this.getCycleName().equals(APConstants.REPORTING_SECTION)) { evaluatingYear = this.getCurrentReportingYear(); } else { evaluatingYear = this.getCurrentPlanningYear(); } ComponentLesson lessons = lessonManager.getProjectComponentLesson(projectID, this.getActionName(), evaluatingYear, this.getCycleName()); this.setProjectLessons(lessons); super.setHistory(historyManager.getCCAFSOutcomesHistory(projectID)); // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); if (this.getCycleName().equals(APConstants.REPORTING_SECTION)) { this.setProjectLessonsPreview(lessonManager.getProjectComponentLesson(projectID, this.getActionName(), this.getCurrentReportingYear(), APConstants.PLANNING_SECTION)); } if (this.getRequest().getMethod().equalsIgnoreCase("post")) { // Clear out the list if it has some element if (project.getIndicators() != null) { project.getIndicators().clear(); } if (project.getOutputs() != null) { project.getOutputs().clear(); } } }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectCrossCuttingAction.java
@Override public void prepare() throws Exception { super.prepare(); projectID = Integer/* w ww .j a va 2s . c o m*/ .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); project = projectManager.getProject(projectID); List<CrossCuttingContribution> listCross = crossManager.getCrossCuttingContributionsByProject(projectID); if (listCross.size() > 0) { contribution = listCross.get(0); } commEngageCategories = new HashMap<>(); List<CategoryCrossCutingEnum> list = Arrays.asList(CategoryCrossCutingEnum.values()); for (CategoryCrossCutingEnum category : list) { commEngageCategories.put(category.getId(), category.getDescription()); } // Getting the Project lessons for this section. int evaluatingYear = 0; if (this.getCycleName().equals(APConstants.REPORTING_SECTION)) { evaluatingYear = this.getCurrentReportingYear(); } else { evaluatingYear = this.getCurrentPlanningYear(); } // Getting the Project lessons for this section. this.setProjectLessons(lessonManager.getProjectComponentLesson(projectID, this.getActionName(), evaluatingYear, this.getCycleName())); // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); if (contribution == null) { project.setCrossCutting(new CrossCuttingContribution()); } else { project.setCrossCutting(contribution); } // Getting the last history }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectDeliverableAction.java
@Override public void prepare() throws Exception { super.prepare(); deliverableID = Integer/*from w w w . ja va2 s. c om*/ .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.DELIVERABLE_REQUEST_ID))); project = projectManager.getProjectFromDeliverableId(deliverableID); // Getting the lists for the front-end. deliverableTypes = deliverableTypeManager.getDeliverableTypes(); deliverableSubTypes = deliverableTypeManager.getDeliverableSubTypes(); allYears = project.getAllYears(); outputs = ipElementManager.getProjectOutputs(project.getId()); List<IPProgram> ipPrograms = ipProgramManager.getProgramsByType(APConstants.FLAGSHIP_PROGRAM_TYPE); ipProgramFlagships = new HashMap<>(); for (IPProgram ipProgram : ipPrograms) { ipProgramFlagships.put(String.valueOf(ipProgram.getId()), ipProgram.getComposedName()); } openAccessStatuses = new HashMap<>(); openAccessStatuses.put(APConstants.OA_OPEN, this.getText("reporting.projectDeliverable.openAccess.open")); openAccessStatuses.put(APConstants.OA_LIMITED, this.getText("reporting.projectDeliverable.openAccess.limited")); /** * TODO CAMBIAR */ disseminationChannels = new HashMap<>(); for (ChannelEnum channel : ChannelEnum.values()) { disseminationChannels.put(channel.getId(), channel.getDesc()); } statuses = new HashMap<>(); List<ProjectStatusEnum> list = Arrays.asList(ProjectStatusEnum.values()); for (ProjectStatusEnum projectStatusEnum : list) { statuses.put(projectStatusEnum.getStatusId(), projectStatusEnum.getStatus()); } crps = new HashMap<>(); List<CRP> listCrp = crpManager.getCRPsList(); for (CRP crp : listCrp) { crps.put(String.valueOf(crp.getId()), crp.getName()); } centers = new HashMap<>(); List<LiaisonInstitution> listInstitutions = institutionManager.getLiaisonInstitutionsCenter(); for (LiaisonInstitution inst : listInstitutions) { centers.put(String.valueOf(inst.getId()), inst.getName() + "(" + inst.getAcronym() + ")"); } int year = 0; if (this.isReportingCycle()) { year = config.getReportingCurrentYear(); } else { year = config.getPlanningCurrentYear(); } projectPartners = projectPartnerManager.getProjectPartners(project, year); // Getting the partner persons in a single HashMap to be displayed in the view. projectPartnerPersons = new HashMap<>(); for (ProjectPartner partner : projectPartners) { for (PartnerPerson person : partner.getPartnerPersons()) { projectPartnerPersons.put(person.getId(), partner.getPersonComposedName(person.getId())); } } // Getting the deliverable information. deliverable = deliverableManager.getDeliverableById(deliverableID); DateFormat dateformatter = new SimpleDateFormat(APConstants.DATE_FORMAT); if (deliverable.getDissemination() != null) { if (deliverable.getDissemination().getRestrictedAccessUntil() != null) { deliverable.getDissemination().setRestrictedAccessUntilText( dateformatter.format(deliverable.getDissemination().getRestrictedAccessUntil())); } if (deliverable.getDissemination().getRestrictedEmbargoed() != null) { deliverable.getDissemination().setRestrictedEmbargoedText( dateformatter.format(deliverable.getDissemination().getRestrictedEmbargoed())); } } // Getting next users. deliverable.setNextUsers(nextUserManager.getNextUsersByDeliverableId(deliverable.getId())); // Getting the responsible partner. List<DeliverablePartner> deliverablePartners = deliverablePartnerManager .getDeliverablePartners(deliverableID, APConstants.DELIVERABLE_PARTNER_RESP); if (deliverablePartners.size() > 0) { deliverable.setResponsiblePartner(deliverablePartners.get(0)); } // Getting the other partners that are contributing to this deliverable. deliverable.setOtherPartners(deliverablePartnerManager.getDeliverablePartners(deliverableID, APConstants.DELIVERABLE_PARTNER_OTHER)); super.setHistory(historyManager.getProjectDeliverablesHistory(deliverableID)); if (this.getRequest().getMethod().equalsIgnoreCase("post")) { // Clear out the list if it has some element if (deliverable.getNextUsers() != null) { deliverable.getNextUsers().clear(); } if (deliverable.getOtherPartners() != null) { deliverable.getOtherPartners().clear(); } if (deliverable.getTypeOther() != null) { deliverable.setTypeOther(null); } if (deliverable.getDataSharingFile() != null) { deliverable.getDataSharingFile().clear(); deliverable.getFiles().clear(); } } try { indexTab = Integer.parseInt(this.getSession().get("indexTab").toString()); this.getSession().remove("indexTab"); } catch (Exception e) { indexTab = 0; } // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectDeliverablesListAction.java
@Override public void prepare() throws Exception { projectID = Integer/*w w w .ja va 2 s. c o m*/ .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); project = projectManager.getProject(projectID); // Getting the Deliverables Main Types. deliverableTypes = deliverableTypeManager.getDeliverableTypes(); allYears = project.getAllYears(); // Getting the List of Expected Deliverables List<Deliverable> deliverables = deliverableManager.getDeliverablesBasciByProject(projectID); project.setDeliverables(deliverables); // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectDescriptionAction.java
@Override public void prepare() throws Exception { super.prepare(); try {//from w w w .j a v a 2 s .co m projectID = Integer .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); } catch (NumberFormatException e) { LOG.error("-- prepare() > There was an error parsing the project identifier '{}'.", projectID, e); projectID = -1; return; // Stop here and go to execute method. } // Getting the information for the Project Owner Contact Persons for the View allOwners = userManager.getAllOwners(); // Getting the information of the Regions program for the View ipProgramRegions = ipProgramManager.getProgramsByType(APConstants.REGION_PROGRAM_TYPE); // Getting the information of the Flagships program for the View ipProgramFlagships = ipProgramManager.getProgramsByType(APConstants.FLAGSHIP_PROGRAM_TYPE); // Get the list of institutions that can be management liaison of a project. liaisonInstitutions = liaisonInstitutionManager.getLiaisonInstitutions(); projectStauses = new HashMap<>(); List<ProjectStatusEnum> list = Arrays.asList(ProjectStatusEnum.values()); for (ProjectStatusEnum projectStatusEnum : list) { projectStauses.put(projectStatusEnum.getStatusId(), projectStatusEnum.getStatus()); } // Getting project project = projectManager.getProject(projectID); if (project != null) { // Getting the information of the Flagships Program associated with the project project.setRegions(ipProgramManager.getProjectFocuses(projectID, APConstants.REGION_PROGRAM_TYPE)); // Getting the information of the Regions Program associated with the project project.setFlagships(ipProgramManager.getProjectFocuses(projectID, APConstants.FLAGSHIP_PROGRAM_TYPE)); } // If project is CCAFS cofounded, we should load the core projects linked to it. if (!project.isBilateralProject()) { project.setLinkedProjects(linkedProjectManager.getLinkedBilateralProjects(projectID)); } else { project.setLinkedProjects(linkedProjectManager.getLinkedCoreProjects(projectID)); } projectTypes = new HashMap<>(); projectTypes.put(APConstants.PROJECT_CORE, this.getText("planning.projectDescription.projectType.core")); projectTypes.put(APConstants.PROJECT_BILATERAL, this.getText("planning.projectDescription.projectType.bilateral")); projectTypes.put(APConstants.PROJECT_CCAFS_COFUNDED, this.getText("planning.projectDescription.projectType.cofounded")); projectTypes.put(APConstants.PROJECT_BILATERAL, this.getText("planning.projectDescription.projectType.bilateral")); // If the user is not admin or the project owner, we should keep some information // unmutable previousProject = new Project(); previousProject.setId(project.getId()); previousProject.setTitle(project.getTitle()); previousProject.setLiaisonInstitution(project.getLiaisonInstitution()); previousProject.setOwner(project.getOwner()); previousProject.setStartDate(project.getStartDate()); previousProject.setEndDate(project.getEndDate()); previousProject.setSummary(project.getSummary()); previousProject.setFlagships(project.getFlagships()); previousProject.setRegions(project.getRegions()); previousProject.setType(project.getType()); previousProject.setWorkplanRequired(project.isWorkplanRequired()); previousProject.setBilateralContractRequired(project.isBilateralContractRequired()); previousProject.setWorkplanName(project.getWorkplanName()); previousProject.setBilateralContractProposalName(project.getBilateralContractProposalName()); previousProject.setAnnualReportDonor(project.getAnnualReportDonor()); if (project.getLinkedProjects() != null) { List<Project> linkedProjects = new ArrayList<>(); for (Project p : project.getLinkedProjects()) { linkedProjects.add(new Project(p.getId())); } previousProject.setLinkedProjects(linkedProjects); } super.setHistory(historyManager.getProjectDescriptionHistory(project.getId())); if (this.isHttpPost()) { if (project.getLinkedProjects() != null) { project.getLinkedProjects().clear(); } } // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectEvaluationAction.java
@Override public void prepare() throws Exception { super.prepare(); try {/* www .ja v a 2 s . com*/ projectID = Integer .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID))); } catch (NumberFormatException e) { LOG.error("-- prepare() > There was an error parsing the project identifier '{}'.", projectID, e); projectID = -1; return; // Stop here and go to execute method. } // Getting project project = projectManager.getProject(projectID); // Getting all the project partners. int year = 0; if (this.isReportingCycle()) { year = config.getReportingCurrentYear(); } else { year = config.getPlanningCurrentYear(); } project.setProjectPartners(projectPartnerManager.getProjectPartners(project, year)); // Getting the information of the Regions Program associated with the project project.setRegions(ipProgramManager.getProjectFocuses(projectID, APConstants.REGION_PROGRAM_TYPE)); // Getting the information of the Flagships Program associated with the project project.setFlagships(ipProgramManager.getProjectFocuses(projectID, APConstants.FLAGSHIP_PROGRAM_TYPE)); // get the Project Leader information projectLeader = project.getLeader(); // get the Project Leader contact information partnerPerson = project.getLeaderPerson(); // calculate the cumulative total budget totalCCAFSBudget = budgetManager.calculateTotalProjectBudgetByType(projectID, BudgetType.W1_W2.getValue()); totalBilateralBudget = budgetManager.calculateTotalProjectBudgetByType(projectID, BudgetType.W3_BILATERAL.getValue()); List<UserRole> roles = userRoleManager.getUserRolesByUserID(String.valueOf(this.getCurrentUser().getId())); List<ProjectEvaluation> lstEvaluations = new ArrayList<ProjectEvaluation>(); // evaluationUser.setId(new Long(-1)); int liaisonInstitutionID = 0; try { liaisonInstitutionID = this.getCurrentUser().getLiaisonInstitution().get(0).getId(); } catch (Exception e) { liaisonInstitutionID = 2; } currentLiaisonInstitution = liaisonInstitutionManager.getLiaisonInstitution(liaisonInstitutionID); if (currentLiaisonInstitution.getIpProgram() == null) { currentLiaisonInstitution.setIpProgram("1"); } lstEvaluations.addAll(projectEvaluationManager.getEvaluationsProject(projectID)); for (UserRole userRole : roles) { ProjectEvaluation evaluationUser = null; switch (userRole.getId()) { case APConstants.ROLE_FLAGSHIP_PROGRAM_LEADER: case APConstants.ROLE_REGIONAL_PROGRAM_LEADER: evaluationUser = new ProjectEvaluation(); evaluationUser.setProjectId(new Long(projectID)); evaluationUser.setYear(this.getCurrentReportingYear()); evaluationUser.setActive(true); evaluationUser.setActiveSince(new Date()); evaluationUser.setProgramId(new Long(currentLiaisonInstitution.getIpProgram())); evaluationUser.setModifiedBy(new Long(this.getCurrentUser().getId())); evaluationUser.setTypeEvaluation(userRole.getAcronym()); if (!this.existEvaluation(lstEvaluations, evaluationUser)) { lstEvaluations.add(evaluationUser); } break; case APConstants.ROLE_PROJECT_LEADER: Project p = projectManager.getProjectBasicInfo(projectID); if (p.getLeaderUserId() == this.getCurrentUser().getId()) { evaluationUser = new ProjectEvaluation(); evaluationUser.setProjectId(new Long(projectID)); evaluationUser.setYear(this.getCurrentReportingYear()); evaluationUser.setActive(true); evaluationUser.setActiveSince(new Date()); evaluationUser.setModifiedBy(new Long(this.getCurrentUser().getId())); evaluationUser.setTypeEvaluation(userRole.getAcronym()); if (!this.existEvaluation(lstEvaluations, evaluationUser)) { lstEvaluations.add(evaluationUser); } } break; case APConstants.ROLE_EXTERNAL_EVALUATOR: case APConstants.ROLE_PROGRAM_DIRECTOR_EVALUATOR: case APConstants.ROLE_COORDINATING_UNIT: evaluationUser = new ProjectEvaluation(); evaluationUser.setProjectId(new Long(projectID)); evaluationUser.setYear(this.getCurrentReportingYear()); evaluationUser.setActive(true); evaluationUser.setActiveSince(new Date()); evaluationUser.setModifiedBy(new Long(this.getCurrentUser().getId())); evaluationUser.setTypeEvaluation(userRole.getAcronym()); if (!this.existEvaluation(lstEvaluations, evaluationUser)) { lstEvaluations.add(evaluationUser); } break; } } for (ProjectEvaluation projectEvaluation : lstEvaluations) { projectEvaluation.setRankingOutcomes(projectEvaluation.getRankingOutcomes() * STAR_DIV); projectEvaluation.setRankingOutputs(projectEvaluation.getRankingOutputs() * STAR_DIV); projectEvaluation.setRankingParternshipComunnication( projectEvaluation.getRankingParternshipComunnication() * STAR_DIV); projectEvaluation.setRankingQuality(projectEvaluation.getRankingQuality() * STAR_DIV); projectEvaluation.setRankingResponseTeam(projectEvaluation.getRankingResponseTeam() * STAR_DIV); } Collections.sort(lstEvaluations, new Comparator<ProjectEvaluation>() { @Override public int compare(ProjectEvaluation s1, ProjectEvaluation s2) { Boolean p1 = s1.isSubmited(); Boolean p2 = s2.isSubmited(); return p1.compareTo(p2) * -1; } }); project.setEvaluations(lstEvaluations); }
From source file:org.cgiar.ccafs.ap.action.projects.ProjectHighlightAction.java
@Override public void prepare() throws Exception { super.prepare(); previewTypes = new ArrayList<>(); highlightID = Integer/*from w w w .j a v a2 s . c o m*/ .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.HIGHLIGHT_REQUEST_ID))); ProjectHighligths higligth = highLightManager.getHighLightById(highlightID); project = projectManager.getProject(Integer.parseInt(higligth.getProjectId() + "")); // Getting highlights Types highlightsTypes = new HashMap<>(); List<ProjectHighlightsType> list = Arrays.asList(ProjectHighlightsType.values()); for (ProjectHighlightsType ProjectHighlightsType : list) { highlightsTypes.put(ProjectHighlightsType.getId(), ProjectHighlightsType.getDescription()); } // Getting statuses statuses = new HashMap<>(); List<ProjectStatusEnum> statusesList = Arrays.asList(ProjectStatusEnum.values()); for (ProjectStatusEnum projectStatusEnum : statusesList) { statuses.put(projectStatusEnum.getStatusId(), projectStatusEnum.getStatus()); } // Getting all years from project allYears = project.getAllYears(); List<Integer> listYears = new ArrayList<Integer>(); for (int i = 0; i < allYears.size(); i++) { if ((allYears.get(i) <= this.getCurrentReportingYear())) { listYears.add(allYears.get(i)); } } allYears.clear(); allYears.addAll(listYears); // Getting countries list countries = locationManager.getAllCountries(); // Getting the highlight information. highlight = highLightManager.getHighLightById(highlightID); DateFormat dateformatter = new SimpleDateFormat(APConstants.DATE_FORMAT); // highlight.setStartDate(dateformatter.parse(dateformatter.format(highlight.getStartDate()))); highlight.setStartDateText(dateformatter.format(highlight.getStartDate())); highlight.setEndDateText(dateformatter.format(highlight.getEndDate())); Iterator<ProjectHighligthsTypes> iteratorTypes = higligth.getProjectHighligthsTypeses().iterator(); List<ProjectHighlightsType> typesids = new ArrayList<>(); List<String> ids = new ArrayList<>(); while (iteratorTypes.hasNext()) { ProjectHighligthsTypes projectHighligthsTypes = iteratorTypes.next(); typesids.add(ProjectHighlightsType.value(projectHighligthsTypes.getIdType() + "")); ids.add(projectHighligthsTypes.getIdType() + ""); } Iterator<ProjectHighligthsCountry> iteratorCountry = higligth.getProjectHighligthsCountries().iterator(); List<Country> countrys = new ArrayList<>(); List<Integer> countryids = new ArrayList<>(); while (iteratorCountry.hasNext()) { ProjectHighligthsCountry projectHighligthsCountry = iteratorCountry.next(); Country country = new Country(); country.setId(projectHighligthsCountry.getIdCountry()); int indexCountry = this.countries.indexOf(country); if (indexCountry > 0) { country.setName(this.countries.get(indexCountry).getName()); countryids.add(projectHighligthsCountry.getIdCountry()); countrys.add(country); } else { country = locationManager.getCountry(projectHighligthsCountry.getIdCountry()); if (country != null) { countryids.add(projectHighligthsCountry.getIdCountry()); countrys.add(country); } } } highlight.setYear(higligth.getYear()); highlight.setCountriesIds(countryids); highlight.setCountries(countrys); highlight.setTypesIds(typesids); previewTypes.addAll(typesids); highlight.setTypesids(ids); super.setHistory(historyManager.getProjectHighLights(project.getId())); // Initializing Section Statuses: this.initializeProjectSectionStatuses(project, this.getCycleName()); }