private void setNarrativePermissions(
      Person user, ProposalDevelopmentDocument doc, Set<String> editModes) {

    List<Narrative> narratives = doc.getDevelopmentProposal().getNarratives();
    synchronized (narratives) {
      for (Narrative narrative : narratives) {
        String prefix = "proposalAttachment." + narrative.getModuleNumber() + ".";
        if (isAuthorizedToViewNarrative(narrative, user)) {
          editModes.add(prefix + "download");
        }
        if (isAuthorizedToReplaceNarrative(narrative, user)) {
          editModes.add(prefix + "replace");
        }
        if (isAuthorizedToDeleteNarrative(narrative, user)) {
          editModes.add(prefix + "delete");
        }
        if (isAuthorizedToModifyNarrative(narrative, user)) {
          editModes.add(prefix + "modifyStatus");
        }
        if (isAuthorizedToModifyNarrative(narrative, user)) {
          editModes.add(prefix + "modifyRights");
        }
      }

      narratives = doc.getDevelopmentProposal().getInstituteAttachments();
      for (Narrative narrative : narratives) {
        String prefix = "instituteAttachment." + narrative.getModuleNumber() + ".";
        if (isAuthorizedToViewNarrative(narrative, user)) {
          editModes.add(prefix + "download");
        }
        if (isAuthorizedToReplaceNarrative(narrative, user)) {
          editModes.add(prefix + "replace");
        }
        if (isAuthorizedToDeleteNarrative(narrative, user)) {
          editModes.add(prefix + "delete");
        }
        if (isAuthorizedToModifyNarrative(narrative, user)) {
          editModes.add(prefix + "modifyRights");
        }
      }

      int i = 0;
      boolean canReplace = isAuthorizedToReplacePersonnelAttachement(doc, user);
      for (ProposalPersonBiography ppb : doc.getDevelopmentProposal().getPropPersonBios()) {
        ppb.setPositionNumber(i);
        String prefix = "biographyAttachments." + ppb.getPositionNumber() + ".";
        if (canReplace) {
          editModes.add(prefix + "replace");
        }

        i++;
      }
    }
  }
  public boolean isAuthorizedToDeleteNarrative(Narrative narrative, Person user) {
    final ProposalDevelopmentDocument pdDocument =
        (ProposalDevelopmentDocument) narrative.getDevelopmentProposal().getDocument();

    // First, the user must have the MODIFY_NARRATIVE permission.  This is really
    // a sanity check.  If they have the MODIFY_NARRATIVE_RIGHT, then they are
    // required to have the MODIFY_NARRATIVE permission.

    KcDocumentRejectionService documentRejectionService = getKcDocumentRejectionService();
    boolean rejectedDocument =
        documentRejectionService.isDocumentOnInitialNode(
            pdDocument.getDocumentHeader().getWorkflowDocument());
    boolean hasPermission = false;

    boolean inWorkflow = getKcWorkflowService().isInWorkflow(pdDocument);

    if ((!inWorkflow || rejectedDocument) && !pdDocument.getDevelopmentProposal().getSubmitFlag()) {
      if (getModifyNarrativePermission(pdDocument, user)) {
        hasPermission =
            hasNarrativeRight(
                user.getPrincipalId(), narrative, NarrativeRight.MODIFY_NARRATIVE_RIGHT);
      }
    }
    return hasPermission;
  }
  protected boolean isAuthorizedToViewNarrative(Narrative narrative, Person user) {
    final ProposalDevelopmentDocument pdDocument =
        (ProposalDevelopmentDocument) narrative.getDevelopmentProposal().getDocument();

    // First, the user must have the VIEW_NARRATIVE permission.  This is really
    // a sanity check.  If they have the VIEW or MODIFY_NARRATIVE_RIGHT, then they are
    // required to have the VIEW_NARRATIVE permission.

    boolean hasPermission = false;
    if (getKcAuthorizationService()
        .hasPermission(user.getPrincipalId(), pdDocument, PermissionConstants.VIEW_NARRATIVE)) {
      hasPermission =
          hasNarrativeRight(user.getPrincipalId(), narrative, NarrativeRight.VIEW_NARRATIVE_RIGHT)
              || hasNarrativeRight(
                  user.getPrincipalId(), narrative, NarrativeRight.MODIFY_NARRATIVE_RIGHT);
    }

    if (!hasPermission) {
      hasPermission =
          getUnitAuthorizationService()
                  .hasPermission(
                      user.getPrincipalId(),
                      pdDocument.getDevelopmentProposal().getOwnedByUnitNumber(),
                      Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                      PermissionConstants.VIEW_NARRATIVE)
              || getKcWorkflowService().hasWorkflowPermission(user.getPrincipalId(), pdDocument);
    }

    return hasPermission;
  }
 /**
  * Does the user have the given narrative right for the given narrative?
  *
  * @param userId the username of the user
  * @param narrative the narrative
  * @param narrativeRight the narrative right we are looking for
  * @return true if the user has the narrative right for the narrative
  */
 protected final boolean hasNarrativeRight(
     String userId, Narrative narrative, NarrativeRight narrativeRight) {
   List<NarrativeUserRights> userRightsList = narrative.getNarrativeUserRights();
   for (NarrativeUserRights userRights : userRightsList) {
     if (StringUtils.equals(userId, userRights.getUserId())) {
       if (StringUtils.equals(userRights.getAccessType(), narrativeRight.getAccessType())) {
         return true;
       }
     }
   }
   return false;
 }
  protected boolean isAuthorizedToReplaceNarrative(Narrative narrative, Person user) {
    final ProposalDevelopmentDocument pdDocument =
        (ProposalDevelopmentDocument) narrative.getDevelopmentProposal().getDocument();

    boolean hasPermission = false;
    if (!pdDocument.getDevelopmentProposal().getSubmitFlag()
        && getModifyNarrativePermission(pdDocument, user)) {
      hasPermission =
          hasNarrativeRight(user.getPrincipalId(), narrative, NarrativeRight.MODIFY_NARRATIVE_RIGHT)
              || isAuthorizedToAlterProposalData(pdDocument, user);
    }

    return hasPermission;
  }
  protected boolean isAuthorizedToModifyNarrative(Narrative narrative, Person user) {
    final ProposalDevelopmentDocument pdDocument =
        (ProposalDevelopmentDocument) narrative.getDevelopmentProposal().getDocument();

    boolean rejectedDocument =
        getKcDocumentRejectionService()
            .isDocumentOnInitialNode(pdDocument.getDocumentHeader().getWorkflowDocument());
    boolean hasPermission = false;
    boolean inWorkflow = getKcWorkflowService().isInWorkflow(pdDocument);

    if ((!inWorkflow || rejectedDocument) && !pdDocument.getDevelopmentProposal().getSubmitFlag()) {
      hasPermission = getModifyNarrativePermission(pdDocument, user);
    } else if (inWorkflow
        && !rejectedDocument
        && !pdDocument.getDevelopmentProposal().getSubmitFlag()) {
      if (getModifyNarrativePermission(pdDocument, user)) {
        hasPermission = getModifyNarrativePermission(pdDocument, user);
      }
    }
    return hasPermission;
  }
