1 package org.kuali.ole.service.impl;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.joda.time.DateTime;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.describe.form.WorkEInstanceOlemlForm;
8 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
9 import org.kuali.ole.docstore.common.document.EHoldings;
10 import org.kuali.ole.docstore.common.document.Holdings;
11 import org.kuali.ole.docstore.common.document.content.instance.*;
12 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
13 import org.kuali.ole.docstore.common.search.SearchParams;
14 import org.kuali.ole.docstore.common.search.SearchResponse;
15 import org.kuali.ole.docstore.common.search.SearchResult;
16 import org.kuali.ole.docstore.common.search.SearchResultField;
17 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
18 import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
19 import org.kuali.ole.select.bo.*;
20 import org.kuali.ole.select.businessobject.*;
21 import org.kuali.ole.select.document.*;
22 import org.kuali.ole.select.form.OLEEResourceRecordForm;
23 import org.kuali.ole.service.OLEEResourceSearchService;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.rice.core.api.config.property.ConfigContext;
26 import org.kuali.rice.core.api.util.type.KualiDecimal;
27 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
28 import org.kuali.rice.coreservice.api.parameter.Parameter;
29 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
30 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
31 import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
32 import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
33 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34 import org.kuali.rice.kew.service.KEWServiceLocator;
35 import org.kuali.rice.krad.service.BusinessObjectService;
36 import org.kuali.rice.krad.service.DocumentHeaderService;
37 import org.kuali.rice.krad.service.KRADServiceLocator;
38 import org.kuali.rice.krad.util.GlobalVariables;
39 import org.kuali.rice.krad.util.KRADConstants;
40
41 import java.text.SimpleDateFormat;
42 import java.util.ArrayList;
43 import java.util.*;
44
45
46
47
48
49
50
51
52 public class OLEEResourceSearchServiceImpl implements OLEEResourceSearchService {
53
54 private static final Logger LOG = Logger.getLogger(OLEEResourceSearchServiceImpl.class);
55 private BusinessObjectService businessObjectService;
56 private final String calendarYearAgo = getParameter(OLEConstants.OLEEResourceRecord.CALENDAR_OR_YEAR_AGO);
57 private final String calendarYearsAgo = getParameter(OLEConstants.OLEEResourceRecord.CALENDAR_OR_YEARS_AGO);
58 private final String monthAgo = getParameter(OLEConstants.OLEEResourceRecord.MONTH_AGO);
59 private final String monthsAgo = getParameter(OLEConstants.OLEEResourceRecord.MONTHS_AGO);
60 private final String weekAgo = getParameter(OLEConstants.OLEEResourceRecord.WEEK_AGO);
61 private final String weeksAgo = getParameter(OLEConstants.OLEEResourceRecord.WEEKS_AGO);
62 private final String dayAgo = getParameter(OLEConstants.OLEEResourceRecord.DAY_AGO);
63 private final String daysAgo = getParameter(OLEConstants.OLEEResourceRecord.DAYS_AGO);
64 private final String firstDayOfYear = getParameter(OLEConstants.OLEEResourceRecord.FIRST_DAY_OF_YEAR);
65 private final String lastDayOfYear = getParameter(OLEConstants.OLEEResourceRecord.LAST_DAY_OF_YEAR);
66
67 public BusinessObjectService getBusinessObjectService() {
68 if (businessObjectService == null) {
69 businessObjectService = KRADServiceLocator.getBusinessObjectService();
70 }
71 return businessObjectService;
72 }
73
74 private DocstoreClientLocator docstoreClientLocator;
75
76 public DocstoreClientLocator getDocstoreClientLocator() {
77 if (docstoreClientLocator == null) {
78 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
79 }
80 return docstoreClientLocator;
81 }
82
83 @Override
84 public List<OLEEResourceRecordDocument> findMatching(Map<String, List<String>> map, DocumentSearchCriteria.Builder docSearchCriteria) {
85 Map<String, List<String>> attributes = new HashMap<String, List<String>>();
86 if (docSearchCriteria != null) {
87 if (!map.isEmpty()) {
88 for (String propertyField : map.keySet()) {
89 if (map.get(propertyField) != null) {
90 attributes.put(propertyField, map.get(propertyField));
91 }
92 }
93 }
94 }
95 docSearchCriteria.setDocumentAttributeValues(attributes);
96 Date currentDate = new Date();
97 docSearchCriteria.setDateCreatedTo(new DateTime(currentDate));
98 DocumentSearchCriteria docSearchCriteriaDTO = docSearchCriteria.build();
99 DocumentSearchResults components = null;
100 components = KEWServiceLocator.getDocumentSearchService().lookupDocuments(GlobalVariables.getUserSession().getPrincipalId(), docSearchCriteriaDTO);
101 List<DocumentSearchResult> docSearchResults = components.getSearchResults();
102 OLEEResourceRecordDocument oleeResourceRecordDocument;
103 List<OLEEResourceRecordDocument> oleeResourceRecordDocumentnew = new ArrayList<OLEEResourceRecordDocument>();
104 if (!docSearchResults.isEmpty()) {
105 for (DocumentSearchResult searchResult : docSearchResults) {
106 oleeResourceRecordDocument = new OLEEResourceRecordDocument();
107 oleeResourceRecordDocument.setResultDetails(searchResult, new ArrayList());
108 if (oleeResourceRecordDocument != null) {
109 oleeResourceRecordDocumentnew.add(oleeResourceRecordDocument);
110 }
111 }
112 }
113 return oleeResourceRecordDocumentnew;
114 }
115
116 @Override
117 public List<OLEEResourceRecordDocument> statusNotNull(List<OLEEResourceRecordDocument> eresourceList, List<String> status) {
118 List<OLEEResourceRecordDocument> eresourceStatusList = new ArrayList<OLEEResourceRecordDocument>();
119 List<String> listOfStatuses = new ArrayList<>();
120 listOfStatuses.addAll(status);
121 for (OLEEResourceRecordDocument oleeResourceRecordDocument : eresourceList) {
122 if (listOfStatuses.contains(oleeResourceRecordDocument.getStatusId())) {
123 eresourceStatusList.add(oleeResourceRecordDocument);
124 }
125 }
126 return eresourceStatusList;
127 }
128
129 @Override
130 public List<OLEEResourceRecordDocument> performSearch(List<OLESearchCondition> oleSearchConditionsList) throws Exception {
131 boolean flag = true;
132 Map<String, List<String>> searchCriteriaMap = new HashMap<String, List<String>>();
133 List<OLEEResourceRecordDocument> eresourceList = new ArrayList<OLEEResourceRecordDocument>();
134 List<OLEEResourceRecordDocument> eresourceDocumentList = new ArrayList<OLEEResourceRecordDocument>();
135 DocumentSearchCriteria.Builder docSearchCriteria = DocumentSearchCriteria.Builder.create();
136 docSearchCriteria.setDocumentTypeName(OLEConstants.OLEEResourceRecord.OLE_ERS_DOC);
137 for (int searchCriteriaCnt = 0; searchCriteriaCnt < oleSearchConditionsList.size(); searchCriteriaCnt++) {
138 if (StringUtils.isNotBlank(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy()) && oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria().isEmpty()) {
139 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.SERACH_CRITERIA_REQUIRED);
140 } else if (!StringUtils.isNotBlank(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy()) && !oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria().isEmpty()) {
141 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.SERACH_BY_REQUIRED);
142 } else if (!GlobalVariables.getMessageMap().hasMessages() && StringUtils.isNotBlank(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy()) && !oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria().isEmpty()
143 && (OLEConstants.OLEEResourceRecord.AND.equals(oleSearchConditionsList.get(searchCriteriaCnt).getOperator()) || OLEConstants.OLEEResourceRecord.OR.equals(oleSearchConditionsList.get(searchCriteriaCnt).getOperator()))) {
144 flag = false;
145 if (searchCriteriaCnt != 0 && OLEConstants.OLEEResourceRecord.AND.equals(oleSearchConditionsList.get(searchCriteriaCnt).getOperator())) {
146 if (!searchCriteriaMap.containsKey(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy())) {
147 searchCriteriaMap = getSearchCriteriaMap(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy(), oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria(), searchCriteriaMap);
148 } else {
149 searchCriteriaMap.clear();
150 break;
151 }
152 } else {
153 searchCriteriaMap = getSearchCriteriaMap(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy(), oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria(), searchCriteriaMap);
154 }
155 if (searchCriteriaCnt < oleSearchConditionsList.size() - 1) {
156 if (StringUtils.isNotBlank(oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchBy()) && !oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchCriteria().isEmpty()) {
157 if (OLEConstants.OLEEResourceRecord.AND.equals(oleSearchConditionsList.get(searchCriteriaCnt).getOperator())) {
158 if (!searchCriteriaMap.containsKey(oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchBy())) {
159 searchCriteriaMap = getSearchCriteriaMap(oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchBy(), oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchCriteria(), searchCriteriaMap);
160 if (searchCriteriaCnt < oleSearchConditionsList.size() - 2 && oleSearchConditionsList.get(searchCriteriaCnt + 2).getSearchBy() != null && !oleSearchConditionsList.get(searchCriteriaCnt + 2).getSearchCriteria().isEmpty()) {
161 if (OLEConstants.OLEEResourceRecord.AND.equals(oleSearchConditionsList.get(searchCriteriaCnt + 1).getOperator())) {
162 searchCriteriaCnt++;
163 }
164 } else {
165 if (searchCriteriaMap.size() > 0) {
166 eresourceList = findMatching(searchCriteriaMap, docSearchCriteria);
167 }
168 break;
169 }
170 } else {
171 searchCriteriaMap.clear();
172 break;
173 }
174 } else if (OLEConstants.OLEEResourceRecord.OR.equals(oleSearchConditionsList.get(searchCriteriaCnt).getOperator())) {
175 if (searchCriteriaMap.size() > 0) {
176 eresourceDocumentList = findMatching(searchCriteriaMap, docSearchCriteria);
177 eresourceList.addAll(eresourceDocumentList);
178 searchCriteriaMap.clear();
179 }
180 if (searchCriteriaCnt == oleSearchConditionsList.size() - 2) {
181 searchCriteriaMap = getSearchCriteriaMap(oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchBy(), oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchCriteria(), searchCriteriaMap);
182 if (searchCriteriaMap.size() > 0) {
183 eresourceDocumentList = findMatching(searchCriteriaMap, docSearchCriteria);
184 eresourceList.addAll(eresourceDocumentList);
185 searchCriteriaMap.clear();
186 }
187 break;
188 }
189 if (OLEConstants.OLEEResourceRecord.AND.equals(oleSearchConditionsList.get(searchCriteriaCnt + 1).getOperator())) {
190 searchCriteriaMap = getSearchCriteriaMap(oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchBy(), oleSearchConditionsList.get(searchCriteriaCnt + 1).getSearchCriteria(), searchCriteriaMap);
191 if (searchCriteriaMap.size() > 0) {
192 eresourceDocumentList = findMatching(searchCriteriaMap, docSearchCriteria);
193 eresourceList.addAll(eresourceDocumentList);
194 }
195 }
196 }
197 } else {
198 if (!searchCriteriaMap.isEmpty()) {
199 if (searchCriteriaMap.size() > 0) {
200 eresourceDocumentList = findMatching(searchCriteriaMap, docSearchCriteria);
201 eresourceList.addAll(eresourceDocumentList);
202 searchCriteriaMap.clear();
203 }
204 }
205 }
206 }
207 if (searchCriteriaCnt == oleSearchConditionsList.size() - 1) {
208 if (searchCriteriaMap.size() > 0) {
209 eresourceDocumentList = findMatching(searchCriteriaMap, docSearchCriteria);
210 eresourceList.addAll(eresourceDocumentList);
211 searchCriteriaMap.clear();
212 }
213 }
214 }
215 }
216 if (flag) {
217 if (!GlobalVariables.getMessageMap().hasMessages()) {
218 eresourceList = findMatching(searchCriteriaMap, docSearchCriteria);
219 }
220 }
221 if (eresourceList.size() > 0) {
222 for (int searchCriteriaCnt = 0; searchCriteriaCnt < oleSearchConditionsList.size(); searchCriteriaCnt++) {
223 if (oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy() != null && StringUtils.isNotEmpty(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy()) && !oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria().isEmpty() &&
224 (OLEConstants.OLEEResourceRecord.NOT.equals(oleSearchConditionsList.get(searchCriteriaCnt).getOperator()))) {
225 searchCriteriaMap.clear();
226 searchCriteriaMap = getSearchCriteriaMap(oleSearchConditionsList.get(searchCriteriaCnt).getSearchBy(), oleSearchConditionsList.get(searchCriteriaCnt).getSearchCriteria(), searchCriteriaMap);
227 if (searchCriteriaMap.size() > 0) {
228 eresourceDocumentList = findMatching(searchCriteriaMap, docSearchCriteria);
229 }
230 List<String> list = new ArrayList<String>();
231 for (OLEEResourceRecordDocument oleEResourceRecordDocument : eresourceDocumentList) {
232 int count = 0;
233 for (OLEEResourceRecordDocument eResourceRecordDocument : eresourceList) {
234 if (oleEResourceRecordDocument.getDocumentNumber().toString().equalsIgnoreCase(eResourceRecordDocument.getDocumentNumber().toString())) {
235 list.add(count + "");
236 }
237 count++;
238 }
239 }
240 for (String str : list) {
241 eresourceList.remove(Integer.parseInt(str));
242 }
243 }
244 }
245 }
246 return eresourceList;
247 }
248
249 public final String getParameter(String parameterName) {
250 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.SELECT_NMSPC, OLEConstants.SELECT_CMPNT, parameterName);
251 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
252 return parameter != null ? parameter.getValue() : null;
253 }
254
255 public void getEResourcesFields(String eResourceId, OleHoldings eHoldings, WorkEInstanceOlemlForm olemlForm) {
256 ExtentOfOwnership extentOfOwnership = null;
257 if (eHoldings.getExtentOfOwnership().size() > 0) {
258 extentOfOwnership = eHoldings.getExtentOfOwnership().get(0);
259 } else if (extentOfOwnership == null) {
260 extentOfOwnership = new ExtentOfOwnership();
261 eHoldings.getExtentOfOwnership().add(extentOfOwnership);
262 }
263 Coverages coverages = extentOfOwnership.getCoverages();
264 if (coverages == null) {
265 coverages = new Coverages();
266 eHoldings.getExtentOfOwnership().get(0).setCoverages(coverages);
267 }
268 PerpetualAccesses perpetualAccesses = extentOfOwnership.getPerpetualAccesses();
269 if (perpetualAccesses == null) {
270 perpetualAccesses = new PerpetualAccesses();
271 eHoldings.getExtentOfOwnership().get(0).setPerpetualAccesses(perpetualAccesses);
272 }
273 List<Coverage> coverage = coverages.getCoverage();
274 List<PerpetualAccess> perpetualAccess = perpetualAccesses.getPerpetualAccess();
275
276
277 Map ersIdMap = new HashMap();
278 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
279 OLEEResourceRecordDocument eResourceDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, ersIdMap);
280 if (eResourceDocument != null && olemlForm.geteResourceId() != null && !olemlForm.geteResourceId().isEmpty()) {
281 olemlForm.setTokenId(eResourceDocument.getDocumentNumber());
282 eHoldings.setEResourceId(eResourceDocument.getOleERSIdentifier());
283 olemlForm.seteResourceTitle(eResourceDocument.getTitle());
284 getAccessLocationFromERS(eResourceDocument, eHoldings, olemlForm);
285 if (eHoldings.getStatisticalSearchingCode() == null) {
286 StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
287 statisticalSearchingCode.setCodeValue(eResourceDocument.getOleStatisticalCode() != null ? eResourceDocument.getOleStatisticalCode().getStatisticalSearchingCode() : "");
288 eHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
289 }
290 if (coverage.size() != 0) {
291 if (eResourceDocument.getDefaultCoverage() != null && !eResourceDocument.getDefaultCoverage().isEmpty()) {
292 if (eResourceDocument.getDefaultCoverage().contains("-")) {
293 String[] defaultCoverageStart = eResourceDocument.getDefaultCoverage().split(getParameter(OLEConstants.OLEEResourceRecord.COVERAGE_DATE_SEPARATOR));
294 String[] covStartSeparator = defaultCoverageStart[0].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
295 String[] covEndSeparator = defaultCoverageStart[1].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
296 for (Coverage coverageList : coverage) {
297 if (coverageList.getCoverageEndDate() == null) {
298 if (covEndSeparator.length > 2 && !covEndSeparator[2].isEmpty()) {
299 if (covEndSeparator[2].contains("/")) {
300 coverageList.setCoverageEndDateFormat(covEndSeparator[2]);
301 } else {
302 coverageList.setCoverageEndDateString(covEndSeparator[2]);
303 }
304 coverageList.setCoverageEndDate(covEndSeparator[2]);
305 }
306 if (covEndSeparator.length > 0 && !covEndSeparator[0].isEmpty()) {
307 coverageList.setCoverageEndVolume(covEndSeparator[0]);
308 }
309 if (covEndSeparator.length > 1 && !covEndSeparator[1].isEmpty()) {
310 coverageList.setCoverageEndIssue(covEndSeparator[1]);
311 }
312 }
313 if (coverageList.getCoverageStartDate() == null) {
314 if (covStartSeparator.length > 2 && !covStartSeparator[2].isEmpty()) {
315 if (covStartSeparator[2].contains("/")) {
316 coverageList.setCoverageStartDateFormat(covStartSeparator[2]);
317 } else {
318 coverageList.setCoverageStartDateString(covStartSeparator[2]);
319 }
320 coverageList.setCoverageStartDate(covStartSeparator[2]);
321 }
322 if (covStartSeparator.length > 0 && !covStartSeparator[0].isEmpty()) {
323 coverageList.setCoverageStartVolume(covStartSeparator[0]);
324 }
325 if (covStartSeparator.length > 1 && !covStartSeparator[1].isEmpty()) {
326 coverageList.setCoverageStartIssue(covStartSeparator[1]);
327 }
328 }
329 }
330 }
331 }
332 }
333 if (perpetualAccess.size() != 0) {
334 if (eResourceDocument.getDefaultPerpetualAccess() != null && !eResourceDocument.getDefaultPerpetualAccess().isEmpty()) {
335 if (eResourceDocument.getDefaultPerpetualAccess().contains("-")) {
336 String[] defaultPerAccStart = eResourceDocument.getDefaultPerpetualAccess().split(getParameter(OLEConstants.OLEEResourceRecord.PERPETUAL_ACCESS_DATE_SEPARATOR));
337 String[] perAccStartSeparator = defaultPerAccStart[0].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
338 String[] perAccEndSeparator = defaultPerAccStart[1].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
339 for (PerpetualAccess perpetualAccessList : perpetualAccess) {
340 if (perpetualAccessList.getPerpetualAccessEndDate() == null) {
341 if (perAccEndSeparator.length > 2 && !perAccEndSeparator[2].isEmpty()) {
342 if (perAccEndSeparator[2].contains("/")) {
343 perpetualAccessList.setPerpetualAccessEndDateFormat(perAccEndSeparator[2]);
344 } else {
345 perpetualAccessList.setPerpetualAccessEndDateString(perAccEndSeparator[2]);
346 }
347 perpetualAccessList.setPerpetualAccessEndDate(perAccEndSeparator[2]);
348 }
349 if (perAccEndSeparator.length > 0 && !perAccEndSeparator[0].isEmpty()) {
350 perpetualAccessList.setPerpetualAccessEndVolume(perAccEndSeparator[0]);
351 }
352 if (perAccEndSeparator.length > 1 && !perAccEndSeparator[1].isEmpty()) {
353 perpetualAccessList.setPerpetualAccessEndIssue(perAccEndSeparator[1]);
354 }
355 }
356 if (perpetualAccessList.getPerpetualAccessStartDate() == null) {
357 if (perAccStartSeparator.length > 2 && !perAccStartSeparator[2].isEmpty()) {
358 if (perAccStartSeparator[2].contains("/")) {
359 perpetualAccessList.setPerpetualAccessStartDateFormat(perAccStartSeparator[2]);
360 } else {
361 perpetualAccessList.setPerpetualAccessStartDateString(perAccStartSeparator[2]);
362 }
363 perpetualAccessList.setPerpetualAccessStartDate(perAccStartSeparator[2]);
364 }
365 if (perAccStartSeparator.length > 0 && !perAccStartSeparator[0].isEmpty()) {
366 perpetualAccessList.setPerpetualAccessStartVolume(perAccStartSeparator[0]);
367 }
368 if (perAccStartSeparator.length > 1 && !perAccStartSeparator[1].isEmpty()) {
369 perpetualAccessList.setPerpetualAccessStartIssue(perAccStartSeparator[1]);
370 }
371 }
372 }
373 }
374 }
375 }
376 if (coverage.size() == 0) {
377 boolean coverageFlag = false;
378 Coverage cov = new Coverage();
379 if (eResourceDocument.getDefaultCoverage() != null && !eResourceDocument.getDefaultCoverage().isEmpty()) {
380 if (eResourceDocument.getDefaultCoverage().contains("-")) {
381 String[] defaultCoverageStart = eResourceDocument.getDefaultCoverage().split(getParameter(OLEConstants.OLEEResourceRecord.COVERAGE_DATE_SEPARATOR));
382 String[] covStartSeparator = defaultCoverageStart[0].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
383 if (covStartSeparator.length > 2 && !covStartSeparator[2].isEmpty()) {
384 if(covStartSeparator[2].contains("/")) {
385 cov.setCoverageStartDateFormat(covStartSeparator[2]);
386 } else {
387 cov.setCoverageStartDateString(covStartSeparator[2]);
388 }
389 cov.setCoverageStartDate(covStartSeparator[2]);
390 coverageFlag = true;
391 }
392 if (covStartSeparator.length > 0 && !covStartSeparator[0].isEmpty()) {
393 cov.setCoverageStartVolume(covStartSeparator[0]);
394 coverageFlag = true;
395 }
396 if (covStartSeparator.length > 1 && !covStartSeparator[1].isEmpty()) {
397 cov.setCoverageStartIssue(covStartSeparator[1]);
398 coverageFlag = true;
399 }
400 String[] covEndSeparator = defaultCoverageStart[1].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
401 if (covEndSeparator.length > 2 && !covEndSeparator[2].isEmpty()) {
402 if(covEndSeparator[2].contains("/")) {
403 cov.setCoverageEndDateFormat(covEndSeparator[2]);
404 } else {
405 cov.setCoverageEndDateString(covEndSeparator[2]);
406 }
407 cov.setCoverageEndDate(covEndSeparator[2]);
408 coverageFlag = true;
409 }
410 if (covEndSeparator.length > 0 && !covEndSeparator[0].isEmpty()) {
411 cov.setCoverageEndVolume(covEndSeparator[0]);
412 coverageFlag = true;
413 }
414 if (covEndSeparator.length > 1 && !covEndSeparator[1].isEmpty()) {
415 cov.setCoverageEndIssue(covEndSeparator[1]);
416 coverageFlag = true;
417 }
418 if (coverageFlag) {
419 eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(cov);
420 }
421 }
422 }
423 }
424 if (perpetualAccess.size() == 0) {
425 boolean perpetualAccFlag = false;
426 PerpetualAccess perpetualAcc = new PerpetualAccess();
427 if (eResourceDocument.getDefaultPerpetualAccess() != null && !eResourceDocument.getDefaultPerpetualAccess().isEmpty()) {
428 if (eResourceDocument.getDefaultPerpetualAccess().contains("-")) {
429 String[] defaultPerAccStart = eResourceDocument.getDefaultPerpetualAccess().split(getParameter(OLEConstants.OLEEResourceRecord.PERPETUAL_ACCESS_DATE_SEPARATOR));
430 String[] perAccStartSeparator = defaultPerAccStart[0].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
431 if (perAccStartSeparator.length > 2 && !perAccStartSeparator[2].isEmpty()) {
432 if(perAccStartSeparator[2].contains("/")) {
433 perpetualAcc.setPerpetualAccessStartDateFormat(perAccStartSeparator[2]);
434 } else {
435 perpetualAcc.setPerpetualAccessStartDateString(perAccStartSeparator[2]);
436 }
437 perpetualAcc.setPerpetualAccessStartDate(perAccStartSeparator[2]);
438 perpetualAccFlag = true;
439 }
440 if (perAccStartSeparator.length > 0 && !perAccStartSeparator[0].isEmpty()) {
441 perpetualAcc.setPerpetualAccessStartVolume(perAccStartSeparator[0]);
442 perpetualAccFlag = true;
443 }
444 if (perAccStartSeparator.length > 1 && !perAccStartSeparator[1].isEmpty()) {
445 perpetualAcc.setPerpetualAccessStartIssue(perAccStartSeparator[1]);
446 perpetualAccFlag = true;
447 }
448 String[] perAccEndSeparator = defaultPerAccStart[1].split(getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR));
449 if (perAccEndSeparator.length > 2 && !perAccEndSeparator[2].isEmpty()) {
450 if(perAccEndSeparator[2].contains("/")) {
451 perpetualAcc.setPerpetualAccessEndDateFormat(perAccEndSeparator[2]);
452 } else {
453 perpetualAcc.setPerpetualAccessEndDateString(perAccEndSeparator[2]);
454 }
455 perpetualAcc.setPerpetualAccessEndDate(perAccEndSeparator[2]);
456 perpetualAccFlag = true;
457 }
458 if (perAccEndSeparator.length > 0 && !perAccEndSeparator[0].isEmpty()) {
459 perpetualAcc.setPerpetualAccessEndVolume(perAccEndSeparator[0]);
460 perpetualAccFlag = true;
461 }
462 if (perAccEndSeparator.length > 1 && !perAccEndSeparator[1].isEmpty()) {
463 perpetualAcc.setPerpetualAccessEndIssue(perAccEndSeparator[1]);
464 perpetualAccFlag = true;
465 }
466 if (perpetualAccFlag) {
467 eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().add(perpetualAcc);
468 }
469 }
470 }
471 }
472 } else {
473 getAccessLocationFromEInstance(eHoldings, olemlForm);
474 }
475 }
476
477 public void getAccessLocationFromERS(OLEEResourceRecordDocument eResourceDocument, OleHoldings eHoldings, WorkEInstanceOlemlForm olemlForm) {
478 if (eResourceDocument != null) {
479 HoldingsAccessInformation accessInformation = eHoldings.getHoldingsAccessInformation();
480 if (accessInformation != null&&accessInformation.getAccessLocation()!=null) {
481 if (olemlForm.getExtendedEHoldingFields().getAccessLocation() != null && olemlForm.getExtendedEHoldingFields().getAccessLocation().size() > 0) {
482 String accessId = "";
483 for (String accessLoc : olemlForm.getExtendedEHoldingFields().getAccessLocation()) {
484 accessId += accessLoc;
485 accessId += OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR;
486 }
487 accessInformation.setAccessLocation(accessId.substring(0, (accessId.lastIndexOf(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR))));
488 eHoldings.setHoldingsAccessInformation(accessInformation);
489 }
490 else{
491 String accessLocationId = accessInformation.getAccessLocation();
492 String accessId = "";
493 if (accessLocationId != null && !accessLocationId.isEmpty()) {
494 String[] accessLocation = accessLocationId.split(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR);
495 List<String> accessLocations = new ArrayList<>();
496 for (String accessLocId : accessLocation) {
497 olemlForm.getExtendedEHoldingFields().getAccessLocation().add(accessLocId);
498 accessLocations.add(accessLocId);
499 }
500 for (String accessLoc : accessLocations) {
501 accessId += accessLoc;
502 accessId += OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR;
503 }
504 accessInformation.setAccessLocation(accessId.substring(0, (accessId.lastIndexOf(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR))));
505 }
506 }
507 }else {
508 accessInformation = new HoldingsAccessInformation();
509 String accessLocationId = eResourceDocument.getAccessLocationId();
510 String accessId = "";
511 if (accessLocationId != null && !accessLocationId.isEmpty()) {
512 String[] accessLocation = accessLocationId.split(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR);
513 List<String> accessLocations = new ArrayList<>();
514 for (String accessLocId : accessLocation) {
515 olemlForm.getExtendedEHoldingFields().getAccessLocation().add(accessLocId);
516 accessLocations.add(accessLocId);
517 }
518 for (String accessLoc : accessLocations) {
519 accessId += accessLoc;
520 accessId += OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR;
521 }
522 accessInformation.setAccessLocation(accessId.substring(0, (accessId.lastIndexOf(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR))));
523 }
524
525 }
526 if (eHoldings.getHoldingsAccessInformation()==null) {
527 accessInformation.setAuthenticationType(eResourceDocument.getOleAuthenticationType() != null ? eResourceDocument.getOleAuthenticationType().getOleAuthenticationTypeName() : "");
528 accessInformation.setNumberOfSimultaneousUser(eResourceDocument.getNumOfSimultaneousUsers());
529 }
530 if (eHoldings.getHoldingsAccessInformation()!=null&&eHoldings.getHoldingsAccessInformation().getAuthenticationType()==null) {
531 accessInformation.setAuthenticationType(eResourceDocument.getOleAuthenticationType() != null ? eResourceDocument.getOleAuthenticationType().getOleAuthenticationTypeName() : "");
532 }
533 if (eHoldings.getHoldingsAccessInformation()!=null&&eHoldings.getHoldingsAccessInformation().getNumberOfSimultaneousUser()==null) {
534 accessInformation.setNumberOfSimultaneousUser(eResourceDocument.getNumOfSimultaneousUsers());
535 }
536 eHoldings.setHoldingsAccessInformation(accessInformation);
537 }
538 }
539
540 public void getAccessLocationFromEInstance(OleHoldings eHoldings, WorkEInstanceOlemlForm olemlForm) {
541 HoldingsAccessInformation accessInformation = eHoldings.getHoldingsAccessInformation();
542 List<String> accessLocations = new ArrayList<>();
543 if (accessInformation != null) {
544 if (olemlForm.getExtendedEHoldingFields().getAccessLocation() != null && olemlForm.getExtendedEHoldingFields().getAccessLocation().size() > 0) {
545 String accessId = "";
546 for (String accessLoc : olemlForm.getExtendedEHoldingFields().getAccessLocation()) {
547 accessId += accessLoc;
548 accessId += OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR;
549 }
550 accessInformation.setAccessLocation(accessId.substring(0, (accessId.lastIndexOf(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR))));
551 eHoldings.setHoldingsAccessInformation(accessInformation);
552 } else if (accessInformation.getAccessLocation() != null && !accessInformation.getAccessLocation().isEmpty()) {
553 String[] accessId = accessInformation.getAccessLocation().split(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR);
554 for (String accessLoc : accessId) {
555 accessLocations.add(accessLoc);
556 }
557 olemlForm.getExtendedEHoldingFields().setAccessLocation(accessLocations);
558 }
559 }
560 }
561
562 public Map<String, List<String>> getSearchCriteriaMap(String searchBy, String searchCriteria, Map<String, List<String>> searchCriteriaMap) throws Exception {
563 List<String> listOfBibs = new ArrayList<>();
564 List<String> valueList = new ArrayList<>();
565 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
566 SearchResponse searchResponse = null;
567 if (searchBy.equals(OLEConstants.OLEEResourceRecord.ERESOURCE_ISBN)) {
568 if ("001".equals(OLEConstants.COMMON_IDENTIFIER_SEARCH)) {
569 String code = "wbm-" + searchCriteria;
570 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id", code), ""));
571 } else {
572 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), OLEConstants.COMMON_IDENTIFIER_SEARCH, searchCriteria), ""));
573 }
574
575
576 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id"));
577
578
579 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
580 for (SearchResult searchResult : searchResponse.getSearchResults()) {
581 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
582 String fieldName = searchResultField.getFieldName();
583 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
584
585 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
586 listOfBibs.add(fieldValue);
587 }
588 }
589 }
590
591
592 if (listOfBibs.size() > 0) {
593 valueList.addAll(listOfBibs);
594 searchCriteriaMap.put(searchBy, valueList);
595
596
597 }
598 } else if (searchBy.equals(OLEConstants.OLEEResourceRecord.ERESOURCE_OCLC)) {
599 if ("001".equals(OLEConstants.OCLC_SEARCH)) {
600 String code = "wbm-" + searchCriteria;
601 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id", code), ""));
602 } else {
603 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), OLEConstants.OCLC_SEARCH, searchCriteria), ""));
604 }
605 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id"));
606 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
607 for (SearchResult searchResult : searchResponse.getSearchResults()) {
608 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
609 String fieldName = searchResultField.getFieldName();
610 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
611
612 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
613 listOfBibs.add(fieldValue);
614 }
615 }
616 }
617 if (listOfBibs.size() > 0) {
618 valueList.addAll(listOfBibs);
619 searchCriteriaMap.put(searchBy, valueList);
620 }
621 } else {
622 valueList.add(searchCriteria);
623 searchCriteriaMap.put(searchBy, valueList);
624 }
625 return searchCriteriaMap;
626 }
627
628 public void getInstanceIdFromERS(List<OLEEResourceInstance> oleERSInstanceList, OleHoldings eHoldings) {
629 String instanceId = "";
630 if (oleERSInstanceList.size() > 0) {
631 for (OLEEResourceInstance oleERSInstance : oleERSInstanceList) {
632 Map ersIdMap = new HashMap();
633 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSInstance.getOleERSIdentifier());
634 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID, oleERSInstance.getInstanceId());
635 List<OLEEResourceInstance> eResourceInstance = (List<OLEEResourceInstance>) KRADServiceLocator.getBusinessObjectService().findMatching(OLEEResourceInstance.class, ersIdMap);
636 if (eResourceInstance.size() > 0) {
637 for (OLEEResourceInstance eInstanceRec : eResourceInstance) {
638 instanceId += eInstanceRec.getInstanceId();
639 instanceId += ",";
640 }
641
642
643 }
644 }
645 }
646 }
647
648 public void getPOIdFromERS(List<OLEEResourcePO> oleERSPOList, OleHoldings eHoldings) {
649 String poId = "";
650 if (oleERSPOList.size() > 0) {
651 for (OLEEResourcePO oleERSPO : oleERSPOList) {
652 Map ersIdMap = new HashMap();
653 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSPO.getOleERSIdentifier());
654 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_PO_ITEM_ID, oleERSPO.getOlePOItemId());
655 List<OLEEResourcePO> eResourcePO = (List<OLEEResourcePO>) KRADServiceLocator.getBusinessObjectService().findMatching(OLEEResourcePO.class, ersIdMap);
656 if (eResourcePO.size() > 0) {
657 for (OLEEResourcePO ePORec : eResourcePO) {
658 poId += ePORec.getOlePOItemId();
659 poId += ",";
660 }
661
662
663 }
664 }
665 }
666 }
667
668 public void getEResourcesLicenseFields(String eResourceId, WorkEInstanceOlemlForm eInstanceOlemlForm) {
669 List<OLEEResourceLicense> oleERSLicenses = new ArrayList<OLEEResourceLicense>();
670 Map ersIdMap = new HashMap();
671 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
672 OLEEResourceRecordDocument eResourceDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, ersIdMap);
673 if (eResourceDocument != null) {
674 oleERSLicenses = eResourceDocument.getOleERSLicenseRequests();
675 if (oleERSLicenses.size() > 0) {
676 for (OLEEResourceLicense oleeResourceLicense : oleERSLicenses) {
677 DocumentRouteHeaderValue documentRouteHeaderValue = oleeResourceLicense.getDocumentRouteHeaderValue();
678 if (documentRouteHeaderValue != null) {
679 String licenceTitle = documentRouteHeaderValue.getDocTitle();
680 if (licenceTitle != null && !licenceTitle.isEmpty()) {
681 licenceTitle = licenceTitle.substring(26);
682 }
683 oleeResourceLicense.setDocumentDescription(licenceTitle);
684 }
685 }
686 eInstanceOlemlForm.getExtendedEHoldingFields().setLicense(oleERSLicenses);
687 }
688 }
689 }
690
691 public OLEEResourceRecordDocument getNewOleERSDoc(OLEEResourceRecordDocument oleERSDoc) {
692 if (oleERSDoc.getOleERSIdentifier() != null && !oleERSDoc.getOleERSIdentifier().isEmpty()) {
693 Map<String, String> tempId = new HashMap<String, String>();
694 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSDoc.getOleERSIdentifier());
695 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
696 if (tempDocument != null) {
697 if (tempDocument.getOleMaterialTypes().size() > 0) {
698 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleMaterialTypes());
699 }
700 if (tempDocument.getOleFormatTypes().size() > 0) {
701 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleFormatTypes());
702 }
703 if (tempDocument.getOleContentTypes().size() > 0) {
704 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleContentTypes());
705 }
706 if (tempDocument.getSelectors().size() > 0) {
707 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getSelectors());
708 }
709 if (tempDocument.getRequestors().size() > 0) {
710 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getRequestors());
711 }
712 if (tempDocument.getReqSelComments().size() > 0) {
713 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getReqSelComments());
714 }
715 if (tempDocument.getEresNotes().size() > 0) {
716 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getEresNotes());
717 }
718 if (tempDocument.getOleERSLicenseRequests().size() > 0) {
719 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleERSLicenseRequests());
720 }
721 if (tempDocument.getOleERSEventLogs().size() > 0) {
722 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleERSEventLogs());
723 }
724 if (tempDocument.getOleERSPOItems().size() > 0) {
725 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleERSPOItems());
726 }
727 if (tempDocument.getOleERSInstances().size() > 0) {
728 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleERSInstances());
729 }
730 if (tempDocument.getOleERSInvoices().size() > 0) {
731 KRADServiceLocator.getBusinessObjectService().delete(tempDocument.getOleERSInvoices());
732 }
733 }
734 }
735 return oleERSDoc;
736 }
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756 public void getDefaultCovergeDate(OLEEResourceRecordDocument oleERSDoc) {
757 String defaultCoverage = oleERSDoc.getDefaultCoverage();
758 String startCov = "";
759 String endCov = "";
760 String dummyStartCov = "";
761 String dummyEndCov = "";
762 String separator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR);
763 String dateSeparator = getParameter(OLEConstants.OLEEResourceRecord.COVERAGE_DATE_SEPARATOR);
764 if (StringUtils.isNotEmpty(defaultCoverage)) {
765 if (defaultCoverage.contains(separator)) {
766 String[] defaultCoverageDates = defaultCoverage.split(dateSeparator);
767 if (defaultCoverageDates[0].contains(separator)) {
768 String[] startCoverage = defaultCoverageDates[0].split(separator);
769 if (startCoverage.length > 0) {
770 if (startCoverage.length > 0 && !startCoverage[0].isEmpty()) {
771 startCov += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL;
772 startCov += startCoverage[0];
773 startCov += separator;
774 dummyStartCov += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL + startCoverage[0] + separator;
775 } else {
776 dummyStartCov += separator;
777 }
778 if (startCoverage.length > 1 && !startCoverage[1].isEmpty()) {
779 startCov += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE;
780 startCov += startCoverage[1];
781 startCov += separator;
782 dummyStartCov += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE + startCoverage[1] + separator;
783 } else {
784 dummyStartCov += separator;
785 }
786 if (startCoverage.length > 2 && !startCoverage[2].isEmpty()) {
787 startCov += OLEConstants.OLEEResourceRecord.SPACE + startCoverage[2] + OLEConstants.OLEEResourceRecord.SPACE;
788 startCov += separator;
789 dummyStartCov += startCoverage[2] + separator;
790 } else {
791 dummyStartCov += separator;
792 }
793
794
795
796
797
798
799 startCov = startCov.substring(0, startCov.lastIndexOf(separator));
800 } else {
801 startCov = "";
802 }
803 }
804 if (defaultCoverageDates[1].contains(separator)) {
805 String[] endCoverage = defaultCoverageDates[1].split(separator);
806 if (endCoverage.length > 0) {
807 if (endCoverage.length > 0 && !endCoverage[0].isEmpty()) {
808 endCov += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL;
809 endCov += endCoverage[0];
810 endCov += separator;
811 dummyEndCov += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL + endCoverage[0] + separator;
812 } else {
813 dummyEndCov += separator;
814 }
815 if (endCoverage.length > 1 && !endCoverage[1].isEmpty()) {
816 endCov += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE;
817 endCov += endCoverage[1];
818 endCov += separator;
819 dummyEndCov += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE + endCoverage[1] + separator;
820 } else {
821 dummyEndCov += separator;
822 }
823 if (endCoverage.length > 2 && !endCoverage[2].isEmpty()) {
824 endCov += OLEConstants.OLEEResourceRecord.SPACE + endCoverage[2];
825 endCov += separator;
826 dummyEndCov += endCoverage[2] + separator;
827 } else {
828 dummyEndCov += separator;
829 }
830
831
832
833
834
835
836 endCov = endCov.substring(0, endCov.lastIndexOf(separator));
837 } else {
838 endCov = "";
839 }
840 }
841 }
842 if ((endCov != null && !endCov.isEmpty()) && (startCov != null && !startCov.isEmpty())) {
843 oleERSDoc.setDefaultCoverageView(startCov + dateSeparator + endCov);
844 oleERSDoc.setDummyDefaultCoverage(dummyStartCov + dateSeparator + dummyEndCov);
845 } else if (startCov != null && !startCov.isEmpty()) {
846 oleERSDoc.setDefaultCoverageView(startCov);
847 oleERSDoc.setDummyDefaultCoverage(dummyStartCov);
848 } else if (endCov != null && !endCov.isEmpty()) {
849 oleERSDoc.setDefaultCoverageView(endCov);
850 oleERSDoc.setDummyDefaultCoverage(dummyEndCov);
851 } else {
852 oleERSDoc.setDefaultCoverageView(null);
853 oleERSDoc.setDummyDefaultCoverage(null);
854 }
855 }
856 }
857
858 public void getDefaultPerpetualAccessDate(OLEEResourceRecordDocument oleERSDoc) {
859 String defaultPerpetualAcc = oleERSDoc.getDefaultPerpetualAccess();
860 String startPerAcc = "";
861 String endPerAcc = "";
862 String dummyStartPerAcc = "";
863 String dummyEndPerAcc = "";
864 String separator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR);
865 String dateSeparator = getParameter(OLEConstants.OLEEResourceRecord.PERPETUAL_ACCESS_DATE_SEPARATOR);
866 if (StringUtils.isNotEmpty(defaultPerpetualAcc)) {
867 if (defaultPerpetualAcc.contains(dateSeparator)) {
868 String[] defaultPerAccDates = defaultPerpetualAcc.split(dateSeparator);
869 if (defaultPerAccDates[0].contains(separator)) {
870 String[] startPerpetualAccess = defaultPerAccDates[0].split(separator);
871 if (startPerpetualAccess.length > 0) {
872 if (startPerpetualAccess.length > 0 && !startPerpetualAccess[0].isEmpty()) {
873 startPerAcc += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL;
874 startPerAcc += startPerpetualAccess[0];
875 startPerAcc += separator;
876 dummyStartPerAcc += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL + startPerpetualAccess[0] + separator;
877 } else {
878 dummyStartPerAcc += separator;
879 }
880 if (startPerpetualAccess.length > 1 && !startPerpetualAccess[1].isEmpty()) {
881 startPerAcc += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE;
882 startPerAcc += startPerpetualAccess[1];
883 startPerAcc += separator;
884 dummyStartPerAcc += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE + startPerpetualAccess[1] + separator;
885 } else {
886 dummyStartPerAcc += separator;
887 }
888 if (startPerpetualAccess.length > 2 && !startPerpetualAccess[2].isEmpty()) {
889 startPerAcc += OLEConstants.OLEEResourceRecord.SPACE + startPerpetualAccess[2] + OLEConstants.OLEEResourceRecord.SPACE;
890 startPerAcc += separator;
891 dummyStartPerAcc += startPerpetualAccess[2] + separator;
892 } else {
893 dummyStartPerAcc += separator;
894 }
895
896
897
898
899
900
901 startPerAcc = startPerAcc.substring(0, startPerAcc.lastIndexOf(separator));
902 } else {
903 startPerAcc = "";
904 }
905 }
906 if (defaultPerAccDates[1].contains(separator)) {
907 String[] endPerpetualAcc = defaultPerAccDates[1].split(separator);
908 if (endPerpetualAcc.length > 0) {
909 if (endPerpetualAcc.length > 0 && !endPerpetualAcc[0].isEmpty()) {
910 endPerAcc += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL;
911 endPerAcc += endPerpetualAcc[0];
912 endPerAcc += separator;
913 dummyEndPerAcc += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL + endPerpetualAcc[0] + separator;
914 } else {
915 dummyEndPerAcc += separator;
916 }
917 if (endPerpetualAcc.length > 1 && !endPerpetualAcc[1].isEmpty()) {
918 endPerAcc += OLEConstants.OLEEResourceRecord.SPACE + OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE;
919 endPerAcc += endPerpetualAcc[1];
920 endPerAcc += separator;
921 dummyEndPerAcc += OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE + endPerpetualAcc[1] + separator;
922 } else {
923 dummyEndPerAcc += separator;
924 }
925 if (endPerpetualAcc.length > 2 && !endPerpetualAcc[2].isEmpty()) {
926 endPerAcc += OLEConstants.OLEEResourceRecord.SPACE + endPerpetualAcc[2];
927 endPerAcc += separator;
928 dummyEndPerAcc += endPerpetualAcc[2] + separator;
929 } else {
930 dummyEndPerAcc += separator;
931 }
932
933
934
935
936
937
938 endPerAcc = endPerAcc.substring(0, endPerAcc.lastIndexOf(separator));
939 } else {
940 endPerAcc = "";
941 }
942 }
943 }
944 if ((endPerAcc != null && !endPerAcc.isEmpty()) && (startPerAcc != null && !startPerAcc.isEmpty())) {
945 oleERSDoc.setDefaultPerpetualAccessView(startPerAcc + dateSeparator + endPerAcc);
946 oleERSDoc.setDummyDefaultPerpetualAccess(dummyStartPerAcc + dateSeparator + dummyEndPerAcc);
947 } else if (startPerAcc != null && !startPerAcc.isEmpty()) {
948 oleERSDoc.setDefaultPerpetualAccessView(startPerAcc);
949 oleERSDoc.setDummyDefaultPerpetualAccess(dummyStartPerAcc);
950 } else if (endPerAcc != null && !endPerAcc.isEmpty()) {
951 oleERSDoc.setDefaultPerpetualAccessView(endPerAcc);
952 oleERSDoc.setDummyDefaultPerpetualAccess(dummyEndPerAcc);
953 } else {
954 oleERSDoc.setDefaultPerpetualAccessView(null);
955 oleERSDoc.setDummyDefaultPerpetualAccess(null);
956 }
957
958 }
959 }
960
961 public OLEEResourceRecordDocument saveDefaultCoverageDate(OLEEResourceRecordDocument oleeResourceRecordDocument) {
962 StringBuffer defaultCoverageDate = new StringBuffer();
963 OLEEResourceInstance oleERSInstance = oleeResourceRecordDocument.getOleERSInstance();
964 String separator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR);
965 if (oleERSInstance != null && oleERSInstance.getCovStartDate() != null) {
966 defaultCoverageDate.append(StringUtils.isNotEmpty(oleERSInstance.getCovStartVolume()) ? oleERSInstance.getCovStartVolume() + separator : separator);
967 defaultCoverageDate.append(StringUtils.isNotEmpty(oleERSInstance.getCovStartIssue()) ? oleERSInstance.getCovStartIssue() + separator : separator);
968 defaultCoverageDate.append(StringUtils.isNotEmpty(oleERSInstance.getCovStartDate()) ? oleERSInstance.getCovStartDate() : "");
969 if (defaultCoverageDate.length() > 0) {
970 defaultCoverageDate.append(getParameter(OLEConstants.OLEEResourceRecord.COVERAGE_DATE_SEPARATOR));
971 }
972 defaultCoverageDate.append(StringUtils.isNotEmpty(oleERSInstance.getCovEndVolume()) ? oleERSInstance.getCovEndVolume() + separator : separator);
973 defaultCoverageDate.append(StringUtils.isNotEmpty(oleERSInstance.getCovEndIssue()) ? oleERSInstance.getCovEndIssue() + separator : separator);
974 defaultCoverageDate.append(StringUtils.isNotEmpty(oleERSInstance.getCovEndDate()) ? oleERSInstance.getCovEndDate() : "");
975 if (StringUtils.isNotEmpty(defaultCoverageDate)) {
976 oleeResourceRecordDocument.setDefaultCoverage(defaultCoverageDate.toString());
977 }
978 }
979 return oleeResourceRecordDocument;
980 }
981
982 public OLEEResourceRecordDocument saveDefaultPerpetualAccessDate(OLEEResourceRecordDocument oleeResourceRecordDocument) {
983 StringBuffer defaultPerpetualDate = new StringBuffer();
984 OLEEResourceInstance oleERSInstance = oleeResourceRecordDocument.getOleERSInstance();
985 String separator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR);
986 if (oleERSInstance != null && oleERSInstance.getPerpetualAccStartDate() != null) {
987 defaultPerpetualDate.append(StringUtils.isNotEmpty(oleERSInstance.getPerpetualAccStartVolume()) ? oleERSInstance.getPerpetualAccStartVolume() + separator : separator);
988 defaultPerpetualDate.append(StringUtils.isNotEmpty(oleERSInstance.getPerpetualAccStartIssue()) ? oleERSInstance.getPerpetualAccStartIssue() + separator : separator);
989 defaultPerpetualDate.append(StringUtils.isNotEmpty(oleERSInstance.getPerpetualAccStartDate()) ? oleERSInstance.getPerpetualAccStartDate() : "");
990 if (defaultPerpetualDate.length() > 0) {
991 defaultPerpetualDate.append(getParameter(OLEConstants.OLEEResourceRecord.PERPETUAL_ACCESS_DATE_SEPARATOR));
992 }
993 defaultPerpetualDate.append(StringUtils.isNotEmpty(oleERSInstance.getPerpetualAccEndVolume()) ? oleERSInstance.getPerpetualAccEndVolume() + separator : separator);
994 defaultPerpetualDate.append(StringUtils.isNotEmpty(oleERSInstance.getPerpetualAccEndIssue()) ? oleERSInstance.getPerpetualAccEndIssue() + separator : separator);
995 defaultPerpetualDate.append(StringUtils.isNotEmpty(oleERSInstance.getPerpetualAccEndDate()) ? oleERSInstance.getPerpetualAccEndDate() : "");
996 if (StringUtils.isNotEmpty(defaultPerpetualDate)) {
997 oleeResourceRecordDocument.setDefaultPerpetualAccess(defaultPerpetualDate.toString());
998 }
999 }
1000 return oleeResourceRecordDocument;
1001 }
1002
1003 public void getNewInstance(OLEEResourceRecordDocument oleERSDoc, String documentNumber) throws Exception {
1004
1005 if (OleDocstoreResponse.getInstance().getEditorResponse() != null) {
1006 HashMap<String, OLEEditorResponse> oleEditorResponses = OleDocstoreResponse.getInstance().getEditorResponse();
1007 OLEEditorResponse oleEditorResponse = oleEditorResponses.get(documentNumber);
1008 String separator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR);
1009 String isbnAndissn = "";
1010 List<String> instanceId = new ArrayList<String>();
1011 List<OLEEResourceInstance> oleeResourceInstances = oleERSDoc.getOleERSInstances();
1012 if (oleeResourceInstances.size() == 0) {
1013 oleeResourceInstances = new ArrayList<OLEEResourceInstance>();
1014 }
1015
1016
1017
1018 if (oleEditorResponse != null && StringUtils.isNotEmpty(oleEditorResponse.getLinkedInstanceId())) {
1019 instanceId.add(oleEditorResponse.getLinkedInstanceId());
1020 }
1021 Holdings holdings = null;
1022 if (oleEditorResponse != null && oleERSDoc.getSelectInstance() != null && (oleERSDoc.getSelectInstance().equals(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE)) || oleERSDoc.getSelectInstance().equals(OLEConstants.OLEEResourceRecord.CREATE_NEW_INSTANCE)) {
1023 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleEditorResponse.getLinkedInstanceId());
1024
1025 }
1026 int index = -1;
1027 if (holdings != null && holdings.getId() != null) {
1028 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1029 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1030 if (holdings instanceof org.kuali.ole.docstore.common.document.EHoldings) {
1031 if (oleEditorResponse != null && oleEditorResponse.getLinkedInstanceId().equalsIgnoreCase(holdings.getId())) {
1032 OLEEResourceInstance oleeResourceInstance = new OLEEResourceInstance();
1033 if (oleERSDoc.getOleERSInstances() != null && oleERSDoc.getOleERSInstances().size() > 0) {
1034 for (OLEEResourceInstance eResourceInstance : oleeResourceInstances) {
1035 if (eResourceInstance.getInstanceId().equals(oleEditorResponse.getLinkedInstanceId())) {
1036 index = oleeResourceInstances.indexOf(eResourceInstance);
1037 oleeResourceInstance = eResourceInstance;
1038 }
1039 }
1040 }
1041 oleeResourceInstance.setInstanceTitle(holdings.getBib().getTitle());
1042 getHoldingsField(oleeResourceInstance, oleHoldings);
1043 oleeResourceInstance.setInstancePublisher(oleHoldings.getPublisher());
1044 oleeResourceInstance.setPlatForm(oleHoldings.getPlatform().getPlatformName());
1045
1046 StringBuffer urls = new StringBuffer();
1047 for(Link link :oleHoldings.getLink()){
1048 urls.append(link.getUrl());
1049 urls.append(",");
1050 }
1051 if(urls.toString().contains(",")){
1052 String url = urls.substring(0,urls.lastIndexOf(","));
1053 oleeResourceInstance.setUrl(url);
1054 }
1055
1056 SearchParams searchParams = new SearchParams();
1057 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(null, searchParams.buildSearchField(OLEConstants.BIB_DOC_TYPE, OLEConstants.BIB_SEARCH, holdings.getBib().getId()), null));
1058 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISBN));
1059 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISSN));
1060 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1061 SearchResult searchResult;
1062 if (searchResponse.getSearchResults().size() > 0) {
1063 searchResult = searchResponse.getSearchResults().get(0);
1064 searchResult.getSearchResultFields();
1065 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1066 isbnAndissn += searchResultField.getFieldValue();
1067 isbnAndissn += separator;
1068 }
1069 }
1070 if (StringUtils.isNotEmpty(isbnAndissn)) {
1071 isbnAndissn = isbnAndissn.substring(0, isbnAndissn.lastIndexOf(separator));
1072 }
1073 oleeResourceInstance.setIsbn(isbnAndissn);
1074 oleeResourceInstance.setStatus(oleHoldings.getAccessStatus());
1075 oleeResourceInstance.setSubscriptionStatus(oleHoldings.getSubscriptionStatus());
1076 oleeResourceInstance.setBibId(holdings.getBib().getId());
1077 oleeResourceInstance.setInstanceId(holdings.getId());
1078 oleeResourceInstance.setInstanceFlag("false");
1079 if (index >= 0) {
1080 oleeResourceInstances.add(index, oleeResourceInstance);
1081 } else {
1082 oleeResourceInstances.add(oleeResourceInstance);
1083 }
1084 updateEResInOleCopy(holdings, oleERSDoc);
1085 }
1086 }
1087 if (holdings instanceof org.kuali.ole.docstore.common.document.PHoldings) {
1088 if (oleEditorResponse != null && oleEditorResponse.getLinkedInstanceId().equalsIgnoreCase(holdings.getId())) {
1089 OLEEResourceInstance oleeResourceInstance = new OLEEResourceInstance();
1090 if (oleERSDoc.getOleERSInstances() != null && oleERSDoc.getOleERSInstances().size() > 0) {
1091 for (OLEEResourceInstance eResourceInstance : oleeResourceInstances) {
1092 if (eResourceInstance.getInstanceId().equals(oleEditorResponse.getLinkedInstanceId())) {
1093 index = oleeResourceInstances.indexOf(eResourceInstance);
1094 oleeResourceInstance = eResourceInstance;
1095 }
1096 }
1097 }
1098 oleeResourceInstance.setInstanceTitle(holdings.getBib().getTitle());
1099 oleeResourceInstance.setInstancePublisher(holdings.getBib().getPublisher());
1100 SearchParams searchParams = new SearchParams();
1101 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(null, searchParams.buildSearchField(OLEConstants.BIB_DOC_TYPE, OLEConstants.BIB_SEARCH, holdings.getBib().getId()), null));
1102 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISBN));
1103 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISSN));
1104 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1105 SearchResult searchResult;
1106 if (searchResponse.getSearchResults().size() > 0) {
1107 searchResult = searchResponse.getSearchResults().get(0);
1108 searchResult.getSearchResultFields();
1109 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1110 isbnAndissn += searchResultField.getFieldValue();
1111 isbnAndissn += separator;
1112 }
1113 }
1114 if (StringUtils.isNotEmpty(isbnAndissn)) {
1115 isbnAndissn = isbnAndissn.substring(0, isbnAndissn.lastIndexOf(separator));
1116 }
1117 oleeResourceInstance.setIsbn(isbnAndissn);
1118 oleeResourceInstance.setBibId(holdings.getBib().getId());
1119 oleeResourceInstance.setInstanceId(holdings.getId());
1120 oleeResourceInstance.setHoldingsId(oleHoldings.getHoldingsIdentifier());
1121 oleeResourceInstance.setInstanceFlag("true");
1122 if (index >= 0) {
1123 oleeResourceInstances.add(index, oleeResourceInstance);
1124 } else {
1125 oleeResourceInstances.add(oleeResourceInstance);
1126 }
1127 updateEResInOleCopy(holdings, oleERSDoc);
1128 }
1129 }
1130 }
1131 oleERSDoc.setOleERSInstances(oleeResourceInstances);
1132 OleDocstoreResponse.getInstance().setEditorResponse(null);
1133 }
1134 }
1135
1136 public void getPOInvoiceForERS(OLEEResourceRecordDocument oleERSDoc) {
1137 try {
1138 Holdings holdings = null;
1139 List<OLEEResourcePO> oleeResourcePOs = new ArrayList<>();
1140 List<OLEEResourceInvoices> oleeResourceInvoiceses = new ArrayList<>();
1141 for (OLEEResourceInstance oleeResourceInstance : oleERSDoc.getOleERSInstances()) {
1142 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleeResourceInstance.getInstanceId());
1143 if (holdings != null) {
1144 Map<String, String> criteriaMap = new HashMap<String, String>();
1145 criteriaMap.put(OLEConstants.INSTANCE_ID, holdings.getId());
1146 List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class,
1147 criteriaMap);
1148 for (OleCopy copy : copies) {
1149 if (copy.getPoItemId() != null) {
1150 OLEEResourcePO oleeResourcePO = new OLEEResourcePO();
1151 oleeResourcePO.setTitle(holdings.getBib().getTitle());
1152 Map<String, String> criteriaPOIdMap = new HashMap<String, String>();
1153 criteriaPOIdMap.put(OLEConstants.OLEEResourceRecord.PO_ITEM_ID, copy.getPoItemId().toString());
1154 List<OlePurchaseOrderItem> olePurchaseOrderItems = (List<OlePurchaseOrderItem>) getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, criteriaPOIdMap);
1155 if (olePurchaseOrderItems.size() > 0) {
1156 for (OlePurchaseOrderItem olePurchaseOrderItem : olePurchaseOrderItems) {
1157 Map map = new HashMap();
1158 map.put(OLEConstants.DOC_NUM, olePurchaseOrderItem.getDocumentNumber());
1159 OlePurchaseOrderDocument olePurchaseOrderDocument = getBusinessObjectService().findByPrimaryKey(OlePurchaseOrderDocument.class, map);
1160 if (olePurchaseOrderDocument != null) {
1161 oleeResourcePO.setOlePOItemId(olePurchaseOrderDocument.getPurapDocumentIdentifier());
1162 Integer poCreatedYear = olePurchaseOrderDocument.getPostingYear();
1163 Integer currentYear = Calendar.getInstance().get(Calendar.YEAR);
1164 if (currentYear.compareTo(poCreatedYear) == 0) {
1165 oleeResourcePO.setPaidAmountCurrentFY(olePurchaseOrderItem.getItemInvoicedTotalAmount().intValue());
1166 } else if (currentYear.compareTo(poCreatedYear) == 1) {
1167 oleeResourcePO.setPaidAmountPreviousFY(olePurchaseOrderItem.getItemInvoicedTotalAmount().intValue());
1168 } else if (currentYear.compareTo(poCreatedYear) > 1) {
1169 oleeResourcePO.setPaidAmountTwoYearsPreviousFY(olePurchaseOrderItem.getItemInvoicedTotalAmount().intValue());
1170 }
1171 }
1172 }
1173 }
1174 oleeResourcePOs.add(oleeResourcePO);
1175
1176
1177 Map<String, String> criteriaInvIdMap = new HashMap<String, String>();
1178 criteriaInvIdMap.put(OLEConstants.OLEEResourceRecord.INV_PO_ITEM_ID, copy.getPoItemId().toString());
1179 List<OleInvoiceItem> oleInvoiceItems = (List<OleInvoiceItem>) getBusinessObjectService().findMatching(OleInvoiceItem.class, criteriaInvIdMap);
1180 if (oleInvoiceItems.size() > 0) {
1181 for (OleInvoiceItem oleInvoiceItem : oleInvoiceItems) {
1182 OLEEResourceInvoices oleEResInvoice = new OLEEResourceInvoices();
1183 oleEResInvoice.setInvoiceId(oleInvoiceItem.getItemIdentifier().toString());
1184 OleInvoiceDocument oleInvoiceDocument = (OleInvoiceDocument) oleInvoiceItem.getInvoiceDocument();
1185 if (oleInvoiceItem.getInvoiceDocument() != null) {
1186 oleEResInvoice.setInvoiceNumber(oleInvoiceItem.getInvoiceDocument().getDocumentNumber());
1187 oleEResInvoice.setInvoiceDate(oleInvoiceItem.getInvoiceDocument().getInvoiceDate());
1188 oleEResInvoice.setVendorName(oleInvoiceItem.getInvoiceDocument().getVendorName());
1189 if (SpringContext.getBean(DocumentHeaderService.class) != null) {
1190 oleInvoiceDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(oleInvoiceDocument.getDocumentNumber()));
1191 oleEResInvoice.setInvoiceStatus(oleInvoiceDocument.getApplicationDocumentStatus());
1192 }
1193 }
1194 oleEResInvoice.setInvoicedAmount(oleInvoiceItem.getExtendedPrice().toString());
1195 Map map = new HashMap();
1196 map.put(OLEConstants.OLEEResourceRecord.INV_PO_ITEM_ID, oleInvoiceItem.getItemIdentifier());
1197 OlePaymentRequestItem olePaymentRequestItem = getBusinessObjectService().findByPrimaryKey(OlePaymentRequestItem.class, map);
1198 if (olePaymentRequestItem != null) {
1199 oleEResInvoice.setPaidDate(olePaymentRequestItem.getPaymentRequestDocument().getPaymentRequestPayDate());
1200 }
1201 StringBuffer fundCode = new StringBuffer();
1202 if (oleInvoiceItem.getSourceAccountingLines() != null && oleInvoiceItem.getSourceAccountingLines().size() > 0) {
1203 for (PurApAccountingLine accountingLine : oleInvoiceItem.getSourceAccountingLines()) {
1204 map.clear();
1205 map.put(OLEConstants.ACCOUNT_NUMBER, accountingLine.getAccountNumber());
1206 map.put(OLEConstants.OBJECT_CODE, accountingLine.getFinancialObjectCode());
1207 OleVendorAccountInfo oleVendorAccountInfo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleVendorAccountInfo.class, map);
1208 if (oleVendorAccountInfo != null) {
1209 fundCode.append(oleVendorAccountInfo.getVendorRefNumber());
1210 fundCode.append(OLEConstants.COMMA);
1211 fundCode.append(' ');
1212 }
1213 }
1214 }
1215 if (fundCode.length() > 0) {
1216 fundCode.deleteCharAt(fundCode.length() - 2);
1217 oleEResInvoice.setFundCode(fundCode.toString());
1218 }
1219 oleeResourceInvoiceses.add(oleEResInvoice);
1220 }
1221 }
1222 }
1223 }
1224 }
1225 }
1226 oleERSDoc.setOleERSPOItems(oleeResourcePOs);
1227 oleERSDoc.setOleERSInvoices(oleeResourceInvoiceses);
1228 } catch (Exception e) {
1229 LOG.error("Exception " + e);
1230 }
1231 }
1232
1233 private void getHoldingsField(OLEEResourceInstance oleeResourceInstance, OleHoldings oleHoldings) {
1234 Map<String,String> map=new HashMap();
1235 String start="";
1236 String end="";
1237 String holdings = "";
1238 String startDate = "";
1239 String endDate = "";
1240 String space = OLEConstants.OLEEResourceRecord.SPACE;
1241 String separator = getParameter(OLEConstants.OLEEResourceRecord.COVERAGE_DATE_SEPARATOR);
1242 String commaSeparator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR) + space;
1243 map.put("oleERSIdentifier",oleHoldings.getEResourceId());
1244 List<OLEEResourceRecordDocument> oleeResourceRecordDocuments = (List<OLEEResourceRecordDocument>) getBusinessObjectService().findMatching(OLEEResourceRecordDocument.class, map);
1245 if (oleeResourceRecordDocuments.size() > 0) {
1246 String defaultCoverage = oleeResourceRecordDocuments.get(0).getDefaultCoverage();
1247 if (defaultCoverage != null) {
1248 String[] defaultCovDates = defaultCoverage.split("-");
1249 String defCovStartDat = defaultCovDates.length > 0 ? defaultCovDates[0] : "";
1250 if (!defCovStartDat.isEmpty()) {
1251 String[] covStartDate = defCovStartDat.split(",");
1252 if (covStartDate.length > 2 && !covStartDate[2].isEmpty()) {
1253 start = covStartDate[2];
1254 }
1255 }
1256 String defCovEndDat = defaultCovDates.length > 1 ? defaultCovDates[1] : "";
1257 if (!defCovEndDat.isEmpty()) {
1258 String[] covEndDate = defCovEndDat.split(",");
1259 if (covEndDate.length > 2 && !covEndDate[2].isEmpty()) {
1260 end = covEndDate[2];
1261 }
1262 }
1263 }
1264 }
1265 if (oleHoldings.getExtentOfOwnership().size() > 0 && oleHoldings.getExtentOfOwnership().get(0).getCoverages() != null) {
1266 List<Coverage> coverageDates = oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage();
1267 if (coverageDates.size() > 0) {
1268 for (Coverage coverageDate : coverageDates) {
1269 startDate = coverageDate.getCoverageStartDate();
1270 endDate = coverageDate.getCoverageEndDate();
1271 if (startDate != null && !startDate.isEmpty() && endDate != null && !endDate.isEmpty()) {
1272 holdings += startDate + space + separator + space + endDate;
1273 holdings += commaSeparator;
1274 } else if (startDate != null && !startDate.isEmpty()) {
1275 holdings += startDate + space + separator + space + end;
1276 holdings += commaSeparator;
1277 } else if (endDate != null && !endDate.isEmpty()) {
1278 holdings += start + space + separator + space + endDate;
1279 holdings += commaSeparator;
1280 }
1281 }
1282 }
1283 } else {
1284 if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) {
1285 holdings += start + space + separator + space + end;
1286 holdings += commaSeparator;
1287 }
1288 else if(start != null && !start.isEmpty()){
1289 holdings += start + space + separator + space + end;
1290 holdings += commaSeparator;
1291 }
1292 else if(end != null && !end.isEmpty()){
1293 holdings += start + space + separator + space + end;
1294 holdings += commaSeparator;
1295 }
1296 }
1297 if (holdings != null && !holdings.isEmpty()) {
1298 holdings = holdings.substring(0, holdings.lastIndexOf(commaSeparator));
1299 }
1300 oleeResourceInstance.setInstanceHoldings(holdings);
1301 }
1302
1303 @Override
1304 public void getDefaultCovDatesToPopup(OLEEResourceRecordDocument oleeResourceRecordDocument, String defaultCov) {
1305 String[] defaultCovDates = defaultCov.split("-");
1306 String defCovStartDat = defaultCovDates.length > 0 ? defaultCovDates[0] : "";
1307 if (oleeResourceRecordDocument.getOleERSInstance() != null) {
1308 if (!defCovStartDat.isEmpty()) {
1309 String[] covStartDate = defCovStartDat.split(",");
1310 if (covStartDate.length > 0 && !covStartDate[0].isEmpty()) {
1311 oleeResourceRecordDocument.getOleERSInstance().setCovStartVolume(covStartDate[0].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL) ? covStartDate[0].substring(7, covStartDate[0].length()) : "");
1312 }
1313 if (covStartDate.length > 1 && !covStartDate[1].isEmpty()) {
1314 oleeResourceRecordDocument.getOleERSInstance().setCovStartIssue(covStartDate[1].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE) ? covStartDate[1].substring(6, covStartDate[1].length()) : "");
1315 }
1316 if (covStartDate.length > 2 && !covStartDate[2].isEmpty()) {
1317 oleeResourceRecordDocument.getOleERSInstance().setCovStartDate(covStartDate[2]);
1318 oleeResourceRecordDocument.setCovStartDate(oleeResourceRecordDocument.getOleERSInstance().getCovStartDate());
1319 }
1320 }
1321 String defCovEndDat = defaultCovDates.length > 1 ? defaultCovDates[1] : "";
1322 if (!defCovEndDat.isEmpty()) {
1323 String[] covEndDate = defCovEndDat.split(",");
1324 if (covEndDate.length > 0 && !covEndDate[0].isEmpty()) {
1325 oleeResourceRecordDocument.getOleERSInstance().setCovEndVolume(covEndDate[0].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL) ? covEndDate[0].substring(7, covEndDate[0].length()) : "");
1326 }
1327 if (covEndDate.length > 1 && !covEndDate[1].isEmpty()) {
1328 oleeResourceRecordDocument.getOleERSInstance().setCovEndIssue(covEndDate[1].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE) ? covEndDate[1].substring(6, covEndDate[1].length()) : "");
1329 }
1330 if (covEndDate.length > 2 && !covEndDate[2].isEmpty()) {
1331 oleeResourceRecordDocument.getOleERSInstance().setCovEndDate(covEndDate[2]);
1332 oleeResourceRecordDocument.setCovEndDate(oleeResourceRecordDocument.getOleERSInstance().getCovEndDate());
1333 }
1334 }
1335 }
1336 }
1337
1338 @Override
1339 public void getDefaultPerAccDatesToPopup(OLEEResourceRecordDocument oleeResourceRecordDocument, String defaultPerpetualAcc) {
1340 String[] defaultPerAccDates = defaultPerpetualAcc.split("-");
1341 String defPerAccStartDat = defaultPerAccDates.length > 0 ? defaultPerAccDates[0] : "";
1342 if (oleeResourceRecordDocument.getOleERSInstance() != null) {
1343 if (!defPerAccStartDat.isEmpty()) {
1344 String[] perAccStartDate = defPerAccStartDat.split(",");
1345 if (perAccStartDate.length > 0 && !perAccStartDate[0].isEmpty()) {
1346 oleeResourceRecordDocument.getOleERSInstance().setPerpetualAccStartVolume(perAccStartDate[0].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL) ? perAccStartDate[0].substring(7, perAccStartDate[0].length()) : "");
1347 }
1348 if (perAccStartDate.length > 1 && !perAccStartDate[1].isEmpty()) {
1349 oleeResourceRecordDocument.getOleERSInstance().setPerpetualAccStartIssue(perAccStartDate[1].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE) ? perAccStartDate[1].substring(6, perAccStartDate[1].length()) : "");
1350 }
1351 if (perAccStartDate.length > 2 && !perAccStartDate[2].isEmpty()) {
1352 oleeResourceRecordDocument.getOleERSInstance().setPerpetualAccStartDate(perAccStartDate[2]);
1353 oleeResourceRecordDocument.setPerAccStartDate(oleeResourceRecordDocument.getOleERSInstance().getPerpetualAccStartDate());
1354 }
1355 }
1356 String defPerAccEndDat = defaultPerAccDates.length > 1 ? defaultPerAccDates[1] : "";
1357 if (!defPerAccEndDat.isEmpty()) {
1358 String[] perAccEndDate = defPerAccEndDat.split(",");
1359 if (perAccEndDate.length > 0 && !perAccEndDate[0].isEmpty()) {
1360 oleeResourceRecordDocument.getOleERSInstance().setPerpetualAccEndVolume(perAccEndDate[0].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_VOL) ? perAccEndDate[0].substring(7, perAccEndDate[0].length()) : "");
1361 }
1362 if (perAccEndDate.length > 1 && !perAccEndDate[1].isEmpty()) {
1363 oleeResourceRecordDocument.getOleERSInstance().setPerpetualAccEndIssue(perAccEndDate[1].contains(OLEConstants.OLEEResourceRecord.DEFAULT_DATE_ISSUE) ? perAccEndDate[1].substring(6, perAccEndDate[1].length()) : "");
1364 }
1365 if (perAccEndDate.length > 2 && !perAccEndDate[2].isEmpty()) {
1366 oleeResourceRecordDocument.getOleERSInstance().setPerpetualAccEndDate(perAccEndDate[2]);
1367 oleeResourceRecordDocument.setPerAccEndDate(oleeResourceRecordDocument.getOleERSInstance().getPerpetualAccEndDate());
1368 }
1369 }
1370 }
1371 }
1372
1373 public boolean validateEResourceDocument(OLEEResourceRecordDocument oleeResourceRecordDocument) {
1374 boolean flag = false;
1375 boolean isSelectorBlank = false;
1376 boolean isRequestorBlank = false;
1377 boolean isReqSelCommentBlank = false;
1378 if (oleeResourceRecordDocument.getOleMaterialTypes().size() == 0) {
1379 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(OLEConstants.OLEEResourceRecord.DOCUMENT_MATERIAL_TYPES, OLEConstants.OLEEResourceRecord.MATERIAL_TYPE_REQUIRED, new String[]{"Material Type"});
1380 flag = true;
1381 }
1382 if (oleeResourceRecordDocument.getOleFormatTypes().size() == 0) {
1383 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(OLEConstants.OLEEResourceRecord.DOCUMENT_FORMAT_TYPES, OLEConstants.OLEEResourceRecord.FORMAT_TYPE_REQUIRED, new String[]{"Format Type"});
1384 flag = true;
1385 }
1386 if (oleeResourceRecordDocument.getOleContentTypes().size() == 0) {
1387 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(OLEConstants.OLEEResourceRecord.DOCUMENT_CONTENT_TYPES, OLEConstants.OLEEResourceRecord.CONTENT_TYPE_REQUIRED, new String[]{"Content Type"});
1388 flag = true;
1389 }
1390 if (oleeResourceRecordDocument.getRequestors().size() > 0) {
1391 for (OLEEResourceRequestor oleeResourceRequestor : oleeResourceRecordDocument.getRequestors()) {
1392 if (oleeResourceRequestor.getRequestorId() == null || oleeResourceRequestor.getRequestorId().equalsIgnoreCase("")) {
1393 if (oleeResourceRecordDocument.getRequestors().size() != 1) {
1394 isRequestorBlank = true;
1395 }
1396 }
1397 }
1398 if (isRequestorBlank) {
1399 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEEResourceRecord.REQUESTOR_SECTION_ID, OLEConstants.OLEEResourceRecord.SHOULD_NOT_BLANK, new String[]{"Requestor Type"});
1400 flag = true;
1401 }
1402 }
1403 if (oleeResourceRecordDocument.getSelectors().size() > 0) {
1404 for (OLEEResourceSelector oleeResourceSelector : oleeResourceRecordDocument.getSelectors()) {
1405 if (oleeResourceSelector.getSelectorId() == null || oleeResourceSelector.getSelectorId().equalsIgnoreCase("")) {
1406 if (oleeResourceRecordDocument.getSelectors().size() != 1) {
1407 isSelectorBlank = true;
1408 }
1409
1410 }
1411 }
1412 if (isSelectorBlank) {
1413 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEEResourceRecord.SELECTOR_SECTION_ID, OLEConstants.OLEEResourceRecord.SHOULD_NOT_BLANK, new String[]{"Selector Type"});
1414 flag = true;
1415 }
1416 }
1417 if (oleeResourceRecordDocument.getReqSelComments().size() > 0) {
1418 for (OLEEResourceReqSelComments oleeResourceReqSelComments : oleeResourceRecordDocument.getReqSelComments()) {
1419 if (oleeResourceReqSelComments.getOleReqSelComments() == null || oleeResourceReqSelComments.getOleReqSelComments().equalsIgnoreCase("")) {
1420 if (oleeResourceRecordDocument.getReqSelComments().size() != 1) {
1421 isReqSelCommentBlank = true;
1422 }
1423 }
1424 }
1425 if (isReqSelCommentBlank) {
1426 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEEResourceRecord.REQUESTOR_SELECTOR_COMMENT_SECTION_ID, OLEConstants.OLEEResourceRecord.SHOULD_NOT_BLANK, new String[]{"RequestorSelectorComment"});
1427 flag = true;
1428 }
1429 }
1430 return flag;
1431 }
1432
1433 public void saveEResourceInstanceToDocstore(OLEEResourceRecordDocument oleeResourceRecordDocument) throws Exception {
1434 if (oleeResourceRecordDocument.getOleERSInstances() != null && oleeResourceRecordDocument.getOleERSInstances().size() != 0) {
1435 List<OLEEResourceInstance> oleeResourceInstanceList = new ArrayList<OLEEResourceInstance>();
1436 oleeResourceInstanceList = oleeResourceRecordDocument.getOleERSInstances();
1437 for (OLEEResourceInstance oleeResourceInstance : oleeResourceInstanceList) {
1438 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1439 String eHoldingsId = oleeResourceInstance.getInstanceId();
1440 Holdings holdings = new EHoldings();
1441 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(eHoldingsId);
1442 OleHoldings eHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1443 eHoldings.setEResourceId(oleeResourceRecordDocument.getOleERSIdentifier());
1444 StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
1445 if (oleeResourceRecordDocument.getOleStatisticalCode() != null) {
1446 statisticalSearchingCode.setCodeValue(oleeResourceRecordDocument.getOleStatisticalCode().getStatisticalSearchingCode());
1447 }
1448 if(eHoldings.getStatisticalSearchingCode()==null||eHoldings.getStatisticalSearchingCode().getCodeValue()==null){
1449 eHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
1450 }
1451 if (eHoldings != null && eHoldings.getHoldingsAccessInformation() == null && oleeResourceRecordDocument != null) {
1452 eHoldings.getHoldingsAccessInformation().setNumberOfSimultaneousUser(oleeResourceRecordDocument.getNumOfSimultaneousUsers());
1453 eHoldings.getHoldingsAccessInformation().setAccessLocation(oleeResourceRecordDocument.getAccessLocationId());
1454 eHoldings.getHoldingsAccessInformation().setAuthenticationType(oleeResourceRecordDocument.getOleAuthenticationType().getOleAuthenticationTypeName());
1455 }
1456 getHoldingsField(oleeResourceInstance,eHoldings);
1457 holdings.setId(eHoldingsId);
1458 holdings.setContent(holdingOlemlRecordProcessor.toXML(eHoldings));
1459 getDocstoreClientLocator().getDocstoreClient().updateHoldings(holdings);
1460 }
1461 }
1462 }
1463
1464 public boolean validateCoverageStartDates(OLEEResourceRecordDocument oleeResourceRecordDocument, OLEEResourceRecordForm oleERSForm) {
1465 boolean coverageStartFlag = true;
1466 OLEEResourceInstance oleeResourceInstance = oleeResourceRecordDocument.getOleERSInstance();
1467 oleERSForm.setDefaultCovStartDateErrorMessage(null);
1468 String coverageStartDate = "";
1469 try {
1470 if (oleeResourceInstance != null) {
1471 coverageStartDate = oleeResourceInstance.getCovStartDate();
1472 if (StringUtils.isNotEmpty(coverageStartDate)) {
1473 if (coverageStartDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
1474
1475 String dateFormat = coverageStartDate;
1476 oleeResourceInstance.setCovStartDate(dateFormat);
1477 } else if (coverageStartDate.matches(calendarYearAgo)) {
1478 String[] coverageStartYear = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1479 if (coverageStartYear.length > 0 && coverageStartYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1480
1481
1482 String previousYearOfCovDate = coverageStartDate;
1483 oleeResourceInstance.setCovStartDate(previousYearOfCovDate);
1484 } else {
1485 coverageStartFlag = false;
1486 oleERSForm.setCoverageFlag(true);
1487 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1488 }
1489 } else if (coverageStartDate.matches(calendarYearsAgo)) {
1490 String[] coverageStartYears = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1491 if (coverageStartYears.length > 0 && !coverageStartYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1492
1493
1494 String previousYearsOfCovDate = coverageStartDate;
1495 oleeResourceInstance.setCovStartDate(previousYearsOfCovDate);
1496 } else {
1497 coverageStartFlag = false;
1498 oleERSForm.setCoverageFlag(true);
1499 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1500 }
1501 } else if (coverageStartDate.matches(monthAgo)) {
1502 String[] coverageStartMonth = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1503 if (coverageStartMonth.length > 0 && coverageStartMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1504
1505 String previousMonthOfCovDate = coverageStartDate;
1506 oleeResourceInstance.setCovStartDate(previousMonthOfCovDate);
1507 } else {
1508 coverageStartFlag = false;
1509 oleERSForm.setCoverageFlag(true);
1510 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1511 }
1512 } else if (coverageStartDate.matches(monthsAgo)) {
1513 String[] coverageStartMonths = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1514 if (coverageStartMonths.length > 0 && !coverageStartMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1515
1516 String previousMonthsOfCovDate = coverageStartDate;
1517 oleeResourceInstance.setCovStartDate(previousMonthsOfCovDate);
1518 } else {
1519 coverageStartFlag = false;
1520 oleERSForm.setCoverageFlag(true);
1521 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1522 }
1523 } else if (coverageStartDate.matches(weekAgo)) {
1524 String[] coverageStartWeek = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1525 if (coverageStartWeek.length > 0 && coverageStartWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1526
1527 String previousWeekOfCovDate = coverageStartDate;
1528 oleeResourceInstance.setCovStartDate(previousWeekOfCovDate);
1529 } else {
1530 coverageStartFlag = false;
1531 oleERSForm.setCoverageFlag(true);
1532 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1533 }
1534 } else if (coverageStartDate.matches(weeksAgo)) {
1535 String[] coverageStartWeeks = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1536 if (coverageStartWeeks.length > 0 && !coverageStartWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1537
1538 String previousYearsOfCovDate = coverageStartDate;
1539 oleeResourceInstance.setCovStartDate(previousYearsOfCovDate);
1540 } else {
1541 coverageStartFlag = false;
1542 oleERSForm.setCoverageFlag(true);
1543 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1544 }
1545 } else if (coverageStartDate.matches(dayAgo)) {
1546 String[] coverageStartDay = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1547 if (coverageStartDay.length > 0 && coverageStartDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1548
1549 String previousDayOfCovDate = coverageStartDate;
1550 oleeResourceInstance.setCovStartDate(previousDayOfCovDate);
1551 } else {
1552 coverageStartFlag = false;
1553 oleERSForm.setCoverageFlag(true);
1554 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1555 }
1556 } else if (coverageStartDate.matches(daysAgo)) {
1557 String[] coverageStartDays = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1558 if (coverageStartDays.length > 0 && !coverageStartDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1559
1560 String previousDaysOfCovDate = coverageStartDate;
1561 oleeResourceInstance.setCovStartDate(previousDaysOfCovDate);
1562 } else {
1563 coverageStartFlag = false;
1564 oleERSForm.setCoverageFlag(true);
1565 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1566 }
1567 } else {
1568 coverageStartFlag = false;
1569 oleERSForm.setCoverageFlag(true);
1570 oleERSForm.setDefaultCovStartDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_START_DATE_FORMAT_INV);
1571 }
1572 }
1573 }
1574 oleeResourceRecordDocument.setCovStartDate(coverageStartDate);
1575 } catch (Exception ex) {
1576 LOG.error("Exception while validating the coverage start date format in EResource" + ex.getMessage());
1577 throw new RuntimeException();
1578 }
1579 return coverageStartFlag;
1580 }
1581
1582 public boolean validateCoverageEndDates(OLEEResourceRecordDocument oleeResourceRecordDocument, OLEEResourceRecordForm oleERSForm) {
1583 boolean coverageEndFlag = true;
1584 OLEEResourceInstance oleeResourceInstance = oleeResourceRecordDocument.getOleERSInstance();
1585 oleERSForm.setDefaultCovEndDateErrorMessage(null);
1586 String coverageEndDate = "";
1587 try {
1588 if (oleeResourceInstance != null) {
1589 coverageEndDate = oleeResourceInstance.getCovEndDate();
1590 if (StringUtils.isNotEmpty(coverageEndDate)) {
1591 if (coverageEndDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
1592
1593 String dateFormat = coverageEndDate;
1594 oleeResourceInstance.setCovEndDate(dateFormat);
1595 } else if (coverageEndDate.matches(calendarYearAgo)) {
1596 String[] coverageEndYear = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1597 if (coverageEndYear.length > 0 && coverageEndYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1598
1599
1600 String previousYearOfCovDate = coverageEndDate;
1601 oleeResourceInstance.setCovEndDate(previousYearOfCovDate);
1602 } else {
1603 coverageEndFlag = false;
1604 oleERSForm.setCoverageFlag(true);
1605 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1606 }
1607 } else if (coverageEndDate.matches(calendarYearsAgo)) {
1608 String[] coverageEndYears = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1609 if (coverageEndYears.length > 0 && !coverageEndYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1610
1611
1612 String previousYearsOfCovDate = coverageEndDate;
1613 oleeResourceInstance.setCovEndDate(previousYearsOfCovDate);
1614 } else {
1615 coverageEndFlag = false;
1616 oleERSForm.setCoverageFlag(true);
1617 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1618 }
1619 } else if (coverageEndDate.matches(monthAgo)) {
1620 String[] coverageEndMonth = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1621 if (coverageEndMonth.length > 0 && coverageEndMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1622
1623 String previousMonthOfCovDate = coverageEndDate;
1624 oleeResourceInstance.setCovEndDate(previousMonthOfCovDate);
1625 } else {
1626 coverageEndFlag = false;
1627 oleERSForm.setCoverageFlag(true);
1628 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1629 }
1630 } else if (coverageEndDate.matches(monthsAgo)) {
1631 String[] coverageEndMonths = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1632 if (coverageEndMonths.length > 0 && !coverageEndMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1633
1634 String previousMonthsOfCovDate = coverageEndDate;
1635 oleeResourceInstance.setCovEndDate(previousMonthsOfCovDate);
1636 } else {
1637 coverageEndFlag = false;
1638 oleERSForm.setCoverageFlag(true);
1639 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1640 }
1641 } else if (coverageEndDate.matches(weekAgo)) {
1642 String[] coverageEndWeek = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1643 if (coverageEndWeek.length > 0 && coverageEndWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1644
1645 String previousWeekOfCovEndDate = coverageEndDate;
1646 oleeResourceInstance.setCovEndDate(previousWeekOfCovEndDate);
1647 } else {
1648 coverageEndFlag = false;
1649 oleERSForm.setCoverageFlag(true);
1650 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1651 }
1652 } else if (coverageEndDate.matches(weeksAgo)) {
1653 String[] coverageEndWeeks = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1654 if (coverageEndWeeks.length > 0 && !coverageEndWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1655
1656 String previousWeeksOfCovEndDate = coverageEndDate;
1657 oleeResourceInstance.setCovEndDate(previousWeeksOfCovEndDate);
1658 } else {
1659 coverageEndFlag = false;
1660 oleERSForm.setCoverageFlag(true);
1661 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1662 }
1663 } else if (coverageEndDate.matches(dayAgo)) {
1664 String[] coverageEndDay = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1665 if (coverageEndDay.length > 0 && coverageEndDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1666
1667 String previousDayOfCovDate = coverageEndDate;
1668 oleeResourceInstance.setCovEndDate(previousDayOfCovDate);
1669 } else {
1670 coverageEndFlag = false;
1671 oleERSForm.setCoverageFlag(true);
1672 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1673 }
1674 } else if (coverageEndDate.matches(daysAgo)) {
1675 String[] coverageEndDays = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1676 if (coverageEndDays.length > 0 && !coverageEndDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1677
1678 String previousDaysOfCovEndDate = coverageEndDate;
1679 oleeResourceInstance.setCovEndDate(previousDaysOfCovEndDate);
1680 } else {
1681 coverageEndFlag = false;
1682 oleERSForm.setCoverageFlag(true);
1683 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1684 }
1685 } else {
1686 coverageEndFlag = false;
1687 oleERSForm.setCoverageFlag(true);
1688 oleERSForm.setDefaultCovEndDateErrorMessage(OLEConstants.OLEEResourceRecord.COV_END_DATE_FORMAT_INV);
1689 }
1690 }
1691 }
1692 oleeResourceRecordDocument.setCovEndDate(coverageEndDate);
1693 } catch (Exception ex) {
1694 LOG.error("Exception while validating the coverage end date format in EResource" + ex.getMessage());
1695 throw new RuntimeException();
1696 }
1697 return coverageEndFlag;
1698 }
1699
1700 public boolean validatePerpetualAccessStartDates(OLEEResourceRecordDocument oleeResourceRecordDocument, OLEEResourceRecordForm oleERSForm) {
1701 boolean perpetualAccessStartFlag = true;
1702 OLEEResourceInstance oleeResourceInstance = oleeResourceRecordDocument.getOleERSInstance();
1703 oleERSForm.setDefaultPerAccStartDateErrorMessage(null);
1704 String perpetualAccessStartDate = "";
1705 try {
1706 if (oleeResourceInstance != null) {
1707 perpetualAccessStartDate = oleeResourceInstance.getPerpetualAccStartDate();
1708 if (StringUtils.isNotEmpty(perpetualAccessStartDate)) {
1709 if (perpetualAccessStartDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
1710
1711 String dateFormat = perpetualAccessStartDate;
1712 oleeResourceInstance.setPerpetualAccStartDate(dateFormat);
1713 } else if (perpetualAccessStartDate.matches(calendarYearAgo)) {
1714 String[] perpetualAccessStartYear = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1715 if (perpetualAccessStartYear.length > 0 && perpetualAccessStartYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1716
1717
1718 String previousYearOfPerpetualAccDate = perpetualAccessStartDate;
1719 oleeResourceInstance.setPerpetualAccStartDate(previousYearOfPerpetualAccDate);
1720 } else {
1721 perpetualAccessStartFlag = false;
1722 oleERSForm.setPerpetualAccessFlag(true);
1723 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1724 }
1725 } else if (perpetualAccessStartDate.matches(calendarYearsAgo)) {
1726 String[] perpetualAccessStartYears = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1727 if (perpetualAccessStartYears.length > 0 && !perpetualAccessStartYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1728
1729
1730 String previousYearsOfPerpetualAccDate = perpetualAccessStartDate;
1731 oleeResourceInstance.setPerpetualAccStartDate(previousYearsOfPerpetualAccDate);
1732 } else {
1733 perpetualAccessStartFlag = false;
1734 oleERSForm.setPerpetualAccessFlag(true);
1735 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1736 }
1737 } else if (perpetualAccessStartDate.matches(monthAgo)) {
1738 String[] perpetualAccessStartMonth = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1739 if (perpetualAccessStartMonth.length > 0 && perpetualAccessStartMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1740
1741 String previousMonthOfPerpetualAccDate = perpetualAccessStartDate;
1742 oleeResourceInstance.setPerpetualAccStartDate(previousMonthOfPerpetualAccDate);
1743 } else {
1744 perpetualAccessStartFlag = false;
1745 oleERSForm.setPerpetualAccessFlag(true);
1746 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1747 }
1748 } else if (perpetualAccessStartDate.matches(monthsAgo)) {
1749 String[] perpetualAccessStartMonths = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1750 if (perpetualAccessStartMonths.length > 0 && !perpetualAccessStartMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1751
1752 String previousMonthsOfPerpetualAccDate = perpetualAccessStartDate;
1753 oleeResourceInstance.setPerpetualAccStartDate(previousMonthsOfPerpetualAccDate);
1754 } else {
1755 perpetualAccessStartFlag = false;
1756 oleERSForm.setPerpetualAccessFlag(true);
1757 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1758 }
1759 } else if (perpetualAccessStartDate.matches(weekAgo)) {
1760 String[] perpetualAccessStartWeek = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1761 if (perpetualAccessStartWeek.length > 0 && perpetualAccessStartWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1762
1763 String previousWeekOfCovEndDate = perpetualAccessStartDate;
1764 oleeResourceInstance.setPerpetualAccStartDate(previousWeekOfCovEndDate);
1765 } else {
1766 perpetualAccessStartFlag = false;
1767 oleERSForm.setPerpetualAccessFlag(true);
1768 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1769 }
1770 } else if (perpetualAccessStartDate.matches(weeksAgo)) {
1771 String[] perpetualAccessStartWeeks = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1772 if (perpetualAccessStartWeeks.length > 0 && !perpetualAccessStartWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1773
1774 String previousWeeksOfCovEndDate = perpetualAccessStartDate;
1775 oleeResourceInstance.setPerpetualAccStartDate(previousWeeksOfCovEndDate);
1776 } else {
1777 perpetualAccessStartFlag = false;
1778 oleERSForm.setPerpetualAccessFlag(true);
1779 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1780 }
1781 } else if (perpetualAccessStartDate.matches(dayAgo)) {
1782 String[] perpetualAccessStartDay = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1783 if (perpetualAccessStartDay.length > 0 && perpetualAccessStartDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1784
1785 String previousDayOfPerpetualAccDate = perpetualAccessStartDate;
1786 oleeResourceInstance.setPerpetualAccStartDate(previousDayOfPerpetualAccDate);
1787 } else {
1788 perpetualAccessStartFlag = false;
1789 oleERSForm.setPerpetualAccessFlag(true);
1790 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1791 }
1792 } else if (perpetualAccessStartDate.matches(daysAgo)) {
1793 String[] perpetualAccessStartDays = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1794 if (perpetualAccessStartDays.length > 0 && !perpetualAccessStartDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1795
1796 String previousDaysOfPerpetualAccDate = perpetualAccessStartDate;
1797 oleeResourceInstance.setPerpetualAccStartDate(previousDaysOfPerpetualAccDate);
1798 } else {
1799 perpetualAccessStartFlag = false;
1800 oleERSForm.setPerpetualAccessFlag(true);
1801 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1802 }
1803 } else {
1804 perpetualAccessStartFlag = false;
1805 oleERSForm.setDefaultPerAccStartDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_START_DATE_FORMAT_INV);
1806 }
1807 }
1808 }
1809 oleeResourceRecordDocument.setPerAccStartDate(perpetualAccessStartDate);
1810 } catch (Exception ex) {
1811 LOG.error("Exception while validating the perpetual access start date format in EResource" + ex.getMessage());
1812 throw new RuntimeException();
1813 }
1814 return perpetualAccessStartFlag;
1815 }
1816
1817 public boolean validatePerpetualAccessEndDates(OLEEResourceRecordDocument oleeResourceRecordDocument, OLEEResourceRecordForm oleERSForm) {
1818 boolean perpetualAccessEndFlag = true;
1819 OLEEResourceInstance oleeResourceInstance = oleeResourceRecordDocument.getOleERSInstance();
1820 oleERSForm.setDefaultPerAccEndDateErrorMessage(null);
1821 String perpetualAccessEndDate = "";
1822 try {
1823 if (oleeResourceInstance != null) {
1824 perpetualAccessEndDate = oleeResourceInstance.getPerpetualAccEndDate();
1825 if (StringUtils.isNotEmpty(perpetualAccessEndDate)) {
1826 if (perpetualAccessEndDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
1827
1828 String dateFormat = perpetualAccessEndDate;
1829 oleeResourceInstance.setPerpetualAccEndDate(dateFormat);
1830 } else if (perpetualAccessEndDate.matches(calendarYearAgo)) {
1831 String[] perpetualAccessEndYear = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1832 if (perpetualAccessEndYear.length > 0 && perpetualAccessEndYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1833
1834
1835 String previousYearOfPerpetualAccDate = perpetualAccessEndDate;
1836 oleeResourceInstance.setPerpetualAccEndDate(previousYearOfPerpetualAccDate);
1837 } else {
1838 perpetualAccessEndFlag = false;
1839 oleERSForm.setPerpetualAccessFlag(true);
1840 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1841 }
1842 } else if (perpetualAccessEndDate.matches(calendarYearsAgo)) {
1843 String[] perpetualAccessEndYears = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1844 if (perpetualAccessEndYears.length > 0 && !perpetualAccessEndYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1845
1846
1847 String previousYearsOfPerpetualAccDate = perpetualAccessEndDate;
1848 oleeResourceInstance.setPerpetualAccEndDate(previousYearsOfPerpetualAccDate);
1849 } else {
1850 perpetualAccessEndFlag = false;
1851 oleERSForm.setPerpetualAccessFlag(true);
1852 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1853 }
1854 } else if (perpetualAccessEndDate.matches(monthAgo)) {
1855 String[] perpetualAccessEndMonth = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1856 if (perpetualAccessEndMonth.length > 0 && perpetualAccessEndMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1857
1858 String previousMonthOfPerpetualAccDate = perpetualAccessEndDate;
1859 oleeResourceInstance.setPerpetualAccEndDate(previousMonthOfPerpetualAccDate);
1860 } else {
1861 perpetualAccessEndFlag = false;
1862 oleERSForm.setPerpetualAccessFlag(true);
1863 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1864 }
1865 } else if (perpetualAccessEndDate.matches(monthsAgo)) {
1866 String[] perpetualAccessEndMonths = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1867 if (perpetualAccessEndMonths.length > 0 && !perpetualAccessEndMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1868
1869 String previousMonthsOfPerpetualAccDate = perpetualAccessEndDate;
1870 oleeResourceInstance.setPerpetualAccEndDate(previousMonthsOfPerpetualAccDate);
1871 } else {
1872 perpetualAccessEndFlag = false;
1873 oleERSForm.setPerpetualAccessFlag(true);
1874 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1875 }
1876 } else if (perpetualAccessEndDate.matches(weekAgo)) {
1877 String[] perpetualAccessEndWeek = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1878 if (perpetualAccessEndWeek.length > 0 && !perpetualAccessEndWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1879
1880 String previousWeekOfPerpetualAccDate = perpetualAccessEndDate;
1881 oleeResourceInstance.setPerpetualAccEndDate(previousWeekOfPerpetualAccDate);
1882 } else {
1883 perpetualAccessEndFlag = false;
1884 oleERSForm.setPerpetualAccessFlag(true);
1885 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1886 }
1887 } else if (perpetualAccessEndDate.matches(weeksAgo)) {
1888 String[] perpetualAccessEndWeeks = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1889 if (perpetualAccessEndWeeks.length > 0 && !perpetualAccessEndWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1890
1891 String previousWeeksOfPerpetualAccDate = perpetualAccessEndDate;
1892 oleeResourceInstance.setPerpetualAccEndDate(previousWeeksOfPerpetualAccDate);
1893 } else {
1894 perpetualAccessEndFlag = false;
1895 oleERSForm.setPerpetualAccessFlag(true);
1896 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1897 }
1898 } else if (perpetualAccessEndDate.matches(dayAgo)) {
1899 String[] perpetualAccessEndDay = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1900 if (perpetualAccessEndDay.length > 0 && perpetualAccessEndDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1901
1902 String previousDayOfPerpetualAccDate = perpetualAccessEndDate;
1903 oleeResourceInstance.setPerpetualAccEndDate(previousDayOfPerpetualAccDate);
1904 } else {
1905 perpetualAccessEndFlag = false;
1906 oleERSForm.setPerpetualAccessFlag(true);
1907 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1908 }
1909 } else if (perpetualAccessEndDate.matches(daysAgo)) {
1910 String[] perpetualAccessEndDays = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
1911 if (perpetualAccessEndDays.length > 0 && !perpetualAccessEndDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
1912
1913 String previousDaysOfPerpetualAccDate = perpetualAccessEndDate;
1914 oleeResourceInstance.setPerpetualAccEndDate(previousDaysOfPerpetualAccDate);
1915 } else {
1916 perpetualAccessEndFlag = false;
1917 oleERSForm.setPerpetualAccessFlag(true);
1918 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1919 }
1920 } else {
1921 perpetualAccessEndFlag = false;
1922 oleERSForm.setDefaultPerAccEndDateErrorMessage(OLEConstants.OLEEResourceRecord.PER_ACC_END_DATE_FORMAT_INV);
1923 }
1924 }
1925 }
1926 oleeResourceRecordDocument.setPerAccEndDate(perpetualAccessEndDate);
1927 } catch (Exception ex) {
1928 LOG.error("Exception while validating the perpetual access end date format in EResource" + ex.getMessage());
1929 throw new RuntimeException();
1930 }
1931 return perpetualAccessEndFlag;
1932 }
1933
1934 public boolean validateDates(OleHoldings eHoldings) {
1935 boolean dateFlag = true;
1936 dateFlag &= validateCoverageStartDateForEHolding(eHoldings);
1937 dateFlag &= validateCoverageEndDateForEHolding(eHoldings);
1938 dateFlag &= validatePerpetualAccStartDateForEHolding(eHoldings);
1939 dateFlag &= validatePerpetualAccEndDateForEHolding(eHoldings);
1940 return dateFlag;
1941 }
1942
1943 public boolean validateCoverageStartDateForEHolding(OleHoldings eHoldings) {
1944 boolean covStartDateFlag = true;
1945 List<Coverage> coverageList = new ArrayList<>();
1946 if (eHoldings.getExtentOfOwnership().size() > 0 && eHoldings.getExtentOfOwnership().get(0).getCoverages() != null
1947 && eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().size() > 0) {
1948 coverageList = eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage();
1949 for (Coverage coverage : coverageList) {
1950 if(StringUtils.isNotEmpty(coverage.getCoverageStartDateString())) {
1951 coverage.setCoverageStartDate(coverage.getCoverageStartDateString());
1952 } else if(StringUtils.isNotEmpty(coverage.getCoverageStartDateFormat())) {
1953 coverage.setCoverageStartDate(coverage.getCoverageStartDateFormat());
1954 }
1955 covStartDateFlag &= validateCoverageStartDates(coverage);
1956 }
1957 if (!covStartDateFlag) {
1958 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleHoldings.ERROR_MSG_COV_START_DATE);
1959 return covStartDateFlag;
1960 }
1961 }
1962 return covStartDateFlag;
1963 }
1964
1965 public boolean validateCoverageEndDateForEHolding(OleHoldings eHoldings) {
1966 boolean covEndDateFlag = true;
1967 List<Coverage> coverageList = new ArrayList<>();
1968 if (eHoldings.getExtentOfOwnership().size() > 0 && eHoldings.getExtentOfOwnership().get(0).getCoverages() != null
1969 && eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().size() > 0) {
1970 coverageList = eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage();
1971 for (Coverage coverage : coverageList) {
1972 if(StringUtils.isNotEmpty(coverage.getCoverageEndDateString())) {
1973 coverage.setCoverageEndDate(coverage.getCoverageEndDateString());
1974 } else if(StringUtils.isNotEmpty(coverage.getCoverageEndDateFormat())) {
1975 coverage.setCoverageEndDate(coverage.getCoverageEndDateFormat());
1976 }
1977 covEndDateFlag &= validateCoverageEndDates(coverage);
1978 }
1979 if (!covEndDateFlag) {
1980 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleHoldings.ERROR_MSG_COV_END_DATE);
1981 return covEndDateFlag;
1982 }
1983 }
1984 return covEndDateFlag;
1985 }
1986
1987 public boolean validatePerpetualAccStartDateForEHolding(OleHoldings eHoldings) {
1988 boolean perpetualAccStartDateFlag = true;
1989 List<PerpetualAccess> perpetualAccessList = new ArrayList<>();
1990 if (eHoldings.getExtentOfOwnership().size() > 0 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses() != null
1991 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() > 0) {
1992 perpetualAccessList = eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess();
1993 for (PerpetualAccess perpetualAccess : perpetualAccessList) {
1994 if(StringUtils.isNotEmpty(perpetualAccess.getPerpetualAccessStartDateFormat())) {
1995 perpetualAccess.setPerpetualAccessStartDate(perpetualAccess.getPerpetualAccessStartDateFormat());
1996 } else if(StringUtils.isNotEmpty(perpetualAccess.getPerpetualAccessStartDateString())) {
1997 perpetualAccess.setPerpetualAccessStartDate(perpetualAccess.getPerpetualAccessStartDateString());
1998 }
1999 perpetualAccStartDateFlag &= validatePerpetualAccessStartDates(perpetualAccess);
2000 }
2001 if (!perpetualAccStartDateFlag) {
2002 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleHoldings.ERROR_MSG_PER_ACC_START_DATE);
2003 return perpetualAccStartDateFlag;
2004 }
2005 }
2006 return perpetualAccStartDateFlag;
2007 }
2008
2009 public boolean validatePerpetualAccEndDateForEHolding(OleHoldings eHoldings) {
2010 boolean perpetualAccEndDateFlag = true;
2011 List<PerpetualAccess> perpetualAccessList = new ArrayList<>();
2012 if (eHoldings.getExtentOfOwnership().size() > 0 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses() != null
2013 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() > 0) {
2014 perpetualAccessList = eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess();
2015 for (PerpetualAccess perpetualAccess : perpetualAccessList) {
2016 if(StringUtils.isNotEmpty(perpetualAccess.getPerpetualAccessEndDateString())) {
2017 perpetualAccess.setPerpetualAccessEndDate(perpetualAccess.getPerpetualAccessEndDateString());
2018 } else if(StringUtils.isNotEmpty(perpetualAccess.getPerpetualAccessEndDateFormat())) {
2019 perpetualAccess.setPerpetualAccessEndDate(perpetualAccess.getPerpetualAccessEndDateFormat());
2020 }
2021 perpetualAccEndDateFlag &= validatePerpetualAccessEndDates(perpetualAccess);
2022 }
2023 if (!perpetualAccEndDateFlag) {
2024 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleHoldings.ERROR_MSG_PER_ACC_END_DATE);
2025 return perpetualAccEndDateFlag;
2026 }
2027 }
2028 return perpetualAccEndDateFlag;
2029 }
2030
2031 private boolean validateCoverageStartDates(Coverage coverage) {
2032 boolean coverageStartFlag = true;
2033 String coverageStartDate = "";
2034 try {
2035 if (coverage != null) {
2036 coverageStartDate = coverage.getCoverageStartDate();
2037 if (StringUtils.isNotEmpty(coverageStartDate)) {
2038 if (coverageStartDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
2039
2040 String dateFormat = coverageStartDate;
2041 coverage.setCoverageStartDate(dateFormat);
2042 } else if (coverageStartDate.matches(calendarYearAgo)) {
2043 String[] coverageStartYear = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2044 if (coverageStartYear.length > 0 && coverageStartYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2045
2046
2047 String previousYearOfCovDate = coverageStartDate;
2048 coverage.setCoverageStartDate(previousYearOfCovDate);
2049 } else {
2050 coverage.setCoverageStartDate(coverageStartDate);
2051 coverageStartFlag = false;
2052 }
2053 } else if (coverageStartDate.matches(calendarYearsAgo)) {
2054 String[] coverageStartYears = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2055 if (coverageStartYears.length > 0 && !coverageStartYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2056
2057
2058 String previousYearsOfCovDate = coverageStartDate;
2059 coverage.setCoverageStartDate(previousYearsOfCovDate);
2060 } else {
2061 coverageStartFlag = false;
2062 }
2063 } else if (coverageStartDate.matches(monthAgo)) {
2064 String[] coverageStartMonth = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2065 if (coverageStartMonth.length > 0 && coverageStartMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2066
2067 String previousMonthOfCovDate = coverageStartDate;
2068 coverage.setCoverageStartDate(previousMonthOfCovDate);
2069 } else {
2070 coverageStartFlag = false;
2071 }
2072 } else if (coverageStartDate.matches(monthsAgo)) {
2073 String[] coverageStartMonths = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2074 if (coverageStartMonths.length > 0 && !coverageStartMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2075
2076 String previousMonthsOfCovDate = coverageStartDate;
2077 coverage.setCoverageStartDate(previousMonthsOfCovDate);
2078 } else {
2079 coverageStartFlag = false;
2080 }
2081 } else if (coverageStartDate.matches(weekAgo)) {
2082 String[] coverageStartWeek = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2083 if (coverageStartWeek.length > 0 && coverageStartWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2084
2085 String previousWeekOfCovDate = coverageStartDate;
2086 coverage.setCoverageStartDate(previousWeekOfCovDate);
2087 } else {
2088 coverageStartFlag = false;
2089 }
2090 } else if (coverageStartDate.matches(weeksAgo)) {
2091 String[] coverageStartWeeks = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2092 if (coverageStartWeeks.length > 0 && !coverageStartWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2093
2094 String previousYearsOfCovDate = coverageStartDate;
2095 coverage.setCoverageStartDate(previousYearsOfCovDate);
2096 } else {
2097 coverageStartFlag = false;
2098 }
2099 } else if (coverageStartDate.matches(dayAgo)) {
2100 String[] coverageStartDay = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2101 if (coverageStartDay.length > 0 && coverageStartDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2102
2103 String previousDayOfCovDate = coverageStartDate;
2104 coverage.setCoverageStartDate(previousDayOfCovDate);
2105 } else {
2106 coverageStartFlag = false;
2107 }
2108 } else if (coverageStartDate.matches(daysAgo)) {
2109 String[] coverageStartDays = coverageStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2110 if (coverageStartDays.length > 0 && !coverageStartDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2111
2112 String previousDaysOfCovDate = coverageStartDate;
2113 coverage.setCoverageStartDate(previousDaysOfCovDate);
2114 } else {
2115 coverageStartFlag = false;
2116 }
2117 } else {
2118 coverage.setCoverageStartDate(coverageStartDate);
2119 coverageStartFlag = false;
2120 }
2121 }
2122 }
2123 } catch (Exception ex) {
2124 LOG.error("Exception while validating the coverage start date format in EHoldings" + ex.getMessage());
2125 throw new RuntimeException();
2126 }
2127 return coverageStartFlag;
2128 }
2129
2130 private boolean validateCoverageEndDates(Coverage coverage) {
2131 boolean coverageEndFlag = true;
2132 String coverageEndDate = "";
2133 try {
2134 if (coverage != null) {
2135 coverageEndDate = coverage.getCoverageEndDate();
2136 if (StringUtils.isNotEmpty(coverageEndDate)) {
2137 if (coverageEndDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
2138
2139 String dateFormat = coverageEndDate;
2140 coverage.setCoverageEndDate(dateFormat);
2141 } else if (coverageEndDate.matches(calendarYearAgo)) {
2142 String[] coverageEndYear = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2143 if (coverageEndYear.length > 0 && coverageEndYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2144
2145
2146 String previousYearOfCovDate = coverageEndDate;
2147 coverage.setCoverageEndDate(previousYearOfCovDate);
2148 } else {
2149 coverageEndFlag = false;
2150 }
2151 } else if (coverageEndDate.matches(calendarYearsAgo)) {
2152 String[] coverageEndYears = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2153 if (coverageEndYears.length > 0 && !coverageEndYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2154
2155
2156 String previousYearsOfCovDate = coverageEndDate;
2157 coverage.setCoverageEndDate(previousYearsOfCovDate);
2158 } else {
2159 coverageEndFlag = false;
2160 }
2161 } else if (coverageEndDate.matches(monthAgo)) {
2162 String[] coverageEndMonth = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2163 if (coverageEndMonth.length > 0 && coverageEndMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2164
2165 String previousMonthOfCovDate = coverageEndDate;
2166 coverage.setCoverageEndDate(previousMonthOfCovDate);
2167 } else {
2168 coverageEndFlag = false;
2169 }
2170 } else if (coverageEndDate.matches(monthsAgo)) {
2171 String[] coverageEndMonths = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2172 if (coverageEndMonths.length > 0 && !coverageEndMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2173
2174 String previousMonthsOfCovDate = coverageEndDate;
2175 coverage.setCoverageEndDate(previousMonthsOfCovDate);
2176 } else {
2177 coverageEndFlag = false;
2178 }
2179 } else if (coverageEndDate.matches(weekAgo)) {
2180 String[] coverageEndWeek = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2181 if (coverageEndWeek.length > 0 && coverageEndWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2182
2183 String previousWeekOfCovEndDate = coverageEndDate;
2184 coverage.setCoverageEndDate(previousWeekOfCovEndDate);
2185 } else {
2186 coverageEndFlag = false;
2187 }
2188 } else if (coverageEndDate.matches(weeksAgo)) {
2189 String[] coverageEndWeeks = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2190 if (coverageEndWeeks.length > 0 && !coverageEndWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2191
2192 String previousWeeksOfCovEndDate = coverageEndDate;
2193 coverage.setCoverageEndDate(previousWeeksOfCovEndDate);
2194 } else {
2195 coverageEndFlag = false;
2196 }
2197 } else if (coverageEndDate.matches(dayAgo)) {
2198 String[] coverageEndDay = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2199 if (coverageEndDay.length > 0 && coverageEndDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2200
2201 String previousDayOfCovDate = coverageEndDate;
2202 coverage.setCoverageEndDate(previousDayOfCovDate);
2203 } else {
2204 coverageEndFlag = false;
2205 }
2206 } else if (coverageEndDate.matches(daysAgo)) {
2207 String[] coverageEndDays = coverageEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2208 if (coverageEndDays.length > 0 && !coverageEndDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2209
2210 String previousDaysOfCovEndDate = coverageEndDate;
2211 coverage.setCoverageEndDate(previousDaysOfCovEndDate);
2212 } else {
2213 coverageEndFlag = false;
2214 }
2215 } else {
2216 coverageEndFlag = false;
2217 }
2218 }
2219 }
2220 } catch (Exception ex) {
2221 LOG.error("Exception while validating the coverage end date format in EHoldings " + ex.getMessage());
2222 throw new RuntimeException();
2223 }
2224 return coverageEndFlag;
2225 }
2226
2227 private boolean validatePerpetualAccessStartDates(PerpetualAccess perpetualAccess) {
2228 boolean perpetualAccessStartFlag = true;
2229 String perpetualAccessStartDate = "";
2230 try {
2231 if (perpetualAccess != null) {
2232 perpetualAccessStartDate = perpetualAccess.getPerpetualAccessStartDate();
2233 if (StringUtils.isNotEmpty(perpetualAccessStartDate)) {
2234 if (perpetualAccessStartDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
2235
2236 String dateFormat = perpetualAccessStartDate;
2237 perpetualAccess.setPerpetualAccessStartDate(dateFormat);
2238 } else if (perpetualAccessStartDate.matches(calendarYearAgo)) {
2239 String[] perpetualAccessStartYear = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2240 if (perpetualAccessStartYear.length > 0 && perpetualAccessStartYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2241
2242
2243 String previousYearOfPerpetualAccDate = perpetualAccessStartDate;
2244 perpetualAccess.setPerpetualAccessStartDate(previousYearOfPerpetualAccDate);
2245 } else {
2246 perpetualAccessStartFlag = false;
2247 }
2248 } else if (perpetualAccessStartDate.matches(calendarYearsAgo)) {
2249 String[] perpetualAccessStartYears = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2250 if (perpetualAccessStartYears.length > 0 && !perpetualAccessStartYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2251
2252
2253 String previousYearsOfPerpetualAccDate = perpetualAccessStartDate;
2254 perpetualAccess.setPerpetualAccessStartDate(previousYearsOfPerpetualAccDate);
2255 } else {
2256 perpetualAccessStartFlag = false;
2257 }
2258 } else if (perpetualAccessStartDate.matches(monthAgo)) {
2259 String[] perpetualAccessStartMonth = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2260 if (perpetualAccessStartMonth.length > 0 && perpetualAccessStartMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2261
2262 String previousMonthOfPerpetualAccDate = perpetualAccessStartDate;
2263 perpetualAccess.setPerpetualAccessStartDate(previousMonthOfPerpetualAccDate);
2264 } else {
2265 perpetualAccessStartFlag = false;
2266 }
2267 } else if (perpetualAccessStartDate.matches(monthsAgo)) {
2268 String[] perpetualAccessStartMonths = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2269 if (perpetualAccessStartMonths.length > 0 && !perpetualAccessStartMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2270
2271 String previousMonthsOfPerpetualAccDate = perpetualAccessStartDate;
2272 perpetualAccess.setPerpetualAccessStartDate(previousMonthsOfPerpetualAccDate);
2273 } else {
2274 perpetualAccessStartFlag = false;
2275 }
2276 } else if (perpetualAccessStartDate.matches(weekAgo)) {
2277 String[] perpetualAccessStartWeek = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2278 if (perpetualAccessStartWeek.length > 0 && perpetualAccessStartWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2279
2280 String previousWeekOfCovEndDate = perpetualAccessStartDate;
2281 perpetualAccess.setPerpetualAccessStartDate(previousWeekOfCovEndDate);
2282 } else {
2283 perpetualAccessStartFlag = false;
2284 }
2285 } else if (perpetualAccessStartDate.matches(weeksAgo)) {
2286 String[] perpetualAccessStartWeeks = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2287 if (perpetualAccessStartWeeks.length > 0 && !perpetualAccessStartWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2288
2289 String previousWeeksOfCovEndDate = perpetualAccessStartDate;
2290 perpetualAccess.setPerpetualAccessStartDate(previousWeeksOfCovEndDate);
2291 } else {
2292 perpetualAccessStartFlag = false;
2293 }
2294 } else if (perpetualAccessStartDate.matches(dayAgo)) {
2295 String[] perpetualAccessStartDay = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2296 if (perpetualAccessStartDay.length > 0 && perpetualAccessStartDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2297
2298 String previousDayOfPerpetualAccDate = perpetualAccessStartDate;
2299 perpetualAccess.setPerpetualAccessStartDate(previousDayOfPerpetualAccDate);
2300 } else {
2301 perpetualAccessStartFlag = false;
2302 }
2303 } else if (perpetualAccessStartDate.matches(daysAgo)) {
2304 String[] perpetualAccessStartDays = perpetualAccessStartDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2305 if (perpetualAccessStartDays.length > 0 && !perpetualAccessStartDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2306
2307 String previousDaysOfPerpetualAccDate = perpetualAccessStartDate;
2308 perpetualAccess.setPerpetualAccessStartDate(previousDaysOfPerpetualAccDate);
2309 } else {
2310 perpetualAccessStartFlag = false;
2311 }
2312 } else {
2313 perpetualAccessStartFlag = false;
2314 }
2315 }
2316 }
2317 } catch (Exception ex) {
2318 LOG.error("Exception while validating the Perpetual access start date format in EHoldings " + ex.getMessage());
2319 throw new RuntimeException();
2320 }
2321 return perpetualAccessStartFlag;
2322 }
2323
2324 private boolean validatePerpetualAccessEndDates(PerpetualAccess perpetualAccess) {
2325 boolean perpetualAccessEndFlag = true;
2326 String perpetualAccessEndDate = "";
2327 try {
2328 if (perpetualAccess != null) {
2329 perpetualAccessEndDate = perpetualAccess.getPerpetualAccessEndDate();
2330 if (StringUtils.isNotEmpty(perpetualAccessEndDate)) {
2331 if (perpetualAccessEndDate.matches(OLEConstants.OLEEResourceRecord.DATE_FORMAT_REGEX)) {
2332
2333 String dateFormat = perpetualAccessEndDate;
2334 perpetualAccess.setPerpetualAccessEndDate(dateFormat);
2335 } else if (perpetualAccessEndDate.matches(calendarYearAgo)) {
2336 String[] perpetualAccessEndYear = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2337 if (perpetualAccessEndYear.length > 0 && perpetualAccessEndYear[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2338
2339
2340 String previousYearOfPerpetualAccDate = perpetualAccessEndDate;
2341 perpetualAccess.setPerpetualAccessEndDate(previousYearOfPerpetualAccDate);
2342 } else {
2343 perpetualAccessEndFlag = false;
2344 }
2345 } else if (perpetualAccessEndDate.matches(calendarYearsAgo)) {
2346 String[] perpetualAccessEndYears = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2347 if (perpetualAccessEndYears.length > 0 && !perpetualAccessEndYears[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2348
2349
2350 String previousYearsOfPerpetualAccDate = perpetualAccessEndDate;
2351 perpetualAccess.setPerpetualAccessEndDate(previousYearsOfPerpetualAccDate);
2352 } else {
2353 perpetualAccessEndFlag = false;
2354 }
2355 } else if (perpetualAccessEndDate.matches(monthAgo)) {
2356 String[] perpetualAccessEndMonth = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2357 if (perpetualAccessEndMonth.length > 0 && perpetualAccessEndMonth[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2358
2359 String previousMonthOfPerpetualAccDate = perpetualAccessEndDate;
2360 perpetualAccess.setPerpetualAccessEndDate(previousMonthOfPerpetualAccDate);
2361 } else {
2362 perpetualAccessEndFlag = false;
2363 }
2364 } else if (perpetualAccessEndDate.matches(monthsAgo)) {
2365 String[] perpetualAccessEndMonths = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2366 if (perpetualAccessEndMonths.length > 0 && !perpetualAccessEndMonths[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2367
2368 String previousMonthsOfPerpetualAccDate = perpetualAccessEndDate;
2369 perpetualAccess.setPerpetualAccessEndDate(previousMonthsOfPerpetualAccDate);
2370 } else {
2371 perpetualAccessEndFlag = false;
2372 }
2373 } else if (perpetualAccessEndDate.matches(weekAgo)) {
2374 String[] perpetualAccessEndWeek = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2375 if (perpetualAccessEndWeek.length > 0 && !perpetualAccessEndWeek[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2376
2377 String previousWeekOfPerpetualAccDate = perpetualAccessEndDate;
2378 perpetualAccess.setPerpetualAccessEndDate(previousWeekOfPerpetualAccDate);
2379 } else {
2380 perpetualAccessEndFlag = false;
2381 }
2382 } else if (perpetualAccessEndDate.matches(weeksAgo)) {
2383 String[] perpetualAccessEndWeeks = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2384 if (perpetualAccessEndWeeks.length > 0 && !perpetualAccessEndWeeks[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2385
2386 String previousWeeksOfPerpetualAccDate = perpetualAccessEndDate;
2387 perpetualAccess.setPerpetualAccessEndDate(previousWeeksOfPerpetualAccDate);
2388 } else {
2389 perpetualAccessEndFlag = false;
2390 }
2391 } else if (perpetualAccessEndDate.matches(dayAgo)) {
2392 String[] perpetualAccessEndDay = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2393 if (perpetualAccessEndDay.length > 0 && perpetualAccessEndDay[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2394
2395 String previousDayOfPerpetualAccDate = perpetualAccessEndDate;
2396 perpetualAccess.setPerpetualAccessEndDate(previousDayOfPerpetualAccDate);
2397 } else {
2398 perpetualAccessEndFlag = false;
2399 }
2400 } else if (perpetualAccessEndDate.matches(daysAgo)) {
2401 String[] perpetualAccessEndDays = perpetualAccessEndDate.split(OLEConstants.OLEEResourceRecord.SPACE);
2402 if (perpetualAccessEndDays.length > 0 && !perpetualAccessEndDays[0].equals(OLEConstants.OLEEResourceRecord.ONE)) {
2403
2404 String previousDaysOfPerpetualAccDate = perpetualAccessEndDate;
2405 perpetualAccess.setPerpetualAccessEndDate(previousDaysOfPerpetualAccDate);
2406 } else {
2407 perpetualAccessEndFlag = false;
2408 }
2409 } else {
2410 perpetualAccessEndFlag = false;
2411 }
2412 }
2413 }
2414 } catch (Exception ex) {
2415 LOG.error("Exception while validating the Perpetual access end date format in EHoldings " + ex.getMessage());
2416 throw new RuntimeException();
2417 }
2418 return perpetualAccessEndFlag;
2419 }
2420
2421 private String getDateFormat(String perpetualAccessEndDate) {
2422 Date date = new Date(perpetualAccessEndDate);
2423 String dateFormat = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(date);
2424 return dateFormat;
2425 }
2426
2427 private String getYearFormat() {
2428 Calendar calendar = Calendar.getInstance();
2429 calendar.add(Calendar.YEAR, -1);
2430 Date previousYear = calendar.getTime();
2431 String year = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousYear);
2432 return year;
2433 }
2434
2435 private String getYearsFormat(String[] years) {
2436 Calendar calendar = Calendar.getInstance();
2437 calendar.add(Calendar.YEAR, -(Integer.parseInt(years[0])));
2438 Date previousYears = calendar.getTime();
2439 String numberOfYears = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousYears);
2440 return numberOfYears;
2441 }
2442
2443 private String getMonthFormat() {
2444 Calendar calendar = Calendar.getInstance();
2445 calendar.add(Calendar.MONTH, -1);
2446 Date previousMonth = calendar.getTime();
2447 String month = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousMonth);
2448 return month;
2449 }
2450
2451 private String getMonthsFormat(String[] months) {
2452 Calendar calendar = Calendar.getInstance();
2453 calendar.add(Calendar.MONTH, -(Integer.parseInt(months[0])));
2454 Date previousMonths = calendar.getTime();
2455 String numberOfMonths = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousMonths);
2456 return numberOfMonths;
2457 }
2458
2459 private String getWeekFormat() {
2460 Calendar calendar = Calendar.getInstance();
2461 int days = 7;
2462 calendar.add(Calendar.DATE, -(days));
2463 Date previousWeek = calendar.getTime();
2464 String week = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousWeek);
2465 return week;
2466 }
2467
2468 private String getWeeksFormat(String[] weeks) {
2469 Calendar calendar = Calendar.getInstance();
2470 int days = Integer.parseInt(weeks[0]) * 7;
2471 calendar.add(Calendar.DATE, -(days));
2472 Date previousWeeks = calendar.getTime();
2473 String numberOfWeeks = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousWeeks);
2474 return numberOfWeeks;
2475 }
2476
2477 private String getDayFormat() {
2478 Calendar calendar = Calendar.getInstance();
2479 calendar.add(Calendar.DATE, -1);
2480 Date previousDay = calendar.getTime();
2481 String day = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousDay);
2482 return day;
2483 }
2484
2485 private String getDaysFormat(String[] days) {
2486 Calendar calendar = Calendar.getInstance();
2487 calendar.add(Calendar.DATE, -(Integer.parseInt(days[0])));
2488 Date previousDays = calendar.getTime();
2489 String numberOfDays = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.DATE_FORMAT).format(previousDays);
2490 return numberOfDays;
2491 }
2492
2493 private String getFirstDay(String firstDay) {
2494 String[] date = firstDay.split(OLEConstants.SLASH);
2495 String yearAlone = "";
2496 if (date.length > 1) {
2497 yearAlone = date[2];
2498 }
2499 yearAlone = firstDayOfYear + yearAlone;
2500 return yearAlone;
2501 }
2502
2503 private String getLastDay(String lastDay) {
2504 String[] date = lastDay.split(OLEConstants.SLASH);
2505 String yearAlone = "";
2506 if (date.length > 1) {
2507 yearAlone = date[2];
2508 }
2509 yearAlone = lastDayOfYear + yearAlone;
2510 return yearAlone;
2511 }
2512
2513 public void getPOAndInvoiceItemsWithoutDuplicate(OLEEResourceRecordDocument oleERSDoc) {
2514 List<OLEEResourcePO> oleeResourcePOItems = oleERSDoc.getOleERSPOItems();
2515 List<OLEEResourceInvoices> oleERSInvoices = oleERSDoc.getOleERSInvoices();
2516 Map avoidingDuplicateMap = new HashMap<>();
2517 for (OLEEResourcePO oleeResourcePO : oleeResourcePOItems) {
2518 avoidingDuplicateMap.put(oleeResourcePO.getOlePOItemId(),oleeResourcePO);
2519 }
2520 oleERSDoc.getOleERSPOItems().clear();
2521 oleERSDoc.getOleERSPOItems().addAll((Collection<? extends OLEEResourcePO>) avoidingDuplicateMap.values());
2522 avoidingDuplicateMap.clear();
2523 for (OLEEResourceInvoices oleeResourceInvoice : oleERSInvoices) {
2524 avoidingDuplicateMap.put(oleeResourceInvoice.getInvoiceId(),oleeResourceInvoice);
2525 }
2526 oleERSDoc.getOleERSInvoices().clear();
2527 oleERSDoc.getOleERSInvoices().addAll((Collection<? extends OLEEResourceInvoices>) avoidingDuplicateMap.values());
2528 }
2529
2530 public void getAcquisitionInfoFromPOAndInvoice(String holdingsId,WorkEInstanceOlemlForm workEInstanceOlemlForm) {
2531 Map map = new HashMap();
2532 map.put(OLEConstants.INSTANCE_ID, holdingsId);
2533 List<OleCopy> oleCopyList = (List) getBusinessObjectService().findMatching(OleCopy.class, map);
2534 StringBuffer linkedPos = new StringBuffer();
2535 StringBuffer vendor = new StringBuffer();
2536 StringBuffer orderType = new StringBuffer();
2537 StringBuffer orderFormat = new StringBuffer();
2538 StringBuffer fundCode = new StringBuffer();
2539 List fundCodeList = new ArrayList();
2540 List<PurApAccountingLine> accountingLines = new ArrayList<>();
2541 KualiDecimal currentFYCost=new KualiDecimal(0);
2542 for (OleCopy oleCopy : oleCopyList) {
2543 if (oleCopy.getPoItemId() != null) {
2544 map.clear();
2545 map.put(OLEConstants.OLEEResourceRecord.PO_ITEM_ID, oleCopy.getPoItemId().toString());
2546 OlePurchaseOrderItem olePurchaseOrderItem = getBusinessObjectService().findByPrimaryKey(OlePurchaseOrderItem.class, map);
2547 if (olePurchaseOrderItem != null) {
2548
2549 map.clear();
2550 map.put(OLEConstants.DOC_NUM, olePurchaseOrderItem.getDocumentNumber());
2551 OlePurchaseOrderDocument olePurchaseOrderDocument = getBusinessObjectService().findByPrimaryKey(OlePurchaseOrderDocument.class, map);
2552 if (olePurchaseOrderDocument != null) {
2553
2554 linkedPos.append(olePurchaseOrderDocument.getPurapDocumentIdentifier());
2555 linkedPos.append(OLEConstants.COMMA);
2556 linkedPos.append(' ');
2557
2558 Integer poCreatedYear = olePurchaseOrderDocument.getPostingYear();
2559 Integer currentYear = Calendar.getInstance().get(Calendar.YEAR);
2560 if (currentYear.compareTo(poCreatedYear) == 0) {
2561 currentFYCost = currentFYCost.add(olePurchaseOrderItem.getItemInvoicedTotalAmount());
2562 }
2563
2564 vendor.append(olePurchaseOrderDocument.getVendorName());
2565 vendor.append(OLEConstants.COMMA);
2566 vendor.append(' ');
2567
2568 map.clear();
2569 map.put(OLEConstants.PURCHASE_ORDER_TYPE_ID, olePurchaseOrderDocument.getPurchaseOrderTypeId());
2570 Collection<PurchaseOrderType> purchaseOrderTypeDocumentList = getBusinessObjectService().findMatching(PurchaseOrderType.class, map);
2571 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
2572 PurchaseOrderType purchaseOrderTypeDoc = purchaseOrderTypeDocumentList.iterator().next();
2573 orderType.append(purchaseOrderTypeDoc.getPurchaseOrderType());
2574 orderType.append(OLEConstants.SEMI_COLON);
2575 orderType.append(' ');
2576 }
2577 }
2578
2579 map.clear();
2580 map.put(OLEConstants.OLEEResourceRecord.INV_PO_ITEM_ID, olePurchaseOrderItem.getItemIdentifier());
2581 List<OleInvoiceItem> oleInvoiceItems = (List<OleInvoiceItem>) getBusinessObjectService().findMatching(OleInvoiceItem.class, map);
2582 if (oleInvoiceItems != null && oleInvoiceItems.size() > 0) {
2583 for (OleInvoiceItem oleInvoiceItem : oleInvoiceItems) {
2584 map.put(OLEConstants.OLEEResourceRecord.INV_PO_ITEM_ID, oleInvoiceItem.getItemIdentifier());
2585 OlePaymentRequestItem olePaymentRequestItem = getBusinessObjectService().findByPrimaryKey(OlePaymentRequestItem.class, map);
2586 if (olePaymentRequestItem != null) {
2587 workEInstanceOlemlForm.getExtendedEHoldingFields().setPaymentStatus(OLEConstants.PAID);
2588 break;
2589 }
2590 }
2591 for (OleInvoiceItem oleInvoiceItem : oleInvoiceItems) {
2592 List purApAccountingLines = oleInvoiceItem.getSourceAccountingLines();
2593 if (purApAccountingLines != null && purApAccountingLines.size() > 0) {
2594 accountingLines.addAll(purApAccountingLines);
2595 }
2596 }
2597 }
2598
2599 if (olePurchaseOrderItem.getFormatTypeId() != null) {
2600 map.clear();
2601 map.put(OLEConstants.FORMAT_TYPE_ID, olePurchaseOrderItem.getFormatTypeId());
2602 OleFormatType oleFormatType = getBusinessObjectService().findByPrimaryKey(OleFormatType.class, map);
2603 if (oleFormatType != null) {
2604 orderFormat.append(oleFormatType.getFormatTypeName());
2605 orderFormat.append(OLEConstants.COMMA);
2606 orderFormat.append(' ');
2607 }
2608 }
2609 }
2610 }
2611 }
2612 if (linkedPos.length() > 0) {
2613 if (vendor.length() > 0) {
2614 vendor.deleteCharAt(vendor.length() - 2);
2615 workEInstanceOlemlForm.getExtendedEHoldingFields().setVendorName(vendor.toString());
2616 }
2617 if (orderType.length() > 0) {
2618 orderType.deleteCharAt(orderType.length() - 2);
2619 workEInstanceOlemlForm.getExtendedEHoldingFields().setOrderType(orderType.toString());
2620 }
2621 if (orderFormat.length() > 0) {
2622 orderFormat.deleteCharAt(orderFormat.length() - 2);
2623 workEInstanceOlemlForm.getExtendedEHoldingFields().setOrderFormat(orderFormat.toString());
2624 }
2625 String pos[] = linkedPos.toString().split(",");
2626 Set set = new HashSet();
2627 for (String po : pos) {
2628 set.add(po.trim());
2629 }
2630 pos = (String[]) set.toArray(new String[0]);
2631 StringBuffer poLink = new StringBuffer();
2632 for (String po : pos) {
2633 String link = null;
2634 if (StringUtils.isNotBlank(po)) {
2635 Map poMap = new HashMap();
2636 poMap.put(org.kuali.ole.sys.OLEConstants.PUR_DOC_IDENTIFIER, po.trim());
2637 List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = (List) getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, poMap);
2638 if (olePurchaseOrderDocumentList != null && olePurchaseOrderDocumentList.size() > 0) {
2639 for (OlePurchaseOrderDocument olePurchaseOrderDocument : olePurchaseOrderDocumentList) {
2640 boolean validPO = olePurchaseOrderDocumentList != null ? olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching() : false;
2641 if (validPO) {
2642 link = ConfigContext.getCurrentContextConfig().getProperty("kew.url") + org.kuali.ole.sys.OLEConstants.PO_LINE_ITEM_URL + olePurchaseOrderDocument.getDocumentNumber();
2643 poLink.append("<a href=" + link + " target='_blank'>" + po.trim() + "</a>, ");
2644 }
2645 }
2646 }
2647 }
2648 }
2649 if (poLink.length() > 0) {
2650 poLink.deleteCharAt(poLink.length() - 2);
2651 workEInstanceOlemlForm.getExtendedEHoldingFields().setPurchaseOrderId(poLink.toString());
2652 }
2653 workEInstanceOlemlForm.getExtendedEHoldingFields().setCurrentFYCost(currentFYCost.toString());
2654 if (org.apache.commons.lang.StringUtils.isBlank(workEInstanceOlemlForm.getExtendedEHoldingFields().getPaymentStatus())) {
2655 workEInstanceOlemlForm.getExtendedEHoldingFields().setPaymentStatus(OLEConstants.NOT_PAID);
2656 }
2657 if (accountingLines.size() > 0) {
2658 for (PurApAccountingLine accountingLine : accountingLines) {
2659 map.clear();
2660 map.put(OLEConstants.ACCOUNT_NUMBER, accountingLine.getAccountNumber());
2661 map.put(OLEConstants.OBJECT_CODE, accountingLine.getFinancialObjectCode());
2662 OleVendorAccountInfo oleVendorAccountInfo = getBusinessObjectService().findByPrimaryKey(OleVendorAccountInfo.class, map);
2663 if (oleVendorAccountInfo != null && !fundCodeList.contains(oleVendorAccountInfo.getVendorRefNumber())) {
2664 fundCodeList.add(oleVendorAccountInfo.getVendorRefNumber());
2665 fundCode.append(oleVendorAccountInfo.getVendorRefNumber());
2666 fundCode.append(OLEConstants.COMMA);
2667 fundCode.append(' ');
2668 }
2669 }
2670 }
2671 if (fundCode.length() > 0) {
2672 fundCode.deleteCharAt(fundCode.length() - 2);
2673 workEInstanceOlemlForm.getExtendedEHoldingFields().setFundCode(fundCode.toString());
2674 }
2675 }
2676 }
2677
2678 private void updateEResInOleCopy(Holdings holdings, OLEEResourceRecordDocument oleERSDoc) {
2679 Map<String, String> criteriaMap = new HashMap<>();
2680 criteriaMap.put(OLEConstants.INSTANCE_ID, holdings.getId());
2681 List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class,
2682 criteriaMap);
2683 if (copies.size() > 0) {
2684 oleERSDoc.getCopyList().addAll(copies);
2685 } else {
2686 List<OleCopy> newCopies = new ArrayList<OleCopy>();
2687 OleCopy oleCopy = new OleCopy();
2688 oleCopy.setBibId(holdings.getBib().getId());
2689 oleCopy.setOleERSIdentifier(oleERSDoc.getOleERSIdentifier() != null ? oleERSDoc.getOleERSIdentifier() : "");
2690 oleCopy.setInstanceId(holdings.getId());
2691 newCopies.add(oleCopy);
2692 oleERSDoc.getCopyList().addAll(newCopies);
2693 }
2694 }
2695 }