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