View Javadoc

1   package org.kuali.ole.describe.bo;
2   
3   import org.kuali.ole.UnQualifiedDublinRecordHandler;
4   import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.*;
5   import org.kuali.ole.describe.form.DublinEditorForm;
6   import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
7   import org.kuali.rice.krad.web.form.UifFormBase;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  /**
13   * DublinEditorFormDataHandler is the data handler class for Dublin Editor
14   */
15  public class DublinEditorFormDataHandler {
16      /**
17       * This method returns response Xml from the docStore for Duplin Record, This method will ingest new record to docstore if uuid is null, else it will update existing record.
18       * the toXml method in UnQualifiedDublinRecordHandler will convert the unQualifiedDublinRecord in to responseXml.
19       *
20       * @param uifFormBase
21       * @param uuid
22       * @return content
23       */
24      public String buildDublinRecordForDocStore(UifFormBase uifFormBase, String uuid) {
25          DublinEditorForm dublinEditorForm = (DublinEditorForm) uifFormBase;
26          UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecord();
27          if (uuid != null && !uuid.trim().equals("")) {
28              unQualifiedDublinRecord.setListRecords(buildDublinDCValuesForEdit(dublinEditorForm));
29          } else {
30              unQualifiedDublinRecord.setListRecords(buildDublinDCValues(dublinEditorForm.getDublinFieldList()));
31          }
32          String content = new UnQualifiedDublinRecordHandler().toXml(unQualifiedDublinRecord);
33          return content;
34      }
35  
36      /**
37       * This method returns List of DublinDcValue records,
38       * In this method each record contains a metadata with oaiDcDocList,
39       * each oaiDcDocList contains list of oaiDcDoc with tagName and value.
40       *
41       * @param dublinFields
42       * @return listRecords
43       */
44      private ListRecords buildDublinDCValues(List<DublinEditorField> dublinFields) {
45          ListRecords listRecords = new ListRecords();
46          Record record = new Record();
47          MetaData metaData = new MetaData();
48          OaiDcDoc oaiDcDoc = new OaiDcDoc();
49          List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
50          for (int i = 0; i < dublinFields.size(); i++) {
51              if (!dublinFields.get(i).getElement().equalsIgnoreCase("default")) {
52                  oaiDcDoc.put(dublinFields.get(i).getElement(), dublinFields.get(i).getValue());
53              }
54          }
55          oaiDcDocList.add(oaiDcDoc);
56          metaData.setOaiDcDocs(oaiDcDocList);
57          record.setMetadata(metaData);
58          listRecords.addRecord(record);
59          return listRecords;
60      }
61  
62      /**
63       * This method returns List of  DublinEditorField,
64       * each dublinEditorField object sets the tagName and value got from unQualifiedDublinRecord.
65       *
66       * @param unQualifiedDublinRecord
67       * @return dublinEditorFieldList
68       */
69  
70      public List<DublinEditorField> buildDublinEditorFields(UnQualifiedDublinRecord unQualifiedDublinRecord) {
71          ListRecords listRecords = unQualifiedDublinRecord.getListRecords();
72          List<Tag> tagList = listRecords.getRecords().get(0).getMetadata().getOaiDcDocs().get(0).getAllTags();
73          List<DublinEditorField> dublinEditorFieldList = new ArrayList<DublinEditorField>();
74          for (int i = 0; i < tagList.size(); i++) {
75              DublinEditorField dublinEditorField = new DublinEditorField();
76              dublinEditorField.setElement(tagList.get(i).getName());
77              dublinEditorField.setValue(tagList.get(i).getValue());
78              dublinEditorFieldList.add(dublinEditorField);
79          }
80          return dublinEditorFieldList;
81      }
82  
83      /**
84       * This method returns updated ListRecords to be set in UnQualifiedDublinRecord  to update the existing docStore records.
85       * In this method each record contains updated metadata with oaiDcDocList,
86       * each oaiDcDocList contains updated list of oaiDcDoc with tagName and value.
87       *
88       * @param dublinEditorForm
89       * @return listRecords
90       */
91      private ListRecords buildDublinDCValuesForEdit(DublinEditorForm dublinEditorForm) {
92          ListRecords listRecords = new ListRecords();
93          Record record = new Record();
94          MetaData metaData = new MetaData();
95          OaiDcDoc oaiDcDoc = new OaiDcDoc();
96          List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
97          List<DublinEditorField> newElementList = dublinEditorForm.getDublinFieldList();
98          List<DublinEditorField> existingElementList = dublinEditorForm.getExistingDublinFieldList();
99          for (int i = 0; i < newElementList.size(); i++) {
100             if (!newElementList.get(i).getElement().equalsIgnoreCase("default")) {
101                 oaiDcDoc.put(newElementList.get(i).getElement(), newElementList.get(i).getValue());
102             }
103         }
104         for (int i = 0; i < existingElementList.size(); i++) {
105             if (!existingElementList.get(i).getElement().equalsIgnoreCase("default")) {
106                 oaiDcDoc.put(existingElementList.get(i).getElement(), existingElementList.get(i).getValue());
107             }
108         }
109         oaiDcDocList.add(oaiDcDoc);
110         metaData.setOaiDcDocs(oaiDcDocList);
111         record.setMetadata(metaData);
112         listRecords.addRecord(record);
113         return listRecords;
114     }
115 
116 }