1 package org.kuali.ole.select.gokb.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.xerces.dom.DeferredElementImpl;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.select.gokb.*;
7 import org.kuali.ole.select.gokb.service.GokbLocalService;
8 import org.kuali.ole.select.gokb.service.GokbRdbmsService;
9 import org.kuali.ole.select.gokb.util.OleGokbXmlUtil;
10 import org.kuali.ole.sys.OLEPropertyConstants;
11 import org.kuali.rice.krad.service.BusinessObjectService;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import org.w3c.dom.Attr;
16 import org.w3c.dom.NamedNodeMap;
17 import org.w3c.dom.Node;
18 import org.w3c.dom.NodeList;
19
20 import java.math.BigInteger;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26
27
28
29 public class GokbLocalServiceImpl implements GokbLocalService {
30
31 private static final Logger LOG = LoggerFactory.getLogger(GokbLocalServiceImpl.class);
32
33 private GokbRdbmsService gokbRdbmsService = null;
34 private BusinessObjectService businessObjectService;
35
36 public BusinessObjectService getBusinessObjectService() {
37 if(businessObjectService == null){
38 this.businessObjectService = KRADServiceLocator.getBusinessObjectService();
39 }
40 return businessObjectService;
41 }
42
43 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
44 this.businessObjectService = businessObjectService;
45 }
46
47
48
49
50
51
52 private GokbRdbmsService getGokbRdbmsService() {
53 if (gokbRdbmsService == null) {
54 gokbRdbmsService = new GokbRdbmsServiceImpl();
55 }
56 return gokbRdbmsService;
57 }
58
59
60
61
62 @Override
63 public void initLocalGokb() {
64 getGokbRdbmsService().truncateTables();
65 int updateId = getGokbRdbmsService().insertStatus();
66 initPackages(updateId);
67 initVendors(updateId);
68 initPlatforms(updateId);
69 initTitles(updateId);
70 getGokbRdbmsService().insertLogEndTime(updateId);
71 }
72
73
74
75
76
77
78 @Override
79 public void updateLocalGokb(String lastUpdatedTime) {
80 int updateId = getGokbRdbmsService().insertStatus();
81 updatePackages(lastUpdatedTime, updateId);
82 updateVendors(lastUpdatedTime, updateId);
83 updatePlatforms(lastUpdatedTime, updateId);
84 updateTitles(lastUpdatedTime, updateId);
85 getGokbRdbmsService().insertLogEndTime(updateId);
86 }
87
88
89
90
91
92
93 private void initPackages(int updateId) {
94 List<OleGokbPackage> oleGokbPackageList = new ArrayList<>();
95 int endIndex = 0;
96 int pageSize = 0;
97 int noOfRecordsInserted = 0;
98 int noOfTippRecordsInserted = 0;
99
100 while (true) {
101 String responseXml = OleGokbXmlUtil.getPackageResponseXmlFromGokb(endIndex);
102
103 NodeList packageNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.PACKAGE_XPATH_EXP);
104
105 if (packageNodeList.getLength() == 0)
106 break;
107
108 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(responseXml);
109
110 for (int i = 0; i < packageNodeList.getLength(); i++) {
111 Node packageNode = packageNodeList.item(i);
112 OleGokbPackage oleGokbPackage = null;
113 if (null != updatedDates.get(i)) {
114 oleGokbPackage = buildPackageFromPackageNode(packageNode, updatedDates.get(i));
115 oleGokbPackageList.add(oleGokbPackage);
116 }
117 if (oleGokbPackageList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
118 getGokbRdbmsService().insertPackages(oleGokbPackageList);
119 noOfRecordsInserted = noOfRecordsInserted + oleGokbPackageList.size();
120 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PKGS + noOfRecordsInserted);
121 oleGokbPackageList.clear();
122 }
123 noOfTippRecordsInserted = processTipps(updateId, oleGokbPackage, packageNode.getChildNodes(), noOfTippRecordsInserted);
124 }
125 if (endIndex == 0) {
126 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
127 }
128 endIndex = endIndex + pageSize;
129 }
130
131 if (oleGokbPackageList.size() > 0) {
132 getGokbRdbmsService().insertPackages(oleGokbPackageList);
133 noOfRecordsInserted = noOfRecordsInserted + oleGokbPackageList.size();
134 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PKGS + noOfRecordsInserted);
135 }
136 }
137
138
139
140
141
142
143
144 private void updatePackages(String lastUpdatedTime, int updateId) {
145 List<OleGokbPackage> oleGokbPackageList = new ArrayList<>();
146 int endIndex = 0;
147 int pageSize = 0;
148 int noOfRecordsInserted = 0;
149 int noOfTippRecordsInserted = 0;
150
151 while (true) {
152 String responseXml = OleGokbXmlUtil.getPackageResponseXmlFromGokb(lastUpdatedTime, endIndex);
153
154 NodeList headerNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.HEADER_XPATH_EXP);
155
156 if (headerNodeList.getLength() == 0)
157 break;
158
159 for (int i = 0; i < headerNodeList.getLength(); i++) {
160 Node headerNode = headerNodeList.item(i);
161 String identifier = OleGokbXmlUtil.getIdentifierFromHeader(headerNode);
162 String recordXml = OleGokbXmlUtil.getPackageResponseXmlFromGokb(identifier);
163
164 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(recordXml);
165
166 NodeList packageNodeList = OleGokbXmlUtil.getElementNodeList(recordXml, OLEConstants.OleGokb.PACKAGE_XPATH_EXP);
167 Node packageNode = packageNodeList.item(0);
168 OleGokbPackage oleGokbPackage = buildPackageFromPackageNode(packageNode, updatedDates.get(0));
169 oleGokbPackageList.add(oleGokbPackage);
170 if (oleGokbPackageList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
171 getGokbRdbmsService().insertOrUpdatePackages(oleGokbPackageList);
172 noOfRecordsInserted = noOfRecordsInserted + oleGokbPackageList.size();
173 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PKGS + noOfRecordsInserted);
174 oleGokbPackageList.clear();
175 }
176 noOfTippRecordsInserted = processTipps(updateId, oleGokbPackage, packageNode.getChildNodes(), noOfTippRecordsInserted);
177 }
178 if (endIndex == 0) {
179 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
180 }
181 if (pageSize == 0)
182 break;
183 endIndex = endIndex + pageSize;
184 }
185
186 if (oleGokbPackageList.size() > 0) {
187 getGokbRdbmsService().insertOrUpdatePackages(oleGokbPackageList);
188 noOfRecordsInserted = noOfRecordsInserted + oleGokbPackageList.size();
189 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PKGS + noOfRecordsInserted);
190 }
191 }
192
193
194
195
196
197
198 private void initTitles(int updateId) {
199 try {
200 List<OleGokbTitle> oleGokbTitleList = new ArrayList<>();
201 int endIndex = 0;
202 int pageSize = 0;
203 int noOfRecordsInserted = 0;
204
205 while (true) {
206 String responseXml = OleGokbXmlUtil.getTitleResponseXmlFromGokb(endIndex);
207 NodeList titleNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.TITLE_XPATH_EXP);
208 int count = 0;
209 if (titleNodeList.getLength() == 0)
210 break;
211
212 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(responseXml);
213 for (int i = 0; i < titleNodeList.getLength(); i++) {
214 Node titleNode = titleNodeList.item(i);
215 if (titleNode.getAttributes().getLength() == 0) {
216 count = count + 1;
217 continue;
218 }
219 OleGokbTitle oleGokbTitle = null;
220 if (null != updatedDates.get(i - count)) {
221 oleGokbTitle = buildTitleFromTitleNode(titleNode, updatedDates.get(i - count));
222 oleGokbTitleList.add(oleGokbTitle);
223 }
224 if (oleGokbTitleList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
225 getGokbRdbmsService().insertTitles(oleGokbTitleList);
226 noOfRecordsInserted = noOfRecordsInserted + oleGokbTitleList.size();
227 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_TITLES + noOfRecordsInserted);
228 oleGokbTitleList.clear();
229 }
230 }
231 if (endIndex == 0) {
232 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
233 }
234 endIndex = endIndex + pageSize;
235 }
236
237 if (oleGokbTitleList.size() > 0) {
238 getGokbRdbmsService().insertTitles(oleGokbTitleList);
239 noOfRecordsInserted = noOfRecordsInserted + oleGokbTitleList.size();
240 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_TITLES + noOfRecordsInserted);
241 }
242 } catch (Exception e) {
243 LOG.error("Exception While Initializing Titles: " + e);
244 }
245 }
246
247
248
249
250
251
252
253 private void updateTitles(String lastUpdatedTime, int updateId) {
254 List<OleGokbTitle> oleGokbTitleList = new ArrayList<>();
255 int endIndex = 0;
256 int pageSize = 0;
257 int noOfRecordsInserted = 0;
258
259 while (true) {
260 String responseXml = OleGokbXmlUtil.getTitleResponseXmlFromGokb(lastUpdatedTime, endIndex);
261
262 NodeList headerNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.HEADER_XPATH_EXP);
263
264 if (headerNodeList.getLength() == 0)
265 break;
266
267 for (int i = 0; i < headerNodeList.getLength(); i++) {
268 Node headerNode = headerNodeList.item(i);
269 String identifier = OleGokbXmlUtil.getIdentifierFromHeader(headerNode);
270 String recordXml = OleGokbXmlUtil.getTitleResponseXmlFromGokb(identifier);
271
272 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(recordXml);
273
274 NodeList titleNodeList = OleGokbXmlUtil.getElementNodeList(recordXml, OLEConstants.OleGokb.TITLE_XPATH_EXP);
275 Node titleNode = titleNodeList.item(0);
276 OleGokbTitle oleGokbTitle = buildTitleFromTitleNode(titleNode, updatedDates.get(0));
277 oleGokbTitleList.add(oleGokbTitle);
278 if (oleGokbTitleList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
279 getGokbRdbmsService().insertOrUpdateTitles(oleGokbTitleList);
280 noOfRecordsInserted = noOfRecordsInserted + oleGokbTitleList.size();
281 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_TITLES + noOfRecordsInserted);
282 oleGokbTitleList.clear();
283 }
284 }
285 if (endIndex == 0) {
286 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
287 }
288 if (pageSize == 0)
289 break;
290 endIndex = endIndex + pageSize;
291 }
292
293 if (oleGokbTitleList.size() > 0) {
294 getGokbRdbmsService().insertOrUpdateTitles(oleGokbTitleList);
295 noOfRecordsInserted = noOfRecordsInserted + oleGokbTitleList.size();
296 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_TITLES + noOfRecordsInserted);
297 }
298 }
299
300
301
302
303
304
305 private void initPlatforms(int updateId) {
306 List<OleGokbPlatform> oleGokbPlatformList = new ArrayList<>();
307 int endIndex = 0;
308 int pageSize = 0;
309 int noOfRecordsInserted = 0;
310
311 while (true) {
312 String responseXml = OleGokbXmlUtil.getPlatformResponseXmlFromGokb(endIndex);
313
314 NodeList platformNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.PLATFORM_XPATH_EXP);
315
316 if (platformNodeList.getLength() == 0)
317 break;
318
319 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(responseXml);
320
321 for (int i = 0; i < platformNodeList.getLength(); i++) {
322 Node platformNode = platformNodeList.item(i);
323 OleGokbPlatform oleGokbPlatform = null;
324 if (null != updatedDates.get(i)) {
325 oleGokbPlatform = buildPlatformFromPlatformNode(platformNode, updatedDates.get(i));
326 oleGokbPlatformList.add(oleGokbPlatform);
327 }
328 if (oleGokbPlatformList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
329 getGokbRdbmsService().insertPlatforms(oleGokbPlatformList);
330 noOfRecordsInserted = noOfRecordsInserted + oleGokbPlatformList.size();
331 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PLTFRMS + noOfRecordsInserted);
332 oleGokbPlatformList.clear();
333 }
334 }
335 if (endIndex == 0) {
336 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
337 }
338 endIndex = endIndex + pageSize;
339 }
340
341 if (oleGokbPlatformList.size() > 0) {
342 getGokbRdbmsService().insertPlatforms(oleGokbPlatformList);
343 noOfRecordsInserted = noOfRecordsInserted + oleGokbPlatformList.size();
344 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PLTFRMS + noOfRecordsInserted);
345 }
346 }
347
348
349
350
351
352
353
354 private void updatePlatforms(String lastUpdatedTime, int updateId) {
355 List<OleGokbPlatform> oleGokbPlatformList = new ArrayList<>();
356 int endIndex = 0;
357 int pageSize = 0;
358 int noOfRecordsInserted = 0;
359
360 while (true) {
361 String responseXml = OleGokbXmlUtil.getPlatformResponseXmlFromGokb(lastUpdatedTime, endIndex);
362
363 NodeList headerNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.HEADER_XPATH_EXP);
364
365 if (headerNodeList.getLength() == 0)
366 break;
367
368 for (int i = 0; i < headerNodeList.getLength(); i++) {
369 Node headerNode = headerNodeList.item(i);
370 String identifier = OleGokbXmlUtil.getIdentifierFromHeader(headerNode);
371 String recordXml = OleGokbXmlUtil.getPlatformResponseXmlFromGokb(identifier);
372
373 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(recordXml);
374
375 NodeList platformNodeList = OleGokbXmlUtil.getElementNodeList(recordXml, OLEConstants.OleGokb.PLATFORM_XPATH_EXP);
376 Node platformNode = platformNodeList.item(0);
377 OleGokbPlatform oleGokbPlatform = buildPlatformFromPlatformNode(platformNode, updatedDates.get(0));
378 oleGokbPlatformList.add(oleGokbPlatform);
379 if (oleGokbPlatformList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
380 getGokbRdbmsService().insertOrUpdatePlatforms(oleGokbPlatformList);
381 noOfRecordsInserted = noOfRecordsInserted + oleGokbPlatformList.size();
382 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PLTFRMS + noOfRecordsInserted);
383 oleGokbPlatformList.clear();
384 }
385 }
386 if (endIndex == 0) {
387 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
388 }
389 if (pageSize == 0)
390 break;
391 endIndex = endIndex + pageSize;
392 }
393
394 if (oleGokbPlatformList.size() > 0) {
395 getGokbRdbmsService().insertOrUpdatePlatforms(oleGokbPlatformList);
396 noOfRecordsInserted = noOfRecordsInserted + oleGokbPlatformList.size();
397 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_PLTFRMS + noOfRecordsInserted);
398 }
399 }
400
401
402
403
404
405
406 public void initVendors(int updateId) {
407 List<OleGokbOrganization> oleGokbOrganizationList = new ArrayList<>();
408 int endIndex = 0;
409 int pageSize = 0;
410 int noOfRecordsInserted = 0;
411
412 while (true) {
413 String responseXml = OleGokbXmlUtil.getOrgsResponseXmlFromGokb(endIndex);
414
415 NodeList orgsNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.ORG_XPATH_EXP);
416
417 if (orgsNodeList.getLength() == 0)
418 break;
419
420 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(responseXml);
421
422 for (int i = 0; i < orgsNodeList.getLength(); i++) {
423 Node orgNode = orgsNodeList.item(i);
424 OleGokbOrganization oleGokbOrganization = null;
425 if (null != updatedDates.get(i)) {
426 oleGokbOrganization = buildOrgFromOrgNode(orgNode, updatedDates.get(i));
427 oleGokbOrganizationList.add(oleGokbOrganization);
428 }
429 if (oleGokbOrganizationList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
430 getGokbRdbmsService().insertOrganizations(oleGokbOrganizationList);
431 noOfRecordsInserted = noOfRecordsInserted + oleGokbOrganizationList.size();
432 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_ORGS + noOfRecordsInserted);
433 oleGokbOrganizationList.clear();
434 }
435 processRoles(oleGokbOrganization, orgNode.getChildNodes());
436 }
437 if (endIndex == 0) {
438 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
439 }
440 endIndex = endIndex + pageSize;
441 }
442
443 if (oleGokbOrganizationList.size() > 0) {
444 getGokbRdbmsService().insertOrganizations(oleGokbOrganizationList);
445 noOfRecordsInserted = noOfRecordsInserted + oleGokbOrganizationList.size();
446 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_ORGS + noOfRecordsInserted);
447 }
448 }
449
450
451
452
453
454
455
456 public void updateVendors(String lastUpdatedTime, int updateId) {
457 List<OleGokbOrganization> oleGokbOrganizationList = new ArrayList<>();
458 int endIndex = 0;
459 int pageSize = 0;
460 int noOfRecordsInserted = 0;
461
462 while (true) {
463 String responseXml = OleGokbXmlUtil.getOrgsResponseXmlFromGokb(lastUpdatedTime, endIndex);
464
465 NodeList headerNodeList = OleGokbXmlUtil.getElementNodeList(responseXml, OLEConstants.OleGokb.HEADER_XPATH_EXP);
466
467 if (headerNodeList.getLength() == 0)
468 break;
469
470 for (int i = 0; i < headerNodeList.getLength(); i++) {
471 Node headerNode = headerNodeList.item(i);
472 String identifier = OleGokbXmlUtil.getIdentifierFromHeader(headerNode);
473 String recordXml = OleGokbXmlUtil.getOrgsResponseXmlFromGokb(identifier);
474
475 List<String> updatedDates = OleGokbXmlUtil.getUpdatedDates(recordXml);
476
477 NodeList orgsNodeList = OleGokbXmlUtil.getElementNodeList(recordXml, OLEConstants.OleGokb.ORG_XPATH_EXP);
478 Node orgNode = orgsNodeList.item(0);
479 OleGokbOrganization oleGokbOrganization = buildOrgFromOrgNode(orgNode, updatedDates.get(0));
480 oleGokbOrganizationList.add(oleGokbOrganization);
481 if (oleGokbOrganizationList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
482 getGokbRdbmsService().insertOrUpdateOrganizations(oleGokbOrganizationList);
483 noOfRecordsInserted = noOfRecordsInserted + oleGokbOrganizationList.size();
484 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_ORGS + noOfRecordsInserted);
485 oleGokbOrganizationList.clear();
486 }
487 processRoles(oleGokbOrganization, orgNode.getChildNodes());
488 }
489 if (endIndex == 0) {
490 pageSize = OleGokbXmlUtil.getPageSizeFromResponse(responseXml);
491 }
492 if (pageSize == 0)
493 break;
494 endIndex = endIndex + pageSize;
495 }
496
497 if (oleGokbOrganizationList.size() > 0) {
498 getGokbRdbmsService().insertOrUpdateOrganizations(oleGokbOrganizationList);
499 noOfRecordsInserted = noOfRecordsInserted + oleGokbOrganizationList.size();
500 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_ORGS + noOfRecordsInserted);
501 }
502 }
503
504
505
506
507
508
509
510
511 public OleGokbPackage buildPackageFromPackageNode(Node packageNode, String updatedDate) {
512 OleGokbPackage oleGokbPackage = new OleGokbPackage();
513 String packageId = ((DeferredElementImpl) packageNode).getAttribute(OLEConstants.OleGokb.ID);
514 if (!packageId.isEmpty()) {
515 try {
516 oleGokbPackage.setGokbPackageId(Integer.parseInt(packageId));
517 } catch (Exception e) {
518 LOG.error("Exception while parsing int for package id : " + packageId + " " + e);
519 }
520 }
521 oleGokbPackage.setDateUpdated(OleGokbXmlUtil.getTimeStampFromString(updatedDate));
522 String nodeName = null;
523 Node packageChildNode = null;
524 NodeList childNodes = packageNode.getChildNodes();
525 for (int j = 0; j < childNodes.getLength(); j++) {
526 nodeName = childNodes.item(j).getNodeName();
527 packageChildNode = childNodes.item(j);
528 if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.SCOPE)) {
529 oleGokbPackage.setPackageScope(packageChildNode.getTextContent());
530 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.STATUS)) {
531 oleGokbPackage.setStatus(packageChildNode.getTextContent());
532 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.BREAKABLE)) {
533 oleGokbPackage.setBreakable(packageChildNode.getTextContent());
534 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.FIXED)) {
535 oleGokbPackage.setFixed(packageChildNode.getTextContent());
536 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.NAME)) {
537 oleGokbPackage.setPackageName(packageChildNode.getTextContent());
538 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.VARIANT_NAMES)) {
539 oleGokbPackage.setVariantName(getVariantNames(packageChildNode));
540 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.DATE_CREATED)) {
541 oleGokbPackage.setDateCreated(OleGokbXmlUtil.getTimeStampFromString(packageChildNode.getTextContent()));
542 }
543 }
544 return oleGokbPackage;
545 }
546
547
548
549
550
551
552
553
554
555
556 public int processTipps(int updateId, OleGokbPackage oleGokbPackage, NodeList packageChildNodeList, int noOfTippRecordsInserted) {
557 List<OleGokbTipp> oleGokbTippList = new ArrayList<>();
558 for (int i = 0; i < packageChildNodeList.getLength(); i++) {
559 if (!packageChildNodeList.item(i).getNodeName().equalsIgnoreCase(OLEConstants.OleGokb.TIPPS))
560 continue;
561 NodeList tippsNodeList = packageChildNodeList.item(i).getChildNodes();
562 for (int j = 0; j < tippsNodeList.getLength(); j++) {
563 OleGokbTipp oleGokbTipp = new OleGokbTipp();
564 Node tippNode = tippsNodeList.item(j);
565 if (tippNode.getAttributes() == null)
566 continue;
567 String tippId = ((DeferredElementImpl) tippNode).getAttribute(OLEConstants.OleGokb.ID);
568 if (!tippId.isEmpty()) {
569 try {
570 oleGokbTipp.setGokbTippId(Integer.parseInt(tippId));
571 } catch (Exception e) {
572 LOG.error("Exception while parsing int for tipp id : " + tippId + " " + e);
573 }
574 }
575 NodeList tippChildNodes = tippNode.getChildNodes();
576 for (int k = 0; k < tippChildNodes.getLength(); k++) {
577 String nodeName = tippChildNodes.item(k).getNodeName();
578 Node tippChildNode = tippChildNodes.item(k);
579 if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.STATUS)) {
580 oleGokbTipp.setStatus(tippChildNode.getTextContent());
581 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.TITLE)) {
582 String titleId = ((DeferredElementImpl) tippChildNode).getAttribute("id");
583 if (!titleId.isEmpty()) {
584 try {
585 oleGokbTipp.setGokbTitleId(Integer.parseInt(titleId));
586 } catch (Exception e) {
587 LOG.error("Exception while parsing int of title id for tipp with id : " + oleGokbTipp.getGokbTippId() + " " + e);
588 }
589 }
590 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.PLATFORM)) {
591 String platformId = ((DeferredElementImpl) tippChildNode).getAttribute(OLEConstants.OleGokb.ID);
592 if (!platformId.isEmpty()) {
593 try {
594 oleGokbTipp.setGokbPlatformId(Integer.parseInt(platformId));
595 } catch (Exception e) {
596 LOG.error("Exception while parsing int of platform id for tipp with id : " + oleGokbTipp.getGokbTippId() + " " + e);
597 }
598 }
599 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.COVERAGE)) {
600 NamedNodeMap namedNodeMap = tippChildNode.getAttributes();
601 for (int l = 0; l < namedNodeMap.getLength(); l++) {
602 Attr attribute = (Attr) namedNodeMap.item(l);
603 if (attribute.getName().equalsIgnoreCase(OLEConstants.OleGokb.START_DATE)) {
604 oleGokbTipp.setStartdate(OleGokbXmlUtil.getTimeStampFromString(attribute.getTextContent()));
605 } else if (attribute.getName().equalsIgnoreCase(OLEConstants.OleGokb.START_VOLUME)) {
606 oleGokbTipp.setStartVolume(attribute.getTextContent());
607 } else if (attribute.getName().equalsIgnoreCase(OLEConstants.OleGokb.START_ISSUE)) {
608 oleGokbTipp.setStartIssue(attribute.getTextContent());
609 } else if (attribute.getName().equalsIgnoreCase(OLEConstants.OleGokb.END_DATE)) {
610 oleGokbTipp.setEndDate(OleGokbXmlUtil.getTimeStampFromString(attribute.getTextContent()));
611 } else if (attribute.getName().equalsIgnoreCase(OLEConstants.OleGokb.END_VOLUME)) {
612 oleGokbTipp.setEndVolume(attribute.getTextContent());
613 } else if (attribute.getName().equalsIgnoreCase(OLEConstants.OleGokb.END_ISSUE)) {
614 oleGokbTipp.setEndIssue(attribute.getTextContent());
615 }
616 }
617 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.URL)) {
618 oleGokbTipp.setPlatformHostUrl(tippChildNode.getTextContent());
619 }
620 }
621 oleGokbTipp.setGokbPackageId(oleGokbPackage.getGokbPackageId());
622 oleGokbTipp.setDateCreated(oleGokbPackage.getDateCreated());
623 oleGokbTipp.setDateUpdated(oleGokbPackage.getDateUpdated());
624 oleGokbTippList.add(oleGokbTipp);
625 if (oleGokbTippList.size() == OLEConstants.OleGokb.BATCH_SIZE) {
626 getGokbRdbmsService().insertOrUpdateTipps(oleGokbTippList);
627 noOfTippRecordsInserted = noOfTippRecordsInserted + oleGokbTippList.size();
628 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_TIPPS + noOfTippRecordsInserted);
629 oleGokbTippList.clear();
630 }
631 }
632 }
633 if (oleGokbTippList.size() > 0) {
634 getGokbRdbmsService().insertOrUpdateTipps(oleGokbTippList);
635 noOfTippRecordsInserted = noOfTippRecordsInserted + oleGokbTippList.size();
636 getGokbRdbmsService().updateStatus(updateId, OLEConstants.OleGokb.NUM_TIPPS + noOfTippRecordsInserted);
637 }
638 return noOfTippRecordsInserted;
639 }
640
641
642
643
644
645
646
647 private void processRoles(OleGokbOrganization oleGokbOrganization, NodeList orgChildNodeList) {
648 List<OleGokbOrganizationRole> oleGokbOrganizationRoles = new ArrayList<>();
649 for (int i = 0; i < orgChildNodeList.getLength(); i++) {
650 if (!orgChildNodeList.item(i).getNodeName().equalsIgnoreCase(OLEConstants.OleGokb.ROLES))
651 continue;
652 NodeList rolesNodeList = orgChildNodeList.item(i).getChildNodes();
653 for (int j = 0; j < rolesNodeList.getLength(); j++) {
654 Node roleNode = rolesNodeList.item(j);
655 if (roleNode.getAttributes() == null)
656 continue;
657 OleGokbOrganizationRole oleGokbOrganizationRole = new OleGokbOrganizationRole();
658 oleGokbOrganizationRole.setGokbOrganizationId(oleGokbOrganization.getGokbOrganizationId());
659 oleGokbOrganizationRole.setRole(roleNode.getTextContent());
660 oleGokbOrganizationRoles.add(oleGokbOrganizationRole);
661 }
662 }
663 if (oleGokbOrganizationRoles.size() > 0) {
664 getGokbRdbmsService().insertOrUpdateOrganizationRoles(oleGokbOrganizationRoles);
665 }
666 }
667
668
669
670
671
672
673
674
675 public OleGokbTitle buildTitleFromTitleNode(Node titleNode, String updatedDate) {
676 OleGokbTitle oleGokbTitle = new OleGokbTitle();
677 String titleId = ((DeferredElementImpl) titleNode).getAttribute(OLEConstants.OleGokb.ID);
678 if (!titleId.isEmpty()) {
679 try {
680 oleGokbTitle.setGokbTitleId(Integer.parseInt(titleId));
681 } catch (Exception e) {
682 LOG.error("Exception while parsing int for title id : " + titleId + " " + e);
683 }
684 }
685 oleGokbTitle.setDateUpdated(OleGokbXmlUtil.getTimeStampFromString(updatedDate));
686 String nodeName = null;
687 Node titleChildNode = null;
688 NodeList titleChildNodes = titleNode.getChildNodes();
689 for (int i = 0; i < titleChildNodes.getLength(); i++) {
690 nodeName = titleChildNodes.item(i).getNodeName();
691 titleChildNode = titleChildNodes.item(i);
692 if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.NAME)) {
693 oleGokbTitle.setTitleName(titleChildNode.getTextContent());
694 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.IMPRINT)) {
695 if (StringUtils.isNotEmpty(titleChildNode.getTextContent())) {
696 oleGokbTitle.setImprint(titleChildNode.getTextContent());
697 }
698 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.MEDIUM)) {
699 oleGokbTitle.setMedium(titleChildNode.getTextContent());
700 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.IDENTIFIERS)) {
701 NodeList identifierNodes = titleChildNode.getChildNodes();
702 for (int j = 0; j < identifierNodes.getLength(); j++) {
703 NamedNodeMap namedNodeMap = identifierNodes.item(j).getAttributes();
704 if (namedNodeMap == null)
705 continue;
706 for (int k = 0; k < namedNodeMap.getLength(); k++) {
707 Attr attribute = (Attr) namedNodeMap.item(k);
708 if (attribute.getNodeValue().equalsIgnoreCase(OLEConstants.OleGokb.ISSN)) {
709 k++;
710 oleGokbTitle.setIssnPrint(namedNodeMap.item(k).getNodeValue());
711 } else if (attribute.getNodeValue().equalsIgnoreCase(OLEConstants.OleGokb.EISSN)) {
712 k++;
713 oleGokbTitle.setIssnOnline(namedNodeMap.item(k).getNodeValue());
714 } else if (attribute.getNodeValue().equalsIgnoreCase(OLEConstants.OleGokb.DOI)) {
715 k++;
716 oleGokbTitle.setDoi(namedNodeMap.item(k).getNodeValue());
717 } else if (attribute.getNodeValue().equalsIgnoreCase(OLEConstants.OleGokb.PROPRIETARY_ID)) {
718 k++;
719 try {
720 oleGokbTitle.setProprietaryId(Integer.parseInt(namedNodeMap.item(k).getNodeValue()));
721 } catch (Exception e) {
722 LOG.error("Exception while parsing int of proprietary id for title with id : " + oleGokbTitle.getGokbTitleId() + " " + e);
723 }
724 } else if (attribute.getNodeValue().equalsIgnoreCase(OLEConstants.OleGokb.OCLC_NUM)) {
725 k++;
726 try {
727 oleGokbTitle.setOclcNumber(Integer.parseInt(namedNodeMap.item(k).getNodeValue()));
728 } catch (Exception e) {
729 LOG.error("Exception while parsing int of oclc number for title with id : " + oleGokbTitle.getGokbTitleId() + " " + e);
730 }
731 }
732 }
733 }
734 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.PUBLISHER)) {
735 String publisherId = ((DeferredElementImpl) titleChildNode).getAttribute(OLEConstants.OleGokb.ID);
736 if (!publisherId.isEmpty()) {
737 try {
738 oleGokbTitle.setPublisherId(Integer.parseInt(publisherId));
739 } catch (Exception e) {
740 LOG.error("Exception while parsing int of publisher for title with id : " + oleGokbTitle.getGokbTitleId() + " " + e);
741 }
742 }
743 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.DATE_CREATED)) {
744 oleGokbTitle.setDateCreated(OleGokbXmlUtil.getTimeStampFromString(titleChildNode.getTextContent()));
745 }
746 }
747 return oleGokbTitle;
748 }
749
750
751
752
753
754
755
756
757 public OleGokbPlatform buildPlatformFromPlatformNode(Node platformNode, String updatedDate) {
758 OleGokbPlatform oleGokbPlatform = new OleGokbPlatform();
759 String platformId = ((DeferredElementImpl) platformNode).getAttribute(OLEConstants.OleGokb.ID);
760 if (!platformId.isEmpty()) {
761 try {
762 oleGokbPlatform.setGokbPlatformId(Integer.parseInt(platformId));
763 } catch (Exception e) {
764 LOG.error("Exception while parsing int for platform id : " + platformId + " " + e);
765 }
766 }
767 oleGokbPlatform.setDateUpdated(OleGokbXmlUtil.getTimeStampFromString(updatedDate));
768 String nodeName = null;
769 Node platformChildNode = null;
770 NodeList platformChildNodes = platformNode.getChildNodes();
771 for (int i = 0; i < platformChildNodes.getLength(); i++) {
772 nodeName = platformChildNodes.item(i).getNodeName();
773 platformChildNode = platformChildNodes.item(i);
774 if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.NAME)) {
775 oleGokbPlatform.setPlatformName(platformChildNode.getTextContent());
776 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.AUTHENTICATION)) {
777 oleGokbPlatform.setAuthentication(platformChildNode.getTextContent());
778 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.SOFTWARE)) {
779 oleGokbPlatform.setSoftwarePlatform(platformChildNode.getTextContent());
780 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.DATE_CREATED)) {
781 oleGokbPlatform.setDateCreated(OleGokbXmlUtil.getTimeStampFromString(platformChildNode.getTextContent()));
782 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.STATUS)) {
783 oleGokbPlatform.setStatus(platformChildNode.getTextContent());
784 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.SERVICE)) {
785 if (StringUtils.isNotBlank(platformChildNode.getTextContent())) {
786 Map<String, String> orgMap = new HashMap<>();
787 orgMap.put(OLEPropertyConstants.ORGANIZATION_NAME, platformChildNode.getTextContent());
788 List<OleGokbOrganization> oleGokbOrganizations = (List<OleGokbOrganization>) getBusinessObjectService().findMatching(OleGokbOrganization.class, orgMap);
789 if (oleGokbOrganizations.size() > 0) {
790 oleGokbPlatform.setPlatformProviderId(oleGokbOrganizations.get(0).getGokbOrganizationId());
791 }
792 }
793 }
794 }
795 return oleGokbPlatform;
796 }
797
798
799
800
801
802
803
804
805 public OleGokbOrganization buildOrgFromOrgNode(Node orgNode, String updatedDate) {
806 OleGokbOrganization oleGokbOrganization = new OleGokbOrganization();
807 String orgId = ((DeferredElementImpl) orgNode).getAttribute(OLEConstants.OleGokb.ID);
808 if (!orgId.isEmpty()) {
809 try {
810 oleGokbOrganization.setGokbOrganizationId(Integer.parseInt(orgId));
811 } catch (Exception e) {
812 LOG.error("Exception while parsing int for organization id : " + orgId + " " + e);
813 }
814 }
815 oleGokbOrganization.setDateUpdated(OleGokbXmlUtil.getTimeStampFromString(updatedDate));
816 String nodeName = null;
817 Node orgChildNode = null;
818 NodeList orgChildNodes = orgNode.getChildNodes();
819 for (int i = 0; i < orgChildNodes.getLength(); i++) {
820 nodeName = orgChildNodes.item(i).getNodeName();
821 orgChildNode = orgChildNodes.item(i);
822 if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.NAME)) {
823 oleGokbOrganization.setOrganizationName(orgChildNode.getTextContent());
824 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.VARIANT_NAMES)) {
825 oleGokbOrganization.setVariantName(getVariantNames(orgChildNode));
826 } else if (nodeName.equalsIgnoreCase(OLEConstants.OleGokb.DATE_CREATED)) {
827 oleGokbOrganization.setDateCreated(OleGokbXmlUtil.getTimeStampFromString(orgChildNode.getTextContent()));
828 }
829 }
830 return oleGokbOrganization;
831 }
832
833
834
835
836
837
838
839 private String getVariantNames(Node orgChildNode) {
840 StringBuilder variantNameBuilder = new StringBuilder();
841 NodeList variantNameNodeList = orgChildNode.getChildNodes();
842 for (int j = 0; j < variantNameNodeList.getLength(); j++) {
843 variantNameBuilder.append(variantNameNodeList.item(j).getTextContent());
844 if (j < variantNameNodeList.getLength() - 1) {
845 variantNameBuilder.append(OLEConstants.OleGokb.PIPE);
846 }
847 }
848 return variantNameBuilder.toString();
849 }
850
851 }