View Javadoc
1   package org.kuali.ole;
2   
3   import com.thoughtworks.xstream.XStream;
4   import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
5   import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
6   
7   import java.text.DateFormat;
8   import java.text.SimpleDateFormat;
9   import java.util.Arrays;
10  import java.util.Date;
11  
12  /**
13   * Created by IntelliJ IDEA.
14   * User: pvsubrah
15   * Date: 4/10/12
16   * Time: 9:08 PM
17   * To change this template use File | Settings | File Templates.
18   */
19  public class OleInstanceRecordHandler {
20      public String generateXML(OleHoldings oleHolding, Item oleItem) {
21          Instance oleInstance = getOleInstance(oleHolding, oleItem);
22          InstanceCollection oleInstanceCollection = new InstanceCollection();
23          oleInstanceCollection.setInstance(Arrays.asList(oleInstance));
24          return toXML(oleInstanceCollection);
25      }
26  
27      public Instance getOleInstance(OleHoldings oleHolding, Item oleItem) {
28          Instance oleInstance = new Instance();
29          oleInstance.getItems().getItem().add(oleItem);
30          oleInstance.setOleHoldings(oleHolding);
31          DateFormat df = new SimpleDateFormat("mm-DD-yyyy");
32          Extension extension = new Extension();
33          AdditionalAttributes additionalAttributes = new AdditionalAttributes();
34          additionalAttributes.setLastUpdated(String.valueOf(df.format(new Date())));
35          additionalAttributes.setDateEntered(String.valueOf(df.format(new Date())));
36          extension.setContent(Arrays.<Object>asList(additionalAttributes));
37          oleInstance.setExtension(extension);
38          return oleInstance;
39      }
40  
41      private String toXML(InstanceCollection oleInstanceCollection) {
42          XStream xs = new XStream();
43          xs.autodetectAnnotations(true);
44          xs.processAnnotations(InstanceCollection.class);
45          String xml = xs.toXML(oleInstanceCollection);
46          return xml;
47      }
48  }