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.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   * Created by IntelliJ IDEA.
16   * User: pvsubrah
17   * Date: 4/10/12
18   * Time: 9:24 PM
19   * To change this template use File | Settings | File Templates.
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          /*oleHolding.setRecordType(resolveRecordType(getAttributeValue(profileAttributes, "recordType")));
49          oleHolding.setEncodingLevel(resolveEncodingLevel(getAttributeValue(profileAttributes, "encodingLevel")));
50          oleHolding.setReceiptStatus(getAttributeValue(profileAttributes, "recieptStatus"));
51          oleHolding.setAcquisitionMethod(getAttributeValue(profileAttributes, "acquisitionMethod"));
52          oleHolding.setReproductionPolicy(getAttributeValue(profileAttributes, "generalRetentionPolicy"));
53          SpecificRetentionPolicy specificRetentionPolicy = new SpecificRetentionPolicy();
54          specificRetentionPolicy.setPolicyType(getAttributeValue(profileAttributes, "policyType"));
55          oleHolding.setSpecificRetentionPolicy(specificRetentionPolicy);
56          oleHolding.setGeneralRetentionPolicy(getAttributeValue(profileAttributes, "generalRetentionPolicy"));*/
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"); // new Record
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 }