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

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

Introduction

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

Prototype

public static String substring(final String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start/end n characters from the end of the String.

The returned substring starts with the character in the start position and ends before the end position.

Usage

From source file:org.kuali.coeus.s2sgen.impl.generate.support.SF424V2_0Generator.java

/**
 * /*from  w  w  w. j  a v  a2 s .  c om*/
 * This method gets SF424 information for the form which includes informations regarding SubmissionTypeCode
 * ApplicationType,RevisionType,AgencyName,ApplicantID,CFDANumber,FederalEntityIdentifier,AuthorizedRepresentative.
 * 
 * @return sf424V2 object containing applicant and application details.
 */
private SF424 getSF424() {

    SF424 sf424V2 = SF424.Factory.newInstance();
    sf424V2.setFormVersion(FormVersion.v2_0.getVersion());
    boolean hasBudgetLineItem = false;
    S2sOpportunityContract s2sOpportunity = pdDoc.getDevelopmentProposal().getS2sOpportunity();
    if (s2sOpportunity != null && s2sOpportunity.getS2sSubmissionType() != null) {
        S2sSubmissionTypeContract submissionType = s2sOpportunity.getS2sSubmissionType();
        SubmissionType.Enum subEnum = SubmissionType.Enum.forInt(Integer.parseInt(submissionType.getCode()));
        sf424V2.setSubmissionType(subEnum);
        ApplicationType.Enum applicationTypeEnum = null;
        if (pdDoc.getDevelopmentProposal().getProposalType() != null) {
            String proposalTypeCode = pdDoc.getDevelopmentProposal().getProposalType().getCode();
            if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_NEW, proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.NEW;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RESUBMISSION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RENEWAL,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_CONTINUATION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_REVISION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            }
        }
        sf424V2.setApplicationType(applicationTypeEnum);
        String revisionType = s2sOpportunity.getS2sRevisionType() != null
                ? s2sOpportunity.getS2sRevisionType().getCode()
                : null;
        if (revisionType != null) {
            RevisionType.Enum revType = null;
            if (revisionType.equals(INCREASE_AWARD_CODE)) {
                revType = RevisionType.A_INCREASE_AWARD;
            } else if (revisionType.equals(DECREASE_AWARD_CODE)) {
                revType = RevisionType.B_DECREASE_AWARD;
            } else if (revisionType.equals(INCREASE_DURATION_CODE)) {
                revType = RevisionType.C_INCREASE_DURATION;
            } else if (revisionType.equals(DECREASE_DURATION_CODE)) {
                revType = RevisionType.D_DECREASE_DURATION;
            } else if (revisionType.equals(INCREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.AD_INCREASE_AWARD_DECREASE_DURATION;
            } else if (revisionType.equals(INCREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.AC_INCREASE_AWARD_INCREASE_DURATION;
            } else if (revisionType.equals(DECREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.BD_DECREASE_AWARD_DECREASE_DURATION;
            } else if (revisionType.equals(DECREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.BC_DECREASE_AWARD_INCREASE_DURATION;
            } else if (revisionType.equals(OTHER_SPECIFY_CODE)) {
                revType = RevisionType.E_OTHER_SPECIFY;
            }

            if (revType != null) {
                sf424V2.setRevisionType(revType);
            }
            if (revisionType.startsWith(REVISIONCODE_STARTS_WITH_E)) {
                sf424V2.setRevisionOtherSpecify(s2sOpportunity.getRevisionOtherDescription());
            }
        }
    }
    sf424V2.setDateReceived(Calendar.getInstance());
    sf424V2.setApplicantID(pdDoc.getDevelopmentProposal().getProposalNumber());
    String federalId = getSubmissionInfoService()
            .getFederalId(pdDoc.getDevelopmentProposal().getProposalNumber());
    if (federalId != null) {
        sf424V2.setFederalEntityIdentifier(federalId);
    }

    OrganizationContract organization = null;
    organization = pdDoc.getDevelopmentProposal().getApplicantOrganization().getOrganization();
    if (organization != null) {
        sf424V2.setOrganizationName(organization.getOrganizationName());
        sf424V2.setEmployerTaxpayerIdentificationNumber(organization.getFederalEmployerId());
        sf424V2.setDUNSNumber(organization.getDunsNumber());
        sf424V2.setOrganizationAffiliation(organization.getOrganizationName());
    } else {
        sf424V2.setOrganizationName(null);
        sf424V2.setEmployerTaxpayerIdentificationNumber(null);
        sf424V2.setDUNSNumber(null);
    }
    RolodexContract rolodex = null;
    rolodex = pdDoc.getDevelopmentProposal().getApplicantOrganization().getRolodex();
    sf424V2.setApplicant(globLibV20Generator.getAddressDataType(rolodex));
    String departmentName = null;
    if (pdDoc.getDevelopmentProposal().getOwnedByUnit() != null) {
        departmentName = pdDoc.getDevelopmentProposal().getOwnedByUnit().getUnitName();
    }
    if (departmentName != null) {
        sf424V2.setDepartmentName(StringUtils.substring(departmentName, 0, DEPARTMENT_NAME_MAX_LENGTH));
    }
    String divisionName = getDivisionName(pdDoc);
    if (divisionName != null) {
        sf424V2.setDivisionName(StringUtils.substring(divisionName, 0, DIVISION_NAME_MAX_LENGTH));
    }
    ProposalPersonContract personInfo = s2SProposalPersonService.getPrincipalInvestigator(pdDoc);
    if (personInfo != null) {
        sf424V2.setContactPerson(globLibV20Generator.getHumanNameDataType(personInfo));
        if (personInfo.getDirectoryTitle() != null) {
            String directoryTitle = personInfo.getDirectoryTitle();
            directoryTitle = directoryTitle.length() > 45 ? directoryTitle.substring(0, 44) : directoryTitle;
            sf424V2.setTitle(directoryTitle);
        }
        sf424V2.setPhoneNumber(personInfo.getOfficePhone());
        if (StringUtils.isNotEmpty(personInfo.getFaxNumber())) {
            sf424V2.setFax(personInfo.getFaxNumber());
        }
        sf424V2.setEmail(personInfo.getEmailAddress());
    } else {
        sf424V2.setPhoneNumber(null);
        sf424V2.setEmail(null);
    }

    setApplicatTypeCodes(sf424V2);

    if (pdDoc.getDevelopmentProposal().getSponsor() != null) {
        sf424V2.setAgencyName(pdDoc.getDevelopmentProposal().getSponsor().getSponsorName());
    }
    if (pdDoc.getDevelopmentProposal().getCfdaNumber() != null) {
        sf424V2.setCFDANumber(pdDoc.getDevelopmentProposal().getCfdaNumber());
    }
    if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle() != null) {
        String announcementTitle;
        if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle()
                .length() > PROGRAM_ANNOUNCEMENT_TITLE_LENGTH) {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle().substring(0,
                    PROGRAM_ANNOUNCEMENT_TITLE_LENGTH);
        } else {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle();
        }
        sf424V2.setCFDAProgramTitle(announcementTitle);
    }
    if (pdDoc.getDevelopmentProposal().getS2sOpportunity() != null) {
        sf424V2.setFundingOpportunityNumber(
                pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId());
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle() != null) {
            sf424V2.setFundingOpportunityTitle(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle());
        }
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId() != null) {
            sf424V2.setCompetitionIdentificationNumber(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId());
        }
    } else {
        sf424V2.setFundingOpportunityTitle(null);
    }
    String areasAffected = null;
    for (ProposalAbstractContract proposalAbstract : pdDoc.getDevelopmentProposal().getProposalAbstracts()) {
        if (proposalAbstract.getAbstractType().getCode() != null && Integer
                .parseInt(proposalAbstract.getAbstractType().getCode()) == ABSTRACTTYPE_CODE_AREAS_AFFECTED) {
            areasAffected = proposalAbstract.getAbstractDetails();
            if (areasAffected != null && areasAffected.length() > AREAS_AFFECTED_MAX_LENGTH) {
                sf424V2.setAffectedAreas(areasAffected.substring(0, AREAS_AFFECTED_MAX_LENGTH));
            } else {
                sf424V2.setAffectedAreas(areasAffected);
            }
        }
    }
    sf424V2.setProjectTitle(pdDoc.getDevelopmentProposal().getTitle());
    AttachmentGroupMin0Max100DataType attachedFileMin0Max100 = AttachmentGroupMin0Max100DataType.Factory
            .newInstance();
    attachedFileMin0Max100.setAttachedFileArray(getAttachedFileDataTypes());
    sf424V2.setAdditionalProjectTitle(attachedFileMin0Max100);
    String congressionalDistrict = organization.getCongressionalDistrict() == null
            ? FieldValueConstants.VALUE_UNKNOWN
            : organization.getCongressionalDistrict();
    if (congressionalDistrict.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
        sf424V2.setCongressionalDistrictApplicant(
                congressionalDistrict.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
    } else {
        sf424V2.setCongressionalDistrictApplicant(congressionalDistrict);
    }
    ProposalSiteContract perfOrganization = pdDoc.getDevelopmentProposal().getPerformingOrganization();
    if (perfOrganization != null) {
        String congDistrictProject = perfOrganization.getFirstCongressionalDistrictName() == null
                ? FieldValueConstants.VALUE_UNKNOWN
                : perfOrganization.getFirstCongressionalDistrictName();
        if (congDistrictProject.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
            sf424V2.setCongressionalDistrictProgramProject(
                    congDistrictProject.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
        } else {
            sf424V2.setCongressionalDistrictProgramProject(congDistrictProject);
        }
    }
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null && Integer
                .parseInt(narrative.getNarrativeType().getCode()) == CONGRESSIONAL_DISTRICTS_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V2.setAdditionalCongressionalDistricts(attachedFileDataType);
                break;
            }
        }
    }
    if (pdDoc.getDevelopmentProposal().getRequestedStartDateInitial() != null) {
        sf424V2.setProjectStartDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedStartDateInitial()));
    } else {
        sf424V2.setProjectStartDate(null);
    }
    if (pdDoc.getDevelopmentProposal().getRequestedEndDateInitial() != null) {
        sf424V2.setProjectEndDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedEndDateInitial()));
    } else {
        sf424V2.setProjectEndDate(null);
    }
    ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService
            .getBudget(pdDoc.getDevelopmentProposal());

    if (budget != null) {
        if (budget.getTotalCost() != null) {
            sf424V2.setFederalEstimatedFunding(budget.getTotalCost().bigDecimalValue());
        }

        ScaleTwoDecimal costSharingAmount = ScaleTwoDecimal.ZERO;

        for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
            for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
                hasBudgetLineItem = true;
                if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) {
                    costSharingAmount = costSharingAmount.add(lineItem.getCostSharingAmount());
                    List<? extends BudgetLineItemCalculatedAmountContract> calculatedAmounts = lineItem
                            .getBudgetLineItemCalculatedAmounts();
                    for (BudgetLineItemCalculatedAmountContract budgetLineItemCalculatedAmount : calculatedAmounts) {
                        costSharingAmount = costSharingAmount
                                .add(budgetLineItemCalculatedAmount.getCalculatedCostSharing());
                    }

                }
            }
        }
        if (!hasBudgetLineItem && budget.getSubmitCostSharingFlag()) {
            costSharingAmount = budget.getCostSharingAmount();
        }

        sf424V2.setApplicantEstimatedFunding(costSharingAmount.bigDecimalValue());
        BigDecimal projectIncome = BigDecimal.ZERO;
        for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
            projectIncome = projectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
        }
        sf424V2.setProgramIncomeEstimatedFunding(projectIncome);

        ScaleTwoDecimal totalEstimatedAmount = ScaleTwoDecimal.ZERO;
        if (budget.getTotalCost() != null) {
            totalEstimatedAmount = totalEstimatedAmount.add(budget.getTotalCost());
        }
        totalEstimatedAmount = totalEstimatedAmount.add(costSharingAmount);
        totalEstimatedAmount = totalEstimatedAmount.add(new ScaleTwoDecimal(projectIncome));
        sf424V2.setTotalEstimatedFunding(totalEstimatedAmount.bigDecimalValue());
    } else {
        sf424V2.setFederalEstimatedFunding(BigDecimal.ZERO);
        sf424V2.setApplicantEstimatedFunding(BigDecimal.ZERO);
        sf424V2.setProgramIncomeEstimatedFunding(BigDecimal.ZERO);
        sf424V2.setTotalEstimatedFunding(BigDecimal.ZERO);
    }
    sf424V2.setStateEstimatedFunding(BigDecimal.ZERO);
    sf424V2.setLocalEstimatedFunding(BigDecimal.ZERO);
    sf424V2.setOtherEstimatedFunding(BigDecimal.ZERO);
    sf424V2.setStateReview(getStateReviewCode());
    if (strReview != null && strReview.equals(STATE_REVIEW_YES)) {
        Calendar reviewDate = null;
        reviewDate = s2SDateTimeService.convertDateStringToCalendar(stateReviewDate);
        sf424V2.setStateReviewAvailableDate(reviewDate);
    }
    YesNoDataType.Enum yesNo = YesNoDataType.N_NO;
    OrganizationContract applicantOrganization = pdDoc.getDevelopmentProposal().getApplicantOrganization()
            .getOrganization();
    if (applicantOrganization != null) {
        for (OrganizationYnqContract orgYnq : applicantOrganization.getOrganizationYnqs()) {
            if (orgYnq.getQuestionId() != null && orgYnq.getQuestionId().equals(PROPOSAL_YNQ_FEDERAL_DEBTS)) {
                String orgYnqanswer = orgYnq.getAnswer();
                if (orgYnqanswer != null) {
                    if (orgYnqanswer.equalsIgnoreCase(ORGANIZATION_YNQ_ANSWER_YES)) {
                        yesNo = YesNoDataType.Y_YES;
                    } else {
                        yesNo = YesNoDataType.N_NO;
                    }
                }
                federalDebtExp = orgYnq.getExplanation();
            }
        }
    }
    sf424V2.setDelinquentFederalDebt(yesNo);
    if (sf424V2.getDelinquentFederalDebt() != null
            && sf424V2.getDelinquentFederalDebt().equals(YesNoDataType.Y_YES)) {
        sf424V2.setDelinquentFederalDebtExplanation(federalDebtExp);
    }
    sf424V2.setCertificationAgree(YesNoDataType.Y_YES);
    sf424V2.setAuthorizedRepresentative(globLibV20Generator.getHumanNameDataType(aorInfo));
    if (aorInfo.getPrimaryTitle() != null) {
        if (aorInfo.getPrimaryTitle().length() > PRIMARY_TITLE_MAX_LENGTH) {
            sf424V2.setAuthorizedRepresentativeTitle(
                    aorInfo.getPrimaryTitle().substring(0, PRIMARY_TITLE_MAX_LENGTH));
        } else {
            sf424V2.setAuthorizedRepresentativeTitle(aorInfo.getPrimaryTitle());
        }
    } else {
        sf424V2.setAuthorizedRepresentativeTitle(null);
    }
    sf424V2.setAuthorizedRepresentativePhoneNumber(aorInfo.getOfficePhone());
    sf424V2.setAuthorizedRepresentativeEmail(aorInfo.getEmailAddress());
    sf424V2.setAuthorizedRepresentativeFax(aorInfo.getFaxNumber());
    sf424V2.setAORSignature(aorInfo.getFullName());
    sf424V2.setDateSigned(Calendar.getInstance());
    return sf424V2;
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.SF424V2_1Generator.java

