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
14
15 public class DublinEditorFormDataHandler {
16
17
18
19
20
21
22
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
38
39
40
41
42
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
64
65
66
67
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
85
86
87
88
89
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 }