public void saveAnswerHeaders(ProposalDevelopmentDocumentForm pdForm, String pageId) {
   if (StringUtils.equalsIgnoreCase(pageId, Constants.KEY_PERSONNEL_PAGE)
       || StringUtils.equalsIgnoreCase(pageId, Constants.CERTIFICATION_PAGE)) {
     saveUpdatePersonAnswerHeaders(
         pdForm.getProposalDevelopmentDocument().getDevelopmentProposal(), pageId);
   } else if (StringUtils.equalsIgnoreCase(pageId, Constants.QUESTIONS_PAGE)) {
     saveUpdateQuestionnaireAnswerHeaders(pdForm.getQuestionnaireHelper(), pageId);
     saveUpdateQuestionnaireAnswerHeaders(pdForm.getS2sQuestionnaireHelper(), pageId);
   }
 }
 public void addEditableCollectionLine(
     ProposalDevelopmentDocumentForm form, String selectedCollectionPath) {
   if (form.getEditableCollectionLines().containsKey(selectedCollectionPath)) {
     updateEditableCollectionLines(form, selectedCollectionPath);
   } else {
     List<String> newKeyList = new ArrayList<>();
     newKeyList.add("0");
     form.getEditableCollectionLines().put(selectedCollectionPath, newKeyList);
   }
 }
 public void updateEditableCollectionLines(
     ProposalDevelopmentDocumentForm form, String selectedCollectionPath) {
   List<String> indexes = new ArrayList<>();
   indexes.add("0");
   for (String index : form.getEditableCollectionLines().get(selectedCollectionPath)) {
     Integer newIndex = Integer.parseInt(index) + 1;
     indexes.add(newIndex.toString());
   }
   form.getEditableCollectionLines().get(selectedCollectionPath).clear();
   form.getEditableCollectionLines().get(selectedCollectionPath).addAll(indexes);
 }
 public void populateDeferredMessages(
     ProposalDevelopmentDocumentForm proposalDevelopmentDocumentForm) {
   if (proposalDevelopmentDocumentForm.getDeferredMessages() != null
       && proposalDevelopmentDocumentForm.getDeferredMessages().hasMessages()) {
     MessageMap messageMap = proposalDevelopmentDocumentForm.getDeferredMessages();
     MessageMap currentMessageMap = getGlobalVariableService().getMessageMap();
     messageMap.getErrorMessages().putAll(currentMessageMap.getErrorMessages());
     messageMap.getInfoMessages().putAll(currentMessageMap.getInfoMessages());
     messageMap.getWarningMessages().putAll(currentMessageMap.getWarningMessages());
     getGlobalVariableService().setMessageMap(messageMap);
   }
   proposalDevelopmentDocumentForm.setDeferredMessages(null);
 }
 protected ModelAndView navigate(
     ProposalDevelopmentDocumentForm form,
     BindingResult result,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   if (form.getDevelopmentProposal().getS2sOpportunity() != null
       && !getProposalDevelopmentService()
           .isGrantsGovEnabledForProposal(form.getDevelopmentProposal())) {
     ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
         .clearOpportunity(form.getDevelopmentProposal());
   }
   populateAdHocRecipients(form.getProposalDevelopmentDocument());
   String navigateToPageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
   if (isNavigateToDeliveryInfoPage(navigateToPageId)) {
     if (form.getDevelopmentProposal().getS2sOpportunity() != null) {
       getGlobalVariableService()
           .getMessageMap()
           .putInfo(
               ProposalDevelopmentConstants.KradConstants.DELIVERY_INFO_PAGE,
               KeyConstants.DELIVERY_INFO_NOT_NEEDED);
     }
   }
   if (form.isCanEditView()) {
     return save(form);
   } else {
     return getNavigationControllerService().navigate(form);
   }
 }
  public ModelAndView save(
      @ModelAttribute("KualiForm") DocumentFormBase form,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response,
      Class<? extends DocumentEventBase> eventClazz)
      throws Exception {
    ProposalDevelopmentDocumentForm pdForm = (ProposalDevelopmentDocumentForm) form;
    ProposalDevelopmentDocument proposalDevelopmentDocument =
        (ProposalDevelopmentDocument) pdForm.getDocument();
    proposalDevelopmentService.initializeUnitOrganizationLocation(proposalDevelopmentDocument);
    proposalDevelopmentService.initializeProposalSiteNumbers(proposalDevelopmentDocument);

    saveAnswerHeaders(pdForm, request.getParameter(UifParameters.PAGE_ID));

    if (eventClazz == null) {
      getTransactionalDocumentControllerService().save(form);
    } else {
      performCustomSave(proposalDevelopmentDocument, SaveDocumentSpecialReviewEvent.class);
    }

    populateAdHocRecipients(pdForm.getProposalDevelopmentDocument());

    String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
    final ModelAndView view;
    if (StringUtils.isNotBlank(pageId)
        && getGlobalVariableService().getMessageMap().hasNoErrors()) {
      form.setDirtyForm(false);
      view = getModelAndViewService().getModelAndView(form, pageId);
    } else {
      view = getModelAndViewService().getModelAndView(form);
    }

    if (pdForm.getProposalDevelopmentDocument().getDevelopmentProposal() != null
        && pdForm.getProposalDevelopmentDocument().getDevelopmentProposal().getPropSpecialReviews()
            != null) {
      pdForm
          .getProposalDevelopmentDocument()
          .getDevelopmentProposal()
          .getPropSpecialReviews()
          .stream()
          .filter(specialReview -> !specialReview.isLinkedToProtocol())
          .forEach(
              specialReview ->
                  pdForm.getSpecialReviewHelper().prepareProtocolLinkViewFields(specialReview));
    }
    getProjectPublisher()
        .publishProject(
            getPropDevProjectRetrievalService()
                .retrieveProject(
                    pdForm
                        .getProposalDevelopmentDocument()
                        .getDevelopmentProposal()
                        .getProposalNumber()));

    return view;
  }
 public AuditHelper.ValidationState getValidationState(ProposalDevelopmentDocumentForm form) {
   AuditHelper.ValidationState severityLevel = AuditHelper.ValidationState.OK;
   form.setAuditActivated(true);
   List<DataValidationItem> dataValidationItems =
       ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
           .populateDataValidation(form);
   if (dataValidationItems != null && dataValidationItems.size() > 0) {
     for (DataValidationItem validationItem : dataValidationItems) {
       if (StringUtils.endsWith(validationItem.getSeverity(), Constants.AUDIT_ERRORS)) {
         severityLevel = AuditHelper.ValidationState.ERROR;
         break;
       }
       if (StringUtils.equals(validationItem.getSeverity(), Constants.AUDIT_WARNINGS)) {
         severityLevel = AuditHelper.ValidationState.WARNING;
       }
     }
     form.setDataValidationItems(dataValidationItems);
   }
   getGlobalVariableService().getMessageMap().clearErrorMessages();
   return severityLevel;
 }
 /**
  * Method calls the permissions service, where it will determine if any user permissions need to
  * be added and/or removed.
  *
  * @param pdForm ProposalDevelopmentDocumentForm that contains the permissions helper
  */
 public void saveDocumentPermissions(ProposalDevelopmentDocumentForm pdForm) {
   List<String> editableLines =
       pdForm
           .getEditableCollectionLines()
           .get(Constants.PERMISSION_PROPOSAL_USERS_COLLECTION_PROPERTY_KEY);
   if (editableLines != null && editableLines.size() > 0) {
     getGlobalVariableService()
         .getMessageMap()
         .putErrorForSectionId(
             Constants.PERMISSION_PROPOSAL_USERS_COLLECTION_ID_KEY,
             KeyConstants.ERROR_UNFINISHED_PERMISSIONS);
   } else if (arePermissionsValid(
       pdForm.getProposalDevelopmentDocument(), pdForm.getWorkingUserRoles())) {
     getProposalDevelopmentPermissionsService()
         .savePermissions(
             pdForm.getProposalDevelopmentDocument(),
             getProposalDevelopmentPermissionsService()
                 .getPermissions(pdForm.getProposalDevelopmentDocument()),
             pdForm.getWorkingUserRoles());
   }
 }
  public ModelAndView save(ProposalDevelopmentDocumentForm form) throws Exception {
    ProposalDevelopmentDocument proposalDevelopmentDocument =
        (ProposalDevelopmentDocument) form.getDocument();

    if (StringUtils.equalsIgnoreCase(form.getPageId(), Constants.PROP_DEV_PERMISSIONS_PAGE)) {
      saveDocumentPermissions(form);
    }

    if (StringUtils.equalsIgnoreCase(
        form.getPageId(), ProposalDevelopmentDataValidationConstants.ATTACHMENT_PAGE_ID)) {
      ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
          .populateAttachmentReferences(form.getDevelopmentProposal());
    }

    if (getGlobalVariableService().getMessageMap().getErrorCount() == 0
        && form.getEditableCollectionLines() != null) {
      form.getEditableCollectionLines().clear();
    }
    if (StringUtils.equalsIgnoreCase(
        form.getPageId(), ProposalDevelopmentDataValidationConstants.DETAILS_PAGE_ID)) {
      handleSponsorChange(proposalDevelopmentDocument);
    }

    preSave(proposalDevelopmentDocument);

    proposalDevelopmentService.initializeUnitOrganizationLocation(proposalDevelopmentDocument);
    proposalDevelopmentService.initializeProposalSiteNumbers(proposalDevelopmentDocument);

    for (ProposalPersonBiography biography : form.getDevelopmentProposal().getPropPersonBios()) {
      getProposalPersonBiographyService()
          .prepareProposalPersonBiographyForSave(form.getDevelopmentProposal(), biography);
    }

    ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
        .setOrdinalPosition(form.getDevelopmentProposal().getProposalPersons());
    saveAnswerHeaders(form, form.getPageId());

    getTransactionalDocumentControllerService().save(form);
    if (form.isAuditActivated()) {
      getAuditHelper().auditConditionally(form);
    }

    populateAdHocRecipients(form.getProposalDevelopmentDocument());

    if (StringUtils.equalsIgnoreCase(form.getPageId(), Constants.CREDIT_ALLOCATION_PAGE)) {
      ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
          .populateCreditSplits(form);
    }

    if (StringUtils.equalsIgnoreCase(form.getPageId(), Constants.QUESTIONS_PAGE)) {
      ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
          .populateQuestionnaires(form);
    }
    String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
    final ModelAndView view;
    if (StringUtils.isNotBlank(pageId)
        && getGlobalVariableService().getMessageMap().hasNoErrors()) {
      form.setDirtyForm(false);
      view = getModelAndViewService().getModelAndView(form, pageId);
    } else {
      view = getModelAndViewService().getModelAndView(form);
    }

    if (form.getProposalDevelopmentDocument().getDevelopmentProposal() != null
        && form.getProposalDevelopmentDocument().getDevelopmentProposal().getPropSpecialReviews()
            != null) {
      form.getProposalDevelopmentDocument()
          .getDevelopmentProposal()
          .getPropSpecialReviews()
          .stream()
          .filter(specialReview -> !specialReview.isLinkedToProtocol())
          .forEach(
              specialReview ->
                  form.getSpecialReviewHelper().prepareProtocolLinkViewFields(specialReview));
    }
    getProjectPublisher()
        .publishProject(
            getPropDevProjectRetrievalService()
                .retrieveProject(
                    form.getProposalDevelopmentDocument()
                        .getDevelopmentProposal()
                        .getProposalNumber()));

    return view;
  }