/**
 * /*from   w  w w.ja  va2 s.c  o m*/
 * This method gets SF42421 information for the form which includes informations regarding SubmissionTypeCode
 * ApplicationType,RevisionType,AgencyName,ApplicantID,CFDANumber,FederalEntityIdentifier,AuthorizedRepresentative.
 * 
 * @return sf424V21 object containing applicant and application details.
 */
private SF42421 getSF42421() {

    SF42421 sf424V21 = SF42421.Factory.newInstance();
    sf424V21.setFormVersion(FormVersion.v2_1.getVersion());
    boolean hasBudgetLineItem = false;
    S2sOpportunityContract s2sOpportunity = pdDoc.getDevelopmentProposal().getS2sOpportunity();
    if (s2sOpportunity != null && s2sOpportunity.getS2sSubmissionType() != null) {
        S2sSubmissionTypeContract submissionType = s2sOpportunity.getS2sSubmissionType();
        SubmissionType.Enum subEnum = SubmissionType.Enum.forInt(Integer.parseInt(submissionType.getCode()));
        sf424V21.setSubmissionType(subEnum);
        ApplicationType.Enum applicationTypeEnum = null;
        if (pdDoc.getDevelopmentProposal().getProposalType() != null) {
            String proposalTypeCode = pdDoc.getDevelopmentProposal().getProposalType().getCode();
            if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_NEW, proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.NEW;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RESUBMISSION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RENEWAL,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_CONTINUATION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_REVISION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            }
        }
        sf424V21.setApplicationType(applicationTypeEnum);

        String revisionType = s2sOpportunity.getS2sRevisionType() != null
                ? s2sOpportunity.getS2sRevisionType().getCode()
                : null;
        if (revisionType != null) {
            RevisionType.Enum revType = null;
            if (revisionType.equals(INCREASE_AWARD_CODE)) {
                revType = RevisionType.A_INCREASE_AWARD;

            } else if (revisionType.equals(DECREASE_AWARD_CODE)) {
                revType = RevisionType.B_DECREASE_AWARD;

            } else if (revisionType.equals(INCREASE_DURATION_CODE)) {
                revType = RevisionType.C_INCREASE_DURATION;

            } else if (revisionType.equals(DECREASE_DURATION_CODE)) {
                revType = RevisionType.D_DECREASE_DURATION;

            } else if (revisionType.equals(INCREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.AD_INCREASE_AWARD_DECREASE_DURATION;

            } else if (revisionType.equals(INCREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.AC_INCREASE_AWARD_INCREASE_DURATION;

            } else if (revisionType.equals(DECREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.BD_DECREASE_AWARD_DECREASE_DURATION;

            } else if (revisionType.equals(DECREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.BC_DECREASE_AWARD_INCREASE_DURATION;

            } else if (revisionType.equals(OTHER_SPECIFY_CODE)) {
                revType = RevisionType.E_OTHER_SPECIFY;
            }

            if (revType != null) {
                sf424V21.setRevisionType(revType);
            }
            if (revisionType.startsWith(REVISIONCODE_STARTS_WITH_E)) {
                sf424V21.setRevisionOtherSpecify(s2sOpportunity.getRevisionOtherDescription());
            }
        }
    }
    sf424V21.setDateReceived(Calendar.getInstance());
    sf424V21.setApplicantID(pdDoc.getDevelopmentProposal().getProposalNumber());
    String federalId = getSubmissionInfoService()
            .getFederalId(pdDoc.getDevelopmentProposal().getProposalNumber());
    if (federalId != null) {
        sf424V21.setFederalEntityIdentifier(federalId);
    }

    OrganizationContract organization = null;
    organization = pdDoc.getDevelopmentProposal().getApplicantOrganization().getOrganization();
    if (organization != null) {
        sf424V21.setOrganizationName(organization.getOrganizationName());
        sf424V21.setEmployerTaxpayerIdentificationNumber(organization.getFederalEmployerId());
        sf424V21.setDUNSNumber(organization.getDunsNumber());
        sf424V21.setOrganizationAffiliation(organization.getOrganizationName());
    } else {
        sf424V21.setOrganizationName(null);
        sf424V21.setEmployerTaxpayerIdentificationNumber(null);
        sf424V21.setDUNSNumber(null);
    }
    RolodexContract rolodex = null;
    rolodex = pdDoc.getDevelopmentProposal().getApplicantOrganization().getRolodex();
    sf424V21.setApplicant(globLibV20Generator.getAddressDataType(rolodex));
    String departmentName = null;
    if (pdDoc.getDevelopmentProposal().getOwnedByUnit() != null) {
        departmentName = pdDoc.getDevelopmentProposal().getOwnedByUnit().getUnitName();
    }
    if (departmentName != null) {
        sf424V21.setDepartmentName(StringUtils.substring(departmentName, 0, DEPARTMENT_NAME_MAX_LENGTH));
    }
    String divisionName = getDivisionName(pdDoc);
    if (divisionName != null) {
        sf424V21.setDivisionName(StringUtils.substring(divisionName, 0, DIVISION_NAME_MAX_LENGTH));
    }
    ProposalPersonContract personInfo = s2SProposalPersonService.getPrincipalInvestigator(pdDoc);
    if (personInfo != null) {
        sf424V21.setContactPerson(globLibV20Generator.getHumanNameDataType(personInfo));
        if (personInfo.getDirectoryTitle() != null) {
            String directoryTitle = personInfo.getDirectoryTitle();
            directoryTitle = directoryTitle.length() > 45 ? directoryTitle.substring(0, 44) : directoryTitle;
            sf424V21.setTitle(directoryTitle);
        }
        sf424V21.setPhoneNumber(personInfo.getOfficePhone());
        if (StringUtils.isNotEmpty(personInfo.getFaxNumber())) {
            sf424V21.setFax(personInfo.getFaxNumber());
        }
        sf424V21.setEmail(personInfo.getEmailAddress());
    } else {
        sf424V21.setPhoneNumber(null);
        sf424V21.setEmail(null);
    }

    setApplicatTypeCodes(sf424V21);

    if (pdDoc.getDevelopmentProposal().getSponsor() != null) {
        sf424V21.setAgencyName(pdDoc.getDevelopmentProposal().getSponsor().getSponsorName());
    }
    if (pdDoc.getDevelopmentProposal().getCfdaNumber() != null) {
        sf424V21.setCFDANumber(pdDoc.getDevelopmentProposal().getCfdaNumber());
    }
    if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle() != null) {
        String announcementTitle;
        if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle()
                .length() > PROGRAM_ANNOUNCEMENT_TITLE_LENGTH) {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle().substring(0,
                    PROGRAM_ANNOUNCEMENT_TITLE_LENGTH);
        } else {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle();
        }
        sf424V21.setCFDAProgramTitle(announcementTitle);
    }
    if (pdDoc.getDevelopmentProposal().getS2sOpportunity() != null) {
        sf424V21.setFundingOpportunityNumber(
                pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId());
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle() != null) {
            sf424V21.setFundingOpportunityTitle(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle());
        }
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId() != null) {
            sf424V21.setCompetitionIdentificationNumber(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId());
        }
    } else {
        sf424V21.setFundingOpportunityTitle(null);
    }
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null
                && Integer.parseInt(narrative.getNarrativeType().getCode()) == AREAS_AFFECTED_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V21.setAreasAffected(attachedFileDataType);
                break;
            }
        }
    }
    sf424V21.setProjectTitle(pdDoc.getDevelopmentProposal().getTitle());
    AttachmentGroupMin0Max100DataType attachedFileMin0Max100 = AttachmentGroupMin0Max100DataType.Factory
            .newInstance();
    attachedFileMin0Max100.setAttachedFileArray(getAttachedFileDataTypes());
    sf424V21.setAdditionalProjectTitle(attachedFileMin0Max100);
    String congressionalDistrict = organization.getCongressionalDistrict() == null
            ? FieldValueConstants.VALUE_UNKNOWN
            : organization.getCongressionalDistrict();
    if (congressionalDistrict.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
        sf424V21.setCongressionalDistrictApplicant(
                congressionalDistrict.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
    } else {
        sf424V21.setCongressionalDistrictApplicant(congressionalDistrict);
    }
    ProposalSiteContract perfOrganization = pdDoc.getDevelopmentProposal().getPerformingOrganization();
    if (perfOrganization != null) {
        String congDistrictProject = perfOrganization.getFirstCongressionalDistrictName() == null
                ? FieldValueConstants.VALUE_UNKNOWN
                : perfOrganization.getFirstCongressionalDistrictName();
        if (congDistrictProject.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
            sf424V21.setCongressionalDistrictProgramProject(
                    congDistrictProject.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
        } else {
            sf424V21.setCongressionalDistrictProgramProject(congDistrictProject);
        }
    }
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null && Integer.parseInt(
                narrative.getNarrativeType().getCode()) == ADDITIONAL_CONGRESSIONAL_DISTRICTS_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V21.setAdditionalCongressionalDistricts(attachedFileDataType);
                break;
            }
        }
    }
    if (pdDoc.getDevelopmentProposal().getRequestedStartDateInitial() != null) {
        sf424V21.setProjectStartDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedStartDateInitial()));
    } else {
        sf424V21.setProjectStartDate(null);
    }
    if (pdDoc.getDevelopmentProposal().getRequestedEndDateInitial() != null) {
        sf424V21.setProjectEndDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedEndDateInitial()));
    } else {
        sf424V21.setProjectEndDate(null);
    }
    ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService
            .getBudget(pdDoc.getDevelopmentProposal());

    if (budget != null) {
        if (budget.getTotalCost() != null) {
            sf424V21.setFederalEstimatedFunding(budget.getTotalCost().bigDecimalValue());
        }
        ScaleTwoDecimal costSharingAmount = ScaleTwoDecimal.ZERO;

        for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
            for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
                hasBudgetLineItem = true;
                if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) {
                    costSharingAmount = costSharingAmount.add(lineItem.getCostSharingAmount());
                    List<? extends BudgetLineItemCalculatedAmountContract> calculatedAmounts = lineItem
                            .getBudgetLineItemCalculatedAmounts();
                    for (BudgetLineItemCalculatedAmountContract budgetLineItemCalculatedAmount : calculatedAmounts) {
                        costSharingAmount = costSharingAmount
                                .add(budgetLineItemCalculatedAmount.getCalculatedCostSharing());
                    }
                }
            }
        }
        if (!hasBudgetLineItem && budget.getSubmitCostSharingFlag()) {
            costSharingAmount = budget.getCostSharingAmount();
        }
        sf424V21.setApplicantEstimatedFunding(costSharingAmount.bigDecimalValue());
        BigDecimal projectIncome = BigDecimal.ZERO;
        for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
            projectIncome = projectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
        }
        sf424V21.setProgramIncomeEstimatedFunding(projectIncome);

        ScaleTwoDecimal totalEstimatedAmount = ScaleTwoDecimal.ZERO;
        if (budget.getTotalCost() != null) {
            totalEstimatedAmount = totalEstimatedAmount.add(budget.getTotalCost());
        }
        totalEstimatedAmount = totalEstimatedAmount.add(costSharingAmount);
        totalEstimatedAmount = totalEstimatedAmount.add(new ScaleTwoDecimal(projectIncome));
        sf424V21.setTotalEstimatedFunding(totalEstimatedAmount.bigDecimalValue());
    } else {
        sf424V21.setFederalEstimatedFunding(BigDecimal.ZERO);
        sf424V21.setApplicantEstimatedFunding(BigDecimal.ZERO);
        sf424V21.setProgramIncomeEstimatedFunding(BigDecimal.ZERO);
        sf424V21.setTotalEstimatedFunding(BigDecimal.ZERO);
    }
    sf424V21.setStateEstimatedFunding(BigDecimal.ZERO);
    sf424V21.setLocalEstimatedFunding(BigDecimal.ZERO);
    sf424V21.setOtherEstimatedFunding(BigDecimal.ZERO);
    sf424V21.setStateReview(getStateReviewCode());
    if (strReview != null && strReview.equals(STATE_REVIEW_YES)) {
        Calendar reviewDate = null;
        reviewDate = s2SDateTimeService.convertDateStringToCalendar(stateReviewDate);
        sf424V21.setStateReviewAvailableDate(reviewDate);
    }
    YesNoDataType.Enum yesNo = YesNoDataType.N_NO;
    OrganizationContract applicantOrganization = pdDoc.getDevelopmentProposal().getApplicantOrganization()
            .getOrganization();
    if (applicantOrganization != null) {
        for (OrganizationYnqContract orgYnq : applicantOrganization.getOrganizationYnqs()) {
            if (orgYnq.getQuestionId() != null && orgYnq.getQuestionId().equals(PROPOSAL_YNQ_FEDERAL_DEBTS)) {
                String orgYnqanswer = orgYnq.getAnswer();
                if (orgYnqanswer != null) {
                    if (orgYnqanswer.equalsIgnoreCase(ORGANIZATION_YNQ_ANSWER_YES)) {
                        yesNo = YesNoDataType.Y_YES;
                    } else {
                        yesNo = YesNoDataType.N_NO;
                    }
                }
            }
        }
    }
    sf424V21.setDelinquentFederalDebt(yesNo);
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null
                && Integer.parseInt(narrative.getNarrativeType().getCode()) == DEBT_EXPLANATION_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V21.setDebtExplanation(attachedFileDataType);
                break;
            }
        }
    }

    sf424V21.setCertificationAgree(YesNoDataType.Y_YES);
    sf424V21.setAuthorizedRepresentative(globLibV20Generator.getHumanNameDataType(aorInfo));
    if (aorInfo.getPrimaryTitle() != null) {
        if (aorInfo.getPrimaryTitle().length() > PRIMARY_TITLE_MAX_LENGTH) {
            sf424V21.setAuthorizedRepresentativeTitle(
                    aorInfo.getPrimaryTitle().substring(0, PRIMARY_TITLE_MAX_LENGTH));
        } else {
            sf424V21.setAuthorizedRepresentativeTitle(aorInfo.getPrimaryTitle());
        }
    } else {
        sf424V21.setAuthorizedRepresentativeTitle(null);
    }
    sf424V21.setAuthorizedRepresentativePhoneNumber(aorInfo.getOfficePhone());
    sf424V21.setAuthorizedRepresentativeEmail(aorInfo.getEmailAddress());
    sf424V21.setAuthorizedRepresentativeFax(aorInfo.getFaxNumber());
    sf424V21.setAORSignature(aorInfo.getFullName());
    sf424V21.setDateSigned(Calendar.getInstance());
    return sf424V21;
}