Example #7
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;
  }
  @Override
  protected void prepareData(ProposalDevelopmentDocument document) throws Exception {

    Narrative narrative = new Narrative();
    List<Narrative> naList = new ArrayList<Narrative>();
    NarrativeAttachment narrativeAttachment = new NarrativeAttachment();
    DefaultResourceLoader resourceLoader =
        new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
    Resource resource = resourceLoader.getResource(S2STestConstants.ATT_PACKAGE + "/exercise1.pdf");
    InputStream inStream = resource.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(inStream);
    byte[] narrativePdf = new byte[bis.available()];
    narrativeAttachment.setData(narrativePdf);
    narrativeAttachment.setName("exercise1.pdf");

    narrative.setDevelopmentProposal(document.getDevelopmentProposal());
    narrative.setModuleNumber(1);
    narrative.setModuleSequenceNumber(1);
    narrative.setModuleStatusCode("C");
    narrative.setNarrativeTypeCode("53");
    narrative.setNarrativeAttachment(narrativeAttachment);
    narrative.setObjectId("12345678890abcd");
    narrative.setName("exercise1");
    NarrativeType narrativeType = new NarrativeType();
    narrativeType.setCode("53");
    narrativeType.setAllowMultiple(true);
    narrativeType.setSystemGenerated(false);
    narrativeType.setDescription("Testing for Project Attachment");
    getService(DataObjectService.class).save(narrativeType);
    narrative.setNarrativeType(narrativeType);
    narrative.setNarrativeTypeCode("53");

    naList.add(narrative);

    document.getDevelopmentProposal().setNarratives(naList);
    saveBO(document.getDevelopmentProposal());
  }
