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