Example usage for org.apache.commons.lang3 StringUtils trim

List of usage examples for org.apache.commons.lang3 StringUtils trim

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils trim.

Prototype

public static String trim(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null .

The String is trimmed using String#trim() .

Usage

From source file:org.cgiar.ccafs.ap.action.json.projects.BilateralCofinancingProjectsAction.java

@Override
public void prepare() throws Exception {

    // Verify if there is a programID parameter
    String stringFlagshipID = StringUtils.trim(this.getRequest().getParameter(APConstants.PROGRAM_REQUEST_ID));
    try {//from  w w w .  ja v  a 2s. c  o  m
        flagshipID = (stringFlagshipID != null) ? Integer.parseInt(stringFlagshipID) : -1;
    } catch (NumberFormatException e) {
        LOG.warn("There was an exception trying to convert to int the parameter {}", stringFlagshipID);
        flagshipID = -1;
    }

    // Verify if there is a regionID parameter
    String stringRegionID = StringUtils.trim(this.getRequest().getParameter(APConstants.REGION_REQUEST_ID));
    try {
        regionID = (stringRegionID != null) ? Integer.parseInt(stringRegionID) : -1;
    } catch (NumberFormatException e) {
        LOG.warn("There was an exception trying to convert to int the parameter {}", stringRegionID);
        regionID = -1;
    }

}

From source file:org.cgiar.ccafs.ap.action.json.reporting.DeliverableSubTypeByTypeAction.java

@Override
public void prepare() throws Exception {

    // Verify if there is a activityID parameter
    if (this.getRequest().getParameter(APConstants.DELIVERABLE_TYPE_REQUEST_ID) == null) {
        deliverableTypeID = "";
        return;/*from  w w  w .jav a2s.  c o m*/
    }

    // If there is a parameter take its values
    deliverableTypeID = StringUtils
            .trim(this.getRequest().getParameter(APConstants.DELIVERABLE_TYPE_REQUEST_ID));
}

From source file:org.cgiar.ccafs.ap.action.json.reporting.MetadataRequiredByDeliverableTypeAction.java

@Override
public void prepare() throws Exception {
    // Verify if there is a activityID parameter
    if (this.getRequest().getParameter(APConstants.DELIVERABLE_TYPE_REQUEST_ID) == null) {
        deliverableTypeID = "";
        return;//  w ww.j a v a 2 s.co m
    }

    // If there is a parameter take its values
    deliverableTypeID = StringUtils
            .trim(this.getRequest().getParameter(APConstants.DELIVERABLE_TYPE_REQUEST_ID));
}

From source file:org.cgiar.ccafs.ap.action.preplanning.MidOutcomesPreplanningAction.java

@Override
public void prepare() throws Exception {
    programID = Integer//  ww w.j a v  a2 s. com
            .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROGRAM_REQUEST_ID)));
    program = ipProgramManager.getIPProgramById(programID);

    // Create an ipElementType with the identifier of the outcomes 2019 type
    IPElementType outcomesType = new IPElementType(APConstants.ELEMENT_TYPE_OUTCOME2025);

    // Create an ipElementType with the identifier of the outcomes 2025 type
    IPElementType midOutcomesType = new IPElementType(APConstants.ELEMENT_TYPE_OUTCOME2019);

    flagshipsList = new ArrayList<>();

    // Fake flagship to add as a placeholder
    IPProgram flagship = new IPProgram(-1);
    flagship.setName(this.getText("preplanning.midOutcomesRPL.selectFlagship"));
    flagshipsList.add(flagship);

    midOutcomes = ipElementManager.getIPElements(program, midOutcomesType);
    outcomesList = ipElementManager.getIPElements(program, outcomesType);
    flagshipsList.addAll(ipProgramManager.getProgramsByType(APConstants.FLAGSHIP_PROGRAM_TYPE));

    midOutcomesFromDatabase = new ArrayList<>();
    midOutcomesFromDatabase.addAll(midOutcomes);

    if (this.getRequest().getMethod().equalsIgnoreCase("post")) {
        // Clear out the list if it has some element
        if (midOutcomes != null) {
            midOutcomes.clear();
        }
    }
}

From source file:org.cgiar.ccafs.ap.action.preplanning.OutcomesPreplanningAction.java

