1 package org.kuali.ole.deliver.maintenance;
2
3
4 import org.apache.commons.lang3.StringUtils;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.bo.OleCirculationDesk;
7 import org.kuali.ole.deliver.bo.OleCirculationDeskDetail;
8 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
9 import org.kuali.ole.deliver.bo.OleDeliverRequestType;
10 import org.kuali.ole.deliver.processor.LoanProcessor;
11 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
12 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
13 import org.kuali.ole.sys.context.SpringContext;
14 import org.kuali.ole.util.DocstoreUtil;
15 import org.kuali.rice.krad.maintenance.MaintainableImpl;
16 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
17 import org.kuali.rice.krad.maintenance.MaintenanceLock;
18 import org.kuali.rice.krad.util.GlobalVariables;
19 import org.kuali.rice.krad.util.ObjectUtils;
20
21 import java.sql.Date;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30
31
32
33
34 public class OleDeliverRequestMaintenanceImpl extends MaintainableImpl {
35
36 private DocstoreUtil docstoreUtil;
37 private LoanProcessor loanProcessor;
38 public DocstoreUtil getDocstoreUtil() {
39
40 if (docstoreUtil == null) {
41 docstoreUtil = SpringContext.getBean(DocstoreUtil.class);
42
43 }
44 return docstoreUtil;
45 }
46
47 public LoanProcessor getLoanProcessor(){
48 if(loanProcessor == null){
49 loanProcessor = new LoanProcessor();
50 }
51 return loanProcessor;
52 }
53
54
55
56
57
58
59
60
61 @Override
62 public void processAfterNew(MaintenanceDocument document,
63 Map<String, String[]> requestParameters) {
64 super.processAfterNew(document, requestParameters);
65 document.getDocumentHeader().setDocumentDescription(OLEConstants.NEW_REQUEST_DOC);
66 OleDeliverRequestBo oleDeliverRequestBo = (OleDeliverRequestBo) document.getNewMaintainableObject().getDataObject();
67 oleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_PATRON);
68 oleDeliverRequestBo.setOperatorCreateId(GlobalVariables.getUserSession().getPrincipalId());
69 oleDeliverRequestBo.setOperatorCreateName(GlobalVariables.getUserSession().getPrincipalName());
70 oleDeliverRequestBo.setCreateDate(new Date(System.currentTimeMillis()));
71 processDefaultRequestTypeAndPickupLocation(oleDeliverRequestBo);
72 }
73
74
75
76
77
78
79
80 @Override
81 public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
82 super.processAfterCopy(document, requestParameters);
83 document.getDocumentHeader().setDocumentDescription(OLEConstants.COPY_REQUEST_DOC);
84 OleDeliverRequestBo oleDeliverRequestBo = (OleDeliverRequestBo) document.getNewMaintainableObject().getDataObject();
85 oleDeliverRequestBo.setCreateDate(new Date(System.currentTimeMillis()));
86 }
87
88
89
90
91
92
93
94 @Override
95 public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
96 super.processAfterEdit(document, requestParameters);
97 OleDeliverRequestBo oleDeliverRequestBo = (OleDeliverRequestBo) document.getNewMaintainableObject().getDataObject();
98 document.getDocumentHeader().setDocumentDescription(OLEConstants.EDIT_REQUEST_DOC);
99 }
100
101 @Override
102 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
103 OleDeliverRequestBo oleDeliverRequestBo = (OleDeliverRequestBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
104 OleDeliverRequestBo newOleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBo);
105 if (newOleDeliverRequestBo.getModifiedDate() == null) {
106 newOleDeliverRequestBo.setModifiedDate(new Date(System.currentTimeMillis()));
107 }
108
109 newOleDeliverRequestBo.setOperatorModifiedId(GlobalVariables.getUserSession().getPrincipalId());
110 newOleDeliverRequestBo.setOperatorModifierName(GlobalVariables.getUserSession().getPrincipalName());
111
112 if (newOleDeliverRequestBo.getOperatorCreateId() != null && !newOleDeliverRequestBo.getOperatorCreateId().isEmpty()) {
113 newOleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR);
114 } else if (newOleDeliverRequestBo.getProxyBorrowerId() != null && !newOleDeliverRequestBo.getProxyBorrowerId().isEmpty()) {
115 newOleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON);
116 } else {
117 newOleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_PATRON);
118 }
119 OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
120
121 OleDeliverRequestBo oleDeliverRequestBo1 = newOleDeliverRequestBo;
122
123 getDocstoreUtil().isItemAvailableInDocStore(newOleDeliverRequestBo);
124
125 newOleDeliverRequestBo.setOleItem(null);
126
127 return newOleDeliverRequestBo;
128
129
130 }
131
132 @Override
133 public List<MaintenanceLock> generateMaintenanceLocks() {
134 return Collections.emptyList();
135 }
136
137 private OleDeliverRequestBo processDefaultRequestTypeAndPickupLocation(OleDeliverRequestBo oleDeliverRequestBo){
138 Map<String,String> criteriaMap = new HashMap<String,String>();
139 List<OleCirculationDesk> oleCirculationDesks = null;
140 List<OleCirculationDeskDetail> oleCirculationDeskDetailList = null;
141 String pickUpLocationCode =getLoanProcessor().getParameter(OLEConstants.DEFAULT_PICK_UP_LOCATION);
142 if(StringUtils.isNotEmpty(pickUpLocationCode)){
143 criteriaMap = new HashMap<>();
144 criteriaMap.put(OLEConstants.PICKUP_LOCATION, "true");
145 criteriaMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, pickUpLocationCode);
146 oleCirculationDesks = (List<OleCirculationDesk>)getBusinessObjectService().findMatching(OleCirculationDesk.class,criteriaMap);
147 if(oleCirculationDesks!=null && oleCirculationDesks.size()>0){
148 oleDeliverRequestBo.setPickUpLocationId(oleCirculationDesks.get(0).getCirculationDeskId());
149 oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDesks.get(0).getCirculationDeskCode());
150 oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDesks.get(0));
151 }
152 }else{
153 criteriaMap = new HashMap<String,String>();
154 criteriaMap.put("operatorId",oleDeliverRequestBo.getOperatorCreateId());
155 criteriaMap.put("defaultLocation","Y");
156 oleCirculationDeskDetailList = (List<OleCirculationDeskDetail>)getBusinessObjectService().findMatching(OleCirculationDeskDetail.class,criteriaMap);
157 if(oleCirculationDeskDetailList.size()>0){
158 if(oleCirculationDeskDetailList.get(0).getOleCirculationDesk()!=null && oleCirculationDeskDetailList.get(0).getOleCirculationDesk().getDefaultPickupLocation()!=null){
159 oleDeliverRequestBo.setPickUpLocationId(oleCirculationDeskDetailList.get(0).getOleCirculationDesk().getDefaultPickupLocation().getCirculationDeskId());
160 oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDeskDetailList.get(0).getOleCirculationDesk().getDefaultPickupLocation().getCirculationDeskCode());
161 oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDeskDetailList.get(0).getOleCirculationDesk());
162 oleDeliverRequestBo.setRequestTypeId(oleCirculationDeskDetailList.get(0).getOleCirculationDesk().getDefaultRequestType().getRequestTypeId());
163 oleDeliverRequestBo.setRequestTypeCode(oleCirculationDeskDetailList.get(0).getOleCirculationDesk().getDefaultRequestType().getRequestTypeCode());
164 oleDeliverRequestBo.setOleDeliverRequestType(oleCirculationDeskDetailList.get(0).getOleCirculationDesk().getDefaultRequestType());
165 }
166 }
167 }
168 String requestType = getLoanProcessor().getParameter(OLEConstants.DEFAULT_REQUEST_TYPE);
169 if(StringUtils.isNotEmpty(requestType)){
170 criteriaMap = new HashMap<>();
171 criteriaMap.put("requestTypeCode", requestType);
172 List<OleDeliverRequestType> oleDeliverRequestTypes = (List<OleDeliverRequestType>)getBusinessObjectService().findMatching(OleDeliverRequestType.class,criteriaMap);
173 if(oleDeliverRequestTypes.size()>0){
174 oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestTypes.get(0).getRequestTypeId());
175 oleDeliverRequestBo.setRequestTypeCode(oleDeliverRequestTypes.get(0).getRequestTypeCode());
176 oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypes.get(0));
177 }
178 }else if(StringUtils.isNotEmpty(pickUpLocationCode)){
179 oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestBo.getOlePickUpLocation().getDefaultRequestType().getRequestTypeId());
180 oleDeliverRequestBo.setRequestTypeCode(oleDeliverRequestBo.getOlePickUpLocation().getDefaultRequestType().getRequestTypeCode());
181 oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestBo.getOlePickUpLocation().getDefaultRequestType());
182 }
183 return oleDeliverRequestBo;
184 }
185
186 }