From source file:org.kuali.coeus.sys.impl.model.KcDataObjectServiceImpl.java

private void setUpdateFields(KcDataObject kcDataObject) {
    if (!kcDataObject.isUpdateUserSet() && globalVariableService.getUserSession() != null) {
        String principalName = globalVariableService.getUserSession().getPrincipalName();
        String lastPrincipalId = (String) globalVariableService.getUserSession()
                .retrieveObject(Constants.LAST_ACTION_PRINCIPAL_ID);
        if (StringUtils.isNotBlank(lastPrincipalId)) {
            principalName = identityService.getPrincipal(lastPrincipalId).getPrincipalName();
        }/*  www .  ja  v  a2 s .c om*/

        kcDataObject.setUpdateUser(principalName);
    }

    kcDataObject.setUpdateTimestamp(new Timestamp(new java.util.Date().getTime()));

    if (kcDataObject.getUpdateUser() != null) {
        kcDataObject.setUpdateUser(
                StringUtils.substring(kcDataObject.getUpdateUser(), 0, KcDataObject.UPDATE_USER_LENGTH));
    }
}

From source file:org.kuali.kra.institutionalproposal.home.InstitutionalProposalNotepad.java

@Override
protected void prePersist() {
    super.prePersist();

    if (createUser == null) {
        setCreateUser(StringUtils.substring(getGlobalVariableService().getUserSession().getPrincipalName(), 0,
                UPDATE_USER_LENGTH));//from   w ww . j  a  v  a2s. co m
    }

    if (createTimestamp == null) {
        Calendar cl = Calendar.getInstance();
        setCreateTimestamp(new Date(cl.getTime().getTime()));
    }
}

