1 package org.kuali.ole.service.impl;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.select.bo.OleEventLogBo;
5 import org.kuali.ole.select.bo.OleLicenseRequestBo;
6 import org.kuali.ole.select.bo.OleLicenseRequestItemTitle;
7 import org.kuali.ole.select.bo.OleLicenseRequestStatus;
8 import org.kuali.ole.service.OleLicenseRequestService;
9 import org.kuali.ole.service.OleLicenseRequestWebService;
10 import org.kuali.rice.core.api.CoreApiServiceLocator;
11 import org.kuali.rice.core.api.config.property.ConfigContext;
12 import org.kuali.rice.core.api.criteria.CriteriaLookupService;
13 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
14 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
15 import org.kuali.rice.kim.api.identity.IdentityService;
16 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
17 import org.kuali.rice.krad.UserSession;
18 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
19 import org.kuali.rice.krad.service.BusinessObjectService;
20 import org.kuali.rice.krad.service.DocumentService;
21 import org.kuali.rice.krad.service.KRADServiceLocator;
22 import org.kuali.rice.krad.util.GlobalVariables;
23
24 import java.util.*;
25
26
27
28
29 public class OleLicenseRequestWebServiceImpl implements OleLicenseRequestWebService {
30 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLicenseRequestWebServiceImpl.class);
31 private BusinessObjectService businessObjectService;
32 private IdentityService identityService;
33 private CriteriaLookupService criteriaLookupService;
34 private OleLicenseRequestService oleLicenseRequestService;
35
36
37
38
39
40
41 protected BusinessObjectService getBusinessObjectService() {
42 if (businessObjectService == null) {
43 businessObjectService = KRADServiceLocator.getBusinessObjectService();
44 }
45 return businessObjectService;
46 }
47
48
49
50
51
52
53 protected IdentityService getIdentityService() {
54 if (identityService == null) {
55 identityService = KimApiServiceLocator.getIdentityService();
56 }
57 return identityService;
58 }
59
60
61
62
63
64
65 protected CriteriaLookupService getCriteriaLookupService() {
66 if(criteriaLookupService == null) {
67 criteriaLookupService = GlobalResourceLoader.getService("criteriaLookupService");
68 }
69 return criteriaLookupService;
70 }
71
72
73
74
75
76 public OleLicenseRequestService getOleLicenseRequestservice() {
77 if(oleLicenseRequestService == null ) {
78 oleLicenseRequestService = GlobalResourceLoader.getService("oleLicenseRequestService");
79 }
80 return oleLicenseRequestService;
81 }
82
83
84
85
86
87 @Override
88 public OleLicenseRequestBo createLicenseRequest(String documentnumber, String itemUUIDs) {
89 try{
90 String user = ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.OleLicenseRequest.LICENSE_DOCUMENT_INITIATOR);
91 GlobalVariables.setUserSession(new UserSession(user));
92 DocumentService documentService= GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
93
94 MaintenanceDocument licenseDoc = (MaintenanceDocument) documentService.getNewDocument(OLEConstants.OleLicenseRequest.LICENSE_REQUEST_DOC_TYPE);
95 OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo) licenseDoc.getDocumentDataObject();
96 oleLicenseRequestBo.setLocationId(OLEConstants.OleLicenseRequest.LICENSE_INITIAL_LOCATON);
97 oleLicenseRequestBo.setLicenseRequestWorkflowTypeCode(OLEConstants.OleLicenseRequest.LICENSE_INITIAL_WORKFLOW);
98 OleEventLogBo eventLog = new OleEventLogBo();
99 eventLog.setEventType("system");
100 eventLog.setCreatedBy(user);
101 eventLog.setEventDescription(OLEConstants.OleLicenseRequest.LICENSE_REQ_INTIAL_EVENT_LOG);
102 eventLog.setCurrentTimeStamp();
103 oleLicenseRequestBo.getEventLogs().add(eventLog);
104 oleLicenseRequestBo.seteResourceDocNumber(documentnumber);
105 oleLicenseRequestBo.setLicenseRequestStatusCode(
106 ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.OleLicenseRequest.LICENSE_REQ_DOCUMENT_STATUS));
107 if(licenseDoc.getDocumentNumber() != null) {
108 oleLicenseRequestBo.setDocumentNumber(licenseDoc.getDocumentNumber());
109 oleLicenseRequestBo.setLicenseDocumentNumber(licenseDoc.getDocumentNumber());
110 }
111
112 List<OleLicenseRequestItemTitle> oleLicenseRequestItemTitles= new ArrayList<OleLicenseRequestItemTitle>();
113 OleLicenseRequestItemTitle oleLicenseRequestItemTitle;
114 String[] bibUUIDs;
115 if (itemUUIDs != null ) {
116 bibUUIDs=itemUUIDs.split(",");
117 for(int i=0;i<bibUUIDs.length;i++){
118 oleLicenseRequestItemTitle=new OleLicenseRequestItemTitle();
119 oleLicenseRequestItemTitle.setItemUUID(bibUUIDs[i]);
120 oleLicenseRequestItemTitles.add(oleLicenseRequestItemTitle);
121 }
122 }
123
124 oleLicenseRequestBo.setOleLicenseRequestItemTitles(oleLicenseRequestItemTitles);
125 Date now = CoreApiServiceLocator.getDateTimeService().getCurrentSqlDate();
126 Map criteria = new HashMap();
127 criteria.put("code",
128 ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.OleLicenseRequest.LICENSE_REQ_DOCUMENT_STATUS));
129 OleLicenseRequestStatus licenseRequestStatus = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleLicenseRequestStatus.class,
130 criteria);
131 licenseDoc.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(licenseRequestStatus.getName());
132
133 licenseDoc.getDocumentHeader().setDocumentDescription(OLEConstants.OleLicenseRequest.LICENSE_DESC+"[date:"+now+"]");
134 licenseDoc.getNewMaintainableObject().setDataObject(oleLicenseRequestBo);
135 MaintenanceDocument createdLicenseRequest = (MaintenanceDocument)documentService.saveDocument(licenseDoc);
136 DocumentRouteHeaderValue documentHeader= DocumentRouteHeaderValue.from(licenseDoc.getDocumentHeader().getWorkflowDocument().getDocument());
137 oleLicenseRequestBo.setDocumentRouteHeaderValue(documentHeader);
138 return oleLicenseRequestBo;
139
140 }catch(Exception e){
141 LOG.error("Exception while creating license request"+e.getMessage());
142 throw new RuntimeException(e);
143 }
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 public String getURL() {
165 String url = ConfigContext.getCurrentContextConfig().getProperty("oleRequisitionWebService.url");
166 return url;
167 }
168
169
170 }