1 package org.kuali.ole.describe.controller;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.UnQualifiedDublinRecordHandler;
5 import org.kuali.ole.describe.form.EditorForm;
6 import org.kuali.ole.describe.form.WorkBibDublinForm;
7 import org.kuali.ole.describe.form.WorkBibMarcForm;
8 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
9 import org.kuali.ole.editor.bo.DublinEditorField;
10 import org.kuali.ole.editor.bo.DublinEditorFormDataHandler;
11 import org.kuali.ole.editor.service.DocstoreHelperService;
12 import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
13 import org.kuali.rice.krad.uif.UifParameters;
14 import org.kuali.rice.krad.web.form.UifFormBase;
15 import org.springframework.validation.BindingResult;
16 import org.springframework.web.bind.annotation.ModelAttribute;
17 import org.springframework.web.bind.annotation.RequestMapping;
18 import org.springframework.web.servlet.ModelAndView;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class WorkBibDublinEditor implements DocumentEditor {
40
41
42
43
44 private DublinEditorFormDataHandler dublinEditorFormDataHandler;
45 private DocstoreHelperService docstoreHelperService;
46
47 private static WorkBibDublinEditor workBibDublinEditor = new WorkBibDublinEditor();
48
49 public static WorkBibDublinEditor getInstance() {
50 return workBibDublinEditor;
51 }
52
53 private WorkBibDublinEditor() {
54 }
55
56 @Override
57 public EditorForm loadDocument(EditorForm editorForm) {
58 WorkBibDublinForm dublinEditorForm = new WorkBibDublinForm();
59 String docId = editorForm.getDocId();
60 if (null != docId) {
61 try {
62
63 String docStoreData = getDocstoreHelperService().getDocstoreData(docId);
64 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecordHandler().fromXML(docStoreData);
65 dublinEditorForm.setExistingDublinFieldList(getDublinEditorFormDataHandler().buildDublinEditorFields(unQualifiedDublinRecord));
66 dublinEditorForm.setDublinFieldList(new ArrayList<DublinEditorField>(Arrays.asList(new DublinEditorField())));
67 }
68 catch (Exception e) {
69
70 dublinEditorForm.setMessage("Error: Could not load Bib record for id:" + docId);
71 }
72 }
73 dublinEditorForm.setViewId("DublinEditorViewPage");
74 dublinEditorForm.setMessage("Please enter details for new Bib record.");
75 return dublinEditorForm;
76 }
77
78
79
80 @Override
81 public EditorForm deleteDocument(EditorForm editorForm) {
82 return new WorkBibMarcForm();
83 }
84
85 @Override
86 public EditorForm createNewRecord(EditorForm editorForm, Request request) {
87 return null;
88 }
89
90 @Override
91 public EditorForm editNewRecord(EditorForm editorForm, Request req) {
92 return null;
93 }
94
95 @Override
96 public String saveDocument(Request req) {
97 return null;
98 }
99
100 @Override
101 public EditorForm saveDocument(EditorForm editorForm) {
102 return null;
103 }
104
105
106
107
108
109
110
111
112
113
114 @RequestMapping(params = "methodToCall=addField")
115 public ModelAndView addDublinField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
116 HttpServletRequest request, HttpServletResponse response) {
117 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
118 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
119 index++;
120 List<DublinEditorField> dublinEditorFieldList = dublinEditorForm.getDublinFieldList();
121 dublinEditorFieldList.add(index, new DublinEditorField());
122
123 return null;
124 }
125
126
127
128
129
130
131
132
133
134 @RequestMapping(params = "methodToCall=removeField")
135 public ModelAndView removeDublinField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
136 HttpServletRequest request, HttpServletResponse response) {
137 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
138 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
139 String selectedCollection = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
140 List<DublinEditorField> dublinEditorFieldList = dublinEditorForm.getDublinFieldList();
141 List<DublinEditorField> existingEditorFieldList;
142 if (dublinEditorFieldList.size() > 1)
143 dublinEditorFieldList.remove(index);
144 if (selectedCollection.equalsIgnoreCase("existingDublinFieldList")) {
145 existingEditorFieldList = dublinEditorForm.getExistingDublinFieldList();
146 if (existingEditorFieldList.size() > 0) {
147 existingEditorFieldList.remove(index);
148 }
149 }
150
151 return null;
152 }
153
154
155
156
157
158
159
160
161
162
163
164 @RequestMapping(params = "methodToCall=submit")
165 public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
166 HttpServletRequest request, HttpServletResponse response) {
167 String responseFromDocstore = null;
168 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
169 String uuid = dublinEditorForm.getUuid();
170 String content = getDublinEditorFormDataHandler().buildDublinRecordForDocStore(form,uuid);
171 try {
172 if (uuid != null && !uuid.trim().equals("")) {
173 responseFromDocstore = getDocstoreHelperService().persistToDocstoreForEditor(content, uuid, OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
174 } else {
175 responseFromDocstore = getDocstoreHelperService().persistToDocstoreForEditor(content, null, OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
176 }
177 System.out.println("responseFromDocstore---->" + responseFromDocstore);
178 dublinEditorForm.setDublinFieldList(Arrays.asList(new DublinEditorField()));
179 dublinEditorForm.setExistingDublinFieldList(new ArrayList<DublinEditorField>());
180 dublinEditorForm.setUuid("");
181 dublinEditorForm.setMessage("Record saved successfully.");
182 } catch (Exception e) {
183 e.printStackTrace();
184 dublinEditorForm.setDublinFieldList(Arrays.asList(new DublinEditorField()));
185 dublinEditorForm.setExistingDublinFieldList(new ArrayList<DublinEditorField>());
186 dublinEditorForm.setMessage("Failed to save record.");
187 }
188
189 return null;
190 }
191
192
193
194
195
196
197
198
199
200 @RequestMapping(params = "methodToCall=loadDublinRecord")
201 public ModelAndView loadDublinRecord(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
202 HttpServletRequest request, HttpServletResponse response) {
203 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
204 String uuid = dublinEditorForm.getUuid();
205 try {
206 String docStoreData = getDocstoreHelperService().getDocstoreData(uuid);
207 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecordHandler().fromXML(docStoreData);
208 dublinEditorForm.setExistingDublinFieldList(getDublinEditorFormDataHandler().buildDublinEditorFields(unQualifiedDublinRecord));
209 dublinEditorForm.setDublinFieldList(new ArrayList<DublinEditorField>(Arrays.asList(new DublinEditorField())));
210
211 } catch (Exception e) {
212 e.printStackTrace();
213 }
214
215 return null;
216 }
217
218
219
220
221
222 private DublinEditorFormDataHandler getDublinEditorFormDataHandler() {
223 if (null == dublinEditorFormDataHandler) {
224 dublinEditorFormDataHandler = new DublinEditorFormDataHandler();
225 }
226 return dublinEditorFormDataHandler;
227 }
228
229
230
231
232
233 private DocstoreHelperService getDocstoreHelperService() {
234 if (null == docstoreHelperService) {
235 return new DocstoreHelperService();
236 }
237 return docstoreHelperService;
238 }
239
240
241
242
243
244 public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
245 this.docstoreHelperService = docstoreHelperService;
246 }
247
248
249
250
251
252
253
254
255
256 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, WorkBibDublinForm dublinEditorForm) {
257
258 return null;
259 }
260
261 @Override
262 public EditorForm addORDeleteFields(EditorForm editorForm, HttpServletRequest request) {
263 return null;
264 }
265
266 @Override
267 public EditorForm deleteVerify(EditorForm editorForm) throws Exception {
268 return null;
269 }
270
271 @Override
272 public EditorForm delete(EditorForm editorForm) throws Exception {
273 return null;
274 }
275
276 }