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