1 package org.kuali.ole.describe.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.UnQualifiedDublinRecordHandler;
6 import org.kuali.ole.describe.bo.OleBibliographicRecordStatus;
7 import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
8 import org.kuali.ole.describe.bo.DublinEditorField;
9 import org.kuali.ole.describe.bo.DublinEditorFormDataHandler;
10 import org.kuali.ole.describe.form.DublinEditorForm;
11 import org.kuali.ole.describe.service.DocstoreHelperService;
12 import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
13 import org.kuali.rice.krad.service.BusinessObjectService;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15 import org.kuali.rice.krad.uif.UifParameters;
16 import org.kuali.rice.krad.util.GlobalVariables;
17 import org.kuali.rice.krad.web.controller.UifControllerBase;
18 import org.kuali.rice.krad.web.form.UifFormBase;
19 import org.springframework.stereotype.Controller;
20 import org.springframework.validation.BindingResult;
21 import org.springframework.web.bind.annotation.ModelAttribute;
22 import org.springframework.web.bind.annotation.RequestMapping;
23 import org.springframework.web.servlet.ModelAndView;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27 import java.util.*;
28
29
30
31
32
33 @Controller
34 @RequestMapping(value = "/dublincomponents")
35 public class DublinEditorController
36 extends UifControllerBase {
37
38
39
40 private static final Logger LOG = Logger.getLogger(DublinEditorController.class);
41
42 private DublinEditorFormDataHandler dublinEditorFormDataHandler;
43 private DocstoreHelperService docstoreHelperService;
44
45
46
47
48
49
50
51 @Override
52 protected DublinEditorForm createInitialForm(HttpServletRequest request) {
53 return new DublinEditorForm();
54 }
55
56
57
58
59
60
61
62
63
64
65 @Override
66 @RequestMapping(params = "methodToCall=start")
67 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
68 HttpServletRequest request, HttpServletResponse response) {
69 DublinEditorForm dublinEditorForm = (DublinEditorForm) form;
70 return super.start(dublinEditorForm, result, request, response);
71 }
72
73
74
75
76
77
78
79
80
81
82 @RequestMapping(params = "methodToCall=addField")
83 public ModelAndView addDublinField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
84 HttpServletRequest request, HttpServletResponse response) {
85 DublinEditorForm dublinEditorForm = (DublinEditorForm) form;
86 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
87 index++;
88 List<DublinEditorField> dublinEditorFieldList = dublinEditorForm.getDublinFieldList();
89 dublinEditorFieldList.add(index, new DublinEditorField());
90
91 return super.getUIFModelAndView(dublinEditorForm);
92 }
93
94
95
96
97
98
99
100
101
102
103 @RequestMapping(params = "methodToCall=removeField")
104 public ModelAndView removeDublinField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
105 HttpServletRequest request, HttpServletResponse response) {
106 DublinEditorForm dublinEditorForm = (DublinEditorForm) form;
107 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
108 String selectedCollection = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
109 List<DublinEditorField> dublinEditorFieldList = dublinEditorForm.getDublinFieldList();
110 List<DublinEditorField> existingEditorFieldList;
111 if (dublinEditorFieldList.size() > 1)
112 dublinEditorFieldList.remove(index);
113 if (selectedCollection.equalsIgnoreCase("existingDublinFieldList")) {
114 existingEditorFieldList = dublinEditorForm.getExistingDublinFieldList();
115 if (existingEditorFieldList.size() > 0) {
116 existingEditorFieldList.remove(index);
117 }
118 }
119
120 return super.getUIFModelAndView(dublinEditorForm);
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134 @RequestMapping(params = "methodToCall=submit")
135 public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
136 HttpServletRequest request, HttpServletResponse response) {
137 String responseFromDocstore = null;
138 DublinEditorForm dublinEditorForm = (DublinEditorForm) form;
139 String bibliographicRecordStatusCode = dublinEditorForm.getBibStatus();
140 String uuid = dublinEditorForm.getUuid();
141 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
142 String content = "";
143 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
144 Map parentCriteria = new HashMap();
145 parentCriteria.put("bibliographicRecordStatusCode", bibliographicRecordStatusCode);
146 OleBibliographicRecordStatus bibliographicRecordStatus = boService
147 .findBySinglePrimaryKey(OleBibliographicRecordStatus.class, parentCriteria);
148 if (bibliographicRecordStatus != null) {
149 dublinEditorForm.setCreatedBy(GlobalVariables.getUserSession().getLoggedInUserPrincipalName());
150 dublinEditorForm.setCreatedDate(bibliographicRecordStatus.getSourceDate());
151 content = getDublinEditorFormDataHandler().buildDublinRecordForDocStore(form, uuid);
152 additionalAttributes.setAttribute("dateEntered", bibliographicRecordStatus.getSourceDate().toString());
153 additionalAttributes.setAttribute("createdBy", GlobalVariables.getUserSession().getLoggedInUserPrincipalName());
154 }
155 try {
156 if (uuid != null && !uuid.trim().equals("")) {
157 responseFromDocstore = getDocstoreHelperService()
158 .persistToDocstoreWithAdditionalAttributesForEditor(content, additionalAttributes, uuid,
159 OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
160 } else {
161 responseFromDocstore = getDocstoreHelperService()
162 .persistToDocstoreWithAdditionalAttributesForEditor(content, additionalAttributes, null,
163 OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
164 }
165 LOG.info("responseFromDocstore---->" + responseFromDocstore);
166 dublinEditorForm.setDublinFieldList(Arrays.asList(new DublinEditorField()));
167 dublinEditorForm.setExistingDublinFieldList(new ArrayList<DublinEditorField>());
168 dublinEditorForm.setUuid("");
169 dublinEditorForm.setMessage("Record saved successfully.");
170 } catch (Exception e) {
171
172 LOG.error("refreshLeftTree Exception:" + e);
173 dublinEditorForm.setDublinFieldList(Arrays.asList(new DublinEditorField()));
174 dublinEditorForm.setExistingDublinFieldList(new ArrayList<DublinEditorField>());
175 dublinEditorForm.setMessage("Failed to save record.");
176 }
177 return getUIFModelAndView(dublinEditorForm, "DublinEditorViewPage");
178 }
179
180
181
182
183
184
185
186
187
188
189 @RequestMapping(params = "methodToCall=loadDublinRecord")
190 public ModelAndView loadDublinRecord(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
191 HttpServletRequest request, HttpServletResponse response) {
192 DublinEditorForm dublinEditorForm = (DublinEditorForm) form;
193 String uuid = dublinEditorForm.getUuid();
194 try {
195 String docStoreData = getDocstoreHelperService().getDocstoreData(uuid);
196 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecordHandler().fromXML(docStoreData);
197 dublinEditorForm.setExistingDublinFieldList(getDublinEditorFormDataHandler().buildDublinEditorFields(unQualifiedDublinRecord));
198 dublinEditorForm.setDublinFieldList(new ArrayList<DublinEditorField>(Arrays.asList(new DublinEditorField())));
199
200 } catch (Exception e) {
201
202 LOG.error("loadDublinRecord Exception:" + e);
203 }
204 return getUIFModelAndView(dublinEditorForm, "DublinEditorViewPage");
205 }
206
207
208
209
210
211
212 private DublinEditorFormDataHandler getDublinEditorFormDataHandler() {
213 if (null == dublinEditorFormDataHandler) {
214 dublinEditorFormDataHandler = new DublinEditorFormDataHandler();
215 }
216 return dublinEditorFormDataHandler;
217 }
218
219
220
221
222
223
224 private DocstoreHelperService getDocstoreHelperService() {
225 if (null == docstoreHelperService) {
226 return new DocstoreHelperService();
227 }
228 return docstoreHelperService;
229 }
230
231
232
233
234
235
236 public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
237 this.docstoreHelperService = docstoreHelperService;
238 }
239
240
241
242
243
244
245
246
247
248
249 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, DublinEditorForm dublinEditorForm) {
250
251 return super.getUIFModelAndView(dublinEditorForm);
252 }
253
254 }