001package org.kuali.ole; 002 003import org.apache.commons.io.FileUtils; 004import org.apache.commons.lang.StringUtils; 005import org.junit.Assert; 006import org.junit.Ignore; 007import org.junit.Test; 008import org.kuali.ole.docstore.common.document.*; 009import org.kuali.ole.docstore.common.document.HoldingsTree; 010import org.kuali.ole.docstore.common.document.Item; 011import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord; 012import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords; 013import org.kuali.ole.docstore.common.document.content.bib.marc.DataField; 014import org.kuali.ole.docstore.common.document.content.bib.marc.SubField; 015import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor; 016import org.kuali.ole.docstore.common.document.content.instance.*; 017import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor; 018import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor; 019import org.kuali.ole.docstore.common.exception.DocstoreException; 020import org.kuali.ole.docstore.common.exception.DocstoreResources; 021import org.kuali.ole.docstore.common.exception.DocstoreValidationException; 022import org.kuali.ole.docstore.common.search.*; 023import org.kuali.ole.docstore.common.service.DocstoreService; 024import org.kuali.ole.docstore.common.util.ParseXml; 025import org.kuali.ole.docstore.engine.service.index.solr.BibConstants; 026import org.kuali.ole.docstore.engine.service.storage.rdbms.RdbmsItemDocumentManager; 027import org.kuali.ole.docstore.model.enums.DocCategory; 028import org.kuali.ole.docstore.model.enums.DocFormat; 029import org.kuali.ole.docstore.model.enums.DocType; 030import org.kuali.ole.docstore.service.BeanLocator; 031 032import java.io.File; 033import java.text.SimpleDateFormat; 034import java.util.*; 035 036/** 037 * Created with IntelliJ IDEA. 038 * User: sambasivam 039 * Date: 12/16/13 040 * Time: 6:17 PM 041 * To change this template use File | Settings | File Templates. 042 */ 043 044@Ignore 045@Deprecated 046public class DocstoreService_UT extends SpringBaseTestCase { 047 048 DocstoreService docstoreService = BeanLocator.getDocstoreService(); 049 050 @Test 051 public void testCreateBib() { 052 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 053 Bib bib = new BibMarc(); 054 bib = (Bib) bib.deserialize(xml); 055 bib.setId(null); 056 docstoreService.createBib(bib); 057 Assert.assertNotNull(bib.getId()); 058 } 059 060 @Test 061 public void testCreateBibFails() { 062 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 063 Bib bib = new BibMarc(); 064 bib = (Bib) bib.deserialize(xml); 065 bib.setId(null); 066 docstoreService.createBib(bib); 067 068 String xml2 = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 069 Bib bib2 = new BibMarc(); 070 bib2 = (Bib) bib2.deserialize(xml2); 071 bib2.setId(bib.getId()); 072 try { 073 docstoreService.createBib(bib2); 074 } 075 catch (Exception e) { 076 DocstoreException docstoreException = (DocstoreException) e; 077 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) { 078 Assert.assertNotNull(docstoreException.getErrorCode()); 079 } else { 080 Assert.assertNotNull(e.getMessage()); 081 } 082 } 083 } 084 085 @Test 086 public void testCreatePHoldings() { 087 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 088 Bib bib = new BibMarc(); 089 bib = (Bib) bib.deserialize(xml); 090 bib.setId(null); 091 docstoreService.createBib(bib); 092 Assert.assertNotNull(bib.getId()); 093 094 xml = getXmlAsString("/org/kuali/ole/documents/PHoldings1.xml"); 095 Holdings holdings = new PHoldings(); 096 holdings = (PHoldings) holdings.deserialize(xml); 097 holdings.setBib(bib); 098 docstoreService.createHoldings(holdings); 099 100 Assert.assertNotNull(holdings.getId()); 101 } 102 103 @Test 104 public void testCreatePHoldingsFails() { 105 Bib bib = getBibRecord(); 106 docstoreService.createBib(bib); 107 Holdings holdings = getHoldingsRecord(); 108 holdings.setBib(null); 109 try { 110 docstoreService.createHoldings(holdings); 111 } 112 catch (Exception e) { 113 DocstoreException docstoreException = (DocstoreException) e; 114 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) { 115 Assert.assertNotNull(docstoreException.getErrorCode()); 116 } else { 117 Assert.assertNotNull(e.getMessage()); 118 } 119 } 120 } 121 122 123 @Test 124 public void testCreateEHoldings() { 125 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 126 Bib bib = new BibMarc(); 127 bib = (Bib) bib.deserialize(xml); 128 bib.setId(null); 129 docstoreService.createBib(bib); 130 Assert.assertNotNull(bib.getId()); 131 132 xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml"); 133 Holdings holdings = new EHoldings(); 134 holdings = (PHoldings) holdings.deserialize(xml); 135 holdings.setBib(bib); 136 docstoreService.createHoldings(holdings); 137 138 Assert.assertNotNull(holdings.getId()); 139 } 140 141 @Test 142 public void testCreateEHoldingsFails() { 143 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 144 Bib bib = new BibMarc(); 145 bib = (Bib) bib.deserialize(xml); 146 bib.setId(null); 147 docstoreService.createBib(bib); 148 Assert.assertNotNull(bib.getId()); 149 150 xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml"); 151 Holdings holdings = new EHoldings(); 152 holdings = (PHoldings) holdings.deserialize(xml); 153 holdings.setBib(null); 154 try { 155 docstoreService.createHoldings(holdings); 156 } 157 catch (Exception e) { 158 DocstoreException docstoreException = (DocstoreException) e; 159 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) { 160 Assert.assertNotNull(docstoreException.getErrorCode()); 161 } else { 162 Assert.assertNotNull(e.getMessage()); 163 } 164 } 165 } 166 @Test 167 public void testCreateItem() { 168 Bib bib = getBibRecord(); 169 docstoreService.createBib(bib); 170 171 Holdings holdings = getHoldingsRecord(); 172 holdings.setBib(bib); 173 docstoreService.createHoldings(holdings); 174 Item item = getItemRecord(); 175 item.setHolding(holdings); 176 docstoreService.createItem(item); 177 Assert.assertNotNull(item.getId()); 178 } 179 180 @Test 181 public void testCreateItemFails() { 182 Bib bib = getBibRecord(); 183 docstoreService.createBib(bib); 184 185 Holdings holdings = getHoldingsRecord(); 186 holdings.setBib(bib); 187 docstoreService.createHoldings(holdings); 188 Item item = getItemRecord(); 189 item.setHolding(null); 190 try { 191 docstoreService.createItem(item); 192 } 193 catch (Exception e) { 194 DocstoreException docstoreException = (DocstoreException) e; 195 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) { 196 Assert.assertNotNull(docstoreException.getErrorCode()); 197 }else { 198 Assert.assertNotNull(e.getMessage()); 199 } 200 } 201 202 } 203 204 @Test 205 public void testCreateHoldingsTree() { 206 HoldingsTree holdingsTree = getHoldingsTreeRecord(); 207 Bib bib = getBibRecord(); 208 docstoreService.createBib(bib); 209 holdingsTree.getHoldings().setBib(bib); 210 docstoreService.createHoldingsTree(holdingsTree); 211 Assert.assertNotNull(holdingsTree.getHoldings().getId()); 212 Assert.assertNotNull(holdingsTree.getItems().get(0).getId()); 213 Holdings holdings = docstoreService.retrieveHoldings(holdingsTree.getHoldings().getId()); 214 Item item = docstoreService.retrieveItem(holdingsTree.getItems().get(0).getId()); 215 Assert.assertEquals(holdingsTree.getHoldings().getId(), holdings.getId()); 216 Assert.assertEquals(holdingsTree.getItems().get(0).getId(), item.getId()); 217 } 218 219 220 @Test 221 public void testCreateHoldingsTreeFails() { 222 HoldingsTree holdingsTree = getHoldingsTreeRecord(); 223 holdingsTree.getHoldings().setBib(null); 224 225 226 try { 227 docstoreService.createHoldingsTree(holdingsTree); 228 } 229 catch (Exception e) { 230 DocstoreException docstoreException = (DocstoreException) e; 231 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) { 232 Assert.assertNotNull(docstoreException.getErrorCode()); 233 }else { 234 Assert.assertNotNull(e.getMessage()); 235 } 236 } 237 238 } 239 240 @Test 241 public void testCreateBibTree() { 242 BibTree bibTree = getBibTree(); 243 docstoreService.createBibTree(bibTree); 244 Assert.assertNotNull(bibTree.getBib().getId()); 245 HoldingsTree holdingsTree = bibTree.getHoldingsTrees().get(0); 246 Assert.assertNotNull(holdingsTree.getHoldings().getId()); 247 Assert.assertNotNull(holdingsTree.getItems().get(0).getId()); 248 Map map = new HashMap(); 249 map.put(BibConstants.DOC_TYPE, "bibliographic"); 250 map.put("ID", bibTree.getBib().getId()); 251 BibTree retrievedBibTree = docstoreService.findBibTree(map); 252 Map holdingsMap = new HashMap(); 253 holdingsMap.put("ID", holdingsTree.getHoldings().getId()); 254 holdingsMap.put(BibConstants.DOC_TYPE, "holdings"); 255 HoldingsTree retrievedHoldingsTree = docstoreService.findHoldingsTree(holdingsMap); 256 Assert.assertEquals(bibTree.getBib().getId(), retrievedBibTree.getBib().getId()); 257 Assert.assertEquals(holdingsTree.getHoldings().getId(), retrievedHoldingsTree.getHoldings().getId()); 258 } 259 260 @Test 261 public void testCreateBibTreeFails() { 262 BibTree bibTree = getBibTree(); 263 docstoreService.createBibTree(bibTree); 264 265 BibTree bibTree2 = getBibTree(); 266 bibTree2.getBib().setId(bibTree.getBib().getId()); 267 268 269 try { 270 docstoreService.createBibTree(bibTree2); 271 } 272 catch (Exception e) { 273 DocstoreException docstoreException = (DocstoreException) e; 274 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) { 275 Assert.assertNotNull(docstoreException.getErrorCode()); 276 }else { 277 Assert.assertNotNull(e.getMessage()); 278 } 279 } 280 281 } 282 283 private HoldingsTree getHoldingsTreeRecord() { 284 HoldingsTree holdingsTree = new HoldingsTree(); 285 holdingsTree.setHoldings(getHoldingsRecord()); 286 List<Item> items = new ArrayList<Item>(0); 287 Item item = getItemRecord(); 288 item.setHolding(holdingsTree.getHoldings()); 289 items.add(item); 290 holdingsTree.getItems().addAll(items); 291 return holdingsTree; 292 } 293 294 private Item getItemRecord() { 295 Item item = new ItemOleml(); 296 item.setCategory("work"); 297 item.setType("item"); 298 item.setFormat("oleml"); 299 org.kuali.ole.docstore.common.document.content.instance.Item item1 = new org.kuali.ole.docstore.common.document.content.instance.Item(); 300 item1.setVolumeNumber("12345"); 301 ShelvingScheme shelvingScheme = new ShelvingScheme(); 302 shelvingScheme.setCodeValue("LCC"); 303 304 CallNumber callNumber = new CallNumber(); 305 callNumber.setNumber("1234"); 306 callNumber.setShelvingScheme(shelvingScheme); 307 item1.setCallNumber(callNumber); 308 item1.setChronology("1234"); 309 item1.setEnumeration("en"); 310 item1.setBarcodeARSL("bararsl"); 311 Location location = new Location(); 312 LocationLevel locationLevel1 = new LocationLevel(); 313 locationLevel1.setName("ARCH"); 314 locationLevel1.setLevel("1"); 315 LocationLevel locationLevel2 = new LocationLevel(); 316 locationLevel2.setName("PA"); 317 locationLevel2.setLevel("2"); 318 location.setLocationLevel(locationLevel1); 319 item1.setLocation(location); 320 item.setContent(new ItemOlemlRecordProcessor().toXML(item1)); 321 return item; 322 } 323 324 325 @Test 326 public void testRetrieveBib() { 327// Bib bib = getBibRecord(); 328// docstoreService.createBib(bib); 329 Bib retrievedBib = docstoreService.retrieveBib("wbm-10000001"); 330 Assert.assertNotNull(retrievedBib); 331// Assert.assertEquals(bib.getId(), retrievedBib.getId()); 332 } 333 334 @Test 335 public void testRetrieveBibFails() { 336 337 Bib retrievedBib = null; 338 String bibId = ""; 339 try { 340 retrievedBib = docstoreService.retrieveBib(bibId); 341 } 342 catch (Exception e) { 343 DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.BIB_ID_NOT_FOUND, DocstoreResources.BIB_ID_NOT_FOUND); 344 docstoreException.addErrorParams("bibId", bibId ); 345 throw docstoreException; 346 } 347 } 348 349 @Test 350 public void testRetrieveBibs() { 351 Bib bib = getBibRecord(); 352 docstoreService.createBib(bib); 353 List<String> bibIds = new ArrayList<String>(); 354 bibIds.add(bib.getId()); 355 List<Bib> retrievedBibs = docstoreService.retrieveBibs(bibIds); 356 Assert.assertNotNull(retrievedBibs); 357 Assert.assertEquals(bib.getId(), retrievedBibs.get(0).getId()); 358 359 } 360 361 @Test 362 public void testUpdateBib() { 363 Bib bib = getBibRecord(); 364 docstoreService.createBib(bib); 365 Bib retrievedBib = docstoreService.retrieveBib(bib.getId()); 366 Assert.assertNotNull(retrievedBib); 367 updateContent(retrievedBib); 368 setDate(retrievedBib); 369 docstoreService.updateBib(retrievedBib); 370 retrievedBib = docstoreService.retrieveBib(retrievedBib.getId()); 371 if (bib.getId().equalsIgnoreCase(retrievedBib.getId())) 372 Assert.assertEquals("The Alchemist", retrievedBib.getTitle()); 373 else 374 Assert.fail(); 375 } 376 377 @Test 378 public void testUpdateBibs() { 379 Bib bib = getBibRecord(); 380 docstoreService.createBib(bib); 381 List<String> bibIds = new ArrayList<String>(); 382 bibIds.add(bib.getId()); 383 Bib retrievedBib = docstoreService.retrieveBib(bib.getId()); 384 Assert.assertNotNull(retrievedBib); 385 updateContent(retrievedBib); 386 setDate(retrievedBib); 387 docstoreService.updateBib(retrievedBib); 388 List<Bib> bibs = new ArrayList<Bib>(); 389 bibs.add(retrievedBib); 390 docstoreService.updateBibs(bibs); 391 retrievedBib = docstoreService.retrieveBib(retrievedBib.getId()); 392 if (bib.getId().equalsIgnoreCase(retrievedBib.getId())) 393 Assert.assertEquals("The Alchemist", retrievedBib.getTitle()); 394 else 395 Assert.fail(); 396 } 397 398 @Test 399 public void testRetrieveHoldings() { 400 String holdingsId = ""; 401 Holdings holdings = docstoreService.retrieveHoldings(holdingsId); 402 OleHoldings oleHoldings = (OleHoldings) holdings.getContentObject(); 403 Assert.assertNotNull(holdings); 404 } 405 @Test 406 public void testRetrieveHoldingsFails() { 407 String holdingsId = ""; 408 Holdings holdings = null; 409 try { 410 holdings = docstoreService.retrieveHoldings(holdingsId); 411 } 412 catch (Exception e) { 413 DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.HOLDING_ID_NOT_FOUND, DocstoreResources.HOLDING_ID_NOT_FOUND); 414 docstoreException.addErrorParams("holdingsId", holdingsId ); 415 throw docstoreException; 416 } 417 418 } 419 420 @Test 421 public void testRetrieveItem() { 422 String itemId = ""; 423 Item item = docstoreService.retrieveItem(itemId); 424 item.getCallNumber(); 425 item.getHolding().getBib().getAuthor(); 426 Assert.assertNotNull(item); 427 } 428 @Test 429 public void testRetrieveItemFails() { 430 String itemId = null; 431 Item item = null; 432 try { 433 item= docstoreService.retrieveItem(itemId); 434 } 435 catch (Exception e) { 436 DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.ITEM_ID_NOT_FOUND, DocstoreResources.ITEM_ID_NOT_FOUND); 437 docstoreException.addErrorParams("itemId", itemId ); 438 throw docstoreException; 439 } 440 } 441 442 @Test 443 public void testRetrieveItems() { 444 List<String> itemIds = new ArrayList<String>(); 445 itemIds.add("1"); 446 itemIds.add("2"); 447 List<Item> items = docstoreService.retrieveItems(itemIds); 448 for (Item item : items) { 449 item.getCallNumber(); 450 item.getHolding().getBib().getAuthor(); 451 Assert.assertNotNull(item); 452 } 453 } 454 455 @Test 456 public void testRetrieveHoldingsTree() { 457 String holdingsId = ""; 458 HoldingsTree holdingsTree = docstoreService.retrieveHoldingsTree(holdingsId); 459 Assert.assertNotNull(holdingsTree); 460 } 461 462 @Test 463 public void testRetrieveBibTree() { 464 String bibId = "wbm-10000001"; 465 BibTree bibTree = docstoreService.retrieveBibTree(bibId); 466 Assert.assertNotNull(bibTree); 467 } 468 469 @Test 470 public void testSortHoldings() { 471 String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml"); 472 BibTree bibTree = new BibTree(); 473 String strHoldings = new String(); 474 bibTree = (BibTree) bibTree.deserialize(xml); 475 476 docstoreService.createBibTree(bibTree); 477 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor(); 478 System.out.println("BEFORE SORTING HOLDINGS:"); 479 System.out.println("HOLDINGS : Loc | ShlOrd"); 480 for(HoldingsTree holdingsTree :bibTree.getHoldingsTrees()){ 481 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent()); 482// System.out.println(strHoldings.format("%s | %s", Holdings.buildLocationString(oleHoldings.getLocation()), oleHoldings.getCallNumber().getShelvingOrder().getCodeValue() + "\n")); 483 } 484 bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId()); 485 System.out.println("AFTER SORTING HOLDINGS:"); 486 System.out.println("HOLDINGS : Loc | ShlOrd "); 487 for(HoldingsTree holdingsTree :bibTree.getHoldingsTrees()){ 488 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent()); 489// System.out.println(strHoldings.format("%s | %s", Holdings.buildLocationString(oleHoldings.getLocation()), oleHoldings.getCallNumber().getShelvingOrder().getCodeValue() + "\n")); 490 491 } 492 } 493 494 495 @Test 496 public void testSortItems() { 497 String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml"); 498 BibTree bibTree = new BibTree(); 499 String strItems = new String(); 500 bibTree = (BibTree) bibTree.deserialize(xml); 501 docstoreService.createBibTree(bibTree); 502 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor(); 503 504 System.out.println("BEFORE SORTING ITEMS:"); 505 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) { 506 System.out.println("***HOLDINGS***"); 507 System.out.println("ITEMS : Loc | Prefix | ShlOrd | Enum | Chro | Copy | bar"); 508 for (Item item : holdingsTree.getItems()) { 509 org.kuali.ole.docstore.common.document.content.instance.Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent()); 510// System.out.println(strItems.format("%s | %s | %s | %s | %s | %s | %s", Holdings.buildLocationString(item1.getLocation()), item1.getCallNumber().getPrefix(), 511// item1.getCallNumber().getShelvingOrder().getCodeValue(), item1.getEnumeration(), item1.getChronology(), item1.getCopyNumber(), item1.getAccessInformation().getBarcode() + "\n")); 512 } 513 } 514 bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId()); 515 System.out.println("AFTER SORTING ITEMS:"); 516 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) { 517 System.out.println("***HOLDINGS***"); 518 System.out.println("ITEMS : Loc | Prefix | ShlOrd | Enum | Chro | Copy | bar"); 519 for (Item item : holdingsTree.getItems()) { 520 org.kuali.ole.docstore.common.document.content.instance.Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent()); 521// System.out.println(strItems.format("%s | %s | %s | %s | %s | %s | %s", Holdings.buildLocationString(item1.getLocation()), item1.getCallNumber().getPrefix(), 522// item1.getCallNumber().getShelvingOrder().getCodeValue(), item1.getEnumeration(), item1.getChronology(), item1.getCopyNumber(), item1.getAccessInformation().getBarcode() + "\n")); 523 } 524 } 525 } 526 527 528 529 /*@Test 530 public void testSortItems() { 531 String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml"); 532 BibTree bibTree = new BibTree(); 533 bibTree = (BibTree) bibTree.deserialize(xml); 534 docstoreService.createBibTree(bibTree); 535 bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId()); 536 String serialize = bibTree.serialize(bibTree); 537 serialize = ParseXml.formatXml(serialize); 538 System.out.println(serialize); 539 540 }*/ 541 542 543 @Test 544 public void createBibTrees2() { 545 List bibTrees = new ArrayList(); 546 BibTree bibTree = new BibTree(); 547 String xml = getXmlAsString("/org/kuali/ole/search/BibTree1.xml"); 548 bibTree = (BibTree) bibTree.deserialize(xml); 549 bibTrees.add(bibTree); 550 bibTree = new BibTree(); 551 xml = getXmlAsString("/org/kuali/ole/search/BibTree2.xml"); 552 bibTree = (BibTree) bibTree.deserialize(xml); 553 bibTrees.add(bibTree); 554 bibTree = new BibTree(); 555 xml = getXmlAsString("/org/kuali/ole/search/BibTree3.xml"); 556 bibTree = (BibTree) bibTree.deserialize(xml); 557 bibTrees.add(bibTree); 558 bibTree = new BibTree(); 559 xml = getXmlAsString("/org/kuali/ole/search/BibTree4.xml"); 560 bibTree = (BibTree) bibTree.deserialize(xml); 561 bibTrees.add(bibTree); 562 bibTree = new BibTree(); 563 xml = getXmlAsString("/org/kuali/ole/search/BibTree5.xml"); 564 bibTree = (BibTree) bibTree.deserialize(xml); 565 bibTrees.add(bibTree); 566 bibTree = new BibTree(); 567 xml = getXmlAsString("/org/kuali/ole/search/BibTree6.xml"); 568 bibTree = (BibTree) bibTree.deserialize(xml); 569 bibTrees.add(bibTree); 570 bibTree = new BibTree(); 571 xml = getXmlAsString("/org/kuali/ole/search/BibTree7.xml"); 572 bibTree = (BibTree) bibTree.deserialize(xml); 573 bibTrees.add(bibTree); 574 bibTree = new BibTree(); 575 xml = getXmlAsString("/org/kuali/ole/search/BibTree8.xml"); 576 bibTree = (BibTree) bibTree.deserialize(xml); 577 bibTrees.add(bibTree); 578 bibTree = new BibTree(); 579 xml = getXmlAsString("/org/kuali/ole/search/BibTree9.xml"); 580 bibTree = (BibTree) bibTree.deserialize(xml); 581 bibTrees.add(bibTree); 582 bibTree = new BibTree(); 583 xml = getXmlAsString("/org/kuali/ole/search/BibTree10.xml"); 584 bibTree = (BibTree) bibTree.deserialize(xml); 585 bibTrees.add(bibTree); 586 bibTree = new BibTree(); 587 xml = getXmlAsString("/org/kuali/ole/search/BibTree11.xml"); 588 bibTree = (BibTree) bibTree.deserialize(xml); 589 bibTrees.add(bibTree); 590 bibTree = new BibTree(); 591 xml = getXmlAsString("/org/kuali/ole/search/BibTree12.xml"); 592 bibTree = (BibTree) bibTree.deserialize(xml); 593 bibTrees.add(bibTree); 594 bibTree = new BibTree(); 595 xml = getXmlAsString("/org/kuali/ole/search/BibTree13.xml"); 596 bibTree = (BibTree) bibTree.deserialize(xml); 597 bibTrees.add(bibTree); 598 bibTree = new BibTree(); 599 xml = getXmlAsString("/org/kuali/ole/search/BibTree14.xml"); 600 bibTree = (BibTree) bibTree.deserialize(xml); 601 bibTrees.add(bibTree); 602 bibTree = new BibTree(); 603 xml = getXmlAsString("/org/kuali/ole/search/BibTree15.xml"); 604 bibTree = (BibTree) bibTree.deserialize(xml); 605 bibTrees.add(bibTree); 606 BibTrees bibTreesobj = new BibTrees(); 607 bibTreesobj.getBibTrees().add(bibTree); 608 bibTreesobj.getBibTrees().addAll(bibTrees); 609 docstoreService.createBibTrees(bibTreesobj); 610 } 611 612 @Test 613 public void testSearch1() { 614 Bib bib = getBibMarc1(); 615 docstoreService.createBib(bib); 616 Assert.assertNotNull(bib.getId()); 617 SearchParams searchParams = getSearchParams1(); 618 SearchField searchField = searchParams.buildSearchField("bibliographic", "bibIdentifier", bib.getId()); 619 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND")); 620 621 Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(0).getSearchField().getDocType()); 622 Assert.assertEquals("Title", searchParams.getSearchConditions().get(0).getSearchField().getFieldName()); 623 Assert.assertEquals("This Title is for Test1", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue()); 624 Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(1).getSearchField().getDocType()); 625 Assert.assertEquals("Author", searchParams.getSearchConditions().get(1).getSearchField().getFieldName()); 626 Assert.assertEquals("This Author is for Test1", searchParams.getSearchConditions().get(1).getSearchField().getFieldValue()); 627 Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(2).getSearchField().getDocType()); 628 Assert.assertEquals("bibIdentifier", searchParams.getSearchConditions().get(2).getSearchField().getFieldName()); 629 Assert.assertEquals(bib.getId(), searchParams.getSearchConditions().get(2).getSearchField().getFieldValue()); 630 631 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(0).getDocType()); 632 Assert.assertEquals("Title", searchParams.getSearchResultFields().get(0).getFieldName()); 633 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(1).getDocType()); 634 Assert.assertEquals("Author", searchParams.getSearchResultFields().get(1).getFieldName()); 635 636 SearchResponse searchResponse = docstoreService.search(searchParams); 637 638 Assert.assertNotNull(searchResponse); 639 Assert.assertNotNull(searchResponse.getSearchResults()); 640 Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields()); 641 642 Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType()); 643 Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName()); 644 Assert.assertEquals("This Title is for Test1", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue()); 645 Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType()); 646 Assert.assertEquals("Author", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName()); 647 Assert.assertEquals("This Author is for Test1", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue()); 648 } 649 650 public Bib getBibMarc1() { 651 Bib bib = new BibMarc(); 652 return (Bib) bib.deserialize(getXmlAsString("/org/kuali/ole/search/BibMarc1.xml")); 653 } 654 655 @Test 656 public void testSearch2() { 657 BibTree bibTree = getBibTree1(); 658 docstoreService.createBibTree(bibTree); 659 Assert.assertNotNull(bibTree.getBib().getId()); 660 SearchParams searchParams = getSearchParams2(); 661 SearchField searchField = searchParams.buildSearchField("bibliographic", "bibIdentifier", bibTree.getBib().getId()); 662 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND")); 663 664 Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(0).getSearchField().getDocType()); 665 Assert.assertEquals("Title", searchParams.getSearchConditions().get(0).getSearchField().getFieldName()); 666 Assert.assertEquals("This Title is for Test2", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue()); 667 Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(1).getSearchField().getDocType()); 668 Assert.assertEquals("bibIdentifier", searchParams.getSearchConditions().get(1).getSearchField().getFieldName()); 669 Assert.assertEquals(bibTree.getBib().getId(), searchParams.getSearchConditions().get(1).getSearchField().getFieldValue()); 670 671 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(0).getDocType()); 672 Assert.assertEquals("Title", searchParams.getSearchResultFields().get(0).getFieldName()); 673 Assert.assertEquals("holdings", searchParams.getSearchResultFields().get(1).getDocType()); 674 Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(1).getFieldName()); 675 Assert.assertEquals("item", searchParams.getSearchResultFields().get(2).getDocType()); 676 Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(2).getFieldName()); 677 Assert.assertEquals("item", searchParams.getSearchResultFields().get(3).getDocType()); 678 Assert.assertEquals("chronology", searchParams.getSearchResultFields().get(3).getFieldName()); 679 Assert.assertEquals("item", searchParams.getSearchResultFields().get(4).getDocType()); 680 Assert.assertEquals("enumeration", searchParams.getSearchResultFields().get(4).getFieldName()); 681 682 SearchResponse searchResponse = docstoreService.search(searchParams); 683 684 Assert.assertNotNull(searchResponse); 685 Assert.assertNotNull(searchResponse.getSearchResults()); 686 Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields()); 687 688 Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType()); 689 Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName()); 690 Assert.assertEquals("This Title is for Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue()); 691 Assert.assertEquals("holdings", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType()); 692 Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName()); 693 Assert.assertEquals("CN Holdings Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue()); 694 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getDocType()); 695 Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldName()); 696 Assert.assertEquals("CN Item Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldValue()); 697 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getDocType()); 698 Assert.assertEquals("chronology", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldName()); 699 Assert.assertEquals("CHN Item Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldValue()); 700 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getDocType()); 701 Assert.assertEquals("enumeration", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldName()); 702 Assert.assertEquals("ENUM Item Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldValue()); 703 } 704 705 public BibTree getBibTree1() { 706 BibTree bibTree = new BibTree(); 707 return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree1.xml")); 708 } 709 710 @Test 711 public void testSearch3() { 712 BibTree bibTree = getBibTree2(); 713 docstoreService.createBibTree(bibTree); 714 Assert.assertNotNull(bibTree.getHoldingsTrees().get(0).getHoldings().getId()); 715 SearchParams searchParams = getSearchParams3(); 716 SearchField searchField = searchParams.buildSearchField("holdings", "holdingsIdentifier", bibTree.getHoldingsTrees().get(0).getHoldings().getId()); 717 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND")); 718 719 Assert.assertEquals("holdings", searchParams.getSearchConditions().get(0).getSearchField().getDocType()); 720 Assert.assertEquals("CallNumber", searchParams.getSearchConditions().get(0).getSearchField().getFieldName()); 721 Assert.assertEquals("CN Holdings Test3", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue()); 722 Assert.assertEquals("holdings", searchParams.getSearchConditions().get(1).getSearchField().getDocType()); 723 Assert.assertEquals("ShelvingOrder_search", searchParams.getSearchConditions().get(1).getSearchField().getFieldName()); 724 Assert.assertEquals("CN-Holdings-Test3", searchParams.getSearchConditions().get(1).getSearchField().getFieldValue()); 725 Assert.assertEquals("holdings", searchParams.getSearchConditions().get(2).getSearchField().getDocType()); 726 Assert.assertEquals("holdingsIdentifier", searchParams.getSearchConditions().get(2).getSearchField().getFieldName()); 727 Assert.assertEquals(bibTree.getHoldingsTrees().get(0).getHoldings().getId(), searchParams.getSearchConditions().get(2).getSearchField().getFieldValue()); 728 729 Assert.assertEquals("holdings", searchParams.getSearchResultFields().get(0).getDocType()); 730 Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(0).getFieldName()); 731 Assert.assertEquals("item", searchParams.getSearchResultFields().get(1).getDocType()); 732 Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(1).getFieldName()); 733 Assert.assertEquals("item", searchParams.getSearchResultFields().get(2).getDocType()); 734 Assert.assertEquals("chronology", searchParams.getSearchResultFields().get(2).getFieldName()); 735 Assert.assertEquals("item", searchParams.getSearchResultFields().get(3).getDocType()); 736 Assert.assertEquals("enumeration", searchParams.getSearchResultFields().get(3).getFieldName()); 737 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(4).getDocType()); 738 Assert.assertEquals("Title", searchParams.getSearchResultFields().get(4).getFieldName()); 739 740 SearchResponse searchResponse = docstoreService.search(searchParams); 741 742 Assert.assertNotNull(searchResponse); 743 Assert.assertNotNull(searchResponse.getSearchResults()); 744 Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields()); 745 746 Assert.assertEquals("holdings", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType()); 747 Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName()); 748 Assert.assertEquals("CN Holdings Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue()); 749 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType()); 750 Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName()); 751 Assert.assertEquals("CN Item Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue()); 752 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getDocType()); 753 Assert.assertEquals("chronology", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldName()); 754 Assert.assertEquals("CHN Item Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldValue()); 755 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getDocType()); 756 Assert.assertEquals("enumeration", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldName()); 757 Assert.assertEquals("ENUM Item Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldValue()); 758 Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getDocType()); 759 Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldName()); 760 Assert.assertEquals("This Title is for Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldValue()); 761 } 762 763 public BibTree getBibTree2() { 764 BibTree bibTree = new BibTree(); 765 return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree2.xml")); 766 } 767 768 @Test 769 public void testSearch4() { 770 BibTree bibTree = getBibTree3(); 771 docstoreService.createBibTree(bibTree); 772 Assert.assertNotNull(bibTree.getHoldingsTrees().get(0).getItems().get(0).getId()); 773 SearchParams searchParams = getSearchParams4(); 774 SearchField searchField = searchParams.buildSearchField("item", "itemIdentifier", bibTree.getHoldingsTrees().get(0).getItems().get(0).getId()); 775 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND")); 776 777 Assert.assertEquals("item", searchParams.getSearchConditions().get(0).getSearchField().getDocType()); 778 Assert.assertEquals("enumeration", searchParams.getSearchConditions().get(0).getSearchField().getFieldName()); 779 Assert.assertEquals("ENUM Item Test4", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue()); 780 Assert.assertEquals("item", searchParams.getSearchConditions().get(1).getSearchField().getDocType()); 781 Assert.assertEquals("itemIdentifier", searchParams.getSearchConditions().get(1).getSearchField().getFieldName()); 782 Assert.assertEquals(bibTree.getHoldingsTrees().get(0).getItems().get(0).getId(), searchParams.getSearchConditions().get(1).getSearchField().getFieldValue()); 783 784 Assert.assertEquals("holdings", searchParams.getSearchResultFields().get(0).getDocType()); 785 Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(0).getFieldName()); 786 Assert.assertEquals("item", searchParams.getSearchResultFields().get(1).getDocType()); 787 Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(1).getFieldName()); 788 Assert.assertEquals("item", searchParams.getSearchResultFields().get(2).getDocType()); 789 Assert.assertEquals("chronology", searchParams.getSearchResultFields().get(2).getFieldName()); 790 Assert.assertEquals("item", searchParams.getSearchResultFields().get(3).getDocType()); 791 Assert.assertEquals("enumeration", searchParams.getSearchResultFields().get(3).getFieldName()); 792 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(4).getDocType()); 793 Assert.assertEquals("Title", searchParams.getSearchResultFields().get(4).getFieldName()); 794 795 SearchResponse searchResponse = docstoreService.search(searchParams); 796 797 Assert.assertNotNull(searchResponse); 798 Assert.assertNotNull(searchResponse.getSearchResults()); 799 Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields()); 800 801 Assert.assertEquals("holdings", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType()); 802 Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName()); 803 Assert.assertEquals("CN Holdings Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue()); 804 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType()); 805 Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName()); 806 Assert.assertEquals("CN Item Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue()); 807 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getDocType()); 808 Assert.assertEquals("chronology", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldName()); 809 Assert.assertEquals("CHN Item Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldValue()); 810 Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getDocType()); 811 Assert.assertEquals("enumeration", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldName()); 812 Assert.assertEquals("ENUM Item Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldValue()); 813 Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getDocType()); 814 Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldName()); 815 Assert.assertEquals("This Title is for Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldValue()); 816 } 817 818 public BibTree getBibTree3() { 819 BibTree bibTree = new BibTree(); 820 return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree3.xml")); 821 } 822 823 @Test 824 public void testSearch5() { 825 createBibTrees2(); 826 SearchParams searchParams = getSearchParams5(); 827 828 Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(0).getSearchField().getDocType()); 829 830 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(0).getDocType()); 831 Assert.assertEquals("bibIdentifier", searchParams.getSearchResultFields().get(0).getFieldName()); 832 Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(1).getDocType()); 833 Assert.assertEquals("Title", searchParams.getSearchResultFields().get(1).getFieldName()); 834 Assert.assertEquals("0", String.valueOf(searchParams.getStartIndex())); 835 Assert.assertEquals("10", String.valueOf(searchParams.getPageSize())); 836 837 SearchResponse searchResponse1 = docstoreService.search(searchParams); 838 839 Assert.assertNotNull(searchResponse1); 840 Assert.assertNotNull(searchResponse1.getSearchResults()); 841 Assert.assertNotNull(searchResponse1.getSearchResults().get(0).getSearchResultFields()); 842 843 Assert.assertTrue(searchResponse1.getTotalRecordCount() > 10); 844 Assert.assertNotNull(searchResponse1.getTotalRecordCount()); 845 Assert.assertEquals("0", String.valueOf(searchResponse1.getStartIndex())); 846 Assert.assertEquals("10", String.valueOf(searchResponse1.getPageSize())); 847 Assert.assertEquals(searchResponse1.getStartIndex() + searchResponse1.getPageSize(), searchResponse1.getEndIndex()); 848 849 searchParams.setStartIndex(10); 850 searchParams.setPageSize(10); 851 852 SearchResponse searchResponse2 = docstoreService.search(searchParams); 853 854 Assert.assertNotNull(searchResponse2); 855 Assert.assertNotNull(searchResponse2.getSearchResults()); 856 Assert.assertNotNull(searchResponse2.getSearchResults().get(0).getSearchResultFields()); 857 858 Assert.assertTrue(searchResponse2.getTotalRecordCount() > 10); 859 Assert.assertNotNull(searchResponse2.getTotalRecordCount()); 860 Assert.assertEquals("10", String.valueOf(searchResponse2.getStartIndex())); 861 Assert.assertEquals("10", String.valueOf(searchResponse2.getPageSize())); 862 Assert.assertEquals(searchResponse1.getStartIndex() + searchResponse1.getPageSize(), searchResponse1.getEndIndex()); 863 } 864 865 public SearchParams getSearchParams1() { 866 SearchParams searchParams = new SearchParams(); 867 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams1.xml"); 868 return (SearchParams) searchParams.deserialize(xml); 869 } 870 871 public SearchParams getSearchParams2() { 872 SearchParams searchParams = new SearchParams(); 873 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams2.xml"); 874 return (SearchParams) searchParams.deserialize(xml); 875 } 876 877 public SearchParams getSearchParams3() { 878 SearchParams searchParams = new SearchParams(); 879 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams3.xml"); 880 return (SearchParams) searchParams.deserialize(xml); 881 } 882 883 public SearchParams getSearchParams4() { 884 SearchParams searchParams = new SearchParams(); 885 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams4.xml"); 886 return (SearchParams) searchParams.deserialize(xml); 887 } 888 889 public SearchParams getSearchParams5() { 890 SearchParams searchParams = new SearchParams(); 891 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams5.xml"); 892 return (SearchParams) searchParams.deserialize(xml); 893 } 894 895 @Test 896 public void createBibTrees1() { 897 List bibTrees = new ArrayList(); 898 BibTree bibTree = new BibTree(); 899 String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml"); 900 bibTree = (BibTree) bibTree.deserialize(xml); 901 bibTrees.add(bibTree); 902 bibTree = new BibTree(); 903 xml = getXmlAsString("/org/kuali/ole/documents/BibTree2.xml"); 904 bibTree = (BibTree) bibTree.deserialize(xml); 905 bibTrees.add(bibTree); 906 bibTree = new BibTree(); 907 xml = getXmlAsString("/org/kuali/ole/documents/BibTree3.xml"); 908 bibTree = (BibTree) bibTree.deserialize(xml); 909 bibTrees.add(bibTree); 910 bibTree = new BibTree(); 911 xml = getXmlAsString("/org/kuali/ole/documents/BibTree4.xml"); 912 bibTree = (BibTree) bibTree.deserialize(xml); 913 bibTrees.add(bibTree); 914 bibTree = new BibTree(); 915 xml = getXmlAsString("/org/kuali/ole/documents/BibTree5.xml"); 916 bibTree = (BibTree) bibTree.deserialize(xml); 917 bibTrees.add(bibTree); 918 BibTrees bibTreesobj = new BibTrees(); 919 //bibTreesobj.getBibTrees().add(bibTree); 920 bibTreesobj.getBibTrees().addAll(bibTrees); 921 docstoreService.createBibTrees(bibTreesobj); 922 } 923 924 @Test 925 public void testBoundHoldingsWithBibs() { 926 String bibId1 = "wbm-10000001"; 927 BibTree bibTree1 = docstoreService.retrieveBibTree(bibId1); 928 System.out.println("Before Boundwith Bib id: " + bibId1 + " Holdings count: " + bibTree1.getHoldingsTrees().size()); 929 String bibId2 = "wbm-10000002"; 930 BibTree bibTree2 = docstoreService.retrieveBibTree(bibId2); 931 System.out.println("Before Boundwith Bib id: " + bibId2 + " Holdings count: " + bibTree2.getHoldingsTrees().size()); 932 String holdingsId = "who-1"; 933 List bibIds = new ArrayList<String>(); 934 bibIds.add(bibId2); 935 docstoreService.boundHoldingsWithBibs(holdingsId, bibIds); 936 bibTree1 = docstoreService.retrieveBibTree(bibId1); 937 System.out.println("After Boundwith Bib id: " + bibId1 + " Holdings count: " + bibTree1.getHoldingsTrees().size()); 938 bibTree2 = docstoreService.retrieveBibTree(bibId2); 939 System.out.println("After Boundwith Bib id: " + bibId2 + " Holdings count: " + bibTree2.getHoldingsTrees().size()); 940 } 941 942 @Test 943 public void transferHoldings() { 944 String bibId = "wbm-10000001"; 945 String holdingsId = "who-2"; 946 List holdingIds = new ArrayList<String>(); 947 holdingIds.add(holdingsId); 948 docstoreService.transferHoldings(holdingIds, bibId); 949 } 950 951 @Test 952 public void transferItems() { 953 String holdingId = "wbm-10000001"; 954 String itemId = "who-2"; 955 List itemIds = new ArrayList<String>(); 956 itemIds.add(itemId); 957 docstoreService.transferItems(itemIds, holdingId); 958 } 959 960 @Test 961 public void findBib() { 962 testCreateBib(); 963 Map map = new HashMap(); 964 map.put(BibConstants.DOC_TYPE, "bibliographic"); 965 map.put("ID", "wbm-10000001"); 966 Bib bib = docstoreService.findBib(map); 967 Assert.assertEquals(bib.getId(), "wbm-10000001"); 968 } 969 970 @Test 971 public void findBibTree() { 972 testCreateBib(); 973 Map map = new HashMap(); 974 map.put(BibConstants.DOC_TYPE, "bibliographic"); 975 map.put("ID", "wbm-10000001"); 976 BibTree bibTree = docstoreService.findBibTree(map); 977 Assert.assertEquals(bibTree.getBib().getId(), "wbm-10000001"); 978 } 979 980 @Test 981 public void findHoldings() { 982 testCreatePHoldings(); 983 Map map = new HashMap(); 984 map.put("ID", "who-1"); 985 map.put(BibConstants.DOC_TYPE, "holdings"); 986 Holdings holdings = docstoreService.findHoldings(map); 987 Assert.assertEquals(holdings.getId(), "who-1"); 988 989 } 990 991 @Test 992 public void findHoldingsTree() { 993 testCreatePHoldings(); 994 Map map = new HashMap(); 995 map.put("ID", "who-1"); 996 map.put(BibConstants.DOC_TYPE, "holdings"); 997 HoldingsTree holdingsTree = docstoreService.findHoldingsTree(map); 998 Assert.assertEquals(holdingsTree.getHoldings().getId(), "who-1"); 999 1000 } 1001 1002 @Test 1003 public void findItem() { 1004 testCreateItem(); 1005 Map map = new HashMap(); 1006 map.put("ID", "wio-1"); 1007 map.put(BibConstants.DOC_TYPE, "item"); 1008 Item item = docstoreService.findItem(map); 1009 Assert.assertEquals(item.getId(), "wio-1"); 1010 } 1011 1012 @Test 1013 public void deleteBibs() { 1014 testCreateBib(); 1015 List bibIds = new ArrayList(); 1016 bibIds.add("wbm-10000001"); 1017 docstoreService.deleteBibs(bibIds); 1018 } 1019 1020 public String getXmlAsString(String filePath) { 1021 String input = ""; 1022 File file = null; 1023 try { 1024 file = new File(getClass().getResource(filePath).toURI()); 1025 input = FileUtils.readFileToString(file); 1026 } catch (Exception e) { 1027 e.printStackTrace(); 1028 } 1029 return input; 1030 } 1031 1032 public Bib getBibRecord() { 1033 Bib bib = new BibMarc(); 1034 bib.setCategory(DocCategory.WORK.getCode()); 1035 bib.setType(DocType.BIB.getCode()); 1036 bib.setFormat(DocFormat.MARC.getCode()); 1037 bib.setContent("<collection xmlns=\"http://www.loc.gov/MARC21/slim\">\n" + 1038 " <record>\n" + 1039 " <leader>#####nam#a22######a#4500</leader>\n" + 1040 "\t<controlfield tag=\"001\"></controlfield>\n" + 1041 " <controlfield tag=\"003\">OCoLC</controlfield>\n" + 1042 " <controlfield tag=\"005\">20090213152530.7</controlfield>\n" + 1043 "\t\t<controlfield tag=\"008\">131031s########xxu###########000#0#eng#d</controlfield>\n" + 1044 " <datafield tag=\"035\" ind1=\" \" ind2=\" \">\n" + 1045 " <subfield code=\"a\">(OCoLC)ocm62378465</subfield>\n" + 1046 " </datafield>\n" + 1047 " <datafield tag=\"040\" ind1=\" \" ind2=\" \">\n" + 1048 " <subfield code=\"a\">DLC</subfield>\n" + 1049 "\t\t\t <subfield code=\"c\">DLC</subfield>\n" + 1050 "\t\t\t <subfield code=\"d\">DLC</subfield>\n" + 1051 "\t\t\t <subfield code=\"d\">HLS</subfield>\n" + 1052 "\t\t\t <subfield code=\"d\">IUL</subfield>\n" + 1053 " </datafield>\n" + 1054 " <datafield tag=\"022\" ind1=\" \" ind2=\" \">\n" + 1055 " <subfield code=\"a\">1729-1070|20</subfield>\n" + 1056 " </datafield>\n" + 1057 " <datafield tag=\"029\" ind1=\"1\" ind2=\" \">\n" + 1058 " <subfield code=\"a\">AU@|b000040176476</subfield>\n" + 1059 "\t\t\t<subfield code=\"b\">000040176476</subfield>\n" + 1060 " </datafield>\n" + 1061 " <datafield tag=\"037\" ind1=\" \" ind2=\" \">\n" + 1062 " <subfield code=\"b\">The Managing Editor, BIAC Journal, P.O. Box 10026, Gaborone, Botswana</subfield>\n" + 1063 " </datafield>\n" + 1064 " <datafield tag=\"042\" ind1=\" \" ind2=\" \">\n" + 1065 " <subfield code=\"a\">lc</subfield>\n" + 1066 " </datafield>\n" + 1067 " <datafield tag=\"043\" ind1=\"1\" ind2=\"0\">\n" + 1068 " <subfield code=\"a\">f-bs---</subfield>\n" + 1069 " </datafield>\n" + 1070 " <datafield tag=\"050\" ind1=\"0\" ind2=\"0\">\n" + 1071 " <subfield code=\"a\">HD70.B55|bB53</subfield>\n" + 1072 " </datafield>\n" + 1073 " <datafield tag=\"049\" ind1=\" \" ind2=\" \">\n" + 1074 " <subfield code=\"a\">IULA</subfield>\n" + 1075 " </datafield>\n" + 1076 " <datafield tag=\"210\" ind1=\"1\" ind2=\" \">\n" + 1077 " <subfield code=\"a\">BIAC j.</subfield>\n" + 1078 " </datafield>\n" + 1079 " <datafield tag=\"222\" ind1=\" \" ind2=\"0\">\n" + 1080 " <subfield code=\"a\">BIAC journal</subfield>\n" + 1081 " </datafield>\n" + 1082 " <datafield tag=\"245\" ind1=\"0\" ind2=\"0\">\n" + 1083 " <subfield code=\"a\">BIAC journal</subfield>\n" + 1084 " </datafield>\n" + 1085 " <datafield tag=\"246\" ind1=\"1\" ind2=\"3\">\n" + 1086 " <subfield code=\"a\">Botswana Institute of Administration and Commerce journal</subfield>\n" + 1087 " </datafield>\n" + 1088 " <datafield tag=\"260\" ind1=\" \" ind2=\" \">\n" + 1089 " <subfield code=\"a\">Gaborone, Botswana :|bBotswana Institute of Administration and Commerce</subfield>\n" + 1090 "\t\t\t<subfield code=\"b\">Botswana Institute of Administration and Commerce</subfield>\n" + 1091 " </datafield>\n" + 1092 " <datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" + 1093 " <subfield code=\"a\">v. ;</subfield>\n" + 1094 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" + 1095 " </datafield>\n" + 1096 "\t\t<datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" + 1097 " <subfield code=\"a\">v. ;</subfield>\n" + 1098 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" + 1099 " </datafield>\n" + 1100 "\t\t<datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" + 1101 " <subfield code=\"a\">v. ;</subfield>\n" + 1102 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" + 1103 " </datafield>\n" + 1104 "\t\t<datafield tag=\"310\" ind1=\" \" ind2=\" \">\n" + 1105 " <subfield code=\"a\">Semiannual</subfield>\n" + 1106 " </datafield>\n" + 1107 "\t\t<datafield tag=\"362\" ind1=\"1\" ind2=\" \">\n" + 1108 " <subfield code=\"a\"> Began in 2004.</subfield>\n" + 1109 " </datafield>\n" + 1110 "\t\t<datafield tag=\"500\" ind1=\" \" ind2=\" \">\n" + 1111 " <subfield code=\"a\">Description based on: Vol. 1, no. 1 (May. 2004); title from cover.</subfield>\n" + 1112 " </datafield>\n" + 1113 "\t\t<datafield tag=\"500\" ind1=\" \" ind2=\" \">\n" + 1114 " <subfield code=\"a\">Latest issue consulted: Vol. 3, no. 1 (May 2006).</subfield>\n" + 1115 " </datafield>\n" + 1116 "\t\t<datafield tag=\"650\" ind1=\"0\" ind2=\" \">\n" + 1117 " <subfield code=\"a\">Industrial management</subfield>\n" + 1118 "\t\t\t<subfield code=\"z\">Botswana</subfield>\n" + 1119 "\t\t\t<subfield code=\"v\">Periodicals.</subfield>\n" + 1120 " </datafield>\n" + 1121 "\t\t<datafield tag=\"650\" ind1=\"0\" ind2=\" \">\n" + 1122 " <subfield code=\"a\">Occupational training</subfield>\n" + 1123 "\t\t\t<subfield code=\"z\">Botswana</subfield>\n" + 1124 "\t\t\t<subfield code=\"v\">Periodicals.</subfield>\n" + 1125 " </datafield>\n" + 1126 "\t\t<datafield tag=\"710\" ind1=\"2\" ind2=\" \">\n" + 1127 " <subfield code=\"a\">Botswana Institute of Administration and Commerce.</subfield>\n" + 1128 " </datafield>\n" + 1129 "\t\t<datafield tag=\"850\" ind1=\" \" ind2=\" \">\n" + 1130 " <subfield code=\"a\">DLC</subfield>\n" + 1131 " </datafield>\n" + 1132 "\t\t<datafield tag=\"891\" ind1=\"2\" ind2=\"0\">\n" + 1133 " <subfield code=\"a\">9853|81.1</subfield>\n" + 1134 "\t\t\t<subfield code=\"a\">v.</subfield>\n" + 1135 "\t\t\t<subfield code=\"b\">no</subfield>\n" + 1136 "\t\t\t<subfield code=\"u\">2</subfield>\n" + 1137 "\t\t\t<subfield code=\"v\">r</subfield>\n" + 1138 "\t\t\t<subfield code=\"i\">(year)</subfield>\n" + 1139 "\t\t\t<subfield code=\"j\">(month)</subfield>\n" + 1140 "\t\t\t<subfield code=\"w\">f</subfield>\n" + 1141 "\t\t\t<subfield code=\"x\">05</subfield>\n" + 1142 " </datafield>\n" + 1143 "\t\t<datafield tag=\"891\" ind1=\"4\" ind2=\"1\">\n" + 1144 " <subfield code=\"a\">9863|81.1</subfield>\n" + 1145 "\t\t\t<subfield code=\"a\">1</subfield>\n" + 1146 "\t\t\t<subfield code=\"b\">1</subfield>\n" + 1147 "\t\t\t<subfield code=\"i\">2004</subfield>\n" + 1148 "\t\t\t<subfield code=\"j\">05</subfield>\n" + 1149 " </datafield>\n" + 1150 "\t\t<datafield tag=\"596\" ind1=\" \" ind2=\" \">\n" + 1151 " <subfield code=\"a\">1</subfield>\n" + 1152 " </datafield>\n" + 1153 " </record>\n" + 1154 "</collection>"); 1155 return bib; 1156 } 1157 1158 private Holdings getHoldingsRecord() { 1159 Holdings holdings = new PHoldings(); 1160// Holdings holdings = new EHoldingsOleml(); 1161 holdings.setCategory(DocCategory.WORK.getCode()); 1162 holdings.setType(DocType.HOLDINGS.getCode()); 1163 holdings.setFormat(DocFormat.OLEML.getCode()); 1164 1165 OleHoldings oleHoldings = new OleHoldings(); 1166 ShelvingScheme shelvingScheme = new ShelvingScheme(); 1167 shelvingScheme.setCodeValue("LCC"); 1168 1169 CallNumber callNumber = new CallNumber(); 1170 callNumber.setNumber("123"); 1171 callNumber.setShelvingScheme(shelvingScheme); 1172 oleHoldings.setCallNumber(callNumber); 1173 1174 ExtentOfOwnership pHoldingsExtentOfOwnership = new ExtentOfOwnership(); 1175 Note note = new Note(); 1176 note.setType("public"); 1177 note.setValue("123"); 1178 pHoldingsExtentOfOwnership.setTextualHoldings("textual holdings"); 1179 pHoldingsExtentOfOwnership.setType("public"); 1180 pHoldingsExtentOfOwnership.getNote().add(note); 1181 1182 ExtentOfOwnership pHoldingsExtentOfOwnership1 = new ExtentOfOwnership(); 1183 pHoldingsExtentOfOwnership1.setTextualHoldings("textual holdings"); 1184 pHoldingsExtentOfOwnership1.setType("public"); 1185 pHoldingsExtentOfOwnership1.getNote().add(note); 1186 1187 oleHoldings.getExtentOfOwnership().add(pHoldingsExtentOfOwnership); 1188 oleHoldings.getExtentOfOwnership().add(pHoldingsExtentOfOwnership1); 1189 1190 oleHoldings.setReceiptStatus("1"); 1191 oleHoldings.getNote().add(note); 1192 oleHoldings.getNote().add(note); 1193 1194 oleHoldings.setCopyNumber("copy1"); 1195 1196 Uri uri = new Uri(); 1197 uri.setValue("1"); 1198 1199 Uri uri1 = new Uri(); 1200 uri1.setValue("2"); 1201 1202 oleHoldings.getUri().add(uri); 1203 oleHoldings.getUri().add(uri1); 1204 1205 1206 ExtentOfOwnership eofCoverage = new ExtentOfOwnership(); 1207 Coverages coverages = new Coverages(); 1208 Coverage coverage = new Coverage(); 1209 coverage.setCoverageEndIssue("endIssue"); 1210 coverage.setCoverageStartIssue("startIssue"); 1211 coverages.getCoverage().add(coverage); 1212 eofCoverage.setCoverages(coverages); 1213 1214 PerpetualAccesses perpetualAccesses = new PerpetualAccesses(); 1215 PerpetualAccess perpetualAccess = new PerpetualAccess(); 1216 perpetualAccess.setPerpetualAccessEndIssue("end issue"); 1217 perpetualAccess.setPerpetualAccessStartIssue("end issue"); 1218 perpetualAccesses.getPerpetualAccess().add(perpetualAccess); 1219 eofCoverage.setPerpetualAccesses(perpetualAccesses); 1220 if (holdings instanceof EHoldings) { 1221 oleHoldings.getExtentOfOwnership().clear(); 1222 oleHoldings.getExtentOfOwnership().add(eofCoverage); 1223 } 1224 1225 oleHoldings.setDonorNote("donor note"); 1226 oleHoldings.setAccessStatus("active"); 1227 StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode(); 1228 statisticalSearchingCode.setCodeValue("BETA"); 1229 oleHoldings.setStatisticalSearchingCode(statisticalSearchingCode); 1230 1231 oleHoldings.setDonorPublicDisplay("donor public display"); 1232// oleHoldings.setStatusDate(""); 1233 oleHoldings.setEResourceId("1001"); 1234 oleHoldings.setStaffOnlyFlag(true); 1235 oleHoldings.setImprint("imprint"); 1236 oleHoldings.setInterLibraryLoanAllowed(true); 1237 Link link = new Link(); 1238 link.setText("text"); 1239 link.setUrl("url"); 1240 //oleHoldings.setLink(link); 1241 oleHoldings.setLocalPersistentLink("local persist link"); 1242 oleHoldings.setPublisher("pub"); 1243 Platform platform = new Platform(); 1244 platform.setAdminPassword("apwd"); 1245 platform.setAdminUrl("aurl"); 1246 platform.setAdminUserName("ausr"); 1247 platform.setPlatformName("platform"); 1248 oleHoldings.setPlatform(platform); 1249 1250 oleHoldings.setSubscriptionStatus("status"); 1251 1252 HoldingsAccessInformation holdingsAccessInformation = new HoldingsAccessInformation(); 1253 holdingsAccessInformation.setAccessLocation("access location"); 1254 holdingsAccessInformation.setAccessPassword("pwd"); 1255 holdingsAccessInformation.setAccessUsername("usr"); 1256 holdingsAccessInformation.setAuthenticationType("1"); 1257 holdingsAccessInformation.setNumberOfSimultaneousUser("2"); 1258 holdingsAccessInformation.setProxiedResource("proxied"); 1259 oleHoldings.setHoldingsAccessInformation(holdingsAccessInformation); 1260 1261 holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings)); 1262 1263 return holdings; 1264 } 1265 1266 private BibTree getBibTree() { 1267 BibTree bibTree = new BibTree(); 1268 bibTree.setBib(getBibRecord()); 1269 HoldingsTree holdingsTree = getHoldingsTree(); 1270 bibTree.getHoldingsTrees().add(holdingsTree); 1271 return bibTree; 1272 } 1273 1274 private HoldingsTree getHoldingsTree() { 1275 HoldingsTree holdingsTree = new HoldingsTree(); 1276 holdingsTree.setHoldings(getHoldingsRecord()); 1277 holdingsTree.getItems().add(getItemRecord()); 1278 return holdingsTree; 1279 } 1280 1281 @Test 1282 public void testDeleteBib() { 1283 Bib bib = getBibRecord(); 1284 docstoreService.deleteBib(bib.getId()); 1285 } 1286 1287 @Test 1288 public void testDeleteHoldings() { 1289 Holdings holdings = getHoldingsRecord(); 1290 docstoreService.deleteHoldings(holdings.getId()); 1291 } 1292 1293 @Test 1294 public void testDeleteItem() { 1295 Item item = getItemRecord(); 1296 docstoreService.deleteItem(item.getId()); 1297 } 1298 1299 @Test 1300 public void testUpdatePHoldings() { 1301 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 1302 Bib bib = new BibMarc(); 1303 bib = (Bib) bib.deserialize(xml); 1304 bib.setId(null); 1305 docstoreService.createBib(bib); 1306 Assert.assertNotNull(bib.getId()); 1307 1308 xml = getXmlAsString("/org/kuali/ole/documents/PHoldings1.xml"); 1309 Holdings holdings = new PHoldings(); 1310 holdings = (PHoldings) holdings.deserialize(xml); 1311 holdings.setBib(bib); 1312 docstoreService.createHoldings(holdings); 1313 1314 Assert.assertNotNull(holdings.getId()); 1315 1316 1317 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor(); 1318 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent()); 1319 oleHoldings.setCopyNumber("1234567"); 1320 holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings)); 1321 docstoreService.updateHoldings(holdings); 1322 1323 Holdings holdings1 = docstoreService.retrieveHoldings(holdings.getId()); 1324 Assert.assertEquals(holdings1.getId(), holdings.getId()); 1325 Assert.assertNotNull(holdings.getId()); 1326 } 1327 1328 @Test 1329 public void testUpdateEHoldings() { 1330 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 1331 Bib bib = new BibMarc(); 1332 bib = (Bib) bib.deserialize(xml); 1333 bib.setId(null); 1334 docstoreService.createBib(bib); 1335 Assert.assertNotNull(bib.getId()); 1336 1337 xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml"); 1338 Holdings holdings = new EHoldings(); 1339 holdings = (EHoldings) holdings.deserialize(xml); 1340 holdings.setBib(bib); 1341 docstoreService.createHoldings(holdings); 1342 1343 Assert.assertNotNull(holdings.getId()); 1344 1345 1346 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor(); 1347 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent()); 1348 oleHoldings.setCopyNumber("1234567"); 1349 holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings)); 1350 docstoreService.updateHoldings(holdings); 1351 1352 Holdings holdings1 = docstoreService.retrieveHoldings(holdings.getId()); 1353 Assert.assertEquals(holdings1.getId(), holdings.getId()); 1354 Assert.assertNotNull(holdings.getId()); 1355 } 1356 1357 @Test 1358 public void testUpdateItem() { 1359 Item item = getItemRecord(); 1360 item.setContent("mock update content"); 1361 docstoreService.updateItem(item); 1362 } 1363 1364 @Test 1365 public void testBrowseHoldings1() { 1366 BrowseParams browseParams = getBrowseParams1(); 1367 SearchResponse searchResponse = docstoreService.browseHoldings(browseParams); 1368 Assert.assertNotNull(searchResponse); 1369 } 1370 1371 @Test 1372 public void testBrowseHoldings2() { 1373 BrowseParams browseParams = getBrowseParams2(); 1374 SearchResponse searchResponse = docstoreService.browseHoldings(browseParams); 1375 Assert.assertNotNull(searchResponse); 1376 } 1377 1378 @Test 1379 public void testBrowseItems1() { 1380 BrowseParams browseParams = getBrowseParams3(); 1381 SearchResponse searchResponse = docstoreService.browseItems(browseParams); 1382 Assert.assertNotNull(searchResponse); 1383 } 1384 1385 @Test 1386 public void testBrowseItems2() { 1387 BrowseParams browseParams = getBrowseParams4(); 1388 SearchResponse searchResponse = docstoreService.browseItems(browseParams); 1389 Assert.assertNotNull(searchResponse); 1390 } 1391 1392 1393 @Test 1394 public void testCreateDc() { 1395 String xml = getXmlAsString("/org/kuali/ole/documents/BibDUnqualified1.xml"); 1396 Bib bibDcUnqualified = new BibDcUnqualified(); 1397 bibDcUnqualified.setCategory("work"); 1398 bibDcUnqualified.setType(DocType.BIB.getCode()); 1399 bibDcUnqualified.setFormat(DocFormat.DUBLIN_UNQUALIFIED.getCode()); 1400 bibDcUnqualified = (BibDcUnqualified) bibDcUnqualified.deserialize(xml); 1401 docstoreService.createBib(bibDcUnqualified); 1402 Assert.assertNotNull(bibDcUnqualified.getId()); 1403 } 1404 1405 public BrowseParams getBrowseParams1() { 1406 BrowseParams browseParams = new BrowseParams(); 1407 String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams1.xml"); 1408 return (BrowseParams) browseParams.deserialize(xml); 1409 } 1410 1411 public BrowseParams getBrowseParams2() { 1412 BrowseParams browseParams = new BrowseParams(); 1413 String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams2.xml"); 1414 return (BrowseParams) browseParams.deserialize(xml); 1415 } 1416 1417 public BrowseParams getBrowseParams3() { 1418 BrowseParams browseParams = new BrowseParams(); 1419 String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams3.xml"); 1420 return (BrowseParams) browseParams.deserialize(xml); 1421 } 1422 1423 public BrowseParams getBrowseParams4() { 1424 BrowseParams browseParams = new BrowseParams(); 1425 String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams4.xml"); 1426 return (BrowseParams) browseParams.deserialize(xml); 1427 } 1428 1429 private void updateContent(Bib bib) { 1430 BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor(); 1431 BibMarcRecords bibMarcRecords = bibMarcRecordProcessor.fromXML(bib.getContent()); 1432 BibMarcRecord bibMarcRecord = bibMarcRecords.getRecords().get(0); 1433 List<DataField> dataFields = bibMarcRecord.getDataFields(); 1434 for (DataField dataField : dataFields) { 1435 if (dataField.getTag().equalsIgnoreCase("245")) { 1436 List<SubField> subFields = dataField.getSubFields(); 1437 subFields.get(0).setValue("The Alchemist"); 1438 } 1439 } 1440 bib.setContent(bibMarcRecordProcessor.generateXML(bibMarcRecord)); 1441 } 1442 1443 private void setDate(Bib bib) { 1444 Date date = new Date(); 1445 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 1446 String dateStr = sdf.format(date); 1447 bib.setCreatedOn(dateStr); 1448 } 1449 1450 @Test 1451 public void testCreateLicenseAttachment() { 1452 LicenseAttachment license = new LicenseAttachment(); 1453 license.setCategory("work"); 1454 license.setType("license"); 1455 license.setFormat("pdf"); 1456 license.setFileName("123.pdf"); 1457 license.setFilePath("file path"); 1458 license.setId("wl-1"); 1459 Licenses licenses = new Licenses(); 1460 licenses.getLicenses().add(license); 1461 docstoreService.createLicenses(licenses); 1462 } 1463 @Test 1464 public void testCreateLicense() { 1465 Licenses licenses = new Licenses(); 1466 License license = new LicenseOnixpl(); 1467 license = (License) license.deserialize(getXmlAsString("/org/kuali/ole/documents/license-onixpl.xml")); 1468 licenses.getLicenses().add(license); 1469 docstoreService.createLicenses(licenses); 1470 } 1471 1472 @Test 1473 public void testBulkUpdatePHoldings() { 1474 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 1475 Bib bib = new BibMarc(); 1476 bib = (Bib) bib.deserialize(xml); 1477 bib.setId(null); 1478 docstoreService.createBib(bib); 1479 Assert.assertNotNull(bib.getId()); 1480 1481 xml = getXmlAsString("/org/kuali/ole/documents/PHoldings1.xml"); 1482 Holdings holdings = new PHoldings(); 1483 holdings = (PHoldings) holdings.deserialize(xml); 1484 holdings.setBib(bib); 1485 docstoreService.createHoldings(holdings); 1486 Assert.assertNotNull(holdings.getId()); 1487 Holdings holdings1 = holdings; 1488 holdings.setId(null); 1489 docstoreService.createHoldings(holdings); 1490 Assert.assertNotNull(holdings.getId()); 1491 Holdings holdings2 = holdings; 1492 Assert.assertNotNull(holdings.getId()); 1493 1494 1495 List<String> holdingIds = new ArrayList<String>(); 1496 holdingIds.add(holdings1.getId()); 1497 holdingIds.add(holdings2.getId()); 1498 1499 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor(); 1500 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent()); 1501 oleHoldings.setCopyNumber("1234567"); 1502 holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings)); 1503 docstoreService.bulkUpdateHoldings(holdings, holdingIds,"false"); 1504 1505 Holdings updatedHoldings1 = docstoreService.retrieveHoldings(holdings1.getId()); 1506 Assert.assertEquals(updatedHoldings1.getId(), holdings1.getId()); 1507 OleHoldings updateOleHoldings1 = holdingOlemlRecordProcessor.fromXML(updatedHoldings1.getContent()); 1508 Assert.assertNotNull(updateOleHoldings1); 1509 Assert.assertEquals(updateOleHoldings1.getCopyNumber(),"1234567"); 1510 1511 Holdings updatedHoldings2 = docstoreService.retrieveHoldings(holdings2.getId()); 1512 Assert.assertEquals(updatedHoldings2.getId(), holdings2.getId()); 1513 OleHoldings updateOleHoldings2 = holdingOlemlRecordProcessor.fromXML(updatedHoldings2.getContent()); 1514 Assert.assertNotNull(updateOleHoldings2); 1515 Assert.assertEquals(updateOleHoldings2.getCopyNumber(),"1234567"); 1516 1517 } 1518 1519 @Test 1520 public void testBulkUpdateEHoldings() { 1521 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 1522 Bib bib = new BibMarc(); 1523 bib = (Bib) bib.deserialize(xml); 1524 bib.setId(null); 1525 docstoreService.createBib(bib); 1526 Assert.assertNotNull(bib.getId()); 1527 1528 xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml"); 1529 Holdings holdings = new EHoldings(); 1530 holdings = (EHoldings) holdings.deserialize(xml); 1531 holdings.setBib(bib); 1532 docstoreService.createHoldings(holdings); 1533 Assert.assertNotNull(holdings.getId()); 1534 Holdings holdings1 = holdings; 1535 holdings.setId(null); 1536 docstoreService.createHoldings(holdings); 1537 Assert.assertNotNull(holdings.getId()); 1538 Holdings holdings2 = holdings; 1539 Assert.assertNotNull(holdings.getId()); 1540 1541 1542 List<String> holdingIds = new ArrayList<String>(); 1543 holdingIds.add(holdings1.getId()); 1544 holdingIds.add(holdings2.getId()); 1545 1546 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor(); 1547 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent()); 1548 oleHoldings.setImprint("Mock Imprint"); 1549 holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings)); 1550 docstoreService.bulkUpdateHoldings(holdings,holdingIds,"false"); 1551 1552 Holdings updatedHoldings1 = docstoreService.retrieveHoldings(holdings1.getId()); 1553 Assert.assertEquals(updatedHoldings1.getId(), holdings1.getId()); 1554 OleHoldings updateOleHoldings1 = holdingOlemlRecordProcessor.fromXML(updatedHoldings1.getContent()); 1555 Assert.assertNotNull(updateOleHoldings1); 1556 Assert.assertEquals(updateOleHoldings1.getImprint(),"Mock Imprint"); 1557 1558 Holdings updatedHoldings2 = docstoreService.retrieveHoldings(holdings2.getId()); 1559 Assert.assertEquals(updatedHoldings2.getId(), holdings2.getId()); 1560 OleHoldings updateOleHoldings2 = holdingOlemlRecordProcessor.fromXML(updatedHoldings2.getContent()); 1561 Assert.assertNotNull(updateOleHoldings2); 1562 Assert.assertEquals(updateOleHoldings2.getImprint(),"Mock Imprint"); 1563 1564 } 1565 1566 @Test 1567 public void testBulkUpdateItem() { 1568 1569 String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml"); 1570 Bib bib = new BibMarc(); 1571 bib = (Bib) bib.deserialize(xml); 1572 bib.setId(null); 1573 docstoreService.createBib(bib); 1574 Assert.assertNotNull(bib.getId()); 1575 1576 xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml"); 1577 Holdings holdings = new EHoldings(); 1578 holdings = (EHoldings) holdings.deserialize(xml); 1579 holdings.setBib(bib); 1580 docstoreService.createHoldings(holdings); 1581 Assert.assertNotNull(holdings.getId()); 1582 1583 xml = getXmlAsString("/org/kuali/ole/documents/ItemOleml1.xml"); 1584 Item item = new Item(); 1585 item = (Item)item.deserialize(xml); 1586 item.setHolding(holdings); 1587 docstoreService.createItem(item); 1588 Assert.assertNotNull(item); 1589 1590 Item item1 = new Item(); 1591 item1 = (Item)item1.deserialize(xml); 1592 item1.setHolding(holdings); 1593 docstoreService.createItem(item1); 1594 Assert.assertNotNull(item1.getId()); 1595 1596 Item item2 = new Item(); 1597 item2 = (Item)item2.deserialize(xml); 1598 item2.setHolding(holdings); 1599 docstoreService.createItem(item2); 1600 Assert.assertNotNull(item2.getId()); 1601 1602 List<String> itemIds = new ArrayList<String>(); 1603 itemIds.add(item1.getId()); 1604 itemIds.add(item2.getId()); 1605 1606 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor(); 1607 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = itemOlemlRecordProcessor.fromXML(item.getContent()); 1608 1609 oleItem.setBarcodeARSL("mock barcodeARSL"); 1610 item.setContent(itemOlemlRecordProcessor.toXML(oleItem)); 1611 docstoreService.bulkUpdateItem(item,itemIds,"false"); 1612 1613 Item updateItem1 = docstoreService.retrieveItem(item1.getId()); 1614 Assert.assertNotNull(updateItem1); 1615 org.kuali.ole.docstore.common.document.content.instance.Item updateOleItem1 = itemOlemlRecordProcessor.fromXML(updateItem1.getContent()); 1616 Assert.assertNotNull(updateOleItem1); 1617 Assert.assertEquals(updateOleItem1.getBarcodeARSL(),"mock barcodeARSL"); 1618 1619 1620 Item updateItem2 = docstoreService.retrieveItem(item2.getId()); 1621 Assert.assertNotNull(updateItem2); 1622 org.kuali.ole.docstore.common.document.content.instance.Item updateOleItem2 = itemOlemlRecordProcessor.fromXML(updateItem2.getContent()); 1623 Assert.assertNotNull(updateOleItem2); 1624 Assert.assertEquals(updateOleItem2.getBarcodeARSL(),"mock barcodeARSL"); 1625 } 1626 1627 @Test 1628 public void testGetNormalised() { 1629 RdbmsItemDocumentManager rdbmsItemDocumentManager = new RdbmsItemDocumentManager(); 1630 String value = "v. 1"; 1631 System.out.println("Before Normalization: " +value); 1632 System.out.println("After Normalization: " + rdbmsItemDocumentManager.getNormalized(value)); 1633 value = "v.2"; 1634 System.out.println("Before Normalization: " +value); 1635 System.out.println("After Normalization: " +rdbmsItemDocumentManager.getNormalized(value)); 1636 value = "v. 3"; 1637 System.out.println("Before Normalization: " +value); 1638 System.out.println("After Normalization: " +rdbmsItemDocumentManager.getNormalized(value)); 1639 BibTree bibTree = new BibTree(); 1640 Bib bib = new Bib(); 1641 bib.setId("wbm-10000001"); 1642 bibTree.setBib(bib); 1643 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor(); 1644 bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId()); 1645 System.out.println("AFTER SORTING ITEMS:"); 1646 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) { 1647 System.out.println("***HOLDINGS***"); 1648 System.out.println("ITEMS : Loc | Prefix | ShlOrd | Enum | Chro | Copy | bar"); 1649 for (Item item : holdingsTree.getItems()) { 1650 org.kuali.ole.docstore.common.document.content.instance.Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent()); 1651// System.out.println(strItems.format("%s | %s | %s | %s | %s | %s | %s", Holdings.buildLocationString(item1.getLocation()), item1.getCallNumber().getPrefix(), 1652// item1.getCallNumber().getShelvingOrder().getCodeValue(), item1.getEnumeration(), item1.getChronology(), item1.getCopyNumber(), item1.getAccessInformation().getBarcode() + "\n")); 1653 } 1654 } 1655 } 1656 1657 @Test 1658 public void processBibTrees() { 1659 BibTrees bibTrees = getBibTrees(); 1660 docstoreService.processBibTrees(bibTrees); 1661 List<String> bibIds = new ArrayList<String>(); 1662 for (BibTree bibTree : bibTrees.getBibTrees()) { 1663 if (null != bibTree.getBib()) { 1664 bibIds.add(bibTree.getBib().getId()); 1665 } 1666 } 1667 docstoreService.retrieveBibTrees(bibIds); 1668 SearchParams searchParams = buildSearchParams(); 1669 docstoreService.search(searchParams); 1670 1671 updateBibTree(bibTrees.getBibTrees().get(0)); 1672 bibTrees.getBibTrees().get(0).getBib().setOperation(DocstoreDocument.OperationType.DELETE); 1673 1674 updateBibTree(bibTrees.getBibTrees().get(1)); 1675 docstoreService.processBibTrees(bibTrees); 1676 docstoreService.retrieveBibTrees(bibIds); 1677 1678 docstoreService.search(searchParams); 1679 1680 1681 } 1682 1683 private void updateBibTree(BibTree bibTree) { 1684 Bib bib=bibTree.getBib(); 1685 1686 bib.setOperation(DocstoreDocument.OperationType.UPDATE); 1687 bib.setResult(null); 1688 BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor(); 1689 BibMarcRecords bibMarcRecords= bibMarcRecordProcessor.fromXML(bib.getContent()); 1690 for(BibMarcRecord bibMarcRecord: bibMarcRecords.getRecords()){ 1691 for(DataField dataField:bibMarcRecord.getDataFields()){ 1692 if("245".equals(dataField.getTag())){ 1693 for(SubField subField:dataField.getSubFields()){ 1694 if(subField.getCode().equals("a")){ 1695 subField.setValue("Author-1 Updated"); 1696 } 1697 } 1698 } 1699 } 1700 } 1701 bib.setContent(bibMarcRecordProcessor.toXml(bibMarcRecords)); 1702 List<HoldingsTree> holdingsTrees = bibTree.getHoldingsTrees(); 1703 1704 HoldingsTree holdingsTree=holdingsTrees.get(0); 1705 //creating another holding 1706 Holdings holdings=holdingsTree.getHoldings(); 1707 holdings.setMessage(null); 1708 holdings.setResult(null); 1709 holdings.setOperation(DocstoreDocument.OperationType.CREATE); 1710 holdings.setId(null); 1711 1712 for(Item item:holdingsTree.getItems()){ 1713 item.setMessage(null); 1714 item.setResult(null); 1715 item.setId(null); 1716 item.setOperation(DocstoreDocument.OperationType.CREATE); 1717 } 1718 1719 holdingsTree=holdingsTrees.get(1); 1720 //creating another holding 1721 holdings=holdingsTree.getHoldings(); 1722 holdings.setOperation(Holdings.OperationType.UPDATE); 1723 holdings.setMessage(null); 1724 holdings.setResult(null); 1725 1726 Item item =holdingsTree.getItems().get(0); 1727 item.setMessage(null); 1728 item.setResult(null); 1729 item.setOperation(DocstoreDocument.OperationType.DELETE); 1730 1731 item =holdingsTree.getItems().get(1); 1732 item.setMessage(null); 1733 item.setResult(null); 1734 item.setOperation(DocstoreDocument.OperationType.UPDATE); 1735 1736 1737 holdingsTree=holdingsTrees.get(2); 1738 //creating another holding 1739 holdings=holdingsTree.getHoldings(); 1740 holdings.setOperation(Holdings.OperationType.DELETE); 1741 holdings.setMessage(null); 1742 holdings.setResult(null); 1743 1744 1745 1746 } 1747 1748 private SearchParams buildSearchParams() { 1749 SearchParams searchParams = new SearchParams(); 1750 String xml = getXmlAsString("/org/kuali/ole/search/BibTreesSearchParams1.xml"); 1751 return (SearchParams) searchParams.deserialize(xml); 1752 } 1753 1754 public BibTrees getBibTrees() { 1755 BibTrees bibTrees = new BibTrees(); 1756 bibTrees= (BibTrees) bibTrees.deserialize(getXmlAsString("/org/kuali/ole/documents/BibTrees1.xml")); 1757 List<BibTree> removeBibtrees = new ArrayList<BibTree>(); 1758 for (BibTree bibTree : bibTrees.getBibTrees()) { 1759 if (null == bibTree.getBib()) { 1760 removeBibtrees.add(bibTree); 1761 } 1762 } 1763 bibTrees.getBibTrees().removeAll(removeBibtrees); 1764 return bibTrees; 1765 } 1766 1767 @Test 1768 public void updateBibsFailure() { 1769 List<String> bibIds = new ArrayList<String>(); 1770 bibIds.add("10000016"); 1771 bibIds.add("10000017"); 1772 bibIds.add("10000018"); 1773 bibIds.add("10000019"); 1774 bibIds.add("10000020"); 1775 List<Bib> bibs = docstoreService.retrieveBibs(bibIds); 1776 bibs.get(0).setStatus("None"); 1777 try { 1778 docstoreService.updateBibs(bibs); 1779 } catch (Exception e) { 1780 bibs = docstoreService.retrieveBibs(bibIds); 1781 Assert.assertEquals("", bibs.get(0).getStatus()); 1782 } 1783 1784 } 1785 1786 1787}