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