private ActionForward getReturnToAwardForward(BudgetForm budgetForm) throws Exception { assert budgetForm != null : "the form is null"; final DocumentService docService = KraServiceLocator.getService(DocumentService.class); Award award = ((AwardDocument) budgetForm.getBudgetDocument().getParentDocument()).getAward(); // find the newest, uncanceled award document to return to String docNumber = budgetForm.getBudgetDocument().getParentDocument().getDocumentNumber(); List<VersionHistory> versions = KraServiceLocator.getService(VersionHistoryService.class) .loadVersionHistory(Award.class, award.getAwardNumber()); for (VersionHistory version : versions) { if (version.getSequenceOwnerSequenceNumber() > award.getSequenceNumber() && version.getStatus() != VersionStatus.CANCELED) { docNumber = ((Award) version.getSequenceOwner()).getAwardDocument().getDocumentNumber(); } } final AwardDocument awardDocument = (AwardDocument) docService.getByDocumentHeaderId(docNumber); String forwardUrl = buildForwardUrl(awardDocument.getDocumentHeader().getWorkflowDocument().getRouteHeaderId()); if (budgetForm.isAuditActivated()) { forwardUrl = StringUtils.replace(forwardUrl, "Award.do?", "Actions.do?"); } // add showAllBudgetVersion to the url to persist that flag until they leave the document forwardUrl = StringUtils.replace( forwardUrl, ".do?", ".do?showAllBudgetVersions=" + budgetForm.isShowAllBudgetVersions() + "&"); return new ActionForward(forwardUrl, true); }
@SuppressWarnings("unchecked") protected List<Award> filterForActiveAwardsAndAwardWithActiveTimeAndMoney( Collection<Award> collectionByQuery) throws WorkflowException { BusinessObjectService businessObjectService = KraServiceLocator.getService(BusinessObjectService.class); DocumentService documentService = KraServiceLocator.getService(DocumentService.class); Set<String> awardNumbers = new TreeSet<String>(); for (Award award : collectionByQuery) { awardNumbers.add(award.getAwardNumber()); } // get submitted docs List<Award> activeAwards = new ArrayList<Award>(); for (String versionName : awardNumbers) { VersionHistory versionHistory = versionHistoryService.findActiveVersion(Award.class, versionName); if (versionHistory != null) { Award activeAward = (Award) versionHistory.getSequenceOwner(); if (activeAward != null) { activeAwards.add(activeAward); } } } // get awards that have associated final T&M doc. for (Award award : collectionByQuery) { Map<String, Object> fieldValues = new HashMap<String, Object>(); String[] splitAwardNumber = award.getAwardNumber().split("-"); StringBuilder rootAwardNumberBuilder = new StringBuilder(12); rootAwardNumberBuilder.append(splitAwardNumber[0]); rootAwardNumberBuilder.append("-00001"); String rootAwardNumber = rootAwardNumberBuilder.toString(); fieldValues.put("rootAwardNumber", rootAwardNumber); List<TimeAndMoneyDocument> timeAndMoneyDocuments = (List<TimeAndMoneyDocument>) businessObjectService.findMatchingOrderBy( TimeAndMoneyDocument.class, fieldValues, "documentNumber", true); if (!(timeAndMoneyDocuments.size() == 0)) { TimeAndMoneyDocument t = timeAndMoneyDocuments.get(0); TimeAndMoneyDocument timeAndMoneyDocument = (TimeAndMoneyDocument) documentService.getByDocumentHeaderId(t.getDocumentNumber()); if (timeAndMoneyDocument.getDocumentHeader().getWorkflowDocument().stateIsFinal() && !(isAwardInAwardList(award.getAwardNumber(), activeAwards))) { activeAwards.add(award); } } } return activeAwards; }
/** * Gets the correct return-to-proposal action forward. * * @param form the budget form * @return the action forward * @throws WorkflowException if there is a problem interacting with workflow */ private ActionForward getReturnToProposalForward(final BudgetForm form) throws WorkflowException { assert form != null : "the form is null"; final DocumentService docService = KraServiceLocator.getService(DocumentService.class); final String docNumber = form.getDocument().getParentDocument().getDocumentNumber(); final ProposalDevelopmentDocument pdDoc = (ProposalDevelopmentDocument) docService.getByDocumentHeaderId(docNumber); String forwardUrl = buildForwardUrl(pdDoc.getDocumentHeader().getWorkflowDocument().getRouteHeaderId()); if (form.isAuditActivated()) { forwardUrl = StringUtils.replace(forwardUrl, "Proposal.do?", "Actions.do?auditActivated=true&"); } forwardUrl += "&methodToCallAttribute=methodToCall.reload"; return new ActionForward(forwardUrl, true); }
/** * Load the document again and ensure that the document header version is the same to avoid * optimistic lock exceptions given that the proposal might save this doc header. * * @param budgetDoc * @throws WorkflowException */ protected void fixDocHeaderVersion(BudgetDocument budgetDoc) throws WorkflowException { DocumentService docService = KraServiceLocator.getService(DocumentService.class); BudgetDocument updatedDoc = (BudgetDocument) docService.getByDocumentHeaderId(budgetDoc.getDocumentNumber()); budgetDoc .getDocumentHeader() .setVersionNumber(updatedDoc.getDocumentHeader().getVersionNumber()); // update all budget versions doc headers as we will try to save them all and can be saved by // proposal under separate lock as well for (int i = 0; i < budgetDoc.getParentDocument().getBudgetDocumentVersions().size(); i++) { BudgetDocumentVersion bdVersion = budgetDoc.getParentDocument().getBudgetDocumentVersion(i); BudgetDocumentVersion updatedVersion = updatedDoc.getParentDocument().getBudgetDocumentVersion(i); if (bdVersion != null && updatedVersion != null) { if (bdVersion.getDocumentHeader().getVersionNumber() < updatedVersion.getDocumentHeader().getVersionNumber()) { bdVersion .getDocumentHeader() .setVersionNumber(updatedVersion.getDocumentHeader().getVersionNumber()); } } } }