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
14
15
16
17
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 }