1 package org.kuali.ole.docstore.common.client;
2
3 import org.apache.commons.io.FileUtils;
4 import org.apache.commons.io.IOUtils;
5 import org.apache.http.HttpEntity;
6 import org.apache.http.HttpResponse;
7 import org.apache.http.ProtocolVersion;
8 import org.apache.http.StatusLine;
9 import org.apache.http.client.HttpClient;
10 import org.apache.http.client.methods.*;
11 import org.apache.http.entity.StringEntity;
12 import org.apache.http.entity.mime.Header;
13 import org.apache.http.entity.mime.MultipartEntity;
14 import org.apache.http.entity.mime.content.FileBody;
15 import org.apache.http.impl.client.DefaultHttpClient;
16 import org.apache.http.message.BasicHttpResponse;
17 import org.apache.http.message.BasicStatusLine;
18 import org.apache.http.util.EntityUtils;
19 import org.kuali.ole.docstore.common.document.*;
20 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
21 import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
22
23 import org.kuali.ole.docstore.common.exception.DocstoreExceptionProcessor;
24 import org.kuali.ole.docstore.common.find.FindParams;
25 import org.kuali.ole.docstore.common.search.BrowseParams;
26 import org.kuali.ole.docstore.common.search.SearchParams;
27 import org.kuali.ole.docstore.common.search.SearchResponse;
28 import org.kuali.rice.core.api.config.property.ConfigContext;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import java.io.*;
33 import java.net.HttpURLConnection;
34 import java.net.URL;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.zip.ZipEntry;
40 import java.util.zip.ZipOutputStream;
41
42
43
44
45
46
47
48
49
50
51
52 public class DocstoreRestClient implements DocstoreClient {
53
54
55 private static String DOCSTORE_URL =getDocstoreUrl();
56 private static String BIB_URL = "bib/doc/";
57 private static String RELOAD_URL = "config/reload";
58 private static String BIB_CONTENT_URL = "bib/";
59 private static String SEARCH_URL = "search/";
60 private static String HOLDINGS_URL = "holdings/doc/";
61 private static String HOLDINGS_DOCS_URL = "holdings/docs/";
62 private static String ITEMS_URL = "item/doc/";
63 private static String ITEMS_DOCS_URL = "item/docs/";
64 private static String ITEM_MAP_URL = "item/doc/map";
65 private static String ITEM_CONTENT_URL = "item/";
66 private static String HOLDINGS_TREE_URL = "holdings/doc/tree/";
67 private static String HOLDINGS_TREES_URL = "holdings/doc/trees/";
68 private static String HOLDINGS_TREES_CONTENT_URL = "holdings/tree/";
69 private static String BIB_TREE_URL = "bib/doc/tree/";
70 private static String BIB_TREES_URL = "bib/doc/trees/";
71 private static String FIND_URL = "/doc/find";
72 private static String BROWSE_URL = "browse/";
73 private static String BOUND_URL = "/bound";
74 private static String UN_BIND_ONE_URL = "/unbind/one";
75 private static String UN_BIND_ALL_URL = "/unbind/all";
76 private static String ANALYTIC_URL = "/analytic";
77 private static String BREAK_ANALYTIC_URL = "/breakAnalytic";
78 private static String TRANSFER_URL = "/transfer/";
79 private static String LICENSES_URL = "license/";
80 private static String LICENSES_TREES_URL = "license/trees/";
81 private static String BULK_UPDATE = "/bulkUpdate";
82 private static String PROCESS_BIB_TREES = "bib/batch";
83
84 private Logger logger = LoggerFactory.getLogger(DocstoreRestClient.class);
85
86 public static String getDocstoreUrl() {
87 if(ConfigContext.getCurrentContextConfig() != null){
88 DOCSTORE_URL = ConfigContext.getCurrentContextConfig().getProperty("ole.docstore.Documentrest.url");
89 }
90 return DOCSTORE_URL;
91 }
92
93 public static void setDocstoreUrl(String url) {
94 DOCSTORE_URL = url;
95 }
96
97 @Override
98 public void createBib(Bib bib) {
99 String requestBody = bib.serialize(bib);
100 RestResponse restResponse = postRequest(requestBody, BIB_URL);
101 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
102 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
103 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
104 }
105 String[] responseString = restResponse.getResponseBody().split("/");
106 if (responseString.length == 4) {
107 bib.setId(responseString[3]);
108 }
109 }
110 }
111
112 @Override
113 public void createHoldings(Holdings holdings) {
114 String requestBody = holdings.serialize(holdings);
115 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL);
116 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
117 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
118 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
119 }
120 String[] responseString = restResponse.getResponseBody().split("/");
121 if (responseString.length == 4) {
122 holdings.setId(responseString[3]);
123 }
124 }
125 }
126
127 @Override
128 public void createItem(Item item) {
129 String requestBody = item.serialize(item);
130 RestResponse restResponse = postRequest(requestBody, ITEMS_URL);
131 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
132 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
133 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
134 }
135 String[] responseString = restResponse.getResponseBody().split("/");
136 if (responseString.length == 4) {
137 item.setId(responseString[3]);
138 }
139 }
140 }
141
142 @Override
143 public void createHoldingsTree(HoldingsTree holdingsTree) {
144 String requestBody = holdingsTree.serialize(holdingsTree);
145 RestResponse restResponse = postRequest(requestBody, HOLDINGS_TREE_URL);
146 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
147 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
148 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
149 }
150 String[] responseString = restResponse.getResponseBody().split("/");
151 holdingsTree.getHoldings().setId(responseString[4]);
152 if (responseString.length > 4) {
153 int j = 0;
154 for (int i = 5; i < responseString.length; i++) {
155 if (responseString[i] != null) {
156 holdingsTree.getItems().get(j).setId(responseString[i]);
157 }
158 j++;
159 }
160 }
161 }
162 }
163
164
165
166 @Override
167 public void createBibTree(BibTree bibTree) {
168 String requestBody = bibTree.serialize(bibTree);
169 RestResponse restResponse = postRequest(requestBody, BIB_TREE_URL);
170 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
171 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
172 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
173 }
174 String[] responseString = restResponse.getResponseBody().split("/");
175 if (responseString.length == 5) {
176 bibTree.getBib().setId(responseString[4]);
177 }
178 }
179 }
180
181
182
183 @Override
184 public BibTrees processBibTrees(BibTrees bibTrees) {
185 String requestBody = bibTrees.serialize(bibTrees);
186 RestResponse restResponse = postRequest(requestBody, PROCESS_BIB_TREES);
187 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
188 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
189 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
190 } else {
191 bibTrees = (BibTrees) BibTrees.deserialize(restResponse.getResponseBody());
192 }
193 }
194 return bibTrees;
195 }
196
197 @Override
198 public List<Bib> retrieveBibs(List<String> bibIds) {
199
200 RestResponse restResponse = getBibResponse(buildQueryString(bibIds, "bibId"), BIB_URL);
201 Bibs bibsObj = new Bibs();
202 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
203 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
204 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
205 } else {
206 if (bibIds.size() == 1) {
207 Bib bib = new Bib();
208 bibsObj.getBibs().add((Bib) bib.deserialize(restResponse.getResponseBody()));
209 return bibsObj.getBibs();
210 }
211 bibsObj = (Bibs) Bibs.deserialize(restResponse.getResponseBody());
212
213 }
214 }
215 return bibsObj.getBibs();
216
217 }
218
219 @Override
220 public List<Item> retrieveItems(List<String> itemIds) {
221 RestResponse restResponse = getRequest(buildQueryString(itemIds, "itemId"), ITEMS_URL);
222 Items itemsObj = new Items();
223 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
224 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
225 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
226 } else {
227 if (itemIds.size() == 1) {
228 Item item = new Item();
229 itemsObj.getItems().add((Item) item.deserialize(restResponse.getResponseBody()));
230 return itemsObj.getItems();
231 }
232 itemsObj = (Items) Items.deserialize(restResponse.getResponseBody());
233 }
234 }
235 return itemsObj.getItems();
236 }
237
238 @Override
239 public HashMap<String, Item> retrieveItemMap(List<String> itemIds) {
240 RestResponse restResponse = getRequest(buildQueryString(itemIds, "itemId"), ITEM_MAP_URL);
241 ItemMap itemsObj = new ItemMap();
242 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
243 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
244 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
245 } else {
246 itemsObj = (ItemMap) ItemMap.deserialize(restResponse.getResponseBody());
247 }
248 }
249 return itemsObj.getItemMap();
250 }
251
252 @Override
253 public void createLicenses(Licenses licenses) {
254
255 File bagitFile = null;
256 try {
257 bagitFile = createBagItfile(licenses);
258 } catch (IOException e) {
259 e.printStackTrace();
260 }
261 RestResponse restResponse = postMultiPartRequest(bagitFile);
262 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
263 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
264 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
265 }
266 String[] responseString = restResponse.getResponseBody().split("/");
267 int idPos = 2;
268 for (License license : licenses.getLicenses()) {
269 license.setId(responseString[idPos]);
270 idPos += 1;
271 }
272 }
273 bagitFile.delete();
274 }
275
276 @Override
277 public License retrieveLicense(String id) {
278 RestResponse restResponse = getRequest(id, LICENSES_URL);
279 License license = new License();
280 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
281 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
282 logger.info(" rest response " + restResponse.getResponseBody());
283 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
284 } else {
285 license = (License) license.deserialize(restResponse.getResponseBody());
286 }
287 }
288 return license;
289
290 }
291
292 private RestResponse postMultiPartRequest(File bagitFile) {
293 HttpClient httpclient = new DefaultHttpClient();
294 FileBody uploadFilePart = new FileBody(bagitFile);
295 MultipartEntity reqEntity = new MultipartEntity();
296 reqEntity.addPart("upload-file", uploadFilePart);
297 HttpPost httpPost = new HttpPost(DOCSTORE_URL + LICENSES_URL);
298 httpPost.setEntity(reqEntity);
299 httpPost.addHeader("multipart/form-data", "text/xml");
300 RestResponse restResponse = new RestResponse();
301 try {
302 EntityUtils.consume(reqEntity);
303 HttpResponse response = httpclient.execute(httpPost);
304 restResponse.setResponse(response);
305 restResponse.setResponseBody(getEncodeEntityValue(response.getEntity()));
306
307 } catch (Exception e) {
308 e.printStackTrace();
309 }
310
311 return restResponse;
312 }
313
314 private File createBagItfile(Licenses licenses) throws IOException {
315 File bagitFolder = new File(FileUtils.getTempDirectoryPath() + File.separator + "bagit");
316 String licensesXml = licenses.serialize(licenses);
317 File licensesXmlFile = new File(bagitFolder + File.separator + "licenses.xml");
318 FileUtils.writeStringToFile(licensesXmlFile, licensesXml);
319 for (License license : licenses.getLicenses()) {
320 if (license instanceof LicenseAttachment) {
321 LicenseAttachment licenseAttachment = (LicenseAttachment) license;
322 File contentFile = new File(licenseAttachment.getFilePath() + File.separator + licenseAttachment.getFileName());
323 FileUtils.copyFileToDirectory(contentFile, bagitFolder);
324 }
325 }
326
327 File bagitFile = createZipFile(bagitFolder);
328 deleteFiles(bagitFile.listFiles());
329 bagitFolder.delete();
330 return bagitFile;
331 }
332
333 @Override
334 public Licenses retrieveLicenses(List<String> ids) {
335 String licenseIds = buildIds(ids, "licenseIds=");
336 RestResponse restResponse = getRequest(licenseIds, LICENSES_URL);
337 Licenses licenses = new Licenses();
338 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
339 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
340 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
341 } else {
342 licenses = (Licenses) Licenses.deserialize(restResponse.getResponseBody());
343 }
344 }
345 return licenses;
346 }
347
348 @Override
349 public void updateLicense(License license) {
350 String requestBody = license.serialize(license);
351 RestResponse restResponse = putRequest(requestBody, LICENSES_URL);
352 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
353 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
354 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
355 }
356 }
357 }
358
359 @Override
360 public void updateLicenses(Licenses licenses) {
361 String requestBody = Licenses.serialize(licenses);
362 RestResponse restResponse = putRequest(requestBody, LICENSES_TREES_URL);
363 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
364 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
365 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
366 }
367 }
368
369 }
370
371 @Override
372 public void deleteLicense(String id) {
373 RestResponse restResponse = deleteRequest(id, LICENSES_URL);
374 if (restResponse.getResponse().getStatusLine().getStatusCode() != 200) {
375 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
376 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
377 }
378 }
379
380 }
381
382 @Override
383 public void createAnalyticsRelation(String seriesHoldingsId, List<String> itemIds) {
384
385 String requestBody = buildIds(itemIds, "");
386 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL + seriesHoldingsId + ANALYTIC_URL);
387 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
388 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
389 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
390 }
391 }
392 }
393
394 @Override
395 public void bulkUpdateHoldings(Holdings holdings, List<String> holdingIds, String canUpdateStaffOnlyFlag) {
396 String requestBody = holdings.serialize(holdings);
397 String holdingUpdateIds = buildIds(holdingIds, "");
398 RestResponse restResponse = putRequest(holdingUpdateIds + "\n" + canUpdateStaffOnlyFlag + "\n" + requestBody, HOLDINGS_URL + "/" + BULK_UPDATE);
399 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
400 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
401 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
402 }
403 }
404 }
405
406 @Override
407 public void bulkUpdateItem(Item item, List<String> itemIds, String canUpdateStaffOnlyFlag) {
408 String requestBody = item.serialize(item);
409 String itemUpdateIds = buildIds(itemIds, "");
410 RestResponse restResponse = putRequest(itemUpdateIds + "\n" + canUpdateStaffOnlyFlag + "\n" + requestBody, ITEMS_URL + "/" + BULK_UPDATE);
411 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
412 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
413 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
414 }
415 }
416 }
417
418 @Override
419 public void breakAnalyticsRelation(String seriesHoldingsId, List<String> itemIds) {
420 String requestBody = buildIds(itemIds, "");
421 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL + seriesHoldingsId + BREAK_ANALYTIC_URL);
422 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
423 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
424 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
425 }
426 }
427 }
428
429 @Override
430 public Bib retrieveBib(String bibId) {
431 String reqParam = "?bibId=" + bibId;
432 RestResponse restResponse = getBibResponse(reqParam, BIB_URL);
433 Bib bib = new Bib();
434 bib = (Bib) bib.deserialize(restResponse.getResponseBody());
435 return bib;
436 }
437
438 @Override
439 public BibMarcRecords retrieveBibContent(List<String> bibIds) {
440 RestResponse restResponse = getBibResponse(buildQueryString(bibIds, "bibId"), BIB_CONTENT_URL);
441 BibMarcRecords bibMarcRecords = new BibMarcRecords();
442 BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
443 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
444 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
445 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
446 } else {
447 bibMarcRecords = bibMarcRecordProcessor.fromXML(restResponse.getResponseBody());
448 }
449 }
450 return bibMarcRecords;
451 }
452
453 @Override
454 public HoldingsTrees retrieveHoldingsTrees(List<String> bibIds) {
455 RestResponse restResponse = getRequest(buildQueryString(bibIds, "bibId"), HOLDINGS_TREES_CONTENT_URL);
456 HoldingsTrees holdingsTrees = new HoldingsTrees();
457 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
458 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
459 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
460 } else {
461 holdingsTrees = (HoldingsTrees) holdingsTrees.deserialize(restResponse.getResponseBody());
462 }
463 }
464 return holdingsTrees;
465 }
466
467 @Override
468 public HoldingsTrees retrieveHoldingsDocTrees(List<String> bibIds) {
469 RestResponse restResponse = getRequest(buildQueryString(bibIds, "bibId"), HOLDINGS_TREES_URL);
470 HoldingsTrees holdingsTrees = new HoldingsTrees();
471 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
472 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
473 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
474 } else {
475 holdingsTrees = (HoldingsTrees) holdingsTrees.deserialize(restResponse.getResponseBody());
476 }
477 }
478 return holdingsTrees;
479 }
480
481 @Override
482 public Item retrieveItemByBarcode(String barcode) {
483 RestResponse restResponse = getRequest("?barcode=" + barcode, ITEM_CONTENT_URL);
484 Item item = new Item();
485 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
486 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
487 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
488 } else {
489 item = (Item) item.deserialize(restResponse.getResponseBody());
490 }
491 }
492 return item;
493 }
494
495 @Override
496 public void reloadConfiguration() {
497 RestResponse restResponse = getRequest("", RELOAD_URL);
498 }
499
500 @Override
501 public Holdings retrieveHoldings(String holdingsId) {
502 String reqParam = "?holdingsId=" + holdingsId;
503 RestResponse restResponse = getRequest(reqParam, HOLDINGS_URL);
504 Holdings holdings = new PHoldings();
505 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
506 holdings = (Holdings) holdings.deserialize(restResponse.getResponseBody());
507 if (!holdings.getHoldingsType().equalsIgnoreCase("print")) {
508 holdings = new EHoldings();
509 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
510 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
511 } else {
512 holdings = (EHoldings) holdings.deserialize(restResponse.getResponseBody());
513 }
514 }
515 }
516 return holdings;
517 }
518
519 @Override
520 public Item retrieveItem(String itemId) {
521 String queryParam = "?itemId=" + itemId;
522 RestResponse restResponse = getRequest(queryParam, ITEMS_URL);
523 Item item = new Item();
524 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
525 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
526 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
527 } else {
528 item = (Item) item.deserialize(restResponse.getResponseBody());
529 }
530 }
531 return item;
532 }
533
534 @Override
535 public HoldingsTree retrieveHoldingsTree(String holdingsId) {
536 HoldingsTree holdingsTree = new HoldingsTree();
537 String reqParam = "?holdingsId=" + holdingsId;
538 RestResponse restResponse = getRequest(reqParam, HOLDINGS_TREE_URL);
539 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
540 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
541 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
542 } else {
543 holdingsTree = (HoldingsTree) holdingsTree.deserialize(restResponse.getResponseBody());
544 }
545 }
546 return holdingsTree;
547 }
548
549 @Override
550 public BibTree retrieveBibTree(String bibId) {
551 BibTree bibTree = new BibTree();
552 String reqParam = "?bibId=" + bibId;
553 RestResponse restResponse = getBibResponse(reqParam, BIB_TREE_URL);
554 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
555 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
556 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
557 } else {
558 bibTree = (BibTree) bibTree.deserialize(restResponse.getResponseBody());
559 }
560 }
561 return bibTree;
562 }
563
564 @Override
565 public BibTrees retrieveBibTrees(List<String> bibIds) {
566 BibTrees bibTrees = new BibTrees();
567
568 RestResponse restResponse = getBibResponse(buildQueryString(bibIds, "bibId"), BIB_TREES_URL);
569 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
570 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
571 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
572 } else {
573 bibTrees = (BibTrees) BibTrees.deserialize(restResponse.getResponseBody());
574 }
575 }
576
577 return bibTrees;
578 }
579
580 @Override
581 public Bib updateBib(Bib bib) {
582 String requestBody = bib.serialize(bib);
583 RestResponse restResponse = putRequest(requestBody, BIB_URL);
584 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
585 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
586 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
587 }
588 }
589 return bib;
590 }
591
592 @Override
593 public Holdings updateHoldings(Holdings holdings) {
594 String requestBody = holdings.serialize(holdings);
595 RestResponse restResponse = putRequest(requestBody, HOLDINGS_URL);
596 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
597 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
598 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
599 }
600 }
601 return holdings;
602 }
603
604 @Override
605 public Item updateItem(Item item) {
606 String requestBody = item.serialize(item);
607 RestResponse restResponse = putRequest(requestBody, ITEMS_URL);
608 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
609 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
610 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
611 }
612 }
613 return item;
614 }
615
616 @Override
617 public String updateItemByBarcode(String barcode, String requestBody) {
618 RestResponse restResponse = patchRequest(requestBody, ITEM_CONTENT_URL + "?barcode=" + barcode);
619 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
620 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
621 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
622 }
623 }
624 return restResponse.getResponseBody();
625 }
626
627 @Override
628 public String patchItem(String requestBody) {
629 RestResponse restResponse = patchRequest(requestBody, ITEM_CONTENT_URL);
630 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
631 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
632 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
633 }
634 }
635 return restResponse.getResponseBody();
636 }
637
638 @Override
639 public void deleteBib(String bibId) {
640 String reqParam = "?bibId=" + bibId;
641 RestResponse restResponse = deleteRequest(reqParam, BIB_URL);
642 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
643 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
644 }
645 }
646
647 @Override
648 public void deleteHoldings(String holdingsId) {
649 String reqParam = "?holdingsId=" + holdingsId;
650 RestResponse restResponse = deleteRequest(reqParam, HOLDINGS_URL);
651 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
652 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
653 }
654 }
655
656 @Override
657 public void deleteItem(String itemId) {
658 String queryString = "?itemId=" + itemId;
659 RestResponse restResponse = deleteRequest(queryString, ITEMS_URL);
660 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
661 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
662 }
663 }
664
665 @Override
666 public void deleteItems(List<String> itemIds) {
667 String queryString = buildIds(itemIds, "?itemId=");
668 RestResponse restResponse = deleteRequest(queryString, ITEMS_DOCS_URL);
669 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
670 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
671 }
672 }
673
674 @Override
675 public SearchResponse search(SearchParams searchParams) {
676 String requestBody = searchParams.serialize(searchParams);
677 RestResponse restResponse = postRequest(requestBody, SEARCH_URL);
678 SearchResponse searchResponse = new SearchResponse();
679 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
680 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
681 logger.info("DocstoreRestClient search : " + restResponse.getResponseBody());
682 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
683 } else {
684 searchResponse = (SearchResponse) searchResponse.deserialize(restResponse.getResponseBody());
685 }
686 }
687 return searchResponse;
688 }
689
690 @Override
691 public Bib findBib(Map<String, String> map) {
692 Bib bib = new Bib();
693 FindParams findParams = buildFindParams(map);
694 String requestBody = findParams.serialize(findParams);
695 RestResponse restResponse = postRequest(requestBody, BIB_URL + FIND_URL);
696 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
697 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
698 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
699 } else {
700 bib = (Bib) bib.deserialize(restResponse.getResponseBody());
701 }
702 }
703 return bib;
704 }
705
706 @Override
707 public BibTree findBibTree(Map<String, String> map) {
708 BibTree bibTree = new BibTree();
709 FindParams findParams = buildFindParams(map);
710 String requestBody = findParams.serialize(findParams);
711 RestResponse restResponse = postRequest(requestBody, BIB_TREE_URL + FIND_URL);
712 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
713 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
714 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
715 } else {
716 bibTree = (BibTree) bibTree.deserialize(restResponse.getResponseBody());
717 }
718 }
719 return bibTree;
720 }
721
722 @Override
723 public Holdings findHoldings(Map<String, String> map) {
724 Holdings holdings = new PHoldings();
725 FindParams findParams = buildFindParams(map);
726 String requestBody = findParams.serialize(findParams);
727 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL + FIND_URL);
728 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
729 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
730 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
731 } else {
732 holdings = (Holdings) holdings.deserialize(restResponse.getResponseBody());
733 }
734 }
735 return holdings;
736 }
737
738 @Override
739 public HoldingsTree findHoldingsTree(Map<String, String> map) {
740 HoldingsTree holdingsTree = new HoldingsTree();
741 FindParams findParams = buildFindParams(map);
742 String requestBody = findParams.serialize(findParams);
743 RestResponse restResponse = postRequest(requestBody, HOLDINGS_TREE_URL + FIND_URL);
744 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
745 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
746 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
747 } else {
748 holdingsTree = (HoldingsTree) holdingsTree.deserialize(restResponse.getResponseBody());
749 }
750 }
751 return holdingsTree;
752 }
753
754 @Override
755 public Item findItem(Map<String, String> map) {
756 Item item = new Item();
757 FindParams findParams = buildFindParams(map);
758 String requestBody = findParams.serialize(findParams);
759 RestResponse restResponse = postRequest(requestBody, ITEMS_URL + FIND_URL);
760 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
761 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
762 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
763 } else {
764 item = (Item) item.deserialize(restResponse.getResponseBody());
765 }
766 }
767 return item;
768 }
769
770 @Override
771 public SearchResponse browseItems(BrowseParams browseParams) {
772 String requestBody = browseParams.serialize(browseParams);
773 RestResponse restResponse = postRequest(requestBody, BROWSE_URL + ITEMS_URL);
774 SearchResponse searchResponse = new SearchResponse();
775 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
776 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
777 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
778 } else {
779 searchResponse = (SearchResponse) searchResponse.deserialize(restResponse.getResponseBody());
780 }
781 }
782 return searchResponse;
783 }
784
785 @Override
786 public SearchResponse browseHoldings(BrowseParams browseParams) {
787 String requestBody = browseParams.serialize(browseParams);
788 RestResponse restResponse = postRequest(requestBody, BROWSE_URL + HOLDINGS_URL);
789 SearchResponse searchResponse = new SearchResponse();
790 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
791 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
792 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
793 } else {
794 searchResponse = (SearchResponse) searchResponse.deserialize(restResponse.getResponseBody());
795 }
796 }
797 return searchResponse;
798 }
799
800 @Override
801 public void boundWithBibs(String holdingsId, List<String> bibIds) {
802 String requestBody = buildIds(bibIds, "");
803 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL + holdingsId + BOUND_URL);
804 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
805 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
806 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
807 }
808 }
809 }
810
811 @Override
812 public void transferHoldings(List<String> holdingsIds, String bibId) {
813 List<String> filteredIds=new ArrayList<>();
814 for(String holdingId:holdingsIds){
815 if(holdingId.contains("eHoldings")){
816 String id=holdingId.replace("eHoldings","");
817 id=id.trim();
818 filteredIds.add(id);
819 }else {
820 filteredIds.add(holdingId);
821 }
822 }
823 RestResponse restResponse = postRequest(" ", BIB_URL + bibId + TRANSFER_URL + buildQueryString(filteredIds, "holdingsId"));
824 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
825 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
826 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
827 }
828 }
829 }
830
831 @Override
832 public void transferItems(List<String> itemIds, String holdingsId) {
833 String reqParam = buildQueryString(itemIds, "itemId");
834 RestResponse restResponse = postRequest(" ", HOLDINGS_URL + holdingsId + TRANSFER_URL + reqParam);
835 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
836 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
837 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
838 }
839 }
840 }
841
842 @Override
843 public void deleteBibs(List<String> bibIds) {
844 RestResponse restResponse = deleteRequest(buildQueryString(bibIds, "bibId"), BIB_URL);
845
846 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
847 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
848 }
849
850 }
851
852
853
854
855
856 private String buildQueryString(List<String> ids, String queryParam) {
857 StringBuilder reqParam = new StringBuilder("?");
858 int size = ids.size();
859 for (int i = 0; i < size; i++) {
860 reqParam.append(queryParam);
861 reqParam.append("=");
862 reqParam.append(ids.get(i));
863 if (i != (size - 1)) {
864 reqParam.append("&");
865 }
866 }
867 return reqParam.toString();
868 }
869
870 private String buildQueryPostString(List<String> ids, String queryParam) {
871 StringBuilder reqParam = new StringBuilder("");
872 int size = ids.size();
873 for (int i = 0; i < size; i++) {
874 if (ids.get(i)!=null) {
875 reqParam.append(queryParam);
876 reqParam.append("=");
877 reqParam.append(ids.get(i));
878 if (i != (size - 1)) {
879 reqParam.append("&");
880 }
881 }
882 }
883 return reqParam.toString();
884 }
885
886 public String buildIds(List<String> ids, String value) {
887 StringBuilder idSb = new StringBuilder(value);
888 for (String id : ids) {
889 if (ids.get(ids.size() - 1).equals(id)) {
890 idSb.append(id);
891 } else {
892 idSb.append(id + ",");
893 }
894 }
895 return idSb.toString();
896 }
897
898 public FindParams buildFindParams(Map<String, String> map) {
899 FindParams findParams = new FindParams();
900 FindParams.Map findMap = new FindParams.Map();
901 for (Map.Entry mapEntry : map.entrySet()) {
902 FindParams.Map.Entry entry = new FindParams.Map.Entry();
903 entry.setKey((String) mapEntry.getKey());
904 entry.setValue((String) mapEntry.getValue());
905 findMap.getEntry().add(entry);
906 }
907 findParams.setMap(findMap);
908 return findParams;
909 }
910
911 public RestResponse patchRequest(String requestBody, String param) {
912 HttpClient client = new DefaultHttpClient();
913 String result = new String();
914 RestResponse response = new RestResponse();
915 HttpPatch patch = new HttpPatch(DOCSTORE_URL + param);
916 try {
917 StringEntity stringEntity = new StringEntity(requestBody, "UTF-8");
918 patch.setEntity(stringEntity);
919 response.setResponse(client.execute(patch));
920 result = getEncodeEntityValue(response.getResponse().getEntity());
921 } catch (Exception e) {
922 logger.error("PATCH response error is ::", e);
923 }
924 response.setResponseBody(result);
925 logger.debug(" PATCH Response Body :: ", response.getResponseBody());
926 return response;
927 }
928
929 public RestResponse postRequest(String requestBody, String param) {
930 HttpClient client = new DefaultHttpClient();
931 String result = new String();
932 RestResponse response = new RestResponse();
933 HttpPost post = new HttpPost(DOCSTORE_URL + param);
934 try {
935 StringEntity stringEntity = new StringEntity(requestBody, "UTF-8");
936 post.setEntity(stringEntity);
937 response.setResponse(client.execute(post));
938 result = getEncodeEntityValue(response.getResponse().getEntity());
939 } catch (Exception e) {
940 logger.error("POST response error is ::", e);
941 }
942 response.setResponseBody(result);
943 logger.debug(" POST Response Body :: ", response.getResponseBody());
944 return response;
945 }
946
947 public RestResponse putRequest(String requestBody, String param) {
948 HttpClient client = new DefaultHttpClient();
949 String result = new String();
950 HttpPut put = new HttpPut(DOCSTORE_URL + param);
951 RestResponse response = new RestResponse();
952 try {
953 StringEntity stringEntity = new StringEntity(requestBody, "UTF-8");
954 put.setEntity(stringEntity);
955 response.setResponse(client.execute(put));
956 result = getEncodeEntityValue(response.getResponse().getEntity());
957 } catch (Exception e) {
958 logger.error("PUT response error is :: ", e);
959 }
960 response.setResponseBody(result);
961 logger.debug(" PUT Response Body :: ", response.getResponseBody());
962 return response;
963 }
964
965 private RestResponse getRequest(String id, String param) {
966 HttpClient client = new DefaultHttpClient();
967 HttpGet get = new HttpGet(DOCSTORE_URL + param + id);
968 String result = new String();
969 RestResponse response = new RestResponse();
970 try {
971 response.setResponse(client.execute(get));
972
973 result = getEncodeEntityValue(response.getResponse().getEntity());
974 } catch (Exception e) {
975 logger.error("GET response error is ::", e);
976 }
977 response.setResponseBody(result);
978 logger.debug(" GET Response Body :: ", response.getResponseBody());
979 return response;
980 }
981
982 private RestResponse getBibResponse(String id, String param) {
983 RestResponse response = new RestResponse();
984 response.setContentType("text/html; charset=utf-8");
985 try {
986 URL aURL = new URL(DOCSTORE_URL + param + id);
987 StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "OK");
988 HttpResponse httpResponse = new BasicHttpResponse(statusLine);
989 String result = getHttpResponse(new InputStreamReader(aURL.openStream()), response.getContentType());
990 response.setResponseBody(result);
991 response.setResponse(httpResponse);
992 logger.debug(" GET Response Body :: ", response.getResponseBody());
993 } catch (Exception ex) {
994 ex.printStackTrace();
995 logger.error("Exception :", ex);
996 }
997 return response;
998 }
999
1000 public RestResponse deleteRequest(String id, String param) {
1001 String result = new String();
1002 RestResponse response = new RestResponse();
1003 HttpClient client = new DefaultHttpClient();
1004 HttpDelete delete = new HttpDelete(DOCSTORE_URL + param + id);
1005 try {
1006 response.setResponse(client.execute(delete));
1007 result = getEncodeEntityValue(response.getResponse().getEntity());
1008 } catch (Exception e) {
1009 logger.error("DELETE response error is ::", e);
1010 }
1011 response.setResponseBody(result);
1012 logger.debug("DELETE Response Body :: ", response.getResponseBody());
1013 return response;
1014 }
1015
1016 private String getEncodeEntityValue(HttpEntity entity) throws Exception {
1017 String result = EntityUtils.toString(entity, "UTF-8");
1018 return result;
1019 }
1020
1021 private String getHttpResponse(InputStreamReader inputStreamReader, String contentType) throws Exception {
1022 StringWriter writer = new StringWriter();
1023
1024 IOUtils.copy(inputStreamReader, writer);
1025 return writer.toString();
1026 }
1027
1028 public File createZipFile(File sourceDir) throws IOException {
1029 File zipFile = File.createTempFile("tmp", ".zip");
1030 String path = sourceDir.getAbsolutePath();
1031 ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipFile));
1032 ArrayList<File> fileList = getAllFilesList(sourceDir);
1033 for (File file : fileList) {
1034 ZipEntry ze = new ZipEntry(file.getAbsolutePath().substring(path.length() + 1));
1035 zip.putNextEntry(ze);
1036 FileInputStream fis = new FileInputStream(file);
1037 org.apache.commons.compress.utils.IOUtils.copy(fis, zip);
1038 fis.close();
1039 zip.closeEntry();
1040 }
1041 zip.close();
1042 return zipFile;
1043 }
1044
1045 public ArrayList<File> getAllFilesList(File directory) {
1046 ArrayList<File> fileList = new ArrayList<File>();
1047 if (directory.isFile())
1048 fileList.add(directory);
1049 else if (directory.isDirectory())
1050 for (File innerFile : directory.listFiles())
1051 fileList.addAll(getAllFilesList(innerFile));
1052 return fileList;
1053 }
1054
1055
1056 public void deleteFiles(File[] files) {
1057 try {
1058 for (File file : files) {
1059 try {
1060 file.delete();
1061 } catch (Exception e) {
1062 }
1063 }
1064 } catch (Exception e) {
1065 }
1066 }
1067
1068 public List<Bib> acquisitionSearchRetrieveBibs(List<String> bibIds) {
1069
1070 RestResponse restResponse = sendPostForAcquisitionSearch(DOCSTORE_URL+BIB_URL+"searchAcquistion",buildQueryPostString(bibIds, "bibId"));
1071 Bibs bibsObj = new Bibs();
1072 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
1073 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
1074 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
1075 } else {
1076 if (bibIds.size() == 1) {
1077 Bib bib = new Bib();
1078 bibsObj.getBibs().add((Bib) bib.deserialize(restResponse.getResponseBody()));
1079 return bibsObj.getBibs();
1080 }
1081 bibsObj = (Bibs) Bibs.deserialize(restResponse.getResponseBody());
1082
1083 }
1084 }
1085 return bibsObj.getBibs();
1086
1087 }
1088
1089 private RestResponse sendPostForAcquisitionSearch(String url, String urlParameters) {
1090
1091 StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "OK");
1092 HttpResponse httpResponse = new BasicHttpResponse(statusLine);
1093 String postResponse = null;
1094 try {
1095 URL obj = new URL(url);
1096 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
1097 con.setRequestMethod("POST");
1098 con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
1099 con.setDoOutput(true);
1100 DataOutputStream wr = new DataOutputStream(con.getOutputStream());
1101 wr.writeBytes(urlParameters);
1102 wr.flush();
1103 wr.close();
1104 int responseCode = con.getResponseCode();
1105 BufferedReader in = new BufferedReader(
1106 new InputStreamReader(con.getInputStream()));
1107 String inputLine;
1108 StringBuffer response = new StringBuffer();
1109 while ((inputLine = in.readLine()) != null) {
1110 response.append(inputLine);
1111 }
1112 in.close();
1113 postResponse = response.toString();
1114 } catch (Exception e) {
1115 e.printStackTrace();
1116 }
1117
1118 RestResponse response = new RestResponse();
1119 response.setContentType("text/html; charset=utf-8");
1120 response.setResponseBody(postResponse);
1121 response.setResponse(httpResponse);
1122 return response;
1123 }
1124
1125 @Override
1126 public void unbindWithOneBib(List<String> holdingsIds, String bibId) {
1127 String requestBody = buildIds(holdingsIds, "");
1128 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL + bibId + UN_BIND_ONE_URL);
1129 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
1130 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
1131 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
1132 }
1133 }
1134 }
1135
1136 @Override
1137 public void unbindWithAllBibs(List<String> holdingsIds, String bibId) {
1138 String requestBody = buildIds(holdingsIds, "");
1139 RestResponse restResponse = postRequest(requestBody, HOLDINGS_URL + bibId + UN_BIND_ALL_URL);
1140 if (restResponse.getResponse().getStatusLine().getStatusCode() == 200) {
1141 if (restResponse.getResponseBody().startsWith("<org.kuali.ole.docstore.common.exception")) {
1142 throw DocstoreExceptionProcessor.fromXML(restResponse.getResponseBody());
1143 }
1144 }
1145 }
1146
1147 }