1 package org.kuali.ole.describe.bo;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.jfree.util.Log;
5 import org.kuali.ole.UnQualifiedDublinRecordHandler;
6 import org.kuali.ole.describe.form.EditorForm;
7 import org.kuali.ole.docstore.model.enums.DocFormat;
8 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.DCValue;
9 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.WorkBibDublinRecord;
10 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.*;
11 import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
12 import org.kuali.rice.krad.web.form.UifFormBase;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17
18
19
20 public class WorkDublinEditorFormDataHandler {
21
22
23
24
25
26
27
28
29 public String buildDublinRecordForDocStore(UifFormBase uifFormBase, String uuid) {
30
31 String content = "";
32 EditorForm dublinEditorForm = (EditorForm) uifFormBase;
33 if (dublinEditorForm.getDocFormat().equals(DocFormat.DUBLIN_UNQUALIFIED.getCode())) {
34 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecord();
35 if (uuid != null && !uuid.trim().equals("")) {
36 unQualifiedDublinRecord.setListRecords(buildDublinDCValuesForEdit(dublinEditorForm));
37 } else {
38 unQualifiedDublinRecord.setListRecords(buildDublinDCValues(dublinEditorForm.getDublinFieldList()));
39 }
40 dublinEditorForm.setTitle(buildDublinUnqTitleField(dublinEditorForm, unQualifiedDublinRecord));
41 content = new UnQualifiedDublinRecordHandler().toXml(unQualifiedDublinRecord);
42 } else if (dublinEditorForm.getDocFormat().equals(DocFormat.DUBLIN_CORE.getCode())) {
43
44 Log.info("Enter Dublin Save");
45
46
47
48
49
50
51
52
53
54
55 }
56 return content;
57 }
58
59
60
61
62
63
64
65
66
67 private ListRecords buildDublinDCValues(List<WorkDublinEditorField> dublinFields) {
68 ListRecords listRecords = new ListRecords();
69 Record record = new Record();
70 MetaData metaData = new MetaData();
71 OaiDcDoc oaiDcDoc = new OaiDcDoc();
72 List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
73 for (int i = 0; i < dublinFields.size(); i++) {
74 if (!dublinFields.get(i).getElement().equalsIgnoreCase("default")) {
75 oaiDcDoc.put(dublinFields.get(i).getElement(), dublinFields.get(i).getValue());
76 }
77 }
78 oaiDcDocList.add(oaiDcDoc);
79 metaData.setOaiDcDocs(oaiDcDocList);
80 record.setMetadata(metaData);
81 listRecords.addRecord(record);
82 return listRecords;
83 }
84
85 private ListRecords buildDublinDCValues1(List<WorkDublinEditorField> dublinFields) {
86 ListRecords listRecords = new ListRecords();
87 Record record = new Record();
88 MetaData metaData = new MetaData();
89 OaiDcDoc oaiDcDoc = new OaiDcDoc();
90 List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
91 for (int i = 0; i < dublinFields.size(); i++) {
92 if (!dublinFields.get(i).getElement().equalsIgnoreCase("default")) {
93 oaiDcDoc.put(dublinFields.get(i).getElement(), dublinFields.get(i).getValue());
94 }
95 }
96 oaiDcDocList.add(oaiDcDoc);
97 metaData.setOaiDcDocs(oaiDcDocList);
98 record.setMetadata(metaData);
99 listRecords.addRecord(record);
100 return listRecords;
101 }
102
103
104
105
106
107
108
109
110
111 public List<WorkDublinEditorField> buildDublinUnqEditorFields(EditorForm editorForm, UnQualifiedDublinRecord unQualifiedDublinRecord) {
112 ListRecords listRecords = unQualifiedDublinRecord.getListRecords();
113 List<Tag> tagList = listRecords.getRecords().get(0).getMetadata().getOaiDcDocs().get(0).getAllTags();
114
115 List<WorkDublinEditorField> dublinEditorFieldList = new ArrayList<WorkDublinEditorField>();
116 for (int i = 0; i < tagList.size(); i++) {
117 WorkDublinEditorField dublinEditorField = new WorkDublinEditorField();
118 dublinEditorField.setElement(tagList.get(i).getName());
119 dublinEditorField.setValue(tagList.get(i).getValue());
120 dublinEditorFieldList.add(dublinEditorField);
121 }
122
123 return dublinEditorFieldList;
124 }
125
126 public String buildDublinUnqTitleField(EditorForm editorForm, UnQualifiedDublinRecord unQualifiedDublinRecord) {
127
128 String title = "";
129 String author = "";
130 ListRecords listRecords = unQualifiedDublinRecord.getListRecords();
131 List<Tag> tagList = listRecords.getRecords().get(0).getMetadata().getOaiDcDocs().get(0).getAllTags();
132 List<WorkDublinEditorField> dublinEditorFieldList = new ArrayList<WorkDublinEditorField>();
133 for (Tag tag : tagList) {
134 if (tag.getName().contains("title")) {
135 if (!(StringUtils.isBlank(tag.getValue()))) {
136 title = tag.getValue();
137 }
138 }
139
140 if (tag.getName().contains("creator")) {
141 if (!StringUtils.isBlank(tag.getValue())) {
142 author = tag.getValue();
143 }
144 }
145 }
146 return title + " / " + author;
147
148 }
149
150 public List<WorkDublinEditorField> buildDublinEditorFields(EditorForm editorForm, WorkBibDublinRecord workBibDublinRecord) {
151 List<DCValue> listRecords = workBibDublinRecord.getDcValues();
152 List<WorkDublinEditorField> dublinEditorFieldList = editorForm.getDublinFieldList();
153 for (int i = 0; i < listRecords.size(); i++) {
154 WorkDublinEditorField dublinEditorField = new WorkDublinEditorField();
155 dublinEditorField.setElement(listRecords.get(i).getElement());
156 dublinEditorField.setValue(listRecords.get(i).getValue());
157 dublinEditorFieldList.add(dublinEditorField);
158 }
159 return dublinEditorFieldList;
160 }
161
162
163
164
165
166
167
168
169
170 private ListRecords buildDublinDCValuesForEdit(EditorForm dublinEditorForm) {
171 ListRecords listRecords = new ListRecords();
172 String element = "";
173 String value = "";
174 Record record = new Record();
175 List<String> elementList = new ArrayList<String>();
176 MetaData metaData = new MetaData();
177 OaiDcDoc oaiDcDoc = new OaiDcDoc();
178 List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
179 List<WorkDublinEditorField> newElementList = dublinEditorForm.getDublinFieldList();
180 List<WorkDublinEditorField> existingElementList = dublinEditorForm.getExistingDublinFieldList();
181 for (int i = 0; i < newElementList.size(); i++) {
182 if (!newElementList.get(i).getElement().equalsIgnoreCase("default")) {
183 element = newElementList.get(i).getElement();
184 value = newElementList.get(i).getValue();
185 if (!elementList.contains(element)) {
186 elementList.add(element);
187 oaiDcDoc.put(element, value);
188 }
189
190 }
191 }
192
193
194
195
196
197 oaiDcDocList.add(oaiDcDoc);
198 metaData.setOaiDcDocs(oaiDcDocList);
199 record.setMetadata(metaData);
200 listRecords.addRecord(record);
201 return listRecords;
202 }
203
204 }