1 package org.kuali.ole.describe.bo;
2
3 import org.kuali.ole.BibliographicRecordHandler;
4 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.ControlField;
5 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.DataField;
6 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.SubField;
7 import org.kuali.ole.describe.form.MarcEditorForm;
8 import org.kuali.ole.pojo.bib.BibliographicRecord;
9 import org.kuali.rice.krad.web.form.UifFormBase;
10
11 import java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.StringTokenizer;
15
16
17
18
19 public class WorkMarcEditorFormDataHandler {
20
21
22
23
24
25
26
27 public String buildBibRecordForDocStore(UifFormBase uifFormBase) {
28 MarcEditorForm marcEditorForm = (MarcEditorForm) uifFormBase;
29 BibliographicRecord bibliographicRecord = new BibliographicRecord();
30 bibliographicRecord.setLeader(marcEditorForm.getLeader());
31 bibliographicRecord.setControlfields(buldBibliographicContrlFields(marcEditorForm.getControlFields()));
32 bibliographicRecord.setDatafields(buildBibliographicDataFields(marcEditorForm.getDataFields()));
33 String content = new BibliographicRecordHandler().generateXML(bibliographicRecord);
34 return content;
35 }
36
37
38
39
40
41
42
43
44 private List<DataField> buildBibliographicDataFields(List<MarcEditorDataField> dataFields) {
45 String marcEditorDataFieldValue;
46 List<DataField> marcDataFieldList = new ArrayList<DataField>();
47 for (int i = 0; i < dataFields.size(); i++) {
48 DataField marcDataField = new DataField();
49 List<SubField> marcSubFieldList = new ArrayList<SubField>();
50 marcEditorDataFieldValue = dataFields.get(i).getValue();
51 StringTokenizer str = new StringTokenizer(marcEditorDataFieldValue, "|");
52 while (str.hasMoreTokens()) {
53 SubField marcSubField = new SubField();
54 String dataFieldTokenizedVal = str.nextToken();
55 String code = Character.toString(dataFieldTokenizedVal.charAt(0));
56 marcSubField.setCode(code);
57 String value = dataFieldTokenizedVal.substring(1, dataFieldTokenizedVal.length());
58 marcSubField.setValue(value);
59 marcSubFieldList.add(marcSubField);
60 }
61 marcDataField.setSubFields(marcSubFieldList);
62 marcDataField.setTag(dataFields.get(i).getTag());
63 marcDataField.setInd1(dataFields.get(i).getInd1());
64 marcDataField.setInd2(dataFields.get(i).getInd2());
65 marcDataFieldList.add(marcDataField);
66 }
67 return marcDataFieldList;
68 }
69
70
71
72
73
74
75
76
77 private List<ControlField> buldBibliographicContrlFields(List<MarcEditorControlField> controlFields) {
78 List<ControlField> marcControlFieldList = new ArrayList<ControlField>();
79 for (int i = 0; i < controlFields.size(); i++) {
80 ControlField marcControlField = new ControlField();
81 marcControlField.setTag(controlFields.get(i).getTag());
82 marcControlField.setValue(controlFields.get(i).getValue());
83 marcControlFieldList.add(marcControlField);
84 }
85 return marcControlFieldList;
86 }
87
88
89
90
91
92
93
94
95 public List<MarcEditorControlField> buildMarcEditorControlFields(List<ControlField> controlFields) {
96 List<MarcEditorControlField> marcControlFieldList = new ArrayList<MarcEditorControlField>();
97 for (int i = 0; i < controlFields.size(); i++) {
98 MarcEditorControlField marcEditorControlField = new MarcEditorControlField();
99 marcEditorControlField.setTag(controlFields.get(i).getTag());
100 marcEditorControlField.setValue(controlFields.get(i).getValue());
101 marcControlFieldList.add(marcEditorControlField);
102 }
103 return marcControlFieldList;
104 }
105
106
107
108
109
110
111
112
113 public List<MarcEditorDataField> buildMarcEditorDataFields(List<DataField> dataFields) {
114 List<MarcEditorDataField> marcEditorDataFields = new ArrayList<MarcEditorDataField>();
115 for (int i = 0; i < dataFields.size(); i++) {
116 MarcEditorDataField marcEditorDataField = new MarcEditorDataField();
117 marcEditorDataField.setTag(dataFields.get(i).getTag());
118 marcEditorDataField.setInd1(dataFields.get(i).getInd1());
119 marcEditorDataField.setInd2(dataFields.get(i).getInd2());
120 List<SubField> subFields = dataFields.get(i).getSubFields();
121 String subFieldVal = null;
122 for (int j = 0; j < subFields.size(); j++) {
123 String code = subFields.get(j).getCode();
124 String value = subFields.get(j).getValue();
125 if (subFieldVal != null)
126 subFieldVal = subFieldVal + "|" + code + value;
127 else
128 subFieldVal = "|" + code + value;
129 }
130 marcEditorDataField.setValue(subFieldVal);
131 marcEditorDataFields.add(marcEditorDataField);
132 }
133 return marcEditorDataFields;
134 }
135
136
137
138
139
140
141
142
143
144 public String getUUIDFromForm(UifFormBase uifFormBase) {
145 MarcEditorForm form = (MarcEditorForm) uifFormBase;
146 List<MarcEditorControlField> controlFields = form.getControlFields();
147 for (Iterator<MarcEditorControlField> iterator = controlFields.iterator(); iterator.hasNext(); ) {
148 MarcEditorControlField controlField = iterator.next();
149 if (controlField.getTag().equals("001")) {
150 return controlField.getValue();
151 }
152 }
153 return null;
154 }
155 }