From source file:org.maodian.flyingcat.xmpp.codec.SASLCodec.java

@Override
public Object decode(XMLStreamReader xmlsr) {
    String mechanism = xmlsr.getAttributeValue("", "mechanism");
    if (StringUtils.equals("PLAIN", mechanism)) {
        String base64Data = null;
        try {/*from w  ww  .j a v  a  2  s  . c o m*/
            base64Data = xmlsr.getElementText();
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        }

        if (!Base64.isBase64(base64Data)) {
            throw new XmppException(SASLError.INCORRECT_ENCODING);
        }

        byte[] value = Base64.decodeBase64(base64Data);
        String text = new String(value, StandardCharsets.UTF_8);

        // apply PLAIN SASL mechanism whose rfc locates at http://tools.ietf.org/html/rfc4616
        int[] nullPosition = { -1, -1 };
        int nullIndex = 0;
        for (int i = 0; i < text.length(); ++i) {
            if (text.codePointAt(i) == 0) {
                // a malicious base64 value may contain more than two null character
                if (nullIndex > 1) {
                    throw new XmppException(SASLError.MALFORMED_REQUEST);
                }
                nullPosition[nullIndex++] = i;
            }
        }

        if (nullPosition[0] == -1 || nullPosition[1] == -1) {
            throw new XmppException("The format is invalid", SASLError.MALFORMED_REQUEST);
        }
        String authzid = StringUtils.substring(text, 0, nullPosition[0]);
        String authcid = StringUtils.substring(text, nullPosition[0] + 1, nullPosition[1]);
        String password = StringUtils.substring(text, nullPosition[1] + 1);

        if (authzid.getBytes(StandardCharsets.UTF_8).length > 255
                || authcid.getBytes(StandardCharsets.UTF_8).length > 255
                || password.getBytes(StandardCharsets.UTF_8).length > 255) {
            throw new XmppException(
                    "authorization id, authentication id and password should be equal or less than 255 bytes",
                    SASLError.MALFORMED_REQUEST);
        }
        return new Auth(authzid, authcid, password);
    } else {
        throw new XmppException(SASLError.INVALID_MECHANISM).set("mechanism", mechanism);
    }
}

