Exemplo n.º 1
0
  /**
   * This method gives information of applications that are used in RRSF424
   *
   * @return rrSF424Document {@link XmlObject} of type RRSF424Document.
   */
  private RRSF424Document getRRSF424() {
    DevelopmentProposal devProp = pdDoc.getDevelopmentProposal();

    RRSF424Document rrSF424Document = RRSF424Document.Factory.newInstance();
    RRSF424 rrsf424 = RRSF424.Factory.newInstance();
    rrsf424.setFormVersion(S2SConstants.FORMVERSION_1_1);
    S2sOpportunity s2sOpportunity = devProp.getS2sOpportunity();
    if (s2sOpportunity != null && s2sOpportunity.getS2sSubmissionTypeCode() != null) {
      s2sOpportunity.refreshNonUpdateableReferences();
      rrsf424.setSubmissionTypeCode(
          SubmissionTypeDataType.Enum.forString(
              devProp.getS2sOpportunity().getS2sSubmissionType().getDescription()));
    }
    rrsf424.setSubmittedDate(Calendar.getInstance());
    Organization applicantOrganization = devProp.getApplicantOrganization().getOrganization();
    if (applicantOrganization != null && applicantOrganization.getRolodex() != null) {
      String state = applicantOrganization.getRolodex().getState();
      rrsf424.setStateID(state);
    }
    String federalId = proposalDevelopmentService.getFederalId(pdDoc);
    if (federalId != null) {
      if (federalId.length() > 30) {
        rrsf424.setFederalID(federalId.substring(0, 30));
      } else {
        rrsf424.setFederalID(federalId);
      }
    }
    rrsf424.setApplicantInfo(getApplicationInfo());
    rrsf424.setApplicantType(getApplicantType());
    rrsf424.setApplicationType(getApplicationType());
    boolean isNih =
        isSponsorInHierarchy(pdDoc.getDevelopmentProposal(), SPONSOR_GROUPS, SPONSOR_NIH);
    if (applicantOrganization != null) {
      if (applicantOrganization.getPhsAccount() != null && isNih) {
        rrsf424.setEmployerID(applicantOrganization.getPhsAccount());
      } else {
        rrsf424.setEmployerID(applicantOrganization.getFedralEmployerId());
      }
    }
    Sponsor sponsor = devProp.getSponsor();
    if (sponsor != null) {
      rrsf424.setFederalAgencyName(sponsor.getSponsorName());
    }
    if (devProp.getCfdaNumber() != null) {
      rrsf424.setCFDANumber(devProp.getCfdaNumber());
    }
    if (devProp.getProgramAnnouncementTitle() != null) {
      String announcementTitle;
      if (devProp.getProgramAnnouncementTitle().length() > 120) {
        announcementTitle = devProp.getProgramAnnouncementTitle().substring(0, 120);
      } else {
        announcementTitle = devProp.getProgramAnnouncementTitle();
      }
      rrsf424.setActivityTitle(announcementTitle);
    }
    rrsf424.setProjectTitle(devProp.getTitle());
    if (devProp.getProposalAbstracts() != null) {
      List<ProposalAbstract> proposalAbstractList = devProp.getProposalAbstracts();
      String state = "";
      for (ProposalAbstract proposalAbstract : proposalAbstractList) {
        if (proposalAbstract.getAbstractTypeCode().equals(AREAS_AFFECTED_ABSTRACT_TYPE_CODE))
          state = proposalAbstract.getAbstractDetails();
      }
      rrsf424.setLocation(state);
    }
    rrsf424.setProposedProjectPeriod(getProjectPeriod());
    rrsf424.setCongressionalDistrict(getCongDistrict());
    rrsf424.setPDPIContactInfo(getPDPI());
    try {
      rrsf424.setEstimatedProjectFunding(getProjectFunding());
    } catch (S2SException e) {
      LOG.error(e.getMessage(), e);
      return rrSF424Document;
    }
    rrsf424.setStateReview(getStateReview());
    // Value is hardcoded
    rrsf424.setTrustAgree(YesNoDataType.Y_YES);
    rrsf424.setAORInfo(getAORInfoType());
    for (Narrative narrative : devProp.getNarratives()) {
      AttachedFileDataType attachedFileDataType = null;
      switch (Integer.parseInt(narrative.getNarrativeTypeCode())) {
        case (PRE_APPLICATION):
          attachedFileDataType = getAttachedFileType(narrative);
          if (attachedFileDataType != null) {
            rrsf424.setPreApplicationAttachment(attachedFileDataType);
          }
          break;
        case (ADDITIONAL_CONGRESSIONAL_DESTRICT):
          attachedFileDataType = getAttachedFileType(narrative);
          if (attachedFileDataType != null) {
            rrsf424.setAdditionalCongressionalDistricts(attachedFileDataType);
          }
          break;
      }
    }
    if (departmentalPerson != null) {
      rrsf424.setAORSignature(departmentalPerson.getFullName());
    } else {
      rrsf424.setAORSignature("");
    }
    rrsf424.setAORSignedDate(Calendar.getInstance());
    rrSF424Document.setRRSF424(rrsf424);
    return rrSF424Document;
  }
  @Transactional
  @RequestMapping(
      value = "/proposalDevelopment",
      params = {"methodToCall=refresh", "refreshCaller=S2sOpportunity-LookupView"})
  public ModelAndView refresh(
      @ModelAttribute("KualiForm") ProposalDevelopmentDocumentForm form,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    ProposalDevelopmentDocument document = form.getProposalDevelopmentDocument();
    DevelopmentProposal proposal = document.getDevelopmentProposal();
    if (form.getNewS2sOpportunity() != null
        && StringUtils.isNotEmpty(form.getNewS2sOpportunity().getOpportunityId())) {

      proposal.setS2sOpportunity(form.getNewS2sOpportunity());
      proposal.getS2sOpportunity().setDevelopmentProposal(proposal);

      // Set default S2S Submission Type
      if (StringUtils.isBlank(form.getNewS2sOpportunity().getS2sSubmissionTypeCode())) {
        String defaultS2sSubmissionTypeCode =
            getProposalTypeService().getDefaultSubmissionTypeCode(proposal.getProposalTypeCode());
        proposal.getS2sOpportunity().setS2sSubmissionTypeCode(defaultS2sSubmissionTypeCode);
        getDataObjectService()
            .wrap(proposal.getS2sOpportunity())
            .fetchRelationship("s2sSubmissionType");
      }

      final String opportunityTitle = form.getNewS2sOpportunity().getOpportunityTitle();
      String trimmedTitle =
          StringUtils.substring(
              opportunityTitle, 0, ProposalDevelopmentConstants.S2sConstants.OPP_TITLE_MAX_LENGTH);
      // Set Opportunity Title and Opportunity ID in the Sponsor & Program Information section
      proposal.setProgramAnnouncementTitle(trimmedTitle);
      proposal.setCfdaNumber(form.getNewS2sOpportunity().getCfdaNumber());
      proposal.setProgramAnnouncementNumber(form.getNewS2sOpportunity().getOpportunityId());
      form.setNewS2sOpportunity(new S2sOpportunity());
    }

    S2sOpportunity s2sOpportunity = proposal.getS2sOpportunity();

    try {
      if (s2sOpportunity != null && s2sOpportunity.getSchemaUrl() != null) {
        List<String> missingMandatoryForms =
            s2sSubmissionService.setMandatoryForms(proposal, s2sOpportunity);

        if (!CollectionUtils.isEmpty(missingMandatoryForms)) {
          globalVariableService
              .getMessageMap()
              .putError(
                  Constants.NO_FIELD,
                  KeyConstants.ERROR_IF_OPPORTUNITY_ID_IS_INVALID,
                  s2sOpportunity.getOpportunityId(),
                  StringUtils.join(missingMandatoryForms, ","));
          proposal.setS2sOpportunity(null);
        }
      }
    } catch (S2sCommunicationException ex) {
      if (ex.getErrorKey().equals(KeyConstants.ERROR_GRANTSGOV_NO_FORM_ELEMENT)) {
        ex.setMessage(s2sOpportunity.getOpportunityId());
      }
      globalVariableService
          .getMessageMap()
          .putError(Constants.NO_FIELD, ex.getErrorKey(), ex.getMessageWithParams());
      proposal.setS2sOpportunity(new S2sOpportunity());
    }
    super.save(form, result, request, response);
    return getRefreshControllerService().refresh(form);
  }