@Override
public void prepare() throws Exception {

    try {/*w  w w  .  ja v  a 2  s .  com*/
        programID = Integer
                .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROGRAM_REQUEST_ID)));
    } catch (Exception e1) {
        programID = 1;
    }

    IPElementType type = new IPElementType(APConstants.ELEMENT_TYPE_OUTCOME2025);

    // The Consortium IDOs are created by the system administrator
    IPProgram systemProgram = new IPProgram(APConstants.SYSTEM_ADMIN_PROGRAM);
    IPProgram ccafsProgram = new IPProgram(APConstants.CCAFS_PROGRAM);

    // Set the element type for IDOs
    IPElementType idoType = new IPElementType(APConstants.ELEMENT_TYPE_IDOS);

    consortiumIDOs = ipElementManager.getIPElements(systemProgram, idoType);
    ccafsIDOs = ipElementManager.getIPElements(ccafsProgram, idoType);

    program = ipProgramManager.getIPProgramById(programID);

    outcomes = ipElementManager.getIPElements(program, type);

    // Keep the id of all outcomes which come from the database
    outcomesFromDatabase = new ArrayList<>();
    outcomesFromDatabase.addAll(outcomes);

    // Create empty outcome if the list is empty
    if (outcomes.isEmpty()) {
        IPElement outcome2025 = new IPElement();
        outcome2025.setId(-1);

        // Indicator
        IPIndicator indicator = new IPIndicator(-1);
        ArrayList<IPIndicator> iList = new ArrayList<>();
        iList.add(indicator);
        outcome2025.setIndicators(iList);

        outcome2025.setContributesTo(new ArrayList<IPElement>());

        outcomes.add(outcome2025);
    }

    // If the user is RPL they should see a list with all the indicators
    // filled by the FPL
    if (securityContext.isRPL()) {
        fplOutcomesIndicators = new ArrayList<>();
        List<IPProgram> flagshipPrograms = ipProgramManager
                .getProgramsByType(APConstants.FLAGSHIP_PROGRAM_TYPE);
        IPElementType outcomesType = new IPElementType(APConstants.ELEMENT_TYPE_OUTCOME2025);

        for (IPProgram flagshipProgram : flagshipPrograms) {
            List<IPElement> elements = ipElementManager.getIPElements(flagshipProgram, outcomesType);
            for (IPElement e : elements) {
                for (IPIndicator indicator : e.getIndicators()) {
                    if (indicator.getParent() == null) {
                        fplOutcomesIndicators.add(indicator);
                    }
                }
            }
        }
    }

    if (this.getRequest().getMethod().equalsIgnoreCase("post")) {
        // Clear out the list if it has some element
        if (outcomes != null) {
            for (IPElement outcome : outcomes) {
                outcome.getIndicators().clear();
                outcome.getContributesTo().clear();
            }
        }
    }
}

From source file:org.cgiar.ccafs.ap.action.preplanning.OutputsPreplanningAction.java

@Override
public void prepare() throws Exception {
    programID = Integer/* ww  w. jav  a2 s  . c  o  m*/
            .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROGRAM_REQUEST_ID)));
    program = ipProgramManager.getIPProgramById(programID);

    // Create an element type for midOutcomes
    IPElementType midOutcomesType = new IPElementType(APConstants.ELEMENT_TYPE_OUTCOME2019);

    // Create an element type for outputs
    IPElementType outputsType = new IPElementType(APConstants.ELEMENT_TYPE_OUTPUTS);

    flagshipsList = new ArrayList<>();
    midOutcomesList = new ArrayList<>();

    // Fake flagship to add as a placeholder
    IPProgram flagship = new IPProgram(-1);
    flagship.setName(this.getText("preplanning.midOutcomesRPL.selectFlagship"));
    flagshipsList.add(flagship);

    // Fake midOutcome to add as a placeholder if user is a FPL
    IPElement outcome = new IPElement(-1);
    outcome.setDescription(this.getText("preplanning.midOutcomesRPL.selectMidOutcome"));
    midOutcomesList.add(outcome);

    flagshipsList.addAll(ipProgramManager.getProgramsByType(APConstants.FLAGSHIP_PROGRAM_TYPE));
    midOutcomesList.addAll(ipElementManager.getIPElements(program, midOutcomesType));
    outputs = ipElementManager.getIPElements(program, outputsType);

    // Set the parents for the translated outputs
    for (int i = 0; i < outputs.size(); i++) {
        if (!outputs.get(i).getTranslatedOf().isEmpty()) {
            int[] intIds = outputs.get(i).getTranslatedOfIDs();
            String[] stringIds = new String[intIds.length];
            for (int c = 0; c < intIds.length; c++) {
                stringIds[c] = String.valueOf(intIds[c]);
            }

            outputs.get(i).setTranslatedOf(ipElementManager.getIPElementList(stringIds));
        }
    }

    outputsFromDatabase = new ArrayList<>();
    outputsFromDatabase.addAll(outputs);

    if (this.getRequest().getMethod().equalsIgnoreCase("post")) {
        // Clear out the list if it has some element
        if (outputs != null) {
            outputs.clear();
        }
    }
}