From source file:org.maodian.flyingcat.xmpp.entity.JabberID.java

public static JabberID fromString(String str) {
    int atIndex = StringUtils.indexOf(str, "@");
    if (atIndex < 1) {
        // TODO: JID mailformed stanzs error
        throw new RuntimeException("JID not well formed");
    }/*from www  .j a v a 2  s .  c o  m*/
    String uid = StringUtils.substring(str, 0, atIndex);
    int slashIndex = StringUtils.indexOf(str, "/");
    if (slashIndex == str.length()) {
        // TODO: JID mailformed stanzs error
        throw new RuntimeException("JID not well formed");
    }
    if (slashIndex != -1) {
        String domain = StringUtils.substring(str, atIndex + 1, slashIndex);
        String resource = StringUtils.substring(str, slashIndex);
        return new JabberID(uid, domain, resource);
    } else {
        String domain = StringUtils.substring(str, atIndex + 1);
        return new JabberID(uid, domain);
    }
}

From source file:org.massyframework.modules.launching.DefaultAssemblyResourceLoader.java

protected List<ClassLoader> parserClassLoader(String identifiers) throws ModuleLoadException {
    List<ClassLoader> result = new ArrayList<ClassLoader>();
    if (identifiers != null) {
        String[] names = StringUtils.split(identifiers, ",");
        for (String name : names) {
            name = StringUtils.deleteWhitespace(name);
            if (!"".equals(name)) {
                int index = StringUtils.indexOf(name, ":");
                String moduleName = name;
                String slot = "main";
                if (index != -1) {
                    moduleName = StringUtils.substring(name, 0, index);
                    slot = StringUtils.substring(name, index + 1, name.length());
                }//from w  w w. jav a 2  s .co m
                ModuleIdentifier identifier = ModuleIdentifier.create(moduleName, slot);
                Module module = this.moduleLoader.loadModule(identifier);
                result.add(module.getClassLoader());
            }
        }
    }

    return result;
}

