View Javadoc
1   package org.kuali.ole.docstore.document.rdbms;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.DocumentUniqueIDPrefix;
5   import org.kuali.ole.docstore.OleDocStoreException;
6   import org.kuali.ole.docstore.document.DocumentManager;
7   import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.*;
8   import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
9   import org.kuali.ole.docstore.model.xmlpojo.ingest.Content;
10  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
11  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
12  import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
13  import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
14  import org.kuali.ole.utility.Constants;
15  import org.kuali.rice.krad.service.BusinessObjectService;
16  import org.kuali.rice.krad.service.KRADServiceLocator;
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  
20  import javax.jcr.Node;
21  import java.sql.Timestamp;
22  import java.text.SimpleDateFormat;
23  import java.util.ArrayList;
24  import java.util.Date;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.regex.Matcher;
29  import java.util.regex.Pattern;
30  
31  /**
32   * Implements the DocumentManager interface for [Work-Bib-*] documents.
33   *
34   * @version %I%, %G%
35   * @author: tirumalesh.b
36   * Date: 31/8/12 Time: 7:04 PM
37   */
38  
39  public class RdbmsWorkBibDocumentManager extends RdbmsAbstarctDocumentManager {
40  
41      private Logger logger = LoggerFactory.getLogger(this.getClass());
42      private static RdbmsWorkBibDocumentManager ourInstance = null;
43  
44      public static RdbmsWorkBibDocumentManager getInstance() {
45          if (null == ourInstance) {
46              ourInstance = new RdbmsWorkBibDocumentManager();
47          }
48          return ourInstance;
49      }
50  
51  
52      public Node storeDocument(RequestDocument requestDocument, Object object, ResponseDocument respDoc) {
53          BusinessObjectService businessObjectService = (BusinessObjectService) object;
54          BibRecord bibRecord = new BibRecord();
55  
56          modifyAdditionalAttributes(requestDocument);
57          AdditionalAttributes attributes = requestDocument.getAdditionalAttributes();
58          bibRecord.setContent(requestDocument.getContent().getContent());
59          boolean isBibIdFlag = getBibIdFromBibXMLContent(bibRecord);
60          if (attributes != null) {
61              /*DateFormat df = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss");
62              Date dateCreated = null;
63              try {
64                  dateCreated = df.parse(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED));
65                  Date dateEntered = df.parse(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED));
66              Date dateStatusUpdated = df.parse(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON));
67              bibRecord.setDateCreated(dateCreated);
68              bibRecord.setDateEntered(dateEntered);
69              bibRecord.setStatusUpdatedDate(dateStatusUpdated);
70              } catch (ParseException e) {
71                  e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
72              }*/
73              bibRecord.setCreatedBy(attributes.getAttribute(AdditionalAttributes.CREATED_BY));
74              bibRecord.setStatusUpdatedBy(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_BY));
75              bibRecord.setDateCreated(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED)));
76              //bibRecord.setDateEntered(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED)));
77              if (StringUtils.isNotEmpty(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON))) {
78                  bibRecord.setStatusUpdatedDate(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON)));
79              }
80              bibRecord.setFassAddFlag(Boolean.valueOf(attributes.getAttribute(AdditionalAttributes.FAST_ADD_FLAG)));
81              bibRecord.setFormerId("");
82              bibRecord.setSuppressFromPublic(attributes.getAttribute(AdditionalAttributes.SUPRESS_FROM_PUBLIC));
83              bibRecord.setStatus(attributes.getAttribute(AdditionalAttributes.STATUS));
84  
85              bibRecord.setStaffOnlyFlag(Boolean.valueOf(attributes.getAttribute(AdditionalAttributes.STAFFONLYFLAG)));
86          }
87          bibRecord.setUniqueIdPrefix(DocumentUniqueIDPrefix.getPrefix(requestDocument.getCategory(), requestDocument.getType(), requestDocument.getFormat()));
88          businessObjectService.save(bibRecord);
89          String uuid = DocumentUniqueIDPrefix.getPrefixedId(bibRecord.getUniqueIdPrefix(), bibRecord.getBibId());
90          if (isBibIdFlag) {
91              modifyDocumentContent(requestDocument, bibRecord.getBibId(), businessObjectService);
92          }
93          requestDocument.setUuid(uuid);
94          buildResponseDocument(requestDocument, bibRecord, respDoc);
95          return null;
96      }
97  
98  
99      public ResponseDocument buildResponseDocument(RequestDocument requestDocument, BibRecord bibRecord, ResponseDocument responseDocument) {
100         responseDocument.setId(requestDocument.getId());
101         responseDocument.setCategory(requestDocument.getCategory());
102         responseDocument.setType(requestDocument.getType());
103         responseDocument.setFormat(requestDocument.getFormat());
104         responseDocument.setStatus("Success");
105         responseDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(bibRecord.getUniqueIdPrefix(), bibRecord.getBibId()));
106         AdditionalAttributes additionalAttributes = new AdditionalAttributes();
107         additionalAttributes.setAttribute(AdditionalAttributes.DATE_ENTERED,bibRecord.getDateEntered() != null ? bibRecord.getDateEntered().toString() : "");
108         additionalAttributes.setAttribute(AdditionalAttributes.STATUS, bibRecord.getStatus());
109         additionalAttributes.setAttribute(AdditionalAttributes.STATUS_UPDATED_ON, "");
110         additionalAttributes.setAttribute(AdditionalAttributes.CREATED_BY, "");
111         additionalAttributes.setAttribute(AdditionalAttributes.LAST_UPDATED, "");
112         if(bibRecord.getFassAddFlag() != null) {
113             additionalAttributes.setAttribute(AdditionalAttributes.FAST_ADD_FLAG, bibRecord.getFassAddFlag().toString());
114         }
115         additionalAttributes.setAttribute(AdditionalAttributes.STATUS, bibRecord.getStatus());
116         if (bibRecord.getStaffOnlyFlag() != null) {
117             additionalAttributes.setAttribute(AdditionalAttributes.STAFFONLYFLAG, bibRecord.getStaffOnlyFlag().toString());
118         } else {
119             additionalAttributes.setAttribute(AdditionalAttributes.STAFFONLYFLAG, "false");
120         }
121         additionalAttributes
122                 .setAttribute(AdditionalAttributes.SUPRESS_FROM_PUBLIC, bibRecord.getSuppressFromPublic());
123         responseDocument.setAdditionalAttributes(additionalAttributes);
124         return responseDocument;
125     }
126 
127 
128     @Override
129     public void deleteDocs(RequestDocument requestDocument, Object object) {
130         ResponseDocument responseDocument = new ResponseDocument();
131         BusinessObjectService businessObjectService = (BusinessObjectService) object;
132         BibRecord bibRecord = new BibRecord();
133         Map map = new HashMap();
134         map.put("bibId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
135         List<BibRecord> bibRecords = (List<BibRecord>) businessObjectService.findMatching(BibRecord.class, map);
136         if (bibRecords != null && bibRecords.size() > 0) {
137             bibRecord = bibRecords.get(0);
138           //  if (bibRecord.getInstanceRecords() != null && bibRecord.getInstanceRecords().size() > 0) {
139                 InstanceRecord instanceRecord = new InstanceRecord();
140                 List<InstanceRecord> instanceRecords = null;//(List<InstanceRecord>) bibRecord.getInstanceRecords();
141                 if (instanceRecords != null && instanceRecords.size() > 0) {
142                     for (int i = 0; i < instanceRecords.size(); i++) {
143                         instanceRecord = instanceRecords.get(i);
144                         if (instanceRecord.getHoldingsRecords() != null && instanceRecord.getHoldingsRecords().size() > 0) {
145                             HoldingsRecord holdingsRecord = instanceRecord.getHoldingsRecords().get(0);
146 
147                             if (holdingsRecord.getExtentOfOwnerShipRecords() != null && holdingsRecord.getExtentOfOwnerShipRecords().size() > 0) {
148                                 List<ExtentOfOwnerShipRecord> extentOfOwnerShipRecords = holdingsRecord.getExtentOfOwnerShipRecords();
149                                 for (int j = 0; j < extentOfOwnerShipRecords.size(); j++) {
150                                     List<ExtentNoteRecord> extentNoteRecords = extentOfOwnerShipRecords.get(j).getExtentNoteRecords();
151                                     if (extentNoteRecords != null && extentNoteRecords.size() > 0) {
152                                         businessObjectService.delete(extentNoteRecords);
153                                     }
154                                 }
155                                 businessObjectService.delete(extentOfOwnerShipRecords);
156                             }
157                             if (holdingsRecord.getHoldingsNoteRecords() != null && holdingsRecord.getHoldingsNoteRecords().size() > 0) {
158                                 List<HoldingsNoteRecord> holdingsNoteRecords = holdingsRecord.getHoldingsNoteRecords();
159                                 businessObjectService.delete(holdingsNoteRecords);
160                             }
161 
162                             /*if (holdingsRecord.getAccessUriRecords() != null && holdingsRecord.getAccessUriRecords().size() > 0) {
163                                 List<AccessUriRecord> accessUriRecords = holdingsRecord.getAccessUriRecords();
164                                 businessObjectService.delete(accessUriRecords);
165                             }*/
166                             holdingsRecord.setCallNumberTypeId(null);
167                             holdingsRecord.setReceiptStatusId(null);
168                             businessObjectService.delete(holdingsRecord);
169                         }
170                         List<ItemRecord> itemRecords = instanceRecord.getItemRecords();
171                         for (ItemRecord itemRecord : itemRecords) {
172                             if (itemRecord.getFormerIdentifierRecords() != null && itemRecord.getFormerIdentifierRecords().size() > 0) {
173                                 List<FormerIdentifierRecord> formerIdentifierRecords = itemRecord.getFormerIdentifierRecords();
174                                 businessObjectService.delete(formerIdentifierRecords);
175                             }
176                             if (itemRecord.getItemNoteRecords() != null && itemRecord.getItemNoteRecords().size() > 0) {
177                                 List<ItemNoteRecord> itemNoteRecords = itemRecord.getItemNoteRecords();
178                                 businessObjectService.delete(itemNoteRecords);
179                             }
180                             if (itemRecord.getLocationsCheckinCountRecords() != null && itemRecord.getLocationsCheckinCountRecords().size() > 0) {
181                                 List<LocationsCheckinCountRecord> locationsCheckinCountRecords = itemRecord.getLocationsCheckinCountRecords();
182                                 businessObjectService.delete(locationsCheckinCountRecords);
183                             }
184                             itemRecord.setItemStatusId(null);
185                             itemRecord.setItemTypeId(null);
186                             itemRecord.setTempItemTypeId(null);
187                             itemRecord.setStatisticalSearchId(null);
188                             itemRecord.setHighDensityStorageId(null);
189                             businessObjectService.delete(itemRecord);
190 
191                         }
192                         businessObjectService.delete(instanceRecord);
193                     }
194                 }
195            // }
196         }
197         businessObjectService.delete(bibRecord);
198         //requestDocument.setUuid(bibRecord.getBibId());
199         buildResponseDocument(requestDocument, bibRecord, responseDocument);
200     }
201 
202     /**
203      * Updating BibStatus fields based on ingest/checking operation is invoked
204      *
205      * @param requestDocument
206      */
207     protected void modifyAdditionalAttributes(RequestDocument requestDocument) {
208         Date date = new Date();
209         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
210         String dateStr = sdf.format(date);
211         String user = requestDocument.getUser();
212         String statusFromReqDoc = "";
213         String statusFromNode = "";
214         AdditionalAttributes additionalAttributes = requestDocument.getAdditionalAttributes();
215         if (additionalAttributes == null) {
216             additionalAttributes = new AdditionalAttributes();
217         }
218         if (requestDocument.getOperation() != null) {
219             if (requestDocument.getOperation().equalsIgnoreCase(Request.Operation.ingest.toString())) {
220                 statusFromReqDoc = additionalAttributes.getAttribute(AdditionalAttributes.STATUS);
221                 additionalAttributes.setAttribute(AdditionalAttributes.DATE_ENTERED, dateStr);
222                 additionalAttributes.setAttribute(AdditionalAttributes.CREATED_BY, user);
223                 //Add statusUpdatedBy and statusUpdatedOn if input request is having non empty status field
224                 if (StringUtils.isNotEmpty(statusFromReqDoc)) {
225                     additionalAttributes.setAttribute(AdditionalAttributes.STATUS_UPDATED_BY, user);
226                     additionalAttributes.setAttribute(AdditionalAttributes.STATUS_UPDATED_ON, dateStr);
227                 }
228             } else if (requestDocument.getOperation().equalsIgnoreCase(Request.Operation.checkIn.toString())) {
229                 if (requestDocument.getAdditionalAttributes() != null) {
230                     statusFromReqDoc = additionalAttributes.getAttribute(Constants.STATUS);
231                 }
232                 HashMap<String, String> bibMap = new HashMap<String, String>();
233                 bibMap.put("bibId", DocumentUniqueIDPrefix.getDocumentId(DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid())));
234                 List<BibRecord> bibRecordList = (List<BibRecord>) KRADServiceLocator.getBusinessObjectService().findMatching(BibRecord.class, bibMap);
235                 if (bibRecordList.size() > 0) {
236                     BibRecord bibRecord = bibRecordList.get(0);
237                     String status = bibRecord.getStatus();
238                     if (status == null) {
239                         status = "";
240                     }
241 
242                     if (status != null && !status.equals(statusFromReqDoc)) {
243                         additionalAttributes.setAttribute(Constants.STATUS_UPDATED_BY, user);
244                         additionalAttributes.setAttribute(Constants.STATUS_UPDATED_ON, dateStr);
245                     }
246 
247                 }
248                 additionalAttributes.setAttribute(Constants.UPDATED_BY, user);
249                 additionalAttributes.setAttribute(Constants.DATE_ENTERED, dateStr);
250             }
251             requestDocument.setAdditionalAttributes(additionalAttributes);
252         }
253     }
254 
255 
256     @Override
257     public ResponseDocument checkoutContent(RequestDocument requestDocument, Object object) {
258         BusinessObjectService businessObjectService = (BusinessObjectService) object;
259         Date date = new Date();
260         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
261         String dateStr = sdf.format(date);
262         ResponseDocument respDoc = new ResponseDocument();
263         if (null == businessObjectService) {
264             businessObjectService = KRADServiceLocator.getBusinessObjectService();
265         }
266         Map parentCriteria1 = new HashMap();
267         parentCriteria1.put("bibId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
268         List<BibRecord> bibRecords = (List<BibRecord>) businessObjectService.findMatching(BibRecord.class, parentCriteria1);
269         if (bibRecords != null && bibRecords.size() > 0) {
270             BibRecord bibRecord = bibRecords.get(0);
271             String content = bibRecord.getContent();
272             AdditionalAttributes additionalAttributes = new AdditionalAttributes();
273             if (bibRecord.getFassAddFlag() != null) {
274                 additionalAttributes.setAttribute(AdditionalAttributes.FAST_ADD_FLAG, bibRecord.getFassAddFlag().toString());
275             }
276             if (bibRecord.getDateEntered() != null && !"".equals(bibRecord.getDateEntered())) {
277                 additionalAttributes.setAttribute(AdditionalAttributes.DATE_ENTERED, bibRecord.getDateEntered().toString());
278             }
279             if (bibRecord.getStatus() != null) {
280                 additionalAttributes.setAttribute(AdditionalAttributes.STATUS, bibRecord.getStatus());
281             }
282             if (bibRecord.getStatusUpdatedDate() != null) {
283                 additionalAttributes.setAttribute(AdditionalAttributes.STATUS_UPDATED_ON, bibRecord.getStatusUpdatedDate().toString());
284             }
285             if (bibRecord.getSuppressFromPublic() != null) {
286                 additionalAttributes.setAttribute(AdditionalAttributes.SUPRESS_FROM_PUBLIC, bibRecord.getSuppressFromPublic());
287             }
288             if (bibRecord.getStaffOnlyFlag() != null) {
289                 additionalAttributes.setAttribute(AdditionalAttributes.STAFFONLYFLAG, bibRecord.getStaffOnlyFlag().toString());
290             }
291             if (bibRecord.getCreatedBy() != null) {
292                 additionalAttributes.setAttribute(AdditionalAttributes.CREATED_BY, bibRecord.getCreatedBy());
293             }
294             if (bibRecord.getUpdatedBy() != null) {
295                 additionalAttributes.setAttribute(AdditionalAttributes.UPDATED_BY, bibRecord.getUpdatedBy());
296             }
297             if (bibRecord.getStatusUpdatedBy() != null) {
298                 additionalAttributes.setAttribute(AdditionalAttributes.STATUS_UPDATED_BY, bibRecord.getStatusUpdatedBy());
299             }
300             if (bibRecord.getDateCreated() != null && !"".equals(bibRecord.getDateCreated())) {
301                 additionalAttributes.setAttribute(AdditionalAttributes.DATE_ENTERED, bibRecord.getDateCreated().toString());
302             }
303 
304             if (bibRecord.getDateEntered() != null && !"".equals(bibRecord.getDateEntered())) {
305                 additionalAttributes.setAttribute(AdditionalAttributes.LAST_UPDATED, bibRecord.getDateEntered().toString());
306             }
307             Content contentObj = new Content();
308             contentObj.setContent(content);
309             respDoc.setUuid(requestDocument.getUuid());
310             respDoc.setCategory(requestDocument.getCategory());
311             respDoc.setType(requestDocument.getType());
312             respDoc.setFormat(requestDocument.getFormat());
313             respDoc.setContent(contentObj);
314             respDoc.setStatus("Success");
315             respDoc.setAdditionalAttributes(additionalAttributes);
316         } else {
317             respDoc.setStatus("Failed");
318             respDoc.setStatusMessage("Bib Record Does not exist.");
319         }
320         return respDoc;
321     }
322 
323 
324     @Override
325     public void checkInContent(RequestDocument requestDocument, Object object, ResponseDocument responseDocument) {
326         modifyAdditionalAttributes(requestDocument);
327         BusinessObjectService businessObjectService = (BusinessObjectService) object;
328         if (null == businessObjectService) {
329             businessObjectService = KRADServiceLocator.getBusinessObjectService();
330         }
331         Map parentCriteria1 = new HashMap();
332         parentCriteria1.put("bibId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
333         AdditionalAttributes attributes = requestDocument.getAdditionalAttributes();
334         BibRecord bibRecord = businessObjectService.findByPrimaryKey(BibRecord.class, parentCriteria1);
335         bibRecord.setContent(requestDocument.getContent().getContent());
336         if (attributes != null) {
337             bibRecord.setFassAddFlag(Boolean.valueOf(attributes.getAttribute(AdditionalAttributes.FAST_ADD_FLAG)));
338             bibRecord.setSuppressFromPublic(attributes.getAttribute(AdditionalAttributes.SUPRESS_FROM_PUBLIC));
339             bibRecord.setStatus(attributes.getAttribute(AdditionalAttributes.STATUS));
340             /* DateFormat df = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss");
341             Date dateStatusUpdated = null;
342             try {
343                 dateStatusUpdated = df.parse(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON));
344             } catch (ParseException e) {
345                 e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
346             }
347             bibRecord.setStatusUpdatedDate(dateStatusUpdated);*/
348             bibRecord.setUpdatedBy(attributes.getAttribute(AdditionalAttributes.UPDATED_BY));
349             bibRecord.setDateEntered(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED)));
350             if (attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_BY) != null) {
351                 bibRecord.setStatusUpdatedBy(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_BY));
352             }
353             if (attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON) != null) {
354                 bibRecord.setStatusUpdatedDate(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON)));
355             }
356             bibRecord.setStaffOnlyFlag(Boolean.valueOf(attributes.getAttribute(AdditionalAttributes.STAFFONLYFLAG)));
357             bibRecord.setUpdatedBy(attributes.getAttribute(AdditionalAttributes.UPDATED_BY));
358         }
359         businessObjectService.save(bibRecord);
360         requestDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(bibRecord.getUniqueIdPrefix(), bibRecord.getBibId()));
361         buildResponseDocument(requestDocument, bibRecord, responseDocument);
362     }
363 
364     protected void modifyDocumentContent(RequestDocument doc, String identifier, BusinessObjectService businessObjectService) {
365 
366     }
367 
368     /*@Override
369     public void validateInput(RequestDocument requestDocument, Object object, List<String> valuesList) throws OleDocStoreException {
370         BusinessObjectService businessObjectService = (BusinessObjectService) object;
371         for (RequestDocument linkDoc : requestDocument.getLinkedRequestDocuments()) {
372             DocumentManager documentManager = RdbmsDocumentManagerFactory.getInstance().getDocumentManager(linkDoc);
373             documentManager.validateInput(linkDoc, businessObjectService, valuesList);
374         }
375     }*/
376 
377     @Override
378     public void validateInput(RequestDocument requestDocument, Object object, List<String> valuesList) throws OleDocStoreException {
379         BusinessObjectService businessObjectService = (BusinessObjectService) object;
380 
381         //To validate req documents
382         //validateRequestDocument(requestDocument);
383 
384         //To validate linked documents.
385         validateLinkedRequestDocument(requestDocument, valuesList, businessObjectService);
386 
387     }
388 
389     protected void validateRequestDocument(RequestDocument requestDocument) throws OleDocStoreException {
390 
391     }
392 
393     protected void validateLinkedRequestDocument(RequestDocument requestDocument, List<String> valuesList, BusinessObjectService businessObjectService) throws OleDocStoreException {
394         for (RequestDocument linkDoc : requestDocument.getLinkedRequestDocuments()) {
395             DocumentManager documentManager = RdbmsDocumentManagerFactory.getInstance().getDocumentManager(linkDoc);
396             documentManager.validateInput(linkDoc, businessObjectService, valuesList);
397         }
398     }
399 
400 
401     @Override
402     public ResponseDocument deleteVerify(RequestDocument requestDocument, Object object) throws Exception {
403         BusinessObjectService businessObjectService = (BusinessObjectService) object;
404         Response response = new Response();
405         ResponseDocument responseDocument = new ResponseDocument();
406         List<ResponseDocument> responseDocumentList = new ArrayList<ResponseDocument>();
407         List<String> instanceIdentifierList = new ArrayList<String>();
408         //get instances for bib
409         Map bibMap = new HashMap();
410         bibMap.put("bibId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
411         List<BibInstanceRecord> bibInstanceRecordList = (List<BibInstanceRecord>) businessObjectService
412                 .findMatching(BibInstanceRecord.class, bibMap);
413         for (BibInstanceRecord bibInstanceRecord : bibInstanceRecordList) {
414             Map instanceMap = new HashMap();
415             instanceMap.put("instanceId", bibInstanceRecord.getInstanceId());
416             List<BibInstanceRecord> bibInstanceRecords = (List<BibInstanceRecord>) businessObjectService.findMatching(BibInstanceRecord.class, instanceMap);
417             if (bibInstanceRecords.size() > 1) {
418                 responseDocument.setCategory(requestDocument.getCategory());
419                 responseDocument.setType(requestDocument.getType());
420                 responseDocument.setFormat(requestDocument.getFormat());
421                 responseDocument.setUuid(requestDocument.getUuid());
422                 responseDocument.setStatus("failure'");
423                 responseDocument
424                         .setStatusMessage("Instance is bound with more than one bib. So deletion cannot be done");
425                 return responseDocument;
426             }
427             boolean exists = checkInstancesOrItemsExistsInOLE(bibInstanceRecord.getInstanceId(), businessObjectService);
428             if (exists) {
429                 responseDocument.setId(requestDocument.getId());
430                 responseDocument.setCategory(requestDocument.getCategory());
431                 responseDocument.setType(requestDocument.getType());
432                 responseDocument.setFormat(requestDocument.getFormat());
433                 responseDocument.setUuid(requestDocument.getUuid());
434                 responseDocument.setStatus("failure");
435                 responseDocument.setStatusMessage("Instances or Items in use. So deletion cannot be done");
436                 return responseDocument;
437             }
438         }
439         responseDocument.setId(requestDocument.getId());
440         responseDocument.setCategory(requestDocument.getCategory());
441         responseDocument.setType(requestDocument.getType());
442         responseDocument.setFormat(requestDocument.getFormat());
443         responseDocument.setUuid(requestDocument.getUuid());
444         responseDocument.setStatus("success");
445         responseDocument.setStatusMessage("success");
446         return responseDocument;
447     }
448 
449 /*    @Override
450     public ResponseDocument deleteVerify(RequestDocument requestDocument, Object object) throws Exception {
451         Response response = new Response();
452         BusinessObjectService businessObjectService = (BusinessObjectService) object;
453         if (null == businessObjectService) {
454             throw new OleDocStoreException("Invalid businessObjectService.");
455         }
456         ResponseDocument responseDocument = new ResponseDocument();
457         List<ResponseDocument> responseDocumentList = new ArrayList<ResponseDocument>();
458         List<String> bibIdentifierList = new ArrayList<String>();
459         List<String> instanceIdentifierList = new ArrayList<String>();
460         Map bibMap = new HashMap();
461         bibMap.put("bibId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
462         List<BibInstanceRecord> bibInstanceRecordList = (List<BibInstanceRecord>) businessObjectService
463                 .findMatching(BibInstanceRecord.class, bibMap);
464         for (BibInstanceRecord bibInstanceRecord : bibInstanceRecordList) {
465             instanceIdentifierList.add(bibInstanceRecord.getHoldingsId());
466             Map instanceMap = new HashMap();
467             instanceMap.put("instanceId", bibInstanceRecord.getHoldingsId());
468             List<BibInstanceRecord> bibInstanceRecords = (List<BibInstanceRecord>) businessObjectService
469                     .findMatching(BibInstanceRecord.class, instanceMap);
470             for (BibInstanceRecord record : bibInstanceRecords) {
471                 bibIdentifierList.add(record.getBibId());
472 
473             }
474 
475         }
476         for (String instanceIdentifierValue : instanceIdentifierList) {
477             if (bibIdentifierList.size() > 1) {
478                 responseDocument.setCategory(requestDocument.getCategory());
479                 responseDocument.setType(requestDocument.getType());
480                 responseDocument.setFormat(requestDocument.getFormat());
481                 responseDocument.setUuid(requestDocument.getUuid());
482                 responseDocument.setStatus("failure'");
483                 responseDocument
484                         .setStatusMessage("Instance is bound with more than one bib. So deletion cannot be done");
485                 return responseDocument;
486             }
487             boolean exists = checkInstancesOrItemsExistsInOLE(instanceIdentifierValue, object);
488             if (exists) {
489                 responseDocument.setId(requestDocument.getId());
490                 responseDocument.setCategory(requestDocument.getCategory());
491                 responseDocument.setType(requestDocument.getType());
492                 responseDocument.setFormat(requestDocument.getFormat());
493                 responseDocument.setUuid(requestDocument.getUuid());
494                 responseDocument.setStatus("failure");
495                 responseDocument.setStatusMessage("Instances or Items in use. So deletion cannot be done");
496                 return responseDocument;
497             }
498 
499             responseDocument.setId(requestDocument.getId());
500             responseDocument.setCategory(requestDocument.getCategory());
501             responseDocument.setType(requestDocument.getType());
502             responseDocument.setFormat(requestDocument.getFormat());
503             responseDocument.setUuid(requestDocument.getUuid());
504             responseDocument.setStatus("success");
505             responseDocument.setStatusMessage("success");
506         }
507         return responseDocument;
508 
509     }*/
510 
511     protected boolean validateIdField (String bibId) {
512         if (StringUtils.isNotEmpty(bibId)) {
513             String idPattern = "[0-9]+";
514             Matcher match = Pattern.compile(idPattern).matcher(bibId);
515             return match.matches();
516         }
517         return false;
518     }
519 
520     protected boolean getBibIdFromBibXMLContent(BibRecord bibRecord) {
521         return true;
522     }
523 }