View Javadoc

1   package org.kuali.ole.editor.service;
2   
3   
4   import org.kuali.ole.*;
5   import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
6   import org.kuali.ole.docstore.model.xmlpojo.ingest.Content;
7   import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
8   import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
9   import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
10  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
11  import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkInstanceOlemlRecordProcessor;
12  import org.kuali.ole.ingest.pojo.ProfileAttributeBo;
13  import org.kuali.ole.pojo.ProfileAttribute;
14  import org.kuali.ole.pojo.bib.BibliographicRecord;
15  //import org.kuali.ole.pojo.item.OleHolding;
16  //import org.kuali.ole.pojo.item.OleItem;
17  
18  import org.kuali.rice.krad.util.GlobalVariables;
19  
20  import java.io.*;
21  import java.net.URL;
22  import java.net.URLConnection;
23  import java.net.URLEncoder;
24  import java.text.DateFormat;
25  import java.text.SimpleDateFormat;
26  import java.util.ArrayList;
27  import java.util.Date;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  /**
32   * DocstoreHelperService is the service class to access Docstore services
33   */
34  public class DocstoreHelperService {
35  
36      private static final String DOCSTORE_URL = "docstore.url";
37      private final String CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING = "docAction=ingestContent&stringContent=";
38      private final String CHECKOUT_DOCSTORE_RECORD_QUERY_STRING = "docAction=checkOut&uuid=";
39      private final String UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING = "docAction=checkIn&stringContent=";
40      private final String ROLLBACK_DATA_FROM_DOCSTORE = "docAction=deleteWithLinkedDocs&requestContent=";
41  
42      private List<ProfileAttribute> attributes = new ArrayList<ProfileAttribute>();
43  
44      public String persistToDocstoreForEditor(String content, String uuid, String format) throws Exception {
45          String responseFromDocstore = callToDocstore(content, uuid, format);
46          return responseFromDocstore;
47      }
48  
49      private String callToDocstore(String content, String uuid, String format) throws Exception {
50          String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
51          String queryString = null;
52  
53          if (null == uuid) {
54              String xmlContent = buildReuestDocXML(content, format);
55              queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
56          } else {
57              String xmlContent = buildReuestDocXML(content, uuid, format);
58              queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
59          }
60  
61          return postData(docstoreURL, queryString);
62      }
63  
64      public String persistNewToDocstoreForIngest(BibliographicRecord bibliographicRecord, List<ProfileAttributeBo> profileAttributes) throws Exception {
65          this.attributes = buildListOfProfileAttributes(profileAttributes);
66          BibliographicRecordHandler bibliographicRecordHandler = new BibliographicRecordHandler();
67          String bibXMLContent = bibliographicRecordHandler.generateXML(bibliographicRecord);
68          String instanceXMLContent = getInstanceXML(bibliographicRecord);
69          String requestXML = buildReuestDocXMLForIngest(bibXMLContent, instanceXMLContent);
70          String queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(requestXML);
71          String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
72          String responseXML = postData(docstoreURL, queryString + queryString);
73          return responseXML;
74      }
75  
76      public String getDocstoreData(String uuid) throws Exception {
77          String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
78          String queryString = CHECKOUT_DOCSTORE_RECORD_QUERY_STRING + uuid;
79          String responseFromDocstore = postData(docstoreURL, queryString);
80          return responseFromDocstore;
81      }
82  
83      public static String postData(String target, String content) throws Exception {
84          String response = "";
85          URL url = new URL(target);
86          URLConnection conn = url.openConnection();
87          conn.setDoInput(true);
88          conn.setDoOutput(true);
89          conn.setUseCaches(false);
90          conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
91  
92          Writer w = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
93          w.write(content);
94          w.close();
95          BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
96          String temp;
97          while ((temp = in.readLine()) != null) {
98              response += temp + "\n";
99          }
100         in.close();
101         return response;
102     }
103 
104 
105     private String buildReuestDocXML(String xmlContent, String format) {
106         return buildReuestDocXML(xmlContent, null, format);
107     }
108 
109 
110     public String buildReuestDocXMLForIngest(String bibXML, String instanceXML) {
111         Request requestObject = new Request();
112         requestObject.setUser(GlobalVariables.getUserSession().getPrincipalName());
113         requestObject.setOperation(OLEConstants.INGEST_OPERATION);
114         RequestDocument requestDocument = new RequestDocument();
115         requestDocument.setId("1");
116         requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
117         requestDocument.setType(OLEConstants.BIB_DOC_TYPE);
118         requestDocument.setFormat(OLEConstants.MARC_FORMAT);
119         requestDocument.setContent(new Content(bibXML));
120 
121         AdditionalAttributes additionalAttributes = new AdditionalAttributes();
122         DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
123         additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
124         additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
125         additionalAttributes.setFastAddFlag("true");
126         additionalAttributes.setSupressFromPublic("false");
127         additionalAttributes.setAttribute("dateEntered",String.valueOf(dateFormat.format(new Date())));
128         additionalAttributes.setAttribute("lastUpdated",String.valueOf(dateFormat.format(new Date())));
129         additionalAttributes.setAttribute("fastAddFlag","true");
130         additionalAttributes.setAttribute("supressFromPublic","false");
131         requestDocument.setAdditionalAttributes(additionalAttributes);
132 
133         RequestDocument linkedRequestDocument = new RequestDocument();
134         linkedRequestDocument.setId("2");
135         linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
136         linkedRequestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
137         linkedRequestDocument.setContent(new Content(instanceXML));
138         linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
139 
140         ArrayList<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
141         linkedRequestDocuments.add(linkedRequestDocument);
142 
143         requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
144 
145         ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
146         requestDocuments.add(requestDocument);
147         requestObject.setRequestDocuments(requestDocuments);
148 
149         RequestHandler requestHandler = new RequestHandler();
150         String xml = requestHandler.toXML(requestObject);
151         return xml;
152     }
153 
154 
155     private String buildReuestDocXML(String xmlContent, String uuid, String format) {
156         String INSTANCE_MARC_XML_STRING = "<instanceCollection>\n" +
157                 "  <instance>\n" +
158                 "<instanceIdentifier></instanceIdentifier>\n" +
159                 "    <oleHoldings primary=\"true\">\n" +
160                 "       <holdingsIdentifier></holdingsIdentifier>\n" +
161                 "       <receiptStatus></receiptStatus>\n" +
162                 "       <uri></uri>\n" +
163                 "       <note type=\"public\"></note>\n" +
164                 "       <location primary=\"true\" status=\"permanent\">\n" +
165                 "           <locationLevel>\n" +
166                 "               <name></name>\n" +
167                 "               <level></level>\n" +
168                 "               <locationLevel>\n" +
169                 "                   <name></name>\n" +
170                 "                   <level></level>\n" +
171                 "                   <locationLevel>\n" +
172                 "                       <name></name>\n" +
173                 "                       <level></level>\n" +
174                 "                       <locationLevel>\n" +
175                 "                           <name></name>\n" +
176                 "                           <level></level>\n" +
177                 "                       </locationLevel>\n" +
178                 "                    </locationLevel>\n" +
179                 "                </locationLevel>\n" +
180                 "        </locationLevel>\n" +
181                 "      </location>\n" +
182                 "      <extension>\n" +
183                 "        <additionalAttributes>\n" +
184                 "          <createdBy></createdBy>\n" +
185                 "          <dateEntered></dateEntered>\n" +
186                 "        </additionalAttributes>\n" +
187                 "      </extension>\n" +
188                 "      <callNumber>\n" +
189                 "        <type></type>\n" +
190                 "        <prefix></prefix>\n" +
191                 "        <number></number>\n" +
192                 "        <shelvingScheme>\n" +
193                 "          <codeValue></codeValue>\n" +
194                 "        </shelvingScheme>\n" +
195                 "        <shelvingOrder>\n" +
196                 "          <codeValue></codeValue>\n" +
197                 "        </shelvingOrder>\n" +
198                 "      </callNumber>\n" +
199                 "    </oleHoldings>\n" +
200                 "    <items>\n" +
201                 "      <item>\n" +
202                 "        <staffOnlyFlag>false</staffOnlyFlag>\n" +
203                 "        <fastAddFlag>false</fastAddFlag>\n" +
204                 "        <extension reference=\"../../../oleHoldings/extension\"/>\n" +
205                 "      </item>\n" +
206                 "    </items>\n" +
207                 "  </instance>\n" +
208                 "</instanceCollection>"  ;
209         Request requestObject = new Request();
210         RequestDocument requestDocument = new RequestDocument();
211 
212         if (null == uuid) {
213             requestDocument.setId("1");
214             RequestDocument linkedRequestDocument = new RequestDocument();
215             linkedRequestDocument.setId("2");
216             linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
217             linkedRequestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
218             linkedRequestDocument.setContent(new Content(INSTANCE_MARC_XML_STRING));
219             linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
220 
221             ArrayList<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
222             linkedRequestDocuments.add(linkedRequestDocument);
223 
224             requestObject.setOperation(OLEConstants.INGEST_OPERATION);
225             requestObject.setUser(GlobalVariables.getUserSession().getPrincipalName());
226             requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
227         } else {
228             requestDocument.setId(uuid);
229             requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
230             requestObject.setUser("editor");
231         }
232         requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
233         requestDocument.setType(OLEConstants.BIB_DOC_TYPE);
234 
235         if (format.equalsIgnoreCase("marc")) {
236             requestDocument.setFormat(OLEConstants.MARC_FORMAT);
237         } else if (format.equalsIgnoreCase("dublinunq")) {
238             requestDocument.setFormat(OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
239         }
240 
241         requestDocument.setContent(new Content(xmlContent));
242 
243         if (format.equalsIgnoreCase("marc")) {
244             AdditionalAttributes additionalAttributes = new AdditionalAttributes();
245             DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
246             if (null == uuid) {
247                 additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
248             }
249             additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
250             additionalAttributes.setFastAddFlag("true");
251             additionalAttributes.setSupressFromPublic("false");
252             requestDocument.setAdditionalAttributes(additionalAttributes);
253         }
254 
255         ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
256         requestDocuments.add(requestDocument);
257         requestObject.setRequestDocuments(requestDocuments);
258 
259         RequestHandler requestHandler = new RequestHandler();
260         String xml = requestHandler.toXML(requestObject);
261 
262         if (format.equalsIgnoreCase(OLEConstants.UNQUALIFIED_DUBLIN_FORMAT)) {
263             xml = modifyXmlContent(xml);
264         }
265         return xml;
266     }
267 
268     public String getInstanceXML(BibliographicRecord bibliographicRecord) {
269         WorkInstanceOlemlRecordProcessor workInstanceOlemlRecordProcessor = new WorkInstanceOlemlRecordProcessor();
270         InstanceCollection instanceCollection = new InstanceCollection();
271         Instance oleInstance = new Instance();
272         List<Item> oleItemList  = new ArrayList<Item>();
273         oleItemList.add(getOleItem(bibliographicRecord)) ;
274         if(oleInstance.getItems() == null){
275             oleInstance.setItems(new Items());
276         }
277         oleInstance.getItems().setItem(oleItemList);
278         oleInstance.setOleHoldings(getOleHolding());
279 
280         Extension extension = new Extension();
281         AdditionalAttributes additionalAttributes = new AdditionalAttributes();
282         DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
283         additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
284         additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
285         additionalAttributes.setSupressFromPublic("false");
286         additionalAttributes.setFastAddFlag("false");
287         additionalAttributes.setHarvestable("true");
288         additionalAttributes.setStatus("n"); // new Record
289         additionalAttributes.setAttribute("dateEntered", additionalAttributes.getDateEntered());
290         additionalAttributes.setAttribute("lastUpdated", additionalAttributes.getLastUpdated());
291         additionalAttributes.setAttribute("fastAddFlag",additionalAttributes.getFastAddFlag());
292         additionalAttributes.setAttribute("supressFromPublic", additionalAttributes.getSupressFromPublic());
293         additionalAttributes.setAttribute("harvestable",additionalAttributes.getHarvestable());
294         additionalAttributes.setAttribute("status",additionalAttributes.getStatus());
295         extension.getContent().add(additionalAttributes);
296         //List<Extension>   extensionList = new ArrayList<Extension>();
297         //extensionList.add(extension);
298         oleInstance.setExtension(extension);
299         oleInstance.getOleHoldings().setPrimary(OLEConstants.TRUE);
300         oleInstance.getOleHoldings().setReceiptStatus("");
301         Uri uri = new Uri();
302         uri.setValue("");
303         uri.setResolvable(null);
304         oleInstance.getOleHoldings().getUri().add(uri);
305         Note note = new Note();
306         note.setType(OLEConstants.NOTE_TYPE);
307         oleInstance.getOleHoldings().getNote().add(note);
308         CallNumber callNumber = new CallNumber();
309         ShelvingScheme shelvingScheme = new ShelvingScheme();
310         ShelvingOrder shelvingOrder = new ShelvingOrder();
311         callNumber.setType("");
312         callNumber.setPrefix("");
313         callNumber.setNumber("");
314         shelvingScheme.setCodeValue("");
315         shelvingOrder.setCodeValue("");
316         callNumber.setShelvingScheme(shelvingScheme);
317         callNumber.setShelvingOrder(shelvingOrder);
318         oleInstance.getOleHoldings().setCallNumber(callNumber);
319         List<Instance> oleInstanceList = new ArrayList<Instance>();
320         OleHoldings oleHoldings = oleInstance.getOleHoldings();
321         if(oleHoldings.getLocation() == null ) {
322             LocationLevel locationLevel = new LocationLevel();
323             Location location = new Location();
324             locationLevel.setLevel("");
325             locationLevel.setName("");
326             location.setPrimary(OLEConstants.TRUE);
327             location.setStatus(OLEConstants.PERMANENT);
328             location.setLocationLevel(locationLevel);
329             oleInstance.getOleHoldings().setLocation(location);
330         }
331         oleInstanceList.add(oleInstance);
332         instanceCollection.setInstance(oleInstanceList);
333         //String instanceXML = workInstanceOlemlRecordProcessor.generateXML(getOleHolding(), getOleItem(bibliographicRecord));
334         String instanceXML = workInstanceOlemlRecordProcessor.toXML(instanceCollection);
335         return instanceXML;
336     }
337 
338     public OleHoldings getOleHolding() {
339         return new OleHoldingsRecordHandler().getOleHoldings(attributes);
340     }
341 
342     public Item getOleItem(BibliographicRecord bibliographicRecord) {
343         return new OleItemRecordHandler().getOleItem(bibliographicRecord, attributes);
344     }
345 
346     private List<ProfileAttribute> buildListOfProfileAttributes(List<ProfileAttributeBo> profileAttributes) {
347         for (Iterator iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
348             ProfileAttributeBo profileAttributeBo = (ProfileAttributeBo) iterator.next();
349             ProfileAttribute profileAttribute = new ProfileAttribute();
350             profileAttribute.setAgendaName(profileAttributeBo.getAgendaName());
351             profileAttribute.setAttributeName(profileAttributeBo.getAttributeName());
352             profileAttribute.setAttributeValue(profileAttributeBo.getAttributeValue());
353             profileAttribute.setSystemValue(profileAttributeBo.getSystemValue());
354             attributes.add(profileAttribute);
355         }
356         return attributes;
357     }
358 
359     private String modifyXmlContent(String inputXmlContent) {
360         StringBuffer modifiedContent = new StringBuffer(inputXmlContent);
361         modifiedContent.replace(modifiedContent.indexOf("<oai_dc:dc"), modifiedContent.indexOf(">", modifiedContent.indexOf("<oai_dc:dc")),
362                 "<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
363         return modifiedContent.toString();
364     }
365 
366     public void rollbackData(String xmlForRollback) throws Exception {
367         String queryString = ROLLBACK_DATA_FROM_DOCSTORE + URLEncoder.encode(xmlForRollback, "UTF-8");
368         String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
369         postData(docstoreURL, queryString + queryString);
370     }
371 
372 
373     public String updateItem(BibliographicRecord bibliographicRecord, String itemUUID){
374         String responseXML = null;
375         try{
376             Item oleItem = getOleItem(bibliographicRecord);
377             OleItemRecordHandler oleItemRecordHandler = new OleItemRecordHandler();
378             String itemXML = oleItemRecordHandler.toXML(oleItem);
379             String requestXML = buildReuestDocXMLForUpdate(itemXML,itemUUID)  ;
380             String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(requestXML, "UTF-8");
381             String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
382             responseXML = postData(docstoreURL, queryString);
383         }catch(Exception e){
384             e.printStackTrace();
385         }
386         return responseXML;
387     }
388     private String buildReuestDocXMLForUpdate(String itemXML,String itemUUID) {
389         Request requestObject = new Request();
390         RequestDocument requestDocument = new RequestDocument();
391         requestDocument.setId(itemUUID);
392         requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
393         requestDocument.setType(OLEConstants.ITEM_DOC_TYPE);
394         requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
395         requestDocument.setContent(new Content(itemXML));
396 
397         ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
398         requestDocuments.add(requestDocument);
399         requestObject.setRequestDocuments(requestDocuments);
400         RequestHandler requestHandler = new RequestHandler();
401         String xml = requestHandler.toXML(requestObject);
402         return xml;
403     }
404 
405     /**
406      *   Method to generate Request XML and ingest Instance record to docstore
407      * @param content
408      * @param uuid
409      * @param format
410      * @return  Docstore response for Ingesting New Instance Record
411      * @throws Exception
412      */
413     public String instanceRecordCallToDocstore(String content, String uuid, String format) throws Exception {
414         String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
415         String queryString = null;
416         String xmlContent = buildInstanceRequestDocXML(content, uuid, format);
417         queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
418         return postData(docstoreURL, queryString);
419     }
420 
421     /**
422      * Method to generate Request xml for Ingesting Instance record
423      * @param xmlContent
424      * @param uuid
425      * @param format
426      * @return   Request XML content
427      */
428     private String buildInstanceRequestDocXML(String xmlContent, String uuid, String format) {
429         Request requestObject = new Request();
430         RequestDocument requestDocument = new RequestDocument();
431         if (null == uuid) {
432             requestDocument.setId("1");
433             requestObject.setOperation(OLEConstants.INGEST_OPERATION);
434         } else {
435             requestDocument.setId(uuid);
436             requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
437         }
438         requestObject.setUser("editor");
439         requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
440         requestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
441         requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
442 
443         requestDocument.setContent(new Content(xmlContent));
444 
445         ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
446         requestDocuments.add(requestDocument);
447         requestObject.setRequestDocuments(requestDocuments);
448 
449         RequestHandler requestHandler = new RequestHandler();
450         String requestXml = requestHandler.toXML(requestObject);
451         return requestXml;
452     }
453 
454     /**
455      * Method to update Holding or Item record of an Instance record
456      * @param uuid
457      * @param docType
458      * @param xmlContent
459      * @return  Docstore XML response with success/failure status
460      * @throws Exception
461      */
462     public String updateInstanceRecord(String uuid, String docType, String xmlContent) throws Exception {
463         String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
464         Request requestObject = new Request();
465         requestObject.setUser(GlobalVariables.getUserSession().getPrincipalId());
466         requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
467         RequestDocument requestDocument = new RequestDocument();
468 
469         requestDocument.setId(uuid);
470         requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
471         requestDocument.setType(docType);  // docType should be either holdings or item
472         requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
473         requestDocument.setContent(new Content(xmlContent));
474 
475         ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
476         requestDocuments.add(requestDocument);
477         requestObject.setRequestDocuments(requestDocuments);
478 
479         RequestHandler requestHandler = new RequestHandler();
480         String xml = requestHandler.toXML(requestObject);
481 
482         String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xml, "UTF-8");
483 
484         return postData(docstoreURL, queryString);
485     }
486 
487     /**
488      * This method used to delete a instance record
489      * @param instance
490      * @return
491      * @throws Exception
492      */
493 
494     public String deleteInstanceRecord(Instance instance) throws Exception {
495         String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
496         //  Request deleteRequest = buildDeleteRequest(instance);
497         String uuid = instance.getInstanceIdentifier();
498         String queryString = "docAction=delete&requestContent=" + uuid;
499         String response = postData(docstoreURL,queryString);
500         return response;
501 
502     }
503 
504     /**
505      * Method to add NEW ITEM for existing Instance record
506      * @param instanceUuid
507      * @param docType
508      * @param xmlContent
509      * @return  Docstore XML response with success/failure status
510      * @throws Exception
511      */
512     public String createItemForInstanceRecord (String instanceUuid, String docType, String xmlContent) throws Exception {
513         String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
514         Request requestObject = new Request();
515         requestObject.setUser(GlobalVariables.getUserSession().getPrincipalId());
516         requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
517         RequestDocument requestDocument = new RequestDocument();
518 
519         requestDocument.setId(instanceUuid);
520         requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
521         requestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
522         requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
523 
524 
525         RequestDocument linkedRequestDocument = new RequestDocument();
526         linkedRequestDocument.setId(OLEConstants.NEW_ITEM_ID);
527         linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
528         linkedRequestDocument.setType(docType);
529         linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
530         linkedRequestDocument.setContent(new Content(xmlContent));
531 
532         List<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
533         linkedRequestDocuments.add(linkedRequestDocument);
534         requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
535 
536 
537         ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
538         requestDocuments.add(requestDocument);
539         requestObject.setRequestDocuments(requestDocuments);
540 
541         RequestHandler requestHandler = new RequestHandler();
542         String xml = requestHandler.toXML(requestObject);
543 
544         String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xml, "UTF-8");
545 
546         return postData(docstoreURL, queryString);
547 
548     }
549 
550     public String deleteItemrecord(String uuid) throws Exception {
551         String docstoreURL = PropertyUtil.getPropertyUtil().getProperty(DOCSTORE_URL);
552         String queryString = "docAction=delete&requestContent=" + uuid;
553         String response = postData(docstoreURL,queryString);
554         return response;
555 
556     }
557 
558 }