From source file:org.cgiar.ccafs.ap.action.preplanning.ProjectBudgetPreplanningAction.java

@Override
public void prepare() throws Exception {
    super.prepare();

    // Getting the project id from the URL parameters.
    // It's assumed that the project parameter is ok. (@See ValidateProjectParameterInterceptor)
    String parameter;//from w ww  . jav a  2 s.c om
    projectID = Integer
            .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID)));

    // Getting the project identified with the id parameter.
    project = projectManager.getProject(projectID);
    project.setBudgets(budgetManager.getBudgetsByProject(project));

    // Getting all the years of the project.
    allYears = project.getAllYears();
    // If there are not years, we stop here.
    if (allYears.size() > 0) {

        // Getting the year from the URL parameters.
        try {
            parameter = this.getRequest().getParameter(APConstants.YEAR_REQUEST);
            if (parameter != null) {
                year = Integer.parseInt(StringUtils.trim(parameter));
            } else {
                year = allYears.get(0);
            }
        } catch (NumberFormatException e) {
            LOG.error("-- prepare() > There was an error parsing the year '{}'.", year);
            return; // Stop here and go to the execute method.
        }

        if (allYears.contains(new Integer(year))) {

            // This code needs to be updated.
            // We validate if the partner leader is already in the employees table. If so, we get this
            // information. If not, we load the information from expected project leader.
            // User projectLeader = projectManager.getProjectLeader(project.getId());
            // if the official leader is defined.
            // if (projectLeader != null) {
            // project.setLeader(projectLeader);
            // } else {
            // project.setLeader(projectManager.getExpectedProjectLeader(projectID));
            // }
            // if the project leader is not defined, stop here.
            if (project.getLeader() != null) {

                // Getting the Total Overall Project Budget
                // totalBudget = budgetManager.calculateTotalOverallBudget(projectID);
                // totalBudgetByYear = budgetManager.calculateTotalOverallBudgetByYear(projectID, year);
                totalW1W2W3BilateralBudget = budgetManager.calculateTotalBudget(projectID);
                totalW1W2W3BilateralBudgetByYear = budgetManager.calculateTotalBudgetByYear(projectID, year);
                // totalW1W2Budget = budgetManager.calculateTotalProjectW1W2(projectID);
                // totalW1W2BudgetByYear = budgetManager.calculateTotalProjectW1W2ByYear(projectID, year);
                // leveragedBudgetByYear = budgetManager.calculateProjectLeveragedBudgetByYear(projectID, year);
                // totalLeveragedBudget = budgetManager.calculateProjectTotalLeveragedBudget(projectID);

                // Getting all the project partners.
                // projectPartners = partnerManager.z_old_getProjectPartners(projectID);

                // Getting the list of budgets.
                project.setBudgets(budgetManager.getBudgetsByYear(project.getId(), year));
                // Creating budgets that do not exist.
                mapBudgets = this.generateMapBudgets(year);

                if (this.getRequest().getMethod().equalsIgnoreCase("post")) {
                    // Clear out the list if it has some element
                    if (project.getBudgets() != null) {
                        project.getBudgets().clear();
                    }
                }

            } else {
                hasLeader = false;
            }
        } else {
            invalidYear = true;
        }
    }
}

From source file:org.cgiar.ccafs.ap.action.preplanning.ProjectDescriptionPreplanningAction.java

@Override
public void prepare() throws Exception {
    super.prepare();
    // It's assumed that the project parameter is ok. (@See ValidateProjectParameterInterceptor)
    projectID = Integer/*from   w  w  w. jav  a 2  s  .c o m*/
            .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID)));

    // 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);

    // Getting project
    project = projectManager.getProject(projectID);

    if (project != null) {

        // Getting all project owners that belongs to the project's program creator.

        // TODO HC - The owner are not ipPrograms anymore, are liaison institutions.
        // allOwners = userManager.getAllOwners(project.getProgramCreator());
        // 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));
    }

}

