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.Extension;
6 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.OleHoldings;
7 import org.kuali.ole.pojo.ProfileAttribute;
8
9 import java.text.DateFormat;
10 import java.text.SimpleDateFormat;
11 import java.util.*;
12
13
14
15
16
17
18
19
20
21 public class OleHoldingsRecordHandler {
22 Map<String, String> recordTypes = new HashMap<String, String>();
23 Map<String, String> encodingLevels = new HashMap<String, String>();
24
25 public OleHoldingsRecordHandler() {
26 recordTypes = new HashMap<String, String>();
27 recordTypes.put("u", "Unknown");
28 recordTypes.put("s", "Single-part item holdings");
29 recordTypes.put("y", "Serial item holdings");
30
31 encodingLevels.put("1", "Holdings level 1");
32 encodingLevels.put("2", "Holdings level 2");
33 encodingLevels.put("3", "Holdings level 3");
34 encodingLevels.put("4", "Holdings level 4");
35 encodingLevels.put("5", "Holdings level 5");
36 encodingLevels.put("m", "Mixed level");
37 encodingLevels.put("u", "Unknown");
38 encodingLevels.put("z", "Other level");
39 }
40
41 public String generateXML(List<ProfileAttribute> profileAttributes) {
42 OleHoldings oleHolding = getOleHoldings(profileAttributes);
43 return toXML(oleHolding);
44 }
45
46 public OleHoldings getOleHoldings(List<ProfileAttribute> profileAttributes) {
47 OleHoldings oleHolding = new OleHoldings();
48
49
50
51
52
53
54
55
56
57
58 oleHolding.setReceiptStatus(getAttributeValue(profileAttributes, "receiptStatus"));
59
60 DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
61 Extension extension = new Extension();
62 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
63 additionalAttributes.setDateEntered(String.valueOf(df.format(new Date())));
64 additionalAttributes.setLastUpdated(String.valueOf(df.format(new Date())));
65 additionalAttributes.setSupressFromPublic("false");
66 additionalAttributes.setFastAddFlag("false");
67 additionalAttributes.setHarvestable("true");
68 additionalAttributes.setStatus("n");
69 additionalAttributes.setAttribute("dateEntered",additionalAttributes.getDateEntered());
70 additionalAttributes.setAttribute("lastUpdated",additionalAttributes.getLastUpdated());
71 additionalAttributes.setAttribute("fastAddFlag",additionalAttributes.getFastAddFlag());
72 additionalAttributes.setAttribute("supressFromPublic",additionalAttributes.getSupressFromPublic());
73 additionalAttributes.setAttribute("harvestable",additionalAttributes.getHarvestable());
74 additionalAttributes.setAttribute("status",additionalAttributes.getStatus());
75
76 extension.getContent().add(additionalAttributes);
77 oleHolding.setExtension(extension);
78 return oleHolding;
79 }
80
81 private String resolveEncodingLevel(String encodingLevel) {
82 return encodingLevels.get(encodingLevel);
83 }
84
85 private String resolveRecordType(String recordType) {
86 return recordTypes.get(recordType);
87 }
88
89 private String getAttributeValue(List<ProfileAttribute> profileAttributes, String attributeName) {
90 for (Iterator<ProfileAttribute> iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
91 ProfileAttribute attribute = iterator.next();
92 if (attribute.getAttributeName().equals(attributeName)) {
93 return attribute.getAttributeValue();
94 }
95 }
96 return null;
97 }
98
99 public String toXML(OleHoldings oleHolding) {
100 XStream xs = new XStream();
101 xs.autodetectAnnotations(true);
102 xs.processAnnotations(OleHoldings.class);
103 String xml = xs.toXML(oleHolding);
104 return xml;
105 }
106
107 }