001package org.kuali.ole.docstore.document.rdbms; 002 003import org.apache.commons.lang.StringUtils; 004import org.kuali.ole.DocumentUniqueIDPrefix; 005import org.kuali.ole.docstore.OleDocStoreException; 006import org.kuali.ole.docstore.document.DocumentManager; 007import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.*; 008import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes; 009import org.kuali.ole.docstore.model.xmlpojo.ingest.Content; 010import org.kuali.ole.docstore.model.xmlpojo.ingest.Request; 011import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument; 012import org.kuali.ole.docstore.model.xmlpojo.ingest.Response; 013import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument; 014import org.kuali.ole.utility.Constants; 015import org.kuali.rice.krad.service.BusinessObjectService; 016import org.kuali.rice.krad.service.KRADServiceLocator; 017import org.slf4j.Logger; 018import org.slf4j.LoggerFactory; 019 020import javax.jcr.Node; 021import java.sql.Timestamp; 022import java.text.SimpleDateFormat; 023import java.util.ArrayList; 024import java.util.Date; 025import java.util.HashMap; 026import java.util.List; 027import java.util.Map; 028import java.util.regex.Matcher; 029import java.util.regex.Pattern; 030 031/** 032 * Implements the DocumentManager interface for [Work-Bib-*] documents. 033 * 034 * @version %I%, %G% 035 * @author: tirumalesh.b 036 * Date: 31/8/12 Time: 7:04 PM 037 */ 038 039public class RdbmsWorkBibDocumentManager extends RdbmsAbstarctDocumentManager { 040 041 private Logger logger = LoggerFactory.getLogger(this.getClass()); 042 private static RdbmsWorkBibDocumentManager ourInstance = null; 043 044 public static RdbmsWorkBibDocumentManager getInstance() { 045 if (null == ourInstance) { 046 ourInstance = new RdbmsWorkBibDocumentManager(); 047 } 048 return ourInstance; 049 } 050 051 052 public Node storeDocument(RequestDocument requestDocument, Object object, ResponseDocument respDoc) { 053 BusinessObjectService businessObjectService = (BusinessObjectService) object; 054 BibRecord bibRecord = new BibRecord(); 055 056 modifyAdditionalAttributes(requestDocument); 057 AdditionalAttributes attributes = requestDocument.getAdditionalAttributes(); 058 bibRecord.setContent(requestDocument.getContent().getContent()); 059 boolean isBibIdFlag = getBibIdFromBibXMLContent(bibRecord); 060 if (attributes != null) { 061 /*DateFormat df = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss"); 062 Date dateCreated = null; 063 try { 064 dateCreated = df.parse(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED)); 065 Date dateEntered = df.parse(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED)); 066 Date dateStatusUpdated = df.parse(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON)); 067 bibRecord.setDateCreated(dateCreated); 068 bibRecord.setDateEntered(dateEntered); 069 bibRecord.setStatusUpdatedDate(dateStatusUpdated); 070 } catch (ParseException e) { 071 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 072 }*/ 073 bibRecord.setCreatedBy(attributes.getAttribute(AdditionalAttributes.CREATED_BY)); 074 bibRecord.setStatusUpdatedBy(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_BY)); 075 bibRecord.setDateCreated(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED))); 076 //bibRecord.setDateEntered(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.DATE_ENTERED))); 077 if (StringUtils.isNotEmpty(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON))) { 078 bibRecord.setStatusUpdatedDate(Timestamp.valueOf(attributes.getAttribute(AdditionalAttributes.STATUS_UPDATED_ON))); 079 } 080 bibRecord.setFassAddFlag(Boolean.valueOf(attributes.getAttribute(AdditionalAttributes.FAST_ADD_FLAG))); 081 bibRecord.setFormerId(""); 082 bibRecord.setSuppressFromPublic(attributes.getAttribute(AdditionalAttributes.SUPRESS_FROM_PUBLIC)); 083 bibRecord.setStatus(attributes.getAttribute(AdditionalAttributes.STATUS)); 084 085 bibRecord.setStaffOnlyFlag(Boolean.valueOf(attributes.getAttribute(AdditionalAttributes.STAFFONLYFLAG))); 086 } 087 bibRecord.setUniqueIdPrefix(DocumentUniqueIDPrefix.getPrefix(requestDocument.getCategory(), requestDocument.getType(), requestDocument.getFormat())); 088 businessObjectService.save(bibRecord); 089 String uuid = DocumentUniqueIDPrefix.getPrefixedId(bibRecord.getUniqueIdPrefix(), bibRecord.getBibId()); 090 if (isBibIdFlag) { 091 modifyDocumentContent(requestDocument, bibRecord.getBibId(), businessObjectService); 092 } 093 requestDocument.setUuid(uuid); 094 buildResponseDocument(requestDocument, bibRecord, respDoc); 095 return null; 096 } 097 098 099 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}