From source file:org.cgiar.ccafs.ap.action.preplanning.ProjectPartnersPreplanningAction.java

@Override
public void prepare() throws Exception {
    super.prepare();

    // Getting the project id from the URL parameter
    // It's assumed that the project parameter is ok. (@See ValidateProjectParameterInterceptor)
    projectID = Integer/*from   ww  w . j a  va2s  . co  m*/
            .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID)));

    // Getting the project identified with the id parameter.
    project = projectManager.getProject(projectID);

    // if there are not partners, please return an empty List.
    // project.setProjectPartners(projectPartnerManager.z_old_getProjectPartners(projectID));

    // Getting all partners.
    allPartners = new ArrayList<>();
    Institution placeHolder = new Institution(-1);
    placeHolder.setType(new InstitutionType());
    placeHolder.setName(this.getText("planning.projectPartners.selectInstitution"));

    allPartners.add(placeHolder);
    allPartners.addAll(institutionManager.getAllInstitutions());

    // Getting all the countries
    countries = locationManager.getInstitutionCountries();

    // Getting all partner types
    partnerTypes = institutionManager.getAllInstitutionTypes();

    // Getting all Project Leaders
    allProjectLeaders = userManager.getAllUsers();

    // THIS CODE IS DEPRECATED
    // // Getting the project partner leader.
    // // We validate if the partner leader is already in the employees table. If so, we need to get this
    // // information and show it as label in the front-end.
    // // If not, we just load the form for the expected project leader.
    // User projectLeader = projectManager.getProjectLeader(project.getId());
    // // if the official leader is defined.
    // if (projectLeader != null) {
    // isExpected = false;
    // project.setLeader(projectLeader);
    // } else {
    // isExpected = true;
    // project.setExpectedLeader(projectManager.getExpectedProjectLeader(projectID));
    // // In case there is not a partner leader defined, an empty partner will be used for the view.
    // if (project.getExpectedLeader() == null) {
    // User exptectedProjectLeader = new User();
    // exptectedProjectLeader.setId(-1);
    // project.setExpectedLeader(exptectedProjectLeader);
    // }
    // }

    if (this.getRequest().getMethod().equalsIgnoreCase("post")) {
        // Clear out the list if it has some element
        if (project.getProjectPartners() != null) {
            project.getProjectPartners().clear();
        }
    }

}

From source file:org.cgiar.ccafs.ap.action.projects.ActivitiesListAction.java

@Override
public void prepare() throws Exception {
    super.prepare();
    projectID = Integer//from  w  w  w  . jav a  2  s.c o  m
            .parseInt(StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_REQUEST_ID)));
    project = projectManager.getProject(projectID);
    project.setActivities(activityManager.getActivitiesByProject(projectID));
    int year = 0;
    if (this.isReportingCycle()) {
        year = config.getReportingCurrentYear();
    } else {
        year = config.getPlanningCurrentYear();
    }
    projectPartners = projectPartnerManager.getProjectPartners(project, year);

    // Creating Map of partner persons 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()));
        }
    }

    statuses = new HashMap<>();
    List<ProjectStatusEnum> list = Arrays.asList(ProjectStatusEnum.values());
    for (ProjectStatusEnum projectStatusEnum : list) {
        statuses.put(projectStatusEnum.getStatusId(), projectStatusEnum.getStatus());
    }

    if (this.getRequest().getMethod().equalsIgnoreCase("post")) {
        // Clear out the list if it has some element
        if (project.getActivities() != null) {
            project.getActivities().clear();
        }
    }

    projectStauses = new HashMap<>();
    List<ProjectStatusEnum> listEnum = Arrays.asList(ProjectStatusEnum.values());
    for (ProjectStatusEnum projectStatusEnum : listEnum) {
        projectStauses.put(projectStatusEnum.getStatusId(), projectStatusEnum.getStatus());
    }
    // Getting the Project lessons for this section.

    int evalutingYear = 0;
    if (this.isReportingCycle()) {

        evalutingYear = this.getCurrentReportingYear();
    } else {
        evalutingYear = this.getCurrentPlanningYear();
    }

    this.setProjectLessons(lessonManager.getProjectComponentLesson(projectID, this.getActionName(),
            evalutingYear, this.getCycleName()));

    // Initializing Section Statuses:
    this.initializeProjectSectionStatuses(project, this.getCycleName());

    // Getting the history for this section.
    super.setHistory(historyManager.getActivitiesHistory(project.getId()));
}