1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.businessobject.ContractManagerAssignmentDetail;
20 import org.kuali.ole.module.purap.document.ContractManagerAssignmentDocument;
21 import org.kuali.ole.module.purap.document.RequisitionDocument;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.ole.sys.document.web.struts.FinancialSystemTransactionalDocumentActionBase;
24 import org.kuali.rice.kew.api.KewApiConstants;
25 import org.kuali.rice.kew.api.exception.WorkflowException;
26 import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
27 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
28 import org.kuali.rice.krad.document.Document;
29 import org.kuali.rice.krad.service.DocumentService;
30 import org.kuali.rice.krad.util.GlobalVariables;
31
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37
38
39
40 public class ContractManagerAssignmentAction extends FinancialSystemTransactionalDocumentActionBase {
41 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ContractManagerAssignmentAction.class);
42
43
44
45
46
47
48 @Override
49 protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
50 super.createDocument(kualiDocumentFormBase);
51 ContractManagerAssignmentDocument acmDocument = (ContractManagerAssignmentDocument) kualiDocumentFormBase.getDocument();
52 acmDocument.getDocumentHeader().setDocumentDescription(PurapConstants.ASSIGN_CONTRACT_MANAGER_DEFAULT_DESC);
53 acmDocument.populateDocumentWithRequisitions();
54 }
55
56
57
58
59
60
61
62
63
64
65 @Override
66 protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
67 super.loadDocument(kualiDocumentFormBase);
68 ContractManagerAssignmentDocument document = (ContractManagerAssignmentDocument) kualiDocumentFormBase.getDocument();
69 List<String> documentHeaderIds = new ArrayList();
70 Map<String, ContractManagerAssignmentDetail> documentHeaderIdsAndDetails = new HashMap();
71
72
73
74 for (ContractManagerAssignmentDetail detail : (List<ContractManagerAssignmentDetail>) document.getContractManagerAssignmentDetails()) {
75 documentHeaderIdsAndDetails.put(detail.getRequisition().getDocumentNumber(), detail);
76 }
77
78
79 documentHeaderIds.addAll(documentHeaderIdsAndDetails.keySet());
80
81
82 List<Document> requisitionDocumentsFromDocService = new ArrayList();
83 try {
84 if (documentHeaderIds.size() > 0)
85 requisitionDocumentsFromDocService = SpringContext.getBean(DocumentService.class).getDocumentsByListOfDocumentHeaderIds(RequisitionDocument.class, documentHeaderIds);
86 } catch (WorkflowException we) {
87 String errorMsg = "Workflow Exception caught: " + we.getLocalizedMessage();
88 LOG.error(errorMsg, we);
89 throw new RuntimeException(errorMsg, we);
90 }
91
92
93
94 for (Document req : requisitionDocumentsFromDocService) {
95 ContractManagerAssignmentDetail detail = (ContractManagerAssignmentDetail) documentHeaderIdsAndDetails.get(req.getDocumentNumber());
96 detail.getRequisition().setDocumentHeader(req.getDocumentHeader());
97 }
98 }
99
100 @Override
101 protected void populateAdHocActionRequestCodes(KualiDocumentFormBase formBase) {
102 Document document = formBase.getDocument();
103 DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(document);
104 Map<String, String> adHocActionRequestCodes = new HashMap<String, String>();
105
106 if (documentAuthorizer.canSendAdHocRequests(document, KewApiConstants.ACTION_REQUEST_FYI_REQ, GlobalVariables.getUserSession().getPerson())) {
107 adHocActionRequestCodes.put(KewApiConstants.ACTION_REQUEST_FYI_REQ, KewApiConstants.ACTION_REQUEST_FYI_REQ_LABEL);
108 }
109 if ((document.getDocumentHeader().getWorkflowDocument().isInitiated()
110 || document.getDocumentHeader().getWorkflowDocument().isSaved()
111 || document.getDocumentHeader().getWorkflowDocument().isEnroute()
112 ) && documentAuthorizer.canSendAdHocRequests(document, KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, GlobalVariables.getUserSession().getPerson())) {
113 adHocActionRequestCodes.put(KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
114 }
115 formBase.setAdHocActionRequestCodes(adHocActionRequestCodes);
116
117 }
118
119 }