From source file:org.massyframework.modules.launching.ModuleIdentifierUtils.java

/**
 * ????ModuleIdentifier//  w  w  w . ja  va 2  s . c o m
 * @param moduleName ???
 * @return {@link ModuleIdentifier}
 */
public static ModuleIdentifier parse(String moduleName) {
    if (moduleName == null)
        return null;

    int index = StringUtils.indexOf(moduleName, DELIMITER);
    if (index == -1) {
        return ModuleIdentifier.create(moduleName);
    } else {
        String name = StringUtils.substring(moduleName, 0, index);
        String slot = StringUtils.substring(moduleName, index + 1, moduleName.length());
        return ModuleIdentifier.create(name, slot);
    }

}

From source file:org.massyframework.modules.utils.SunJdkModuleExporter.java

/**
 * ?SunJdk??//from  ww  w .ja v a2 s  .c  o m
 * 
 * @param fileName
 * @return
 * @throws IOException
 */
protected List<String> getSunJdkPackageNames(String rtJar) throws IOException {
    Set<String> packageNames = new HashSet<String>();
    JarFile file = null;
    try {
        file = new JarFile(rtJar);
        Enumeration<JarEntry> em = file.entries();
        while (em.hasMoreElements()) {
            JarEntry entry = em.nextElement();
            if (!entry.isDirectory()) {
                String name = entry.getName();
                if (name.endsWith(".class")) {
                    int index = StringUtils.lastIndexOf(name, "/");
                    packageNames.add(StringUtils.substring(name, 0, index));
                }
            }
        }
    } finally {
        IOUtils.closeStream(file);
    }
    List<String> result = new ArrayList<String>(packageNames);
    Collections.sort(result);
    return result;
}

From source file:org.nanoframework.orm.jedis.AbstractRedisClient.java

protected Map<String, String> info0(final String info) {
    final String[] attributes = info.split("\n");
    final Map<String, String> decodeInfo = Maps.newLinkedHashMap();
    for (final String attribute : attributes) {
        if (!StringUtils.isEmpty(StringUtils.trim(attribute)) && !StringUtils.startsWith(attribute, "#")) {
            final String[] keyvalue = attribute.substring(0, attribute.length() - 1).split(":");
            if (keyvalue.length == 2) {
                final String key = keyvalue[0];
                final String value = StringUtils.endsWith(keyvalue[1], "\r")
                        ? StringUtils.substring(keyvalue[1], 0, keyvalue[1].length() - 1)
                        : keyvalue[1];/*w  ww .j a va  2 s  . co m*/
                decodeInfo.put(key, value);
            } else {
                decodeInfo.put(keyvalue[0], "");
            }
        }
    }

    return decodeInfo;
}