Example #9
0
  @Override
  protected void prepareData(ProposalDevelopmentDocument document) throws Exception {

    Organization organization =
        getService(DataObjectService.class)
            .findUnique(
                Organization.class,
                QueryByCriteria.Builder.forAttribute("organizationId", "000001").build());
    document.getDevelopmentProposal().getApplicantOrganization().setOrganization(organization);

    NarrativeAttachment narrativeAttachment = new NarrativeAttachment();
    DefaultResourceLoader resourceLoader =
        new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
    Resource resource = resourceLoader.getResource(S2STestConstants.ATT_PACKAGE + "/exercise2.pdf");
    InputStream inputStream = resource.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(inputStream);
    byte[] narrativePdf = new byte[bis.available()];
    narrativeAttachment.setData(narrativePdf);
    narrativeAttachment.setName("exercise1");
    Narrative narrative = new Narrative();
    List<Narrative> narrativeList = new ArrayList<Narrative>();
    narrative.setDevelopmentProposal(document.getDevelopmentProposal());
    NarrativeType narrativeType =
        getService(DataObjectService.class)
            .findUnique(
                NarrativeType.class, QueryByCriteria.Builder.forAttribute("code", "7").build());
    narrative.setName("exercise1");
    narrative.setNarrativeType(narrativeType);
    narrative.setNarrativeTypeCode(narrativeType.getCode());
    narrative.setNarrativeAttachment(narrativeAttachment);
    narrative.setModuleNumber(1);
    narrative.setModuleSequenceNumber(1);
    narrative.setModuleStatusCode("C");
    narrativeList.add(narrative);
    document.getDevelopmentProposal().setNarratives(narrativeList);

    List<ProposalPerson> proposalPersons = new ArrayList<ProposalPerson>();
    ProposalPerson principalInvestigator = new ProposalPerson();
    principalInvestigator.setFirstName("ALAN");
    principalInvestigator.setLastName("MCAFEE");
    principalInvestigator.setProposalPersonRoleId("PI");
    principalInvestigator.setPersonId("0001");
    principalInvestigator.setRolodexId(0010);
    principalInvestigator.setProposalPersonNumber(1);
    principalInvestigator.setDevelopmentProposal(document.getDevelopmentProposal());
    proposalPersons.add(principalInvestigator);
    document.getDevelopmentProposal().setProposalPersons(proposalPersons);

    ProposalDevelopmentBudgetExt proposalDevelopmentBudgetExt = new ProposalDevelopmentBudgetExt();
    proposalDevelopmentBudgetExt.setDevelopmentProposal(document.getDevelopmentProposal());
    proposalDevelopmentBudgetExt.setBudgetVersionNumber(1);
    proposalDevelopmentBudgetExt.setBudgetStatus("1");
    proposalDevelopmentBudgetExt.setBudgetId(1L);
    proposalDevelopmentBudgetExt.setName("test Document Description");
    proposalDevelopmentBudgetExt.setOnOffCampusFlag("Y");
    proposalDevelopmentBudgetExt.setStartDate(new Date(new Long("1183316613046")));
    proposalDevelopmentBudgetExt.setEndDate(new Date(new Long("1214852613046")));
    proposalDevelopmentBudgetExt.setOhRateTypeCode("1");
    proposalDevelopmentBudgetExt.setOhRateClassCode("1");
    proposalDevelopmentBudgetExt.setModularBudgetFlag(false);
    proposalDevelopmentBudgetExt.setUrRateClassCode("1");

    List<BudgetPeriod> budgetPeriods = new ArrayList<BudgetPeriod>();
    BudgetPeriod budgetPeriod = new BudgetPeriod();
    budgetPeriod.setBudgetPeriodId(1L);
    budgetPeriod.setStartDate(new Date(new Long("1183316613046")));
    budgetPeriod.setEndDate(new Date(new Long("1214852613046")));
    budgetPeriod.setBudgetPeriod(1);

    budgetPeriod.setBudget(proposalDevelopmentBudgetExt);
    budgetPeriods.add(budgetPeriod);
    proposalDevelopmentBudgetExt.setBudgetPeriods(budgetPeriods);

    List<ProposalDevelopmentBudgetExt> proposalDevelopmentBudgetExtList =
        new ArrayList<ProposalDevelopmentBudgetExt>();
    proposalDevelopmentBudgetExtList.add(proposalDevelopmentBudgetExt);
    document.getDevelopmentProposal().setBudgets(proposalDevelopmentBudgetExtList);
    document.getDevelopmentProposal().setFinalBudget(proposalDevelopmentBudgetExt);
  }