View Javadoc
1   package org.kuali.ole.describe.controller;
2   
3   import com.lowagie.text.*;
4   import com.lowagie.text.pdf.PdfPCell;
5   import com.lowagie.text.pdf.PdfPTable;
6   import com.lowagie.text.pdf.PdfWriter;
7   import org.apache.commons.collections.CollectionUtils;
8   import org.apache.commons.lang.StringUtils;
9   import org.apache.log4j.Logger;
10  import org.kuali.ole.DocumentUniqueIDPrefix;
11  import org.kuali.ole.OLEConstants;
12  import org.kuali.ole.OLEPropertyConstants;
13  import org.kuali.ole.deliver.bo.OlePatronDocument;
14  import org.kuali.ole.deliver.bo.OlePatronLostBarcode;
15  import org.kuali.ole.describe.bo.*;
16  import org.kuali.ole.describe.bo.marc.structuralfields.ControlFields;
17  import org.kuali.ole.describe.bo.marc.structuralfields.LeaderField;
18  import org.kuali.ole.describe.bo.marc.structuralfields.controlfield006.ControlField006;
19  import org.kuali.ole.describe.bo.marc.structuralfields.controlfield006.ControlField006Text;
20  import org.kuali.ole.describe.bo.marc.structuralfields.controlfield007.ControlField007Text;
21  import org.kuali.ole.describe.bo.marc.structuralfields.controlfield008.ControlField008;
22  import org.kuali.ole.describe.bo.marc.structuralfields.controlfield007.ControlField007;
23  import org.kuali.ole.describe.form.EditorForm;
24  import org.kuali.ole.describe.form.WorkBibMarcForm;
25  import org.kuali.ole.describe.form.WorkEInstanceOlemlForm;
26  import org.kuali.ole.describe.form.WorkInstanceOlemlForm;
27  import org.kuali.ole.describe.service.DiscoveryHelperService;
28  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
29  import org.kuali.ole.docstore.common.document.Bib;
30  import org.kuali.ole.docstore.common.document.BibTree;
31  import org.kuali.ole.docstore.common.document.config.DocFieldConfig;
32  import org.kuali.ole.docstore.common.document.config.DocFormatConfig;
33  import org.kuali.ole.docstore.common.document.config.DocTypeConfig;
34  import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
35  import org.kuali.ole.docstore.common.document.content.bib.marc.*;
36  import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
37  import org.kuali.ole.docstore.common.document.content.instance.*;
38  import org.kuali.ole.docstore.common.search.*;
39  import org.kuali.ole.docstore.model.bo.WorkBibDocument;
40  import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
41  import org.kuali.ole.docstore.model.bo.WorkItemDocument;
42  import org.kuali.ole.docstore.model.enums.DocFormat;
43  import org.kuali.ole.docstore.model.enums.DocType;
44  import org.kuali.ole.select.bo.OLEDonor;
45  import org.kuali.ole.sys.context.SpringContext;
46  import org.kuali.ole.util.StringUtil;
47  import org.kuali.rice.core.api.config.property.ConfigContext;
48  import org.kuali.rice.kim.api.permission.PermissionService;
49  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
50  import org.kuali.rice.krad.service.KRADServiceLocator;
51  import org.kuali.rice.krad.uif.UifParameters;
52  import org.kuali.rice.krad.uif.container.CollectionGroup;
53  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
54  import org.kuali.rice.krad.uif.view.View;
55  import org.kuali.rice.krad.util.GlobalVariables;
56  import org.kuali.rice.krad.web.controller.UifControllerBase;
57  import org.kuali.rice.krad.web.form.UifFormBase;
58  import org.springframework.stereotype.Controller;
59  import org.springframework.validation.BindingResult;
60  import org.springframework.web.bind.annotation.ModelAttribute;
61  import org.springframework.web.bind.annotation.RequestMapping;
62  import org.springframework.web.servlet.ModelAndView;
63  
64  import javax.servlet.http.HttpServletRequest;
65  import javax.servlet.http.HttpServletResponse;
66  import java.io.IOException;
67  import java.io.OutputStream;
68  import java.sql.*;
69  import java.util.*;
70  import java.util.Date;
71  import java.util.List;
72  
73  /**
74   * Created with IntelliJ IDEA.
75   * User: PP7788
76   * Date: 12/6/12
77   * Time: 4:34 PM
78   * To change this template use File | Settings | File Templates.
79   */
80  
81  @Controller
82  @RequestMapping(value = "/editorcontroller")
83  
84  public class EditorController extends UifControllerBase {
85  
86      private DocumentEditor editor;
87      private EditorFormDataHandler editorFormDataHandler;
88      private DiscoveryHelperService discoveryHelperService;
89      private boolean isFormInitialized = false;
90      private DocstoreClientLocator docstoreClientLocator;
91  
92      public DocstoreClientLocator getDocstoreClientLocator() {
93          if (null == docstoreClientLocator) {
94              return SpringContext.getBean(DocstoreClientLocator.class);
95          }
96          return docstoreClientLocator;
97      }
98  
99      private static final Logger LOG = Logger.getLogger(EditorController.class);
100 
101     private boolean canDeleteItem(String principalId) {
102         PermissionService service = KimApiServiceLocator.getPermissionService();
103         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_DELETE_ITEM);
104     }
105 
106     private boolean canDeleteInstance(String principalId) {
107         PermissionService service = KimApiServiceLocator.getPermissionService();
108         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_DELETE_INSTANCE);
109     }
110 
111     private boolean canAddItem(String principalId) {
112         PermissionService service = KimApiServiceLocator.getPermissionService();
113         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_ADD_ITEM);
114     }
115 
116     private boolean canDeleteEInstance(String principalId) {
117         PermissionService service = KimApiServiceLocator.getPermissionService();
118         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_DELETE_EINSTANCE);
119     }
120 
121     @Override
122     protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
123         UifFormBase uifFormBase = null;
124         uifFormBase = new EditorForm();
125         return uifFormBase;
126     }
127 
128     @RequestMapping(params = "methodToCall=copy")
129     public ModelAndView copy(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
130                              HttpServletRequest request, HttpServletResponse response) {
131         if (!isFormInitialized) {
132             super.start(form, result, request, response);
133             isFormInitialized = true;
134         }
135         EditorForm editorForm = (EditorForm) form;
136         editorForm.setCopyFlag(true);
137         if (null != editorForm.getDocumentForm()) {
138             editorForm.getDocumentForm().setCopyFlag(true);
139         }
140         ModelAndView modelAndView = null;
141         String docCategory = request.getParameter("docCategory");
142         String docType = request.getParameter("docType");
143         String docFormat = request.getParameter("docFormat");
144         ((EditorForm) form).setDocCategory(docCategory);
145         ((EditorForm) form).setDocType(docType);
146         ((EditorForm) form).setDocFormat(docFormat);
147         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
148                 .getDocumentEditor(docCategory, docType, docFormat);
149         editorForm = documentEditor.copy((EditorForm) form);
150         modelAndView = getUIFModelAndView(editorForm);
151         return modelAndView;
152     }
153 
154     @RequestMapping(params = "methodToCall=copyInstance")
155     public ModelAndView copyInstance(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
156                                      HttpServletRequest request, HttpServletResponse response) {
157         if (!isFormInitialized) {
158             super.start(form, result, request, response);
159             isFormInitialized = true;
160         }
161         EditorForm editorForm = (EditorForm) form;
162         ModelAndView modelAndView = null;
163         String docCategory = request.getParameter("docCategory");
164         String docType = request.getParameter("docType");
165         String docFormat = request.getParameter("docFormat");
166         ((EditorForm) form).setDocCategory(docCategory);
167         ((EditorForm) form).setDocType(docType);
168         ((EditorForm) form).setDocFormat(docFormat);
169         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
170                 .getDocumentEditor(docCategory, docType, docFormat);
171         editorForm = documentEditor.copy((EditorForm) form);
172         modelAndView = getUIFModelAndView(editorForm, "WorkHoldingsViewPage");
173         return modelAndView;
174     }
175 
176     @Override
177     @RequestMapping(params = "methodToCall=start")
178     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
179                               HttpServletRequest request, HttpServletResponse response) {
180 
181         if (!isFormInitialized) {
182             super.start(form, result, request, response);
183             isFormInitialized = true;
184         }
185         EditorForm editorForm = (EditorForm) form;
186         editorForm.setMainSerialReceivingHistoryList(null);
187         editorForm.setSupplementSerialReceivingHistoryList(null);
188         editorForm.setIndexSerialReceivingHistoryList(null);
189         editorForm.setBibFlag(false);
190         editorForm.setHoldingFlag(false);
191         editorForm.setItemFlag(false);
192         editorForm.seteHoldingsFlag(false);
193 
194         ModelAndView modelAndView = null;
195         // get the document details from request and set them in the form.
196         String docCategory = request.getParameter("docCategory");
197         String docType = request.getParameter("docType");
198         String docFormat = request.getParameter("docFormat");
199         String docId = request.getParameter("docId");
200         String bibId = request.getParameter("bibId");
201         String instanceId = request.getParameter("instanceId");
202         String editable = request.getParameter("editable");
203         String callNumberFlag = request.getParameter("isCallNumberFlag");
204 
205 
206         if (null == editable || editable.length() > 0) {
207             editable = "true";
208         }
209 
210         if (docFormat == null || docFormat.length() == 0) {
211             docFormat = ((EditorForm) form).getDocFormat();
212         }
213         if (docId == null || docId.length() == 0) {
214             docId = ((EditorForm) form).getDocId();
215         }
216 
217         if (DocType.ITEM.getCode().equalsIgnoreCase(docType)) {
218             ((EditorForm) form).setItemLocalIdentifier(docId);
219         }
220 
221         /* if (docType.equalsIgnoreCase("holdings")) {
222             ((EditorForm) form).setHoldingLocalIdentifier(docId);
223         }*/
224 
225         // modified code for Global Edit - start
226 
227         if (Boolean.parseBoolean(editorForm.getGlobalEditFlag())) {
228             prepareGlobalEditFields(editorForm, docType);
229         }
230 
231         // modified code for Global Edit - end
232 
233         ((EditorForm) form).setEditable(editable);
234         ((EditorForm) form).setDocCategory(docCategory);
235         ((EditorForm) form).setDocType(docType);
236         ((EditorForm) form).setDocFormat(docFormat);
237 
238         if (DocFormat.MARC.getCode().equals(docFormat) && ((EditorForm) form).getViewId().equalsIgnoreCase(OLEConstants.EDITOR_WORKFORM_VIEW)) {
239             editorForm.setDocumentForm(new WorkBibMarcForm());
240             modelAndView = getUIFModelAndView(form, OLEConstants.EDITOR_WORKFORM_VIEW_PAGE);
241         } else if (DocFormat.MARC.getCode().equals(docFormat)) {
242             editorForm.setDocumentForm(new WorkBibMarcForm());
243             modelAndView = getUIFModelAndView(form, OLEConstants.WORK_BIB_EDITOR_VIEW_PAGE);
244         } else if (DocType.INSTANCE.getCode().equals(docType) || DocType.HOLDINGS.getCode().equals(docType)) {
245             editorForm.setDocumentForm(new WorkInstanceOlemlForm());
246             modelAndView = getUIFModelAndView(form, OLEConstants.WORK_HOLDINGS_VIEW_PAGE);
247         } else if (DocType.EINSTANCE.getCode().equals(docType) || DocType.EHOLDINGS.getCode().equals(docType)) {
248             editorForm.setDocumentForm(new WorkEInstanceOlemlForm());
249             if (Boolean.parseBoolean(editorForm.getGlobalEditFlag())) {
250                 OleHoldings eHoldings = new OleHoldings();
251                 eHoldings.setStatusDate(new java.sql.Date(System.currentTimeMillis()).toString());
252                 eHoldings.setEResourceId(editorForm.geteResourceId());
253                 //getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
254                 if (eHoldings.getExtentOfOwnership() != null && eHoldings.getExtentOfOwnership().size() > 0
255                         && eHoldings.getExtentOfOwnership().get(0).getCoverages() != null
256                         && eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().size() == 0) {
257                     eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(new Coverage());
258                 }
259                 else if (eHoldings.getExtentOfOwnership() == null || eHoldings.getExtentOfOwnership().size() == 0) {
260                     eHoldings.getExtentOfOwnership().add(new ExtentOfOwnership());
261                     eHoldings.getExtentOfOwnership().get(0).setCoverages(new Coverages());
262                     eHoldings.getExtentOfOwnership().get(0).setPerpetualAccesses(new PerpetualAccesses());
263                 }
264                 if (eHoldings.getExtentOfOwnership() != null && eHoldings.getExtentOfOwnership().size() > 0
265                         && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses() != null
266                         && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() == 0) {
267                     eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(new Coverage());
268                     eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().add(new PerpetualAccess());
269                 }
270                 if (eHoldings.getNote() != null && eHoldings.getNote().size() == 0) {
271                     eHoldings.getNote().add(new Note());
272                 }
273                 ((WorkEInstanceOlemlForm)editorForm.getDocumentForm()).setSelectedEHoldings(eHoldings);
274             }
275             modelAndView = getUIFModelAndView(form, OLEConstants.WORK_EINSTANCE_VIEW_PAGE);
276         } else if (DocType.ITEM.getCode().equals(docType)) {
277             editorForm.setDocumentForm(new WorkInstanceOlemlForm());
278             modelAndView = getUIFModelAndView(form, OLEConstants.WORK_ITEM_VIEW_PAGE);
279         }
280         return modelAndView;
281     }
282 
283 
284     /**
285      * Load a (new or existing) document in the editor.
286      *
287      * @param form
288      * @param result
289      * @param request
290      * @param response
291      * @return
292      */
293     @RequestMapping(params = "methodToCall=load")
294     public ModelAndView load(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
295                              HttpServletRequest request, HttpServletResponse response) {
296 
297         String tokenId = request.getParameter("tokenId");
298         EditorForm editorForm = (EditorForm) form;
299         if (tokenId != null) {
300             editorForm.setTokenId(tokenId);
301         }
302         if (editorForm.getBibId() == null) {
303             request.getSession().removeAttribute("treeDocumentList");
304         }
305         if (!isFormInitialized) {
306             super.start(form, result, request, response);
307             isFormInitialized = true;
308         }
309         editorForm.setMainSerialReceivingHistoryList(null);
310         editorForm.setSupplementSerialReceivingHistoryList(null);
311         editorForm.setIndexSerialReceivingHistoryList(null);
312         editorForm.setShowTime(true);
313         // get the document details from request and set them in the form.
314         String docCategory = request.getParameter("docCategory");
315         String docType = request.getParameter("docType");
316         String docFormat = request.getParameter("docFormat");
317         String docId = request.getParameter("docId");
318         String bibId = request.getParameter("bibId");
319         String instanceId = request.getParameter("instanceId");
320         String editable = request.getParameter("editable");
321         String callNumberFlag = request.getParameter("isCallNumberFlag");
322         String eResourceId = request.getParameter("eResourceId");
323         String holdingsId = request.getParameter("holdingsId");
324         String fromSearch = request.getParameter("fromSearch");
325 
326         //Verifying editable at form object
327         if ((null == editable) || (editable.length() == 0)) {
328             editable = ((EditorForm) form).getEditable();
329         }
330 
331         //Default value for editable field if it is null
332         if (null == editable || editable.length() == 0) {
333             editable = "true";
334         }
335 
336         if (StringUtils.isBlank(docId)) {
337             editorForm.setNewDocument(true);
338         }
339 
340         /*if (docType.equalsIgnoreCase("item")) {
341             ((EditorForm) form).setItemLocalIdentifier(docId);
342         }*/
343 
344         if (docType.equalsIgnoreCase("holdings")) {
345             if(StringUtils.isNotEmpty(docId) && !DocumentUniqueIDPrefix.hasPrefix(docId)){
346                 docId="who-" +docId;
347             }
348             ((EditorForm) form).setInstanceId(docId);
349         }
350 
351         if (docType.equalsIgnoreCase("item")) {
352             if(StringUtils.isNotEmpty(docId) && !DocumentUniqueIDPrefix.hasPrefix(docId)){
353                 docId="wio-" +docId;
354             }
355         }
356         if (docType.equalsIgnoreCase("instance")) {
357             ((EditorForm) form).setInstanceId(docId);
358         }
359         ((EditorForm) form).setEditable(editable);
360         ((EditorForm) form).setDocCategory(docCategory);
361         ((EditorForm) form).setDocType(docType);
362         ((EditorForm) form).setDocFormat(docFormat);
363         ((EditorForm) form).setDocId(docId);
364         ((EditorForm) form).setBibId(bibId);
365         ((EditorForm) form).setCallNumberFlag(callNumberFlag);
366         ((EditorForm) form).setFromSearch(Boolean.valueOf(fromSearch));
367         ((EditorForm) form).setHideFooter(true);
368         boolean canDelete = canDeleteItem(GlobalVariables.getUserSession().getPrincipalId()) && canDeleteInstance(GlobalVariables.getUserSession().getPrincipalId());
369         ((EditorForm) form).setCanDelete(canDelete);
370         boolean canAdd = canAddItem(GlobalVariables.getUserSession().getPrincipalId());
371         ((EditorForm) form).setCanAdd(canAdd);
372         //if the user doesn't have permission to add or edit item, editable will be set as false
373         if (!canAdd) {
374             ((EditorForm) form).setEditable(String.valueOf(canAdd));
375         }
376         boolean canDeleteEInstance = canDeleteEInstance(GlobalVariables.getUserSession().getPrincipalId());
377         ((EditorForm) form).setCanDeleteEInstance(canDeleteEInstance);
378 
379         if (eResourceId != null) {
380             ((EditorForm) form).seteResourceId(eResourceId);
381         }
382         if (holdingsId != null) {
383             ((EditorForm) form).setHoldingsId(holdingsId);
384         }
385         // Identify the document editor to be used for the requested document.
386         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
387                 .getDocumentEditor(docCategory, docType, docFormat);
388 
389         // TODO: Need to save the editorForm in the session.
390         // Get documentList from session.
391         /*List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
392         if (null != workBibDocumentList) {
393             ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
394         }*/
395 
396         List<BibTree> bibTreeList = (List) request.getSession().getAttribute("treeDocumentList");
397         if (null != bibTreeList) {
398             ((EditorForm) form).setBibTreeList(bibTreeList);
399         }
400         if ("bibliographic".equals(editorForm.getDocType())) {
401             editorForm.setBibFlag(false);
402         }
403         if ("holdings".equals(editorForm.getDocType())) {
404             editorForm.setHoldingFlag(false);
405         }
406         if ("item".equals(editorForm.getDocType())) {
407             editorForm.setItemFlag(false);
408         }
409         if ("eHoldings".equals(editorForm.getDocType())) {
410             editorForm.seteHoldingsFlag(false);
411         }
412 
413         EditorForm documentForm = null;
414         //get request object fromm session and build new work bib marc record.
415         if (request.getSession() != null && request.getSession().getAttribute("bibTree") != null &&
416                 "true".equalsIgnoreCase(request.getParameter("loadFromSession"))) {
417             BibTree bibTree = (BibTree) request.getSession().getAttribute("bibTree");
418             if (docId != null && docId.length() > 0 && !docId.equalsIgnoreCase("null")) {
419                 ((EditorForm) form).setShowLeftPane(false);
420             } else {
421                 ((EditorForm) form).setShowLeftPane(false);
422                 ((EditorForm) form).setShowEditorFooter(false);
423             }
424             documentForm = documentEditor.createNewRecord((EditorForm) form, bibTree);
425         } else {
426             // Send the input through one (request)form and get the output through another (response) form.
427             documentForm = documentEditor.loadDocument((EditorForm) form);
428             if (documentForm instanceof WorkInstanceOlemlForm) {
429                 Item item = ((WorkInstanceOlemlForm) documentForm).getSelectedItem();
430                 if (item.getCurrentBorrower() != null && !item.getCurrentBorrower().isEmpty()) {
431                     OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OlePatronDocument.class, item.getCurrentBorrower());
432                     ((WorkInstanceOlemlForm) documentForm).setCurrentBarcode(olePatronDocument.getBarcode());
433                 }
434                 if (item.getProxyBorrower() != null && !item.getProxyBorrower().isEmpty()) {
435                     OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OlePatronDocument.class, item.getProxyBorrower());
436                     ((WorkInstanceOlemlForm) documentForm).setProxyBarcode(olePatronDocument.getBarcode());
437                 }
438                 setClaimsAndDamagedPatronBarcode(item);
439                 setMissingPieceItemRecord(item);
440             }
441         }
442 
443         // Set the output (response) form containing document info into the current form.
444         ((EditorForm) form).setDocumentForm(documentForm);
445         // Set documentlist to session.
446         request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getDocumentForm().getBibTreeList());
447 
448         // Build or update left pane data (tree structure of documents)
449         getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
450 
451         // Return the next view to be shown to user.
452         ModelAndView modelAndView = getUIFModelAndView(form, documentForm.getViewId());
453         return modelAndView;
454     }
455 
456     private void setClaimsAndDamagedPatronBarcode(Item item) {
457         if(CollectionUtils.isNotEmpty(item.getItemClaimsReturnedRecords())){
458             for(int index=0 ; index < item.getItemClaimsReturnedRecords().size() ; index++){
459                 if(item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronId() != null && !item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronId().isEmpty()){
460                     OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OlePatronDocument.class,item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronId());
461                     if(olePatronDocument != null){
462                         item.getItemClaimsReturnedRecords().get(index).setClaimsReturnedPatronBarcode(olePatronDocument.getBarcode());
463                     }
464                 } else if(item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronBarcode() != null && !item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronBarcode().isEmpty()) {
465                     Map criteria = new HashMap();
466                     criteria.put("barcode",item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronBarcode());
467                     List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>)KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class,criteria);
468                     if(olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
469                         for(OlePatronDocument olePatronDocument : olePatronDocumentList) {
470                             item.getItemClaimsReturnedRecords().get(index).setClaimsReturnedPatronId(olePatronDocument.getOlePatronId());
471                         }
472                     } else {
473                         criteria = new HashMap();
474                         criteria.put("invalidOrLostBarcodeNumber", item.getItemClaimsReturnedRecords().get(index).getClaimsReturnedPatronBarcode());
475                         List<OlePatronLostBarcode> olePatronLostBarcodeList = (List<OlePatronLostBarcode>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class, criteria);
476                         if(CollectionUtils.isNotEmpty(olePatronLostBarcodeList)){
477                             for(OlePatronLostBarcode olePatronLostBarcode : olePatronLostBarcodeList) {
478                                 item.getItemClaimsReturnedRecords().get(index).setClaimsReturnedPatronId(olePatronLostBarcode.getOlePatronId());
479                             }
480                         }
481                     }
482                 }
483             }
484         }
485         if(CollectionUtils.isNotEmpty(item.getItemDamagedRecords())){
486             for(int index=0 ; index < item.getItemDamagedRecords().size() ; index++){
487                 if(item.getItemDamagedRecords().get(index).getDamagedPatronId() != null && !item.getItemDamagedRecords().get(index).getDamagedPatronId().isEmpty()){
488                     OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OlePatronDocument.class,item.getItemDamagedRecords().get(index).getDamagedPatronId());
489                     if(olePatronDocument != null){
490                         item.getItemDamagedRecords().get(index).setPatronBarcode(olePatronDocument.getBarcode());
491                     }
492                 } else if(item.getItemDamagedRecords().get(index).getPatronBarcode() != null && !item.getItemDamagedRecords().get(index).getPatronBarcode().isEmpty()) {
493                     Map criteria = new HashMap();
494                     criteria.put("barcode",item.getItemDamagedRecords().get(index).getPatronBarcode());
495                     List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>)KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class,criteria);
496                     if(olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
497                         for(OlePatronDocument olePatronDocument : olePatronDocumentList) {
498                             item.getItemDamagedRecords().get(index).setDamagedPatronId(olePatronDocument.getOlePatronId());
499                         }
500                     } else {
501                         criteria = new HashMap();
502                         criteria.put("invalidOrLostBarcodeNumber", item.getItemDamagedRecords().get(index).getPatronBarcode());
503                         List<OlePatronLostBarcode> olePatronLostBarcodeList = (List<OlePatronLostBarcode>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class, criteria);
504                         if(CollectionUtils.isNotEmpty(olePatronLostBarcodeList)){
505                             for(OlePatronLostBarcode olePatronLostBarcode : olePatronLostBarcodeList) {
506                                 item.getItemDamagedRecords().get(index).setDamagedPatronId(olePatronLostBarcode.getOlePatronId());
507                             }
508                         }
509                     }
510                 }
511             }
512         }
513     }
514 
515     public void setMissingPieceItemRecord (Item item){
516         if(item.getMissingPieceItemRecordList() != null && !item.getMissingPieceItemRecordList().isEmpty()){
517             for(int index=0 ; index < item.getMissingPieceItemRecordList().size() ; index++){
518                 if(item.getMissingPieceItemRecordList().get(index).getPatronId() != null && !item.getMissingPieceItemRecordList().get(index).getPatronId().isEmpty()){
519                     OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OlePatronDocument.class, item.getMissingPieceItemRecordList().get(index).getPatronId());
520                     if(olePatronDocument != null ){
521                         item.getMissingPieceItemRecordList().get(index).setPatronBarcode(olePatronDocument.getBarcode());
522                     }
523                 }else if(item.getMissingPieceItemRecordList().get(index).getPatronBarcode() != null && !item.getMissingPieceItemRecordList().get(index).getPatronBarcode().isEmpty()){
524                     Map map = new HashMap();
525                     map.put("patronBarcode" ,item.getMissingPieceItemRecordList().get(index).getPatronBarcode());
526                     List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>)KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class ,map );
527                     if(!CollectionUtils.isEmpty(olePatronDocumentList)){
528                         for(OlePatronDocument olePatronDocument : olePatronDocumentList){
529                             item.getMissingPieceItemRecordList().get(index).setPatronId(olePatronDocument.getOlePatronId());
530                         }
531                     }
532                 }else{
533                     Map criteria1 = new HashMap();
534                     criteria1.put("invalidOrLostBarcodeNumber" ,item.getMissingPieceItemRecordList().get(index).getPatronBarcode());
535                     List<OlePatronLostBarcode> olePatronLostBarcodeList = (List<OlePatronLostBarcode>)KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class , criteria1);
536                     if(olePatronLostBarcodeList != null && olePatronLostBarcodeList.size()>0){
537                         for(OlePatronLostBarcode olePatronLostBarcode : olePatronLostBarcodeList){
538                             item.getMissingPieceItemRecordList().get(index).setPatronId(olePatronLostBarcode.getOlePatronId());
539                         }
540                     }
541                 }
542             }
543         }
544     }
545 
546     @RequestMapping(params = "methodToCall=updateLeftPane")
547     public ModelAndView updateLeftPane(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
548                                        HttpServletRequest request, HttpServletResponse response) {
549         EditorForm editorForm = (EditorForm) form;
550         String hiddenVal = editorForm.getHdnUuid();
551         int hdnIndex = editorForm.getHdnIndex();
552         DiscoveryHelperService discoveryHelperService = getDiscoveryHelperService();
553         List responseFromSOLR = discoveryHelperService.getResponseFromSOLR("id", hiddenVal);
554         String docType = null;
555         for (Iterator iterator = responseFromSOLR.iterator(); iterator.hasNext(); ) {
556             Map map = (Map) iterator.next();
557             if (map.containsKey(OLEConstants.DOC_TYPE)) {
558                 String list = (String) map.get(OLEConstants.DOC_TYPE);
559                 docType = list;
560                 break;
561             }
562         }
563         if ((docType.toString().equals(OLEConstants.ITEM_DOC_TYPE))) {
564             WorkInstanceOlemlForm instanceEditorForm = new WorkInstanceOlemlForm();
565             //instanceEditorForm.setInstance(editorForm.getInstance());
566             //instanceEditorForm.setUuid(editorForm.getInstance().getInstanceIdentifier());
567             //editor = new WorkInstanceOlemlEditor();
568             //instanceEditorForm.setSelectedItem(editorForm.getInstance().getItems().getItem().get(hdnIndex));
569             //return getUIFModelAndView(editorForm, "WorkItemViewPage");
570             //ModelAndView modelAndView = editor.load(form, result, request, response);
571             //return modelAndView;
572             return null;
573         } else {
574             //editorForm.setSelectedHolding(editorForm.getInstance().getOleHoldings());
575             return getUIFModelAndView(editorForm, "WorkHoldingsViewPage");
576         }
577     }
578 
579     public DiscoveryHelperService getDiscoveryHelperService() {
580         if (null == discoveryHelperService) {
581             return new DiscoveryHelperService();
582         }
583         return discoveryHelperService;
584     }
585 
586     public EditorFormDataHandler getEditorFormDataHandler() {
587         if (null == editorFormDataHandler) {
588             editorFormDataHandler = new EditorFormDataHandler();
589         }
590         return editorFormDataHandler;
591     }
592 
593     @RequestMapping(params = "methodToCall=EditNewInstance")
594     public ModelAndView EditNewInstance(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
595                                         HttpServletRequest request, HttpServletResponse response) {
596 
597         EditorForm editorForm = (EditorForm) form;
598         // get request object from session
599         BibTree bibTree = (BibTree) request.getSession().getAttribute("bibTree");
600         // Get documentList from session.
601         /*List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
602         if (null != workBibDocumentList) {
603             ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
604         }*/
605         if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkHoldingsViewPage")) {
606             // call instance editor
607             DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
608                     .getDocumentEditor("work", "item", "oleml");
609             // set item record to display on item tab
610             editorForm = documentEditor.createNewRecord((EditorForm) form, bibTree);
611             editorForm.setNeedToCreateInstance(false);
612 
613         } else {
614             // call bib editor to store bib data
615             DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
616                     .getDocumentEditor("work", "bibliographic", "marc");
617             // update request object with modified marc data.
618             EditorForm marcEditorForm = documentEditor.editNewRecord(editorForm, bibTree);
619 
620             // validate bib before going to instance
621             if (!marcEditorForm.isValidInput()) {
622                 return getUIFModelAndView(form, marcEditorForm.getViewId());
623             }
624 
625             // call instance editor and set holding record to display on holding tab
626             documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor("work", "holdings", "oleml");
627             ((EditorForm) form).setDocCategory("work");
628             ((EditorForm) form).setDocType("holdings");
629             ((EditorForm) form).setDocFormat("oleml");
630             editorForm = documentEditor.createNewRecord((EditorForm) form, bibTree);
631         }
632 
633         // Set the output (response) form containing document info into the current form.
634         ((EditorForm) form).setDocumentForm(editorForm);
635         // Set documentlist to session.
636         //request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
637 
638         // Build or update left pane data (tree structure of documents)
639         getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
640 
641         // Return the next view to be shown to user.
642         ModelAndView modelAndView = getUIFModelAndView(form, editorForm.getViewId());
643         return modelAndView;
644 
645     }
646 
647     @RequestMapping(params = "methodToCall=save")
648     public ModelAndView save(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
649                              HttpServletRequest request, HttpServletResponse response) {
650         long startTime = System.currentTimeMillis();
651         if ("bibliographic".equals(((EditorForm) form).getDocType())) {
652             ((EditorForm) form).setBibFlag(false);
653         }
654         if ("holdings".equals(((EditorForm) form).getDocType())) {
655             ((EditorForm) form).setHoldingFlag(false);
656         }
657         if ("item".equals(((EditorForm) form).getDocType())) {
658             ((EditorForm) form).setItemFlag(false);
659         }
660         if ("eHoldings".equals(((EditorForm) form).getDocType())) {
661             ((EditorForm) form).seteHoldingsFlag(false);
662         }
663         if (request.getSession() != null && request.getSession().getAttribute("bibTree") != null) {
664             DocumentEditor documentEditor = null;
665             if (((EditorForm) form).getDocId() == null || "null".equalsIgnoreCase(((EditorForm) form).getDocId())) {
666                 documentEditor = DocumentEditorFactory.getInstance()
667                         .getDocumentEditor("work", "item", "oleml");
668             } else {
669                 documentEditor = DocumentEditorFactory.getInstance()
670                         .getDocumentEditor("work", "bibliographic", "marc");
671             }
672 
673             BibTree bibTree = (BibTree) request.getSession().getAttribute("bibTree");
674             EditorForm editorForm = documentEditor.editNewRecord((EditorForm) form, bibTree);
675 
676             // validate user entered item data before saving to docstore.
677             if (!editorForm.isValidInput()) {
678                 return getUIFModelAndView(form, editorForm.getViewId());
679             }
680 
681             String responseFromDocstore = documentEditor.saveDocument(bibTree, (EditorForm) form);
682             if (StringUtils.isNotEmpty(responseFromDocstore) && responseFromDocstore.contains("success")) {
683                 request.getSession().setAttribute("responseBibTree", bibTree);
684 
685                 String url = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
686                 url = url + "/portal.do?channelTitle=Import Bib&channelUrl=" + url +
687                         "/ole-kr-krad/importBibController?viewId=ImportBibView&methodToCall=viewRecordNext";
688                 return performRedirect(editorForm, url);
689             }
690         } else {
691             if (!isFormInitialized) {
692                 super.start(form, result, request, response);
693                 isFormInitialized = true;
694             }
695 
696             // get the document details from request and set them in the form.
697             String docCategory = request.getParameter("docCategory");
698             String docType = request.getParameter("docType");
699             String docFormat = request.getParameter("docFormat");
700             String docId = request.getParameter("docId");
701             String bibId = request.getParameter("bibId");
702             String instanceId = request.getParameter("instanceId");
703 
704             String editable = request.getParameter("editable");
705 
706             if (docType != null && docType.equalsIgnoreCase("item")) {
707                 ((EditorForm) form).setItemLocalIdentifier(docId);
708             }
709 
710             /* if (docType != null && docType.equalsIgnoreCase("holdings")) {
711                 ((EditorForm) form).setHoldingLocalIdentifier(docId);
712             }*/
713 
714             if ((null == editable) || (editable.length() == 0)) {
715                 editable = "true";
716             }
717             if (docCategory == null || docCategory.length() == 0) {
718                 docCategory = ((EditorForm) form).getDocCategory();
719             }
720             if (docType == null || docType.length() == 0) {
721                 docType = ((EditorForm) form).getDocType();
722             }
723 
724             if (docFormat == null || docFormat.length() == 0) {
725                 docFormat = ((EditorForm) form).getDocFormat();
726             }
727             if (docId == null || docId.length() == 0) {
728                 docId = ((EditorForm) form).getDocId();
729             }
730 
731             ((EditorForm) form).setEditable(editable);
732             ((EditorForm) form).setDocCategory(docCategory);
733             ((EditorForm) form).setDocType(docType);
734             ((EditorForm) form).setDocFormat(docFormat);
735             ((EditorForm) form).setDocId(docId);
736             ((EditorForm) form).setBibId(bibId);
737             ((EditorForm) form).setInstanceId(instanceId);
738 
739             // Identify the document editor to be used for the requested document.
740             DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
741                     .getDocumentEditor(docCategory, docType, docFormat);
742 
743             // TODO: Need to save the editorForm in the session.
744             // Get documentList from session.
745             /* List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
746             if (null != workBibDocumentList) {
747                 ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
748             }*/
749 
750             List<BibTree> bibTreeList = (List) request.getSession().getAttribute("treeDocumentList");
751             if (null != bibTreeList) {
752                 ((EditorForm) form).getDocumentForm().setBibTreeList(bibTreeList);
753                 ((EditorForm) form).setBibTreeList(bibTreeList);
754             }
755             if("overwrite".equals(((EditorForm) form).getCheckOverwriteFlag())) {
756                 EditorForm documentForm = documentEditor.saveDocument((EditorForm) form);
757                 if (documentForm instanceof WorkInstanceOlemlForm) {
758                     Item item = ((WorkInstanceOlemlForm) documentForm).getSelectedItem();
759                     setClaimsAndDamagedPatronBarcode(item);
760                     setMissingPieceItemRecord(item);
761                 }
762                 ((EditorForm) form).setDocumentForm(documentForm);
763             } else {
764                 if (documentEditor.isValidUpdate((EditorForm) form) && ((EditorForm) form).getAllowUpdate().equals
765                         ("true") || documentEditor.isValidUpdate((EditorForm) form) && ((EditorForm) form).getAllowUpdate().equals
766                         ("")) {
767                     // Send the input through one (request)form and get the output through another (response) form.
768                     EditorForm documentForm = documentEditor.saveDocument((EditorForm) form);
769                     if (documentForm instanceof WorkInstanceOlemlForm) {
770                         Item item = ((WorkInstanceOlemlForm) documentForm).getSelectedItem();
771                         setClaimsAndDamagedPatronBarcode(item);
772                         setMissingPieceItemRecord(item);
773                     }
774                     // Set the output (response) form containing docum ((EditorForm) form).isAllowUpdate()ent info into the current form.
775                     ((EditorForm) form).setDocumentForm(documentForm);
776                     ((EditorForm) form).setAllowUpdate("true");
777                 } else {
778                     ((EditorForm) form).setAllowUpdate("false");
779                     // EditorForm documentForm = documentEditor.loadDocument((EditorForm) form);
780                     // ((EditorForm) form).setDocumentForm(documentForm);
781                 }
782 
783             }
784             ((EditorForm) form).setCheckOverwriteFlag("");
785             // Set documentlist to session.
786             request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getDocumentForm().getBibTreeList());
787 
788             // Build or update left pane data (tree structure of documents)
789             getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
790 
791         }
792         ((EditorForm) form).setDisplayField006(Boolean.FALSE.toString());
793         ((EditorForm) form).setDisplayField007(Boolean.FALSE.toString());
794         ((EditorForm) form).setDisplayField008(Boolean.FALSE.toString());
795         ((EditorForm) form).setBibFlag(false);
796         ((EditorForm) form).setHoldingFlag(false);
797         ((EditorForm) form).setItemFlag(false);
798         ((EditorForm) form).seteHoldingsFlag(false);
799 
800         if (StringUtils.isBlank(((EditorForm) form).getDocId()) && GlobalVariables.getMessageMap().getErrorCount() > 0) {
801             ((EditorForm) form).setNewDocument(true);
802         } else {
803             ((EditorForm) form).setNewDocument(false);
804         }
805 
806         // Return the next view to be shown to user.
807         long endTime = System.currentTimeMillis();
808         ((EditorForm) form).setTotalTime(String.valueOf((endTime-startTime)/1000));
809         ModelAndView modelAndView = getUIFModelAndView(form, ((EditorForm) form).getDocumentForm().getViewId());
810         return modelAndView;
811     }
812 
813     /**
814      * This method will add the controlField 006 record based on the selected Line index and updates the component.
815      *
816      * @param form
817      * @param result
818      * @param request
819      * @param response
820      * @return ModelAndView
821      */
822     @RequestMapping(params = "methodToCall=addControlField006")
823     public ModelAndView addControlField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
824                                         HttpServletRequest request, HttpServletResponse response) {
825         if (!isFormInitialized) {
826             super.start(form, result, request, response);
827             isFormInitialized = true;
828         }
829         EditorForm editorForm = (EditorForm) form;
830         String docCategory = request.getParameter("docCategory");
831         String docType = request.getParameter("docType");
832         String docFormat = request.getParameter("docFormat");
833         if (docCategory == null) {
834             docCategory = editorForm.getDocCategory();
835         }
836         if (docType == null) {
837             docType = editorForm.getDocType();
838         }
839         if (docFormat == null) {
840             docFormat = editorForm.getDocFormat();
841         }
842 
843         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
844                 .getDocumentEditor(docCategory, docType, docFormat);
845 
846         editorForm = documentEditor.addORDeleteFields(editorForm, request);
847         return super.navigate(editorForm, result, request, response);
848     }
849 
850     /**
851      * This method will remove the controlField  006 based on the index position and updates the component.
852      *
853      * @param form
854      * @param result
855      * @param request
856      * @param response
857      * @return ModelAndView
858      */
859     @RequestMapping(params = "methodToCall=removeControlField006")
860     public ModelAndView removeControlField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
861                                            HttpServletRequest request, HttpServletResponse response) {
862         if (!isFormInitialized) {
863             super.start(form, result, request, response);
864             isFormInitialized = true;
865         }
866         EditorForm editorForm = (EditorForm) form;
867         String docCategory = request.getParameter("docCategory");
868         String docType = request.getParameter("docType");
869         String docFormat = request.getParameter("docFormat");
870         if (docCategory == null) {
871             docCategory = editorForm.getDocCategory();
872         }
873         if (docType == null) {
874             docType = editorForm.getDocType();
875         }
876         if (docFormat == null) {
877             docFormat = editorForm.getDocFormat();
878         }
879 
880         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
881                 .getDocumentEditor(docCategory, docType, docFormat);
882 
883         editorForm = documentEditor.addORDeleteFields(editorForm, request);
884         return super.navigate(editorForm, result, request, response);
885     }
886 
887 
888     /**
889      * This method will add the controlField 007 record based on the selected Line index and updates the component.
890      *
891      * @param form
892      * @param result
893      * @param request
894      * @param response
895      * @return ModelAndView
896      */
897     @RequestMapping(params = "methodToCall=addControlField007")
898     public ModelAndView addControlField007(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
899                                            HttpServletRequest request, HttpServletResponse response) {
900         if (!isFormInitialized) {
901             super.start(form, result, request, response);
902             isFormInitialized = true;
903         }
904         EditorForm editorForm = (EditorForm) form;
905         String docCategory = request.getParameter("docCategory");
906         String docType = request.getParameter("docType");
907         String docFormat = request.getParameter("docFormat");
908         if (docCategory == null) {
909             docCategory = editorForm.getDocCategory();
910         }
911         if (docType == null) {
912             docType = editorForm.getDocType();
913         }
914         if (docFormat == null) {
915             docFormat = editorForm.getDocFormat();
916         }
917 
918         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
919                 .getDocumentEditor(docCategory, docType, docFormat);
920 
921         editorForm = documentEditor.addORDeleteFields(editorForm, request);
922         return super.navigate(editorForm, result, request, response);
923     }
924 
925     /**
926      * This method will remove the controlField  007 based on the index position and updates the component.
927      *
928      * @param form
929      * @param result
930      * @param request
931      * @param response
932      * @return ModelAndView
933      */
934     @RequestMapping(params = "methodToCall=removeControlField007")
935     public ModelAndView removeControlField007(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
936                                               HttpServletRequest request, HttpServletResponse response) {
937         if (!isFormInitialized) {
938             super.start(form, result, request, response);
939             isFormInitialized = true;
940         }
941         EditorForm editorForm = (EditorForm) form;
942         String docCategory = request.getParameter("docCategory");
943         String docType = request.getParameter("docType");
944         String docFormat = request.getParameter("docFormat");
945         if (docCategory == null) {
946             docCategory = editorForm.getDocCategory();
947         }
948         if (docType == null) {
949             docType = editorForm.getDocType();
950         }
951         if (docFormat == null) {
952             docFormat = editorForm.getDocFormat();
953         }
954 
955         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
956                 .getDocumentEditor(docCategory, docType, docFormat);
957 
958         editorForm = documentEditor.addORDeleteFields(editorForm, request);
959         return super.navigate(editorForm, result, request, response);
960     }
961 
962 
963     /**
964      * This method will add the datField record based on the selected Line index and updates the component.
965      *
966      * @param form
967      * @param result
968      * @param request
969      * @param response
970      * @return ModelAndView
971      */
972     @RequestMapping(params = "methodToCall=addDataField")
973     public ModelAndView addDataField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
974                                      HttpServletRequest request, HttpServletResponse response) {
975         if (!isFormInitialized) {
976             super.start(form, result, request, response);
977             isFormInitialized = true;
978         }
979         EditorForm editorForm = (EditorForm) form;
980         String docCategory = request.getParameter("docCategory");
981         String docType = request.getParameter("docType");
982         String docFormat = request.getParameter("docFormat");
983         if (docCategory == null) {
984             docCategory = editorForm.getDocCategory();
985         }
986         if (docType == null) {
987             docType = editorForm.getDocType();
988         }
989         if (docFormat == null) {
990             docFormat = editorForm.getDocFormat();
991         }
992 
993         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
994                 .getDocumentEditor(docCategory, docType, docFormat);
995 
996         editorForm = documentEditor.addORDeleteFields(editorForm, request);
997         return super.navigate(editorForm, result, request, response);
998     }
999 
1000     /**
1001      * This method will remove the dataField based on the index position and updates the component.
1002      *
1003      * @param form
1004      * @param result
1005      * @param request
1006      * @param response
1007      * @return ModelAndView
1008      */
1009     @RequestMapping(params = "methodToCall=removeDataField")
1010     public ModelAndView removeDataField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1011                                         HttpServletRequest request, HttpServletResponse response) {
1012         if (!isFormInitialized) {
1013             super.start(form, result, request, response);
1014             isFormInitialized = true;
1015         }
1016         EditorForm editorForm = (EditorForm) form;
1017         String docCategory = request.getParameter("docCategory");
1018         String docType = request.getParameter("docType");
1019         String docFormat = request.getParameter("docFormat");
1020         if (docCategory == null) {
1021             docCategory = editorForm.getDocCategory();
1022         }
1023         if (docType == null) {
1024             docType = editorForm.getDocType();
1025         }
1026         if (docFormat == null) {
1027             docFormat = editorForm.getDocFormat();
1028         }
1029 
1030         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1031                 .getDocumentEditor(docCategory, docType, docFormat);
1032 
1033         editorForm = documentEditor.addORDeleteFields(editorForm, request);
1034         return super.navigate(editorForm, result, request, response);
1035     }
1036 
1037 /*
1038     private UifFormBase buildUifForm (HttpServletRequest httpServletRequest) {
1039         UifFormBase uifFormBase = null;
1040 
1041         String docType = httpServletRequest.getParameter("docType");
1042         String docFormat = httpServletRequest.getParameter("docFormat");
1043         if ("bibliographic".equalsIgnoreCase(docType)) {
1044             if ("marc".equalsIgnoreCase(docFormat)) {
1045                 LOG.info("Inside EditorController createInitialForm if bibliographic marc");
1046                 editor = new WorkBibMarcEditor();
1047                 uifFormBase = editor.createInitialForm(httpServletRequest);
1048             } else if ("dublin".equalsIgnoreCase(docFormat)) {
1049                 editor = new WorkBibDublinEditor();
1050                 uifFormBase = editor.createInitialForm(httpServletRequest);
1051             }
1052         } else if ("instance".equalsIgnoreCase(docType)) {
1053             if ("oleml".equalsIgnoreCase(docFormat)) {
1054                 editor = new WorkInstanceOlemlEditor();
1055                 uifFormBase = editor.createInitialForm(httpServletRequest);
1056             }
1057         } else if ("holdings".equalsIgnoreCase(docType) || "item".equalsIgnoreCase(docType)) {
1058             if ("oleml".equalsIgnoreCase(docFormat)) {
1059                 editor = new WorkInstanceOlemlEditor();
1060                 uifFormBase = editor.createInitialForm(httpServletRequest);
1061             }
1062         }
1063         return uifFormBase;
1064 
1065     }
1066 */
1067 
1068     /**
1069      * DeleteVerify a  document in the editor.
1070      *
1071      * @param form
1072      * @param result
1073      * @param request
1074      * @param response
1075      * @return
1076      */
1077     @RequestMapping(params = "methodToCall=deleteVerify")
1078     public ModelAndView deleteVerify(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1079                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
1080         ModelAndView modelAndView = null;
1081         if (!isFormInitialized) {
1082             super.start(form, result, request, response);
1083             isFormInitialized = true;
1084         }
1085 
1086         // get the document details from request and set them in the form.
1087         String docCategory = request.getParameter("docCategory");
1088         String docType = request.getParameter("docType");
1089         String docFormat = request.getParameter("docFormat");
1090         String docId = request.getParameter("docId");
1091         ((EditorForm) form).setDocCategory(docCategory);
1092         ((EditorForm) form).setDocType(docType);
1093         ((EditorForm) form).setDocFormat(docFormat);
1094         ((EditorForm) form).setDocId(docId);
1095         ((EditorForm) form).setMessage("");
1096 //        ((EditorForm) form).setEditable("false");
1097         ((EditorForm) form).setHideFooter(false);
1098 
1099         DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
1100         EditorForm documentForm = documentEditor.deleteVerify((EditorForm) form);
1101         LOG.info("view id-->" + documentForm.getViewId());
1102         //List<String> uuidList  = new ArrayList<String>();
1103         EditorForm editorForm = (EditorForm) form;
1104         //uuidList.add(docId);
1105 
1106 /*        DocumentSelectionTree dst = new DocumentSelectionTree();
1107         LOG.info("get uud list from form-->"+editorForm.getUuidList());
1108         Node<DocumentTreeNode, String> rootNode = dst.add(editorForm.getUuidList());
1109 
1110          editorForm.getDocTree().setRootElement(rootNode);*/
1111 
1112         return getUIFModelAndView(editorForm, documentForm.getViewId());
1113 /*
1114         System.out.println("delete verify method is executed-----1");
1115 
1116         ((EditorForm) form).setDocCategory(docCategory);
1117         ((EditorForm) form).setDocType(docType);
1118         ((EditorForm) form).setDocFormat(docFormat);
1119         ((EditorForm) form).setDocId(docId);
1120 
1121         // Identify the document editor to be used for the requested document.
1122         DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
1123         System.out.println("delete verify method is executed-----2");
1124         //EditorForm documentForm = null;
1125         EditorForm documentForm = documentEditor.deleteVerify((EditorForm) form);
1126         ((EditorForm) form).setDocumentForm(documentForm);
1127 
1128         try {
1129             documentForm = documentEditor.deleteVerify((EditorForm) form);
1130             modelAndView =getUIFModelAndView(form,documentForm.getViewId());
1131             System.out.println("delete verify method is executed-----3");
1132         }catch (Exception e) {
1133             modelAndView =getUIFModelAndView(form,"WorkBibEditorViewPage");
1134             System.out.println("delete verify method is executed-----4");
1135         }
1136         System.out.println("delete verify method is executed-----5");
1137         return modelAndView;
1138 */
1139     }
1140 
1141     /**
1142      * Delete a  document in the editor.
1143      *
1144      * @param form
1145      * @param result
1146      * @param request
1147      * @param response
1148      * @return
1149      */
1150     @RequestMapping(params = "methodToCall=delete")
1151     public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1152                                HttpServletRequest request, HttpServletResponse response) throws Exception {
1153         ModelAndView modelAndView = null;
1154         EditorForm editorForm = (EditorForm) form;
1155         if (!isFormInitialized) {
1156             super.start(form, result, request, response);
1157             isFormInitialized = true;
1158         }
1159 
1160         // get the document details from request and set them in the form.
1161         String docCategory = ((EditorForm) form).getDocCategory();
1162         String docType = ((EditorForm) form).getDocType();
1163         String docFormat = ((EditorForm) form).getDocFormat();
1164         String docId = ((EditorForm) form).getDocId();
1165 
1166 
1167         LOG.info("docCategory-->" + docCategory);
1168         LOG.info("docType-->" + docType);
1169         LOG.info("docFormat-->" + docFormat);
1170         LOG.info("uuid-->" + docId);
1171 
1172 
1173 /*        ((EditorForm) form).setDocCategory(docCategory);
1174         ((EditorForm) form).setDocType(docType);
1175         ((EditorForm) form).setDocFormat(docFormat);
1176         ((EditorForm) form).setUuid(docId);*/
1177 
1178         // Identify the document editor to be used for the requested document.
1179         DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
1180 
1181         EditorForm documentForm = documentEditor.delete((EditorForm) form);
1182 
1183         /*       //boolean hasLinks = delete();
1184         try {
1185 
1186             modelAndView =getUIFModelAndView(form,"deleteConfirmation");
1187         } catch (Exception e) {
1188             modelAndView =getUIFModelAndView(form,"");
1189             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
1190         }*/
1191         // Send the input through one (request)form and get the output through another (response) form.
1192 
1193         // Build or update left pane data (tree structure of documents)
1194         getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
1195 
1196         // Redirect to bib page after deleting eholdings.
1197         //Commented the code for the jira OLE-6862
1198         /*if (documentForm.isCanDeleteEHoldings() && docType.equalsIgnoreCase(DocType.EHOLDINGS.getCode())) {
1199             String url = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
1200             url = url + "/portal.do?channelTitle=Editor&channelUrl=" + url +
1201                     "/ole-kr-krad/editorcontroller?viewId=EditorView&methodToCall=load&docCategory=work&docType=bibliographic&docFormat=marc&bibId=&editable=true&docId=" + editorForm.getBibId();
1202             return performRedirect(editorForm, url);
1203         }*/
1204 
1205         return getUIFModelAndView(editorForm, documentForm.getViewId());
1206     }
1207 
1208     /**
1209      * This method will add the ExtentOfOwnership record based on the selected Line index and updates the component.
1210      *
1211      * @param form
1212      * @param result
1213      * @param request
1214      * @param response
1215      * @return ModelAndView
1216      */
1217     @RequestMapping(params = "methodToCall=addExtentOfOwnership")
1218     public ModelAndView addExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1219                                              HttpServletRequest request, HttpServletResponse response) {
1220         if (!isFormInitialized) {
1221             super.start(form, result, request, response);
1222             isFormInitialized = true;
1223         }
1224         EditorForm editorForm = (EditorForm) form;
1225         String docCategory = request.getParameter("docCategory");
1226         String docType = request.getParameter("docType");
1227         String docFormat = request.getParameter("docFormat");
1228         if (docCategory == null) {
1229             docCategory = editorForm.getDocCategory();
1230         }
1231         if (docType == null) {
1232             docType = editorForm.getDocType();
1233         }
1234         if (docFormat == null) {
1235             docFormat = editorForm.getDocFormat();
1236         }
1237 
1238         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1239                 .getDocumentEditor(docCategory, docType, docFormat);
1240 
1241         editorForm = documentEditor.addORRemoveExtentOfOwnership(editorForm, request);
1242         return super.navigate(editorForm, result, request, response);
1243     }
1244 
1245     /**
1246      * This method will remove the ExtentOfOwnership based on the index position and updates the component.
1247      *
1248      * @param form
1249      * @param result
1250      * @param request
1251      * @param response
1252      * @return ModelAndView
1253      */
1254     @RequestMapping(params = "methodToCall=removeExtentOfOwnership")
1255     public ModelAndView removeExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1256                                                 HttpServletRequest request, HttpServletResponse response) {
1257         if (!isFormInitialized) {
1258             super.start(form, result, request, response);
1259             isFormInitialized = true;
1260         }
1261         EditorForm editorForm = (EditorForm) form;
1262         String docCategory = request.getParameter("docCategory");
1263         String docType = request.getParameter("docType");
1264         String docFormat = request.getParameter("docFormat");
1265         if (docCategory == null) {
1266             docCategory = editorForm.getDocCategory();
1267         }
1268         if (docType == null) {
1269             docType = editorForm.getDocType();
1270         }
1271         if (docFormat == null) {
1272             docFormat = editorForm.getDocFormat();
1273         }
1274 
1275         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1276                 .getDocumentEditor(docCategory, docType, docFormat);
1277 
1278         editorForm = documentEditor.addORRemoveExtentOfOwnership(editorForm, request);
1279         return super.navigate(editorForm, result, request, response);
1280     }
1281 
1282     /**
1283      * This method will add the EOWHoldingNotes record based on the selected Line index and updates the component.
1284      *
1285      * @param form
1286      * @param result
1287      * @param request
1288      * @param response
1289      * @return ModelAndView
1290      */
1291     @RequestMapping(params = "methodToCall=addEOWHoldingNotes")
1292     public ModelAndView addEOWHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1293                                            HttpServletRequest request, HttpServletResponse response) {
1294         if (!isFormInitialized) {
1295             super.start(form, result, request, response);
1296             isFormInitialized = true;
1297         }
1298         EditorForm editorForm = (EditorForm) form;
1299         String docCategory = request.getParameter("docCategory");
1300         String docType = request.getParameter("docType");
1301         String docFormat = request.getParameter("docFormat");
1302         if (docCategory == null) {
1303             docCategory = editorForm.getDocCategory();
1304         }
1305         if (docType == null) {
1306             docType = editorForm.getDocType();
1307         }
1308         if (docFormat == null) {
1309             docFormat = editorForm.getDocFormat();
1310         }
1311 
1312         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1313                 .getDocumentEditor(docCategory, docType, docFormat);
1314 
1315         editorForm = documentEditor.addORRemoveExtentOfOwnership(editorForm, request);
1316         return super.navigate(editorForm, result, request, response);
1317     }
1318 
1319     /**
1320      * This method will remove the EOWHoldingNotes based on the index position and updates the component.
1321      *
1322      * @param form
1323      * @param result
1324      * @param request
1325      * @param response
1326      * @return ModelAndView
1327      */
1328     @RequestMapping(params = "methodToCall=removeEOWHoldingNotes")
1329     public ModelAndView removeEOWHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1330                                               HttpServletRequest request, HttpServletResponse response) {
1331         if (!isFormInitialized) {
1332             super.start(form, result, request, response);
1333             isFormInitialized = true;
1334         }
1335         EditorForm editorForm = (EditorForm) form;
1336         String docCategory = request.getParameter("docCategory");
1337         String docType = request.getParameter("docType");
1338         String docFormat = request.getParameter("docFormat");
1339         if (docCategory == null) {
1340             docCategory = editorForm.getDocCategory();
1341         }
1342         if (docType == null) {
1343             docType = editorForm.getDocType();
1344         }
1345         if (docFormat == null) {
1346             docFormat = editorForm.getDocFormat();
1347         }
1348 
1349         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1350                 .getDocumentEditor(docCategory, docType, docFormat);
1351 
1352         editorForm = documentEditor.addORRemoveExtentOfOwnership(editorForm, request);
1353         return super.navigate(editorForm, result, request, response);
1354     }
1355 
1356     /**
1357      * This method will add the AccessInformation record based on the selected Line index and updates the component.
1358      *
1359      * @param form
1360      * @param result
1361      * @param request
1362      * @param response
1363      * @return ModelAndView
1364      */
1365     @RequestMapping(params = "methodToCall=addAccessInformation")
1366     public ModelAndView addAccessInformation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1367                                              HttpServletRequest request, HttpServletResponse response) {
1368         if (!isFormInitialized) {
1369             super.start(form, result, request, response);
1370             isFormInitialized = true;
1371         }
1372         EditorForm editorForm = (EditorForm) form;
1373         String docCategory = request.getParameter("docCategory");
1374         String docType = request.getParameter("docType");
1375         String docFormat = request.getParameter("docFormat");
1376         if (docCategory == null) {
1377             docCategory = editorForm.getDocCategory();
1378         }
1379         if (docType == null) {
1380             docType = editorForm.getDocType();
1381         }
1382         if (docFormat == null) {
1383             docFormat = editorForm.getDocFormat();
1384         }
1385 
1386         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1387                 .getDocumentEditor(docCategory, docType, docFormat);
1388 
1389         editorForm = documentEditor.addORRemoveAccessInformationAndHoldingsNotes(editorForm, request);
1390         return super.navigate(editorForm, result, request, response);
1391     }
1392 
1393     /**
1394      * This method will remove the AccessInformation based on the index position and updates the component.
1395      *
1396      * @param form
1397      * @param result
1398      * @param request
1399      * @param response
1400      * @return ModelAndView
1401      */
1402     @RequestMapping(params = "methodToCall=removeAccessInformation")
1403     public ModelAndView removeAccessInformation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1404                                                 HttpServletRequest request, HttpServletResponse response) {
1405         if (!isFormInitialized) {
1406             super.start(form, result, request, response);
1407             isFormInitialized = true;
1408         }
1409         EditorForm editorForm = (EditorForm) form;
1410         String docCategory = request.getParameter("docCategory");
1411         String docType = request.getParameter("docType");
1412         String docFormat = request.getParameter("docFormat");
1413         if (docCategory == null) {
1414             docCategory = editorForm.getDocCategory();
1415         }
1416         if (docType == null) {
1417             docType = editorForm.getDocType();
1418         }
1419         if (docFormat == null) {
1420             docFormat = editorForm.getDocFormat();
1421         }
1422 
1423         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1424                 .getDocumentEditor(docCategory, docType, docFormat);
1425 
1426         editorForm = documentEditor.addORRemoveAccessInformationAndHoldingsNotes(editorForm, request);
1427         return super.navigate(editorForm, result, request, response);
1428     }
1429 
1430     /**
1431      * This method will add the HoldingNotes record based on the selected Line index and updates the component.
1432      *
1433      * @param form
1434      * @param result
1435      * @param request
1436      * @param response
1437      * @return ModelAndView
1438      */
1439     @RequestMapping(params = "methodToCall=addHoldingNotes")
1440     public ModelAndView addHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1441                                         HttpServletRequest request, HttpServletResponse response) {
1442         if (!isFormInitialized) {
1443             super.start(form, result, request, response);
1444             isFormInitialized = true;
1445         }
1446         EditorForm editorForm = (EditorForm) form;
1447         String docCategory = request.getParameter("docCategory");
1448         String docType = request.getParameter("docType");
1449         String docFormat = request.getParameter("docFormat");
1450         if (docCategory == null) {
1451             docCategory = editorForm.getDocCategory();
1452         }
1453         if (docType == null) {
1454             docType = editorForm.getDocType();
1455         }
1456         if (docFormat == null) {
1457             docFormat = editorForm.getDocFormat();
1458         }
1459 
1460         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1461                 .getDocumentEditor(docCategory, docType, docFormat);
1462 
1463         editorForm = documentEditor.addORRemoveAccessInformationAndHoldingsNotes(editorForm, request);
1464         return super.navigate(editorForm, result, request, response);
1465     }
1466 
1467     /**
1468      * This method will remove the HoldingNotes based on the index position and updates the component.
1469      *
1470      * @param form
1471      * @param result
1472      * @param request
1473      * @param response
1474      * @return ModelAndView
1475      */
1476     @RequestMapping(params = "methodToCall=removeHoldingNotes")
1477     public ModelAndView removeHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1478                                            HttpServletRequest request, HttpServletResponse response) {
1479         if (!isFormInitialized) {
1480             super.start(form, result, request, response);
1481             isFormInitialized = true;
1482         }
1483         EditorForm editorForm = (EditorForm) form;
1484         String docCategory = request.getParameter("docCategory");
1485         String docType = request.getParameter("docType");
1486         String docFormat = request.getParameter("docFormat");
1487         if (docCategory == null) {
1488             docCategory = editorForm.getDocCategory();
1489         }
1490         if (docType == null) {
1491             docType = editorForm.getDocType();
1492         }
1493         if (docFormat == null) {
1494             docFormat = editorForm.getDocFormat();
1495         }
1496 
1497         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1498                 .getDocumentEditor(docCategory, docType, docFormat);
1499 
1500         editorForm = documentEditor.addORRemoveAccessInformationAndHoldingsNotes(editorForm, request);
1501         return super.navigate(editorForm, result, request, response);
1502     }
1503 
1504     @RequestMapping(params = "methodToCall=addField")
1505     public ModelAndView addField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1506                                  HttpServletRequest request, HttpServletResponse response) {
1507         if (!isFormInitialized) {
1508             super.start(form, result, request, response);
1509             isFormInitialized = true;
1510         }
1511         EditorForm editorForm = (EditorForm) form;
1512         String docCategory = request.getParameter("docCategory");
1513         String docType = request.getParameter("docType");
1514         String docFormat = request.getParameter("docFormat");
1515         if (docCategory == null) {
1516             docCategory = editorForm.getDocCategory();
1517         }
1518         if (docType == null) {
1519             docType = editorForm.getDocType();
1520         }
1521         if (docFormat == null) {
1522             docFormat = editorForm.getDocFormat();
1523         }
1524 
1525         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1526                 .getDocumentEditor(docCategory, docType, docFormat);
1527 
1528         editorForm = documentEditor.addORDeleteFields(editorForm, request);
1529         return super.navigate(editorForm, result, request, response);
1530     }
1531 
1532     @RequestMapping(params = "methodToCall=removeField")
1533     public ModelAndView removeField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1534                                     HttpServletRequest request, HttpServletResponse response) {
1535         if (!isFormInitialized) {
1536             super.start(form, result, request, response);
1537             isFormInitialized = true;
1538         }
1539         EditorForm editorForm = (EditorForm) form;
1540         String docCategory = request.getParameter("docCategory");
1541         String docType = request.getParameter("docType");
1542         String docFormat = request.getParameter("docFormat");
1543         if (docCategory == null) {
1544             docCategory = editorForm.getDocCategory();
1545         }
1546         if (docType == null) {
1547             docType = editorForm.getDocType();
1548         }
1549         if (docFormat == null) {
1550             docFormat = editorForm.getDocFormat();
1551         }
1552 
1553         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1554                 .getDocumentEditor(docCategory, docType, docFormat);
1555 
1556         editorForm = documentEditor.addORDeleteFields(editorForm, request);
1557         return super.navigate(editorForm, result, request, response);
1558     }
1559 
1560 
1561     /**
1562      * Used for Test-case
1563      *
1564      * @param result
1565      * @param request
1566      * @param response
1567      * @param editorForm
1568      * @return ModelAndView
1569      */
1570     protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response,
1571                                      EditorForm editorForm) {
1572         return super.navigate(editorForm, result, request, response);
1573     }
1574 
1575     @RequestMapping(params = "methodToCall=addItemNote")
1576     public ModelAndView addItemNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1577                                     HttpServletRequest request, HttpServletResponse response) {
1578         if (!isFormInitialized) {
1579             super.start(form, result, request, response);
1580             isFormInitialized = true;
1581         }
1582         EditorForm editorForm = (EditorForm) form;
1583         String docCategory = request.getParameter("docCategory");
1584         String docType = request.getParameter("docType");
1585         String docFormat = request.getParameter("docFormat");
1586         if (docCategory == null) {
1587             docCategory = editorForm.getDocCategory();
1588         }
1589         if (docType == null) {
1590             docType = editorForm.getDocType();
1591         }
1592         if (docFormat == null) {
1593             docFormat = editorForm.getDocFormat();
1594         }
1595 
1596         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1597                 .getDocumentEditor(docCategory, docType, docFormat);
1598 
1599         editorForm = documentEditor.addORRemoveItemNote(editorForm, request);
1600         return super.navigate(editorForm, result, request, response);
1601     }
1602 
1603     @RequestMapping(params = "methodToCall=addDonorToItem")
1604     public ModelAndView addDonorToItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1605                                        HttpServletRequest request, HttpServletResponse response) {
1606         EditorForm editorForm = (EditorForm) form;
1607         String docCategory = request.getParameter("docCategory");
1608         String docType = request.getParameter("docType");
1609         String docFormat = request.getParameter("docFormat");
1610         if (docCategory == null) {
1611             docCategory = editorForm.getDocCategory();
1612         }
1613         if (docType == null) {
1614             docType = editorForm.getDocType();
1615         }
1616         if (docFormat == null) {
1617             docFormat = editorForm.getDocFormat();
1618         }
1619 
1620         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1621                 .getDocumentEditor(docCategory, docType, docFormat);
1622         documentEditor.addORRemoveItemDonor(editorForm, request);
1623         return getUIFModelAndView(form);
1624     }
1625 
1626     @RequestMapping(params = "methodToCall=removeDonorFromItem")
1627     public ModelAndView removeDonorFromItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1628                                             HttpServletRequest request, HttpServletResponse response) {
1629         EditorForm editorForm = (EditorForm) form;
1630         String docCategory = request.getParameter("docCategory");
1631         String docType = request.getParameter("docType");
1632         String docFormat = request.getParameter("docFormat");
1633         if (docCategory == null) {
1634             docCategory = editorForm.getDocCategory();
1635         }
1636         if (docType == null) {
1637             docType = editorForm.getDocType();
1638         }
1639         if (docFormat == null) {
1640             docFormat = editorForm.getDocFormat();
1641         }
1642         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1643                 .getDocumentEditor(docCategory, docType, docFormat);
1644         documentEditor.addORRemoveItemDonor(editorForm, request);
1645         return getUIFModelAndView(form);
1646     }
1647 
1648     @RequestMapping(params = "methodToCall=addDonorToEInstance")
1649     public ModelAndView addDonorToEInstance(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1650                                             HttpServletRequest request, HttpServletResponse response) {
1651         EditorForm editorForm = (EditorForm) form;
1652         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
1653         List<DonorInfo> donorInfoList = workEInstanceOlemlForm.getSelectedEHoldings().getDonorInfo();
1654         String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1655         CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
1656                 selectedCollectionPath);
1657         String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
1658         Object eventObject = ObjectPropertyUtils.getPropertyValue(form, addLinePath);
1659         DonorInfo donorInfo = (DonorInfo) eventObject;
1660         if (donorInfo != null && StringUtils.isNotEmpty(donorInfo.getDonorCode())) {
1661             Map map = new HashMap();
1662             map.put("donorCode", donorInfo.getDonorCode());
1663             OLEDonor oleDonor = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEDonor.class, map);
1664             if (oleDonor != null) {
1665                 for (DonorInfo donor : donorInfoList) {
1666                     if (donor.getDonorCode().equals(donorInfo.getDonorCode())) {
1667                         GlobalVariables.getMessageMap().putErrorForSectionId("OleEInstanceDonorInformation-ListOfDonors", "error.donor.code.exist");
1668                         return getUIFModelAndView(form);
1669                     }
1670                 }
1671             } else {
1672                 GlobalVariables.getMessageMap().putErrorForSectionId("OleEInstanceDonorInformation-ListOfDonors", "error.donor.code.doesnt.exist");
1673                 return getUIFModelAndView(form);
1674             }
1675         }
1676         View view = form.getPostedView();
1677         view.getViewHelperService().processCollectionAddLine(view, form, selectedCollectionPath);
1678         return getUIFModelAndView(form);
1679     }
1680 
1681     @RequestMapping(params = "methodToCall=removeItemNote")
1682     public ModelAndView removeItemNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1683                                        HttpServletRequest request, HttpServletResponse response) {
1684         if (!isFormInitialized) {
1685             super.start(form, result, request, response);
1686             isFormInitialized = true;
1687         }
1688         EditorForm editorForm = (EditorForm) form;
1689         String docCategory = request.getParameter("docCategory");
1690         String docType = request.getParameter("docType");
1691         String docFormat = request.getParameter("docFormat");
1692         if (docCategory == null) {
1693             docCategory = editorForm.getDocCategory();
1694         }
1695         if (docType == null) {
1696             docType = editorForm.getDocType();
1697         }
1698         if (docFormat == null) {
1699             docFormat = editorForm.getDocFormat();
1700         }
1701 
1702         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1703                 .getDocumentEditor(docCategory, docType, docFormat);
1704 
1705         editorForm = documentEditor.addORRemoveItemNote(editorForm, request);
1706         return super.navigate(editorForm, result, request, response);
1707     }
1708 
1709     /**
1710      * Display the linked Bib details for corresponding Holdings/Items.
1711      *
1712      * @param form
1713      * @param result
1714      * @param request
1715      * @param response
1716      * @return
1717      */
1718     @RequestMapping(params = "methodToCall=showBibs")
1719     public ModelAndView showBibs(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1720                                  HttpServletRequest request, HttpServletResponse response) {
1721         EditorForm documentForm = null;
1722         if (!isFormInitialized) {
1723             super.start(form, result, request, response);
1724             isFormInitialized = true;
1725         }
1726         // get the document details from request and set them in the form.
1727         String docCategory = request.getParameter("docCategory");
1728         String docType = request.getParameter("docType");
1729         String docFormat = request.getParameter("docFormat");
1730         String docId = request.getParameter("docId");
1731         String instanceId = request.getParameter("instanceId");
1732         String editable = request.getParameter("editable");
1733 
1734         //Verifying editable at form object
1735         if ((null == editable) || (editable.length() == 0)) {
1736             editable = ((EditorForm) form).getEditable();
1737         }
1738 
1739         //Default value for editable field if it is null
1740         if (null == editable || editable.length() == 0) {
1741             editable = "true";
1742         }
1743 
1744         ((EditorForm) form).setEditable(editable);
1745         ((EditorForm) form).setDocCategory(docCategory);
1746         ((EditorForm) form).setDocType(docType);
1747         ((EditorForm) form).setDocFormat(docFormat);
1748         ((EditorForm) form).setDocId(docId);
1749         ((EditorForm) form).setInstanceId(instanceId);
1750 
1751         // Identify the document editor to be used for the requested document.
1752         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1753                 .getDocumentEditor(docCategory, docType, docFormat);
1754 
1755         documentForm = documentEditor.showBibs((EditorForm) form);
1756         // Set the output (response) form containing document info into the current form.
1757         ((EditorForm) form).setDocumentForm(documentForm);
1758 
1759         // Return the next view to be shown to user.
1760         ModelAndView modelAndView = getUIFModelAndView(form, ((EditorForm) form).getDocumentForm().getViewId());
1761         return modelAndView;
1762     }
1763 
1764 
1765     @RequestMapping(params = "methodToCall=leaderFieldReset")
1766     public ModelAndView resetLeaderField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1767                                          HttpServletRequest request, HttpServletResponse response) {
1768         LOG.debug("Inside the clear leader method");
1769         EditorForm editForm = (EditorForm) form;
1770         WorkBibMarcForm workBibMarcForm = (WorkBibMarcForm) editForm.getDocumentForm();
1771         workBibMarcForm.setLeaderField(new LeaderField());
1772         ((EditorForm) form).setDocumentForm(workBibMarcForm);
1773         return navigate(form, result, request, response);
1774     }
1775 
1776 
1777     @RequestMapping(params = "methodToCall=createSerialReceiving")
1778     public ModelAndView createSerialReceiving(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1779                                               HttpServletRequest request, HttpServletResponse response) {
1780         LOG.debug("Inside the createSerialReceiving method");
1781         ModelAndView modelAndView = getUIFModelAndView(form, ((EditorForm) form).getDocumentForm().getViewId());
1782         return modelAndView;
1783 
1784     }
1785 
1786 
1787     @RequestMapping(params = "methodToCall=loadControlField006")
1788     public ModelAndView loadControlField006(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1789                                             HttpServletRequest request, HttpServletResponse response) {
1790         ((EditorForm) form).setDisplayField006("true");
1791         WorkBibMarcForm workBibMarcForm = (WorkBibMarcForm) ((EditorForm) form).getDocumentForm();
1792         String controlField006Format = workBibMarcForm.getMarcControlFields().getValue();
1793         if(workBibMarcForm.getMarcControlFields().getControlField006()==null){
1794             ControlField006 controlField006 = new ControlField006();
1795             workBibMarcForm.getMarcControlFields().setControlField006(controlField006);
1796         }
1797         String controlField006Format1 = workBibMarcForm.getMarcControlFields().getControlField006().getFormat();
1798         if(controlField006Format1!=null){
1799             controlField006Format=controlField006Format1;
1800         }
1801         ControlField006 controlFiled006 = new ControlField006();
1802         controlFiled006.setFormat(workBibMarcForm.getMarcControlFields().getValue());
1803         if(controlField006Format1==null){
1804             controlFiled006.setFormat(workBibMarcForm.getMarcControlFields().getValue());
1805             workBibMarcForm.getMarcControlFields().setControlField006(controlFiled006);
1806         }else {
1807             controlFiled006.setFormat(controlField006Format1);
1808             workBibMarcForm.getMarcControlFields().setControlField006(controlFiled006);
1809 
1810         }
1811         workBibMarcForm.getMarcControlFields().setMapVisible("false");
1812         workBibMarcForm.getMarcControlFields().setBooksVisible("false");
1813         workBibMarcForm.getMarcControlFields().setMusicVisible("false");
1814         workBibMarcForm.getMarcControlFields().setComputerFilesVisible("false");
1815         workBibMarcForm.getMarcControlFields().setContinuingResourcesVisible("false");
1816         workBibMarcForm.getMarcControlFields().setMixedMaterialVisible("false");
1817         workBibMarcForm.getMarcControlFields().setVisualMaterialsVisible("false");
1818 
1819         if (controlField006Format.equalsIgnoreCase("e") || controlField006Format.equalsIgnoreCase("f")) {
1820             workBibMarcForm.getMarcControlFields().setMapVisible("true");
1821         } else if (controlField006Format.equalsIgnoreCase("a") || controlField006Format.equalsIgnoreCase("t")) {
1822             workBibMarcForm.getMarcControlFields().setBooksVisible("true");
1823         } else if (controlField006Format.equalsIgnoreCase("c") || controlField006Format.equalsIgnoreCase("d") ||
1824                 controlField006Format.equalsIgnoreCase("i") || controlField006Format.equalsIgnoreCase("j")) {
1825             workBibMarcForm.getMarcControlFields().setMusicVisible("true");
1826         } else if (controlField006Format.equalsIgnoreCase("m")) {
1827             workBibMarcForm.getMarcControlFields().setComputerFilesVisible("true");
1828         } else if (controlField006Format.equalsIgnoreCase("s")) {
1829             workBibMarcForm.getMarcControlFields().setContinuingResourcesVisible("true");
1830         } else if (controlField006Format.equalsIgnoreCase("p")) {
1831             workBibMarcForm.getMarcControlFields().setMixedMaterialVisible("true");
1832         } else if (controlField006Format.equalsIgnoreCase("g") || controlField006Format.equalsIgnoreCase("k") ||
1833                 controlField006Format.equalsIgnoreCase("o") || controlField006Format.equalsIgnoreCase("r")) {
1834             workBibMarcForm.getMarcControlFields().setVisualMaterialsVisible("true");
1835         }
1836         ((EditorForm) form).setDocumentForm(workBibMarcForm);
1837         return navigate(form, result, request, response);
1838     }
1839 
1840     @RequestMapping(params = "methodToCall=loadControlField007")
1841     public ModelAndView loadControlField007(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1842                                             HttpServletRequest request, HttpServletResponse response) {
1843         ((EditorForm) form).setDisplayField007("true");
1844         WorkBibMarcForm workBibMarcForm = (WorkBibMarcForm) ((EditorForm) form).getDocumentForm();
1845         if(workBibMarcForm.getMarcControlFields().getControlField007()==null){
1846             ControlField007 controlField007 = new ControlField007();
1847             workBibMarcForm.getMarcControlFields().setControlField007(controlField007);
1848         }
1849 
1850         String controlField007Format = workBibMarcForm.getMarcControlFields().getValue007();
1851         String controlField007Format1 = workBibMarcForm.getMarcControlFields().getControlField007().getFormat();
1852 
1853         ControlField007 controlFiled007 = new ControlField007();
1854 
1855         if(controlField007Format1!=null){
1856             controlField007Format=controlField007Format1;
1857         }
1858         if(controlField007Format1!=null){
1859             controlFiled007.setFormat(controlField007Format1);
1860             workBibMarcForm.getMarcControlFields().setControlField007(controlFiled007);
1861         }   else{
1862             controlFiled007.setFormat(controlField007Format);
1863             workBibMarcForm.getMarcControlFields().setControlField007(controlFiled007);
1864         }
1865 
1866         workBibMarcForm.getMarcControlFields().setMapVisible007("false");
1867         workBibMarcForm.getMarcControlFields().setElectronicResourcesVisible007("false");
1868         workBibMarcForm.getMarcControlFields().setGlobeVisible007("false");
1869         workBibMarcForm.getMarcControlFields().setTactileMaterialVisible007("false");
1870         workBibMarcForm.getMarcControlFields().setProjectGraphicVisible007("false");
1871         workBibMarcForm.getMarcControlFields().setMicroFormVisible007("false");
1872         workBibMarcForm.getMarcControlFields().setNonProjectedGraphicVisible007("false");
1873         workBibMarcForm.getMarcControlFields().setMotionPictureVisible007("false");
1874         workBibMarcForm.getMarcControlFields().setKitVisible007("false");
1875         workBibMarcForm.getMarcControlFields().setNotatedMusicVisible007("false");
1876         workBibMarcForm.getMarcControlFields().setRemoteSensingImageVisible007("false");
1877         workBibMarcForm.getMarcControlFields().setSoundRecordingVisible007("false");
1878         workBibMarcForm.getMarcControlFields().setTextVisible007("false");
1879         workBibMarcForm.getMarcControlFields().setVideoRecordingVisible007("false");
1880         workBibMarcForm.getMarcControlFields().setUnspecifiedVisible007("false");
1881 
1882         if (controlField007Format.equalsIgnoreCase("a")) {
1883             workBibMarcForm.getMarcControlFields().setMapVisible007("true");
1884         } else if (controlField007Format.equalsIgnoreCase("c")) {
1885             workBibMarcForm.getMarcControlFields().setElectronicResourcesVisible007("true");
1886         } else if (controlField007Format.equalsIgnoreCase("d")) {
1887             workBibMarcForm.getMarcControlFields().setGlobeVisible007("true");
1888         } else if (controlField007Format.equalsIgnoreCase("f")) {
1889             workBibMarcForm.getMarcControlFields().setTactileMaterialVisible007("true");
1890         } else if (controlField007Format.equalsIgnoreCase("g")) {
1891             workBibMarcForm.getMarcControlFields().setProjectGraphicVisible007("true");
1892         } else if (controlField007Format.equalsIgnoreCase("h")) {
1893             workBibMarcForm.getMarcControlFields().setMicroFormVisible007("true");
1894         } else if (controlField007Format.equalsIgnoreCase("k")) {
1895             workBibMarcForm.getMarcControlFields().setNonProjectedGraphicVisible007("true");
1896         } else if (controlField007Format.equalsIgnoreCase("m")) {
1897             workBibMarcForm.getMarcControlFields().setMotionPictureVisible007("true");
1898         } else if (controlField007Format.equalsIgnoreCase("o")) {
1899             workBibMarcForm.getMarcControlFields().setKitVisible007("true");
1900         } else if (controlField007Format.equalsIgnoreCase("q")) {
1901             workBibMarcForm.getMarcControlFields().setNotatedMusicVisible007("true");
1902         } else if (controlField007Format.equalsIgnoreCase("r")) {
1903             workBibMarcForm.getMarcControlFields().setRemoteSensingImageVisible007("true");
1904         } else if (controlField007Format.equalsIgnoreCase("s")) {
1905             workBibMarcForm.getMarcControlFields().setSoundRecordingVisible007("true");
1906         } else if (controlField007Format.equalsIgnoreCase("t")) {
1907             workBibMarcForm.getMarcControlFields().setTextVisible007("true");
1908         } else if (controlField007Format.equalsIgnoreCase("v")) {
1909             workBibMarcForm.getMarcControlFields().setVideoRecordingVisible007("true");
1910         } else if (controlField007Format.equalsIgnoreCase("z")) {
1911             workBibMarcForm.getMarcControlFields().setUnspecifiedVisible007("true");
1912         }
1913         ((EditorForm) form).setDocumentForm(workBibMarcForm);
1914 
1915         return navigate(form, result, request, response);
1916     }
1917 
1918     @RequestMapping(params = "methodToCall=loadControlField008")
1919     public ModelAndView loadControlField008(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1920                                             HttpServletRequest request, HttpServletResponse response) {
1921         ((EditorForm) form).setDisplayField008("true");
1922         WorkBibMarcForm workBibMarcForm = (WorkBibMarcForm) ((EditorForm) form).getDocumentForm();
1923 
1924         if(workBibMarcForm.getMarcControlFields().getControlField008()==null){
1925             ControlField008 controlField008 = new ControlField008();
1926             workBibMarcForm.getMarcControlFields().setControlField008(controlField008);
1927         }
1928         String controlField008Format = workBibMarcForm.getMarcControlFields().getValue008();
1929         workBibMarcForm.getMarcControlFields().setControlField008(new ControlField008());
1930 
1931 
1932         workBibMarcForm.getMarcControlFields().setMapVisible008("false");
1933         workBibMarcForm.getMarcControlFields().setBooksVisible008("false");
1934         workBibMarcForm.getMarcControlFields().setMusicVisible008("false");
1935         workBibMarcForm.getMarcControlFields().setComputerFilesVisible008("false");
1936         workBibMarcForm.getMarcControlFields().setContinuingResourcesVisible008("false");
1937         workBibMarcForm.getMarcControlFields().setMixedMaterialVisible008("false");
1938         workBibMarcForm.getMarcControlFields().setVisualMaterialsVisible008("false");
1939 
1940         if (controlField008Format.equalsIgnoreCase("map")) {
1941             workBibMarcForm.getMarcControlFields().setMapVisible008("true");
1942         } else if (controlField008Format.equalsIgnoreCase("books")) {
1943             workBibMarcForm.getMarcControlFields().setBooksVisible008("true");
1944         } else if (controlField008Format.equalsIgnoreCase("music")) {
1945             workBibMarcForm.getMarcControlFields().setMusicVisible008("true");
1946         } else if (controlField008Format.equalsIgnoreCase("computer")) {
1947             workBibMarcForm.getMarcControlFields().setComputerFilesVisible008("true");
1948         } else if (controlField008Format.equalsIgnoreCase("countRes")) {
1949             workBibMarcForm.getMarcControlFields().setContinuingResourcesVisible008("true");
1950         } else if (controlField008Format.equalsIgnoreCase("mixMat")) {
1951             workBibMarcForm.getMarcControlFields().setMixedMaterialVisible008("true");
1952         } else if (controlField008Format.equalsIgnoreCase("visMat")) {
1953             workBibMarcForm.getMarcControlFields().setVisualMaterialsVisible008("true");
1954         }
1955 
1956         ((EditorForm) form).setDocumentForm(workBibMarcForm);
1957         return navigate(form, result, request, response);
1958     }
1959 
1960     @RequestMapping(params = "methodToCall=addCoverageSection")
1961     public ModelAndView addCoverageSection(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1962                                            HttpServletRequest request, HttpServletResponse response) {
1963         if (!isFormInitialized) {
1964             super.start(form, result, request, response);
1965             isFormInitialized = true;
1966         }
1967         EditorForm editorForm = (EditorForm) form;
1968         String docCategory = request.getParameter("docCategory");
1969         String docType = request.getParameter("docType");
1970         String docFormat = request.getParameter("docFormat");
1971         if (docCategory == null) {
1972             docCategory = editorForm.getDocCategory();
1973         }
1974         if (docType == null) {
1975             docType = editorForm.getDocType();
1976         }
1977         if (docFormat == null) {
1978             docFormat = editorForm.getDocFormat();
1979         }
1980 
1981         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
1982                 .getDocumentEditor(docCategory, docType, docFormat);
1983 
1984         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
1985         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1986         workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getCoverages().getCoverage().add(new Coverage());
1987         return super.navigate(editorForm, result, request, response);
1988     }
1989 
1990     @RequestMapping(params = "methodToCall=removeCoverageSection")
1991     public ModelAndView removeCoverageSection(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1992                                               HttpServletRequest request, HttpServletResponse response) {
1993         if (!isFormInitialized) {
1994             super.start(form, result, request, response);
1995             isFormInitialized = true;
1996         }
1997         EditorForm editorForm = (EditorForm) form;
1998         String docCategory = request.getParameter("docCategory");
1999         String docType = request.getParameter("docType");
2000         String docFormat = request.getParameter("docFormat");
2001         if (docCategory == null) {
2002             docCategory = editorForm.getDocCategory();
2003         }
2004         if (docType == null) {
2005             docType = editorForm.getDocType();
2006         }
2007         if (docFormat == null) {
2008             docFormat = editorForm.getDocFormat();
2009         }
2010 
2011         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2012                 .getDocumentEditor(docCategory, docType, docFormat);
2013 
2014         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2015         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
2016         if (workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getCoverages().getCoverage().size() > 1) {
2017             workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getCoverages().getCoverage().remove(index);
2018         } else {
2019             if (workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getCoverages().getCoverage().size() == 1) {
2020                 workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getCoverages().getCoverage().remove(index);
2021                 Coverage coverage = new Coverage();
2022                 workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getCoverages().getCoverage().add(coverage);
2023             }
2024         }
2025         return super.navigate(editorForm, result, request, response);
2026     }
2027 
2028     @RequestMapping(params = "methodToCall=addLink")
2029     public ModelAndView addLink(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2030                                 HttpServletRequest request, HttpServletResponse response) {
2031         if (!isFormInitialized) {
2032             super.start(form, result, request, response);
2033             isFormInitialized = true;
2034         }
2035         EditorForm editorForm = (EditorForm) form;
2036         String docCategory = request.getParameter("docCategory");
2037         String docType = request.getParameter("docType");
2038         String docFormat = request.getParameter("docFormat");
2039         if (docCategory == null) {
2040             docCategory = editorForm.getDocCategory();
2041         }
2042         if (docType == null) {
2043             docType = editorForm.getDocType();
2044         }
2045         if (docFormat == null) {
2046             docFormat = editorForm.getDocFormat();
2047         }
2048 
2049         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2050                 .getDocumentEditor(docCategory, docType, docFormat);
2051 
2052         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2053         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
2054         workEInstanceOlemlForm.getSelectedEHoldings().getLink().add(index+1,new Link());
2055         return super.navigate(editorForm, result, request, response);
2056     }
2057 
2058     @RequestMapping(params = "methodToCall=deleteLink")
2059     public ModelAndView deleteLink(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2060                                    HttpServletRequest request, HttpServletResponse response) {
2061         if (!isFormInitialized) {
2062             super.start(form, result, request, response);
2063             isFormInitialized = true;
2064         }
2065         EditorForm editorForm = (EditorForm) form;
2066         String docCategory = request.getParameter("docCategory");
2067         String docType = request.getParameter("docType");
2068         String docFormat = request.getParameter("docFormat");
2069         if (docCategory == null) {
2070             docCategory = editorForm.getDocCategory();
2071         }
2072         if (docType == null) {
2073             docType = editorForm.getDocType();
2074         }
2075         if (docFormat == null) {
2076             docFormat = editorForm.getDocFormat();
2077         }
2078 
2079         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2080                 .getDocumentEditor(docCategory, docType, docFormat);
2081 
2082         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2083         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
2084         if (workEInstanceOlemlForm.getSelectedEHoldings().getLink().size() > 1) {
2085             workEInstanceOlemlForm.getSelectedEHoldings().getLink().remove(index);
2086         } else {
2087             if (workEInstanceOlemlForm.getSelectedEHoldings().getLink().size() == 1) {
2088                 workEInstanceOlemlForm.getSelectedEHoldings().getLink().remove(index);
2089                 Link link = new Link();
2090                 workEInstanceOlemlForm.getSelectedEHoldings().getLink().add(link);
2091             }
2092         }
2093         return super.navigate(editorForm, result, request, response);
2094     }
2095 
2096     @RequestMapping(params = "methodToCall=addPerpetualAccessSection")
2097     public ModelAndView addPerpetualAccessSection(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2098                                                   HttpServletRequest request, HttpServletResponse response) {
2099         if (!isFormInitialized) {
2100             super.start(form, result, request, response);
2101             isFormInitialized = true;
2102         }
2103         EditorForm editorForm = (EditorForm) form;
2104         String docCategory = request.getParameter("docCategory");
2105         String docType = request.getParameter("docType");
2106         String docFormat = request.getParameter("docFormat");
2107         if (docCategory == null) {
2108             docCategory = editorForm.getDocCategory();
2109         }
2110         if (docType == null) {
2111             docType = editorForm.getDocType();
2112         }
2113         if (docFormat == null) {
2114             docFormat = editorForm.getDocFormat();
2115         }
2116 
2117         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2118                 .getDocumentEditor(docCategory, docType, docFormat);
2119 
2120         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2121         //int index = Integer.parseInt(workEInstanceOlemlForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
2122        /* String selectedPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
2123         int selectedExtentIndex = Integer.parseInt(StringUtils.substring(selectedPath,
2124                 (StringUtils.indexOf(selectedPath, "[") + 1),
2125                 StringUtils.lastIndexOf(selectedPath, "]")));*/
2126         workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().add(new PerpetualAccess());
2127         return super.navigate(editorForm, result, request, response);
2128     }
2129 
2130     @RequestMapping(params = "methodToCall=removePerpetualAccessSection")
2131     public ModelAndView removePerpetualAccessSection(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2132                                                      HttpServletRequest request, HttpServletResponse response) {
2133         if (!isFormInitialized) {
2134             super.start(form, result, request, response);
2135             isFormInitialized = true;
2136         }
2137         EditorForm editorForm = (EditorForm) form;
2138         String docCategory = request.getParameter("docCategory");
2139         String docType = request.getParameter("docType");
2140         String docFormat = request.getParameter("docFormat");
2141         if (docCategory == null) {
2142             docCategory = editorForm.getDocCategory();
2143         }
2144         if (docType == null) {
2145             docType = editorForm.getDocType();
2146         }
2147         if (docFormat == null) {
2148             docFormat = editorForm.getDocFormat();
2149         }
2150 
2151         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2152                 .getDocumentEditor(docCategory, docType, docFormat);
2153 
2154         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2155         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
2156         if (workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() > 1) {
2157             workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().remove(index);
2158         } else {
2159             if (workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() == 1) {
2160                 workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().remove(index);
2161                 PerpetualAccess perpetualAccess = new PerpetualAccess();
2162                 workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().add(perpetualAccess);
2163             }
2164         }
2165         return super.navigate(editorForm, result, request, response);
2166     }
2167 
2168     @RequestMapping(params = "methodToCall=addOleEInstanceHoldingNotes")
2169     public ModelAndView addOleEInstanceHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2170                                                     HttpServletRequest request, HttpServletResponse response) {
2171         if (!isFormInitialized) {
2172             super.start(form, result, request, response);
2173             isFormInitialized = true;
2174         }
2175         EditorForm editorForm = (EditorForm) form;
2176         String docCategory = request.getParameter("docCategory");
2177         String docType = request.getParameter("docType");
2178         String docFormat = request.getParameter("docFormat");
2179         if (docCategory == null) {
2180             docCategory = editorForm.getDocCategory();
2181         }
2182         if (docType == null) {
2183             docType = editorForm.getDocType();
2184         }
2185         if (docFormat == null) {
2186             docFormat = editorForm.getDocFormat();
2187         }
2188 
2189         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2190                 .getDocumentEditor(docCategory, docType, docFormat);
2191 
2192         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2193         workEInstanceOlemlForm.getSelectedEHoldings().getNote().add(new Note());
2194         return super.navigate(editorForm, result, request, response);
2195     }
2196 
2197     @RequestMapping(params = "methodToCall=removeOleEInstanceHoldingNotes")
2198     public ModelAndView removeOleEInstanceHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2199                                                        HttpServletRequest request, HttpServletResponse response) {
2200         if (!isFormInitialized) {
2201             super.start(form, result, request, response);
2202             isFormInitialized = true;
2203         }
2204         EditorForm editorForm = (EditorForm) form;
2205         String docCategory = request.getParameter("docCategory");
2206         String docType = request.getParameter("docType");
2207         String docFormat = request.getParameter("docFormat");
2208         if (docCategory == null) {
2209             docCategory = editorForm.getDocCategory();
2210         }
2211         if (docType == null) {
2212             docType = editorForm.getDocType();
2213         }
2214         if (docFormat == null) {
2215             docFormat = editorForm.getDocFormat();
2216         }
2217 
2218         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2219                 .getDocumentEditor(docCategory, docType, docFormat);
2220 
2221         WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
2222         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
2223         if (workEInstanceOlemlForm.getSelectedEHoldings().getNote().size() > 1) {
2224             workEInstanceOlemlForm.getSelectedEHoldings().getNote().remove(index);
2225         } else {
2226             if (workEInstanceOlemlForm.getSelectedEHoldings().getNote().size() == 1) {
2227                 workEInstanceOlemlForm.getSelectedEHoldings().getNote().remove(index);
2228                 Note note = new Note();
2229                 workEInstanceOlemlForm.getSelectedEHoldings().getNote().add(note);
2230             }
2231         }
2232         return super.navigate(editorForm, result, request, response);
2233     }
2234 
2235 
2236     @RequestMapping(params = "methodToCall=globalEditSave")
2237     public ModelAndView globalEditSave(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2238                                        HttpServletRequest request, HttpServletResponse response) {
2239         if (!isFormInitialized) {
2240             super.start(form, result, request, response);
2241             isFormInitialized = true;
2242         }
2243         EditorForm editorForm = (EditorForm) form;
2244         String docCategory = request.getParameter("docCategory");
2245         String docType = request.getParameter("docType");
2246         String docFormat = request.getParameter("docFormat");
2247         List<String> ids = (List<String>) request.getSession().getAttribute("Ids");
2248         if (docCategory == null) {
2249             docCategory = editorForm.getDocCategory();
2250         }
2251         if (docType == null) {
2252             docType = editorForm.getDocType();
2253         }
2254         if (docFormat == null) {
2255             docFormat = editorForm.getDocFormat();
2256         }
2257 
2258         ((EditorForm) form).setDocCategory(docCategory);
2259         ((EditorForm) form).setDocType(docType);
2260         ((EditorForm) form).setDocFormat(docFormat);
2261         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
2262                 .getDocumentEditor(docCategory, docType, docFormat);
2263 
2264         if (documentEditor != null && documentEditor.isValidUpdate((EditorForm) form) || ((EditorForm) form).getAllowUpdate().equals
2265                 ("true")) {
2266             // Send the input through one (request)form and get the output through another (response) form.
2267             EditorForm documentForm = documentEditor.bulkUpdate((EditorForm) form, ids);
2268             // Set the output (response) form containing docum ((EditorForm) form).isAllowUpdate()ent info into the current form.
2269             ((EditorForm) form).setDocumentForm(documentForm);
2270             ((EditorForm) form).setAllowUpdate(" ");
2271         } else {
2272             ((EditorForm) form).setAllowUpdate("false");
2273         }
2274         return super.navigate(editorForm, result, request, response);
2275     }
2276 
2277 
2278     @RequestMapping(params = "methodToCall=printCallSlip")
2279     public void printCallSlip(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
2280         String formKey = request.getParameter("formKey");
2281         EditorForm editorForm = (EditorForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
2282         generateCallSlip(editorForm, response);
2283     }
2284 
2285     private void generateCallSlip(EditorForm editorForm, HttpServletResponse response) {
2286         LOG.debug("Creating pdf");
2287         String title = "", author = "", callNumber = "", location = "", copyNumber = "", enumeration = "", chronology = "", barcode = "";
2288         SearchResponse searchResponse = null;
2289         SearchParams searchParams = new SearchParams();
2290         SearchField searchField1 = searchParams.buildSearchField("item", "ItemIdentifier_search", editorForm.getDocId());
2291         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("OR", searchField1, "AND"));
2292         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title"));
2293         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Author"));
2294         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CallNumber"));
2295         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "LocationName"));
2296         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CopyNumber"));
2297         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "enumeration"));
2298         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "chronology"));
2299         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode"));
2300         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "CallNumber"));
2301         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "LocationName"));
2302         try {
2303             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
2304         } catch (Exception e) {
2305             LOG.error(e, e);
2306         }
2307         if (CollectionUtils.isNotEmpty(searchResponse.getSearchResults())) {
2308             for (SearchResultField searchResultField : searchResponse.getSearchResults().get(0).getSearchResultFields()) {
2309                 if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("Title")) {
2310                     if (StringUtils.isBlank(title)) {
2311                         title = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2312                     }
2313                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("Author")) {
2314                     if (StringUtils.isBlank(author)) {
2315                         author = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2316                     }
2317                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("CallNumber")) {
2318                     callNumber = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2319                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("LocationName")) {
2320                     location = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2321                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("CopyNumber")) {
2322                     copyNumber = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2323                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("enumeration")) {
2324                     enumeration = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2325                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("chronology")) {
2326                     chronology = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2327                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("ItemBarcode")) {
2328                     barcode = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2329                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("CallNumber")) {
2330                     if (StringUtils.isBlank(callNumber)) {
2331                         callNumber = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2332                     }
2333                 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase("LocationName")) {
2334                     if (StringUtils.isBlank(location)) {
2335                         location = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2336                     }
2337                 }
2338             }
2339         }
2340         String fileName = "Call/Paging Slip" + "_" + (editorForm.getTitle() != null ? editorForm.getTitle() : "") + "_" + new Date(System.currentTimeMillis()) + ".pdf";
2341         if (LOG.isInfoEnabled()) {
2342             LOG.info("File Created :" + title + "file name ::" + fileName + "::");
2343         }
2344         try {
2345             Document document = this.getDocument(0, 0, 5, 5);
2346             OutputStream outputStream = null;
2347             response.setContentType("application/pdf");
2348             //response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
2349             outputStream = response.getOutputStream();
2350             PdfWriter.getInstance(document, outputStream);
2351             Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
2352             document.open();
2353             document.newPage();
2354             PdfPTable pdfTable = new PdfPTable(3);
2355             pdfTable.setWidths(new int[]{20, 2, 30});
2356             Paragraph paraGraph = new Paragraph();
2357             paraGraph.setAlignment(Element.ALIGN_CENTER);
2358             paraGraph.add(new Chunk("Call/Paging Slip", boldFont));
2359             paraGraph.add(Chunk.NEWLINE);
2360             paraGraph.add(Chunk.NEWLINE);
2361             paraGraph.add(Chunk.NEWLINE);
2362             document.add(paraGraph);
2363 
2364             pdfTable.addCell(getPdfPCellInJustified("Title"));
2365             pdfTable.addCell(getPdfPCellInLeft(":"));
2366             pdfTable.addCell(getPdfPCellInJustified(title));
2367 
2368             pdfTable.addCell(getPdfPCellInJustified("Author"));
2369             pdfTable.addCell(getPdfPCellInLeft(":"));
2370             pdfTable.addCell(getPdfPCellInJustified(author));
2371 
2372             pdfTable.addCell(getPdfPCellInJustified("Call Number"));
2373             pdfTable.addCell(getPdfPCellInLeft(":"));
2374             pdfTable.addCell(getPdfPCellInJustified(callNumber));
2375 
2376             pdfTable.addCell(getPdfPCellInJustified("Location"));
2377             pdfTable.addCell(getPdfPCellInLeft(":"));
2378             pdfTable.addCell(getPdfPCellInJustified(location));
2379 
2380             pdfTable.addCell(getPdfPCellInJustified("Copy Number"));
2381             pdfTable.addCell(getPdfPCellInLeft(":"));
2382             pdfTable.addCell(getPdfPCellInJustified(copyNumber));
2383 
2384             pdfTable.addCell(getPdfPCellInJustified("Enumeration"));
2385             pdfTable.addCell(getPdfPCellInLeft(":"));
2386             pdfTable.addCell(getPdfPCellInJustified(enumeration));
2387 
2388             pdfTable.addCell(getPdfPCellInJustified("Chronology"));
2389             pdfTable.addCell(getPdfPCellInLeft(":"));
2390             pdfTable.addCell(getPdfPCellInJustified(chronology));
2391 
2392             pdfTable.addCell(getPdfPCellInJustified("Barcode"));
2393             pdfTable.addCell(getPdfPCellInLeft(":"));
2394             pdfTable.addCell(getPdfPCellInJustified(barcode));
2395 
2396             document.add(pdfTable);
2397             document.close();
2398             outputStream.flush();
2399             outputStream.close();
2400         } catch (Exception e) {
2401             LOG.error(e, e);
2402         }
2403     }
2404 
2405     private PdfPCell getPdfPCellInJustified(String chunk) {
2406         PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk)));
2407         pdfPCell.setBorder(pdfPCell.NO_BORDER);
2408         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
2409         return pdfPCell;
2410     }
2411 
2412     private PdfPCell getPdfPCellInLeft(String chunk) {
2413         PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk)));
2414         pdfPCell.setBorder(pdfPCell.NO_BORDER);
2415         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
2416         return pdfPCell;
2417     }
2418 
2419     public Document getDocument(float f1, float f2, float f3, float f4) {
2420         Document document = new Document(PageSize.A4);
2421         document.setMargins(f1, f2, f3, f4);
2422         return document;
2423     }
2424 
2425 
2426     private void prepareGlobalEditFields(EditorForm editorForm, String docType) {
2427 
2428         if (DocType.INSTANCE.getCode().equals(docType) || DocType.HOLDINGS.getCode().equals(docType)) {
2429             editorForm.setHeaderText(OLEConstants.GLOBAL_EDIT_HOLDINGS_HEADER_MESSAGE);
2430         } else if (DocType.EINSTANCE.getCode().equals(docType) || DocType.EHOLDINGS.getCode().equals(docType)) {
2431             editorForm.setHeaderText(OLEConstants.GLOBAL_EDIT_EHOLDINGS_HEADER_MESSAGE);
2432         } else if (DocType.ITEM.getCode().equals(docType)) {
2433             editorForm.setHeaderText(OLEConstants.GLOBAL_EDIT_ITEM_HEADER_MESSAGE);
2434         }
2435 
2436         DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig();
2437         List<DocTypeConfig> docTypeFields = documentSearchConfig.getDocTypeConfigs();
2438 
2439         for (DocTypeConfig docTypeConfig : docTypeFields) {
2440 
2441             List<DocFormatConfig> docFormatConfigList = docTypeConfig.getDocFormatConfigList();
2442 
2443             if (DocType.HOLDINGS.getCode().equals(docTypeConfig.getName()) && DocType.HOLDINGS.getCode().equals(docType)) {
2444                 setGlobalEditFlagValues(editorForm, docFormatConfigList, docType);
2445             } else if (DocType.EHOLDINGS.getCode().equals(docTypeConfig.getName()) && DocType.EHOLDINGS.getCode().equals(docType)) {
2446                 setGlobalEditFlagValues(editorForm, docFormatConfigList, docType);
2447             } else if (DocType.ITEM.getCode().equals(docType) && DocType.ITEM.getCode().equals(docTypeConfig.getName())) {
2448                 setGlobalEditFlagValues(editorForm, docFormatConfigList, docType);
2449             }
2450 
2451         }
2452 
2453     }
2454 
2455     private void setGlobalEditFlagValues(EditorForm editorForm, List<DocFormatConfig> docFormatConfigList, String docType) {
2456 
2457         for (DocFormatConfig docFormatConfig : docFormatConfigList) {
2458 
2459             List<DocFieldConfig> docFieldConfigList = docFormatConfig.getDocFieldConfigList();
2460 
2461             if (OLEConstants.OLEML_FORMAT.equals(docFormatConfig.getName())) {
2462                 if (DocType.INSTANCE.getCode().equals(docType) || DocType.HOLDINGS.getCode().equals(docType)) {
2463                     GlobalEditHoldingsFieldsFlagBO globalEditHoldingsFieldsFlagBO = editorForm.getGlobalEditHoldingsFieldsFlagBO();
2464                     for (DocFieldConfig docFieldConfig : docFieldConfigList) {
2465 
2466                         if (docFieldConfig.isGloballyEditable()) {
2467 
2468                             if (OLEConstants.CALL_NUMBER.equals(docFieldConfig.getName())) {
2469                                 globalEditHoldingsFieldsFlagBO.setCallNumberEditFlag(true);
2470                             } else if (OLEConstants.CALL_NUMBER_PREFIX.equals(docFieldConfig.getName())) {
2471                                 globalEditHoldingsFieldsFlagBO.setCallNumberPrefixEditFlag(true);
2472                             } else if (OLEConstants.CALL_NUMBER_TYPE_CODE.equals(docFieldConfig.getName())) {
2473                                 globalEditHoldingsFieldsFlagBO.setCallNumberTypeEditFlag(true);
2474                             } else if (OLEConstants.SHELVING_ORDER.equals(docFieldConfig.getName())) {
2475                                 globalEditHoldingsFieldsFlagBO.setShelvingOrderEditFlag(true);
2476                             } else if (OLEConstants.LOCATION_LEVEL.equals(docFieldConfig.getName())) {
2477                                 globalEditHoldingsFieldsFlagBO.setLocationEditFlag(true);
2478                             } else if (OLEConstants.HOLDINGS_NOTE.equals(docFieldConfig.getName())) {
2479                                 globalEditHoldingsFieldsFlagBO.setHoldingsNoteEditFlag(true);
2480                             } else if (OLEConstants.URI.equals(docFieldConfig.getName())) {
2481                                 globalEditHoldingsFieldsFlagBO.setAccessInformationEditFlag(true);
2482                             } else if (OLEConstants.RECEIPT_STATUS_CODE.equals(docFieldConfig.getName())) {
2483                                 globalEditHoldingsFieldsFlagBO.setReceiptStatusEditFlag(true);
2484                             } else if (OLEConstants.COPY_NUMBER_LABEL.equals(docFieldConfig.getName())) {
2485                                 globalEditHoldingsFieldsFlagBO.setCopyNumberEditFlag(true);
2486                             } else if (OLEConstants.EXTENTOFOWNERSHIP_NOTE_VALUE_DISPLAY.equals(docFieldConfig.getName()) || OLEConstants.EXTENTOFOWNERSHIP_NOTE_TYPE_DISPLAY.equals(docFieldConfig.getName()) || OLEConstants.EXTENTOFOWNERSHIP_Type_display.equals(docFieldConfig.getName())) {
2487                                 globalEditHoldingsFieldsFlagBO.setExtentOwnerShipEditFlag(true);
2488                             } else if (OLEConstants.URI_SEARCH.equals(docFieldConfig.getName()) || OLEConstants.URI_DISPLAY.equals(docFieldConfig.getName())) {
2489                                 globalEditHoldingsFieldsFlagBO.setExtendedInfoEditFlag(true);
2490                             }
2491                             //TODO - Need to do for other fields in holdings
2492                         }
2493                     }
2494                 } else if (DocType.EINSTANCE.getCode().equals(docType) || DocType.EHOLDINGS.getCode().equals(docType)) {
2495                     GlobalEditEHoldingsFieldsFlagBO globalEditEHoldingsFieldsFlagBO = editorForm.getGlobalEditEHoldingsFieldsFlagBO();
2496                     for (DocFieldConfig docFieldConfig : docFieldConfigList) {
2497 
2498                         if (docFieldConfig.isGloballyEditable()) {
2499                             if (OLEConstants.CALL_NUMBER.equals(docFieldConfig.getName())) {
2500                                 globalEditEHoldingsFieldsFlagBO.setCallNumberEditFlag(true);
2501                             } else if (OLEConstants.CALL_NUMBER_PREFIX.equals(docFieldConfig.getName())) {
2502                                 globalEditEHoldingsFieldsFlagBO.setCallNumberPrefixEditFlag(true);
2503                             } else if (OLEConstants.CALL_NUMBER_TYPE_CODE.equals(docFieldConfig.getName())) {
2504                                 globalEditEHoldingsFieldsFlagBO.setCallNumberTypeEditFlag(true);
2505                             } else if (OLEConstants.SHELVING_ORDER.equals(docFieldConfig.getName())) {
2506                                 globalEditEHoldingsFieldsFlagBO.setShelvingOrderEditFlag(true);
2507                             } else if (OLEConstants.LOCATION_LEVEL.equals(docFieldConfig.getName())) {
2508                                 globalEditEHoldingsFieldsFlagBO.setLocationEditFlag(true);
2509                             } else if (OLEConstants.EHOLDING_ACCESS_STATUS.equals(docFieldConfig.getName())) {
2510                                 globalEditEHoldingsFieldsFlagBO.setAccessStatusEditFlag(true);
2511                             } else if (OLEConstants.EHOLDING_PLATFORM_DISPLAY.equals(docFieldConfig.getName())) {
2512                                 globalEditEHoldingsFieldsFlagBO.setPlatformEditFlag(true);
2513                             } else if (OLEConstants.EHOLDING_IMPRINT.equals(docFieldConfig.getName())) {
2514                                 globalEditEHoldingsFieldsFlagBO.setImprintEditFlag(true);
2515                             } else if (OLEConstants.EHOLDING_E_PUBLISHER.equals(docFieldConfig.getName())) {
2516                                 globalEditEHoldingsFieldsFlagBO.setPublisherEditFlag(true);
2517                             } else if (OLEConstants.EHOLDING_STATISTICAL_CODE.equals(docFieldConfig.getName())) {
2518                                 globalEditEHoldingsFieldsFlagBO.setStatisticalCodeEditFlag(true);
2519                             } /*else if (OLEConstants.EHOLDING_SUBSCRIPTION_STATUS.equals(docFieldConfig.getName())) {
2520                                 // TODO add field to js staffOnlyEditFlag
2521                                 globalEditEHoldingsFieldsFlagBO.setSubscriptionEditFlag(true);
2522                             }*/ else if (OLEConstants.EHOLDING_SUBSCRIPTION_STATUS.equals(docFieldConfig.getName())) {
2523                                 globalEditEHoldingsFieldsFlagBO.setAcquisitionInformationEditFlag(true);
2524                                 globalEditEHoldingsFieldsFlagBO.setSubscriptionEditFlag(true);
2525                             } else if (OLEConstants.EHOLDING_LINK.equals(docFieldConfig.getName())) {
2526                                 globalEditEHoldingsFieldsFlagBO.setLinkEditFlag(true);
2527                                 globalEditEHoldingsFieldsFlagBO.setAccessInformationEditFlag(true);
2528                             } else if (OLEConstants.EHOLDING_SIMULTANEOUS_USER.equals(docFieldConfig.getName())) {
2529                                 globalEditEHoldingsFieldsFlagBO.setSimultaneousEditFlag(true);
2530                                 globalEditEHoldingsFieldsFlagBO.setAccessInformationEditFlag(true);
2531                             } else if (OLEConstants.EHOLDING_PERSIST_LINK.equals(docFieldConfig.getName())) {
2532                                 globalEditEHoldingsFieldsFlagBO.setPersistentLinkEditFlag(true);
2533                                 globalEditEHoldingsFieldsFlagBO.setAccessInformationEditFlag(true);
2534                             } else if (OLEConstants.EHOLDING_ACCESS_LOCATION.equals(docFieldConfig.getName())) {
2535                                 globalEditEHoldingsFieldsFlagBO.setAccessInformationEditFlag(true);
2536                                 globalEditEHoldingsFieldsFlagBO.setAccessLocationEditFlag(true);
2537                             } else if (OLEConstants.EHOLDING_LINK_TEXT.equals(docFieldConfig.getName())) {
2538                                 globalEditEHoldingsFieldsFlagBO.setLinkTextEditFlag(true);
2539                             } else if (OLEConstants.EHOLDING_ADMIN_USER.equals(docFieldConfig.getName())) {
2540                                 globalEditEHoldingsFieldsFlagBO.setAdminUserNameEditFlag(true);
2541                             } else if (OLEConstants.EHOLDING_ADMIN_PWSD.equals(docFieldConfig.getName())) {
2542                                 globalEditEHoldingsFieldsFlagBO.setAdminPasswordEditFlag(true);
2543                             } else if (OLEConstants.EHOLDING_ACCESS_USR_NAME.equals(docFieldConfig.getName())) {
2544                                 globalEditEHoldingsFieldsFlagBO.setAccessUserNameEditFlag(true);
2545                             } else if (OLEConstants.EHOLDING_ACCESS_PSWD.equals(docFieldConfig.getName())) {
2546                                 globalEditEHoldingsFieldsFlagBO.setAccessPasswordEditFlag(true);
2547                             } else if (OLEConstants.EHOLDING_ADMIN_URL.equals(docFieldConfig.getName())) {
2548                                 globalEditEHoldingsFieldsFlagBO.setAdminUrlEditFlag(true);
2549                             } else if (OLEConstants.EHOLDING_AUTHENTICATION_TYPE.equals(docFieldConfig.getName())) {
2550                                 globalEditEHoldingsFieldsFlagBO.setAuthenticationEditFlag(true);
2551                             } else if (OLEConstants.EHOLDING_PROXIED.equals(docFieldConfig.getName())) {
2552                                 globalEditEHoldingsFieldsFlagBO.setProxiedEditFlag(true);
2553                             } else if (OLEConstants.EHOLDING_ILL_IND.equals(docFieldConfig.getName())) {
2554                                 globalEditEHoldingsFieldsFlagBO.setLicenseDetailsEditFlag(true);
2555                                 globalEditEHoldingsFieldsFlagBO.setIllEditFlag(true);
2556                             } else if (OLEConstants.EHOLDING_COVERAGE.equals(docFieldConfig.getName())) {
2557                                 //globalEditEHoldingsFieldsFlagBO.setExtentOfOwnerShipEditFlag(true);
2558                                 globalEditEHoldingsFieldsFlagBO.setCoverageExtentOfOwnerShipEditFlag(true);
2559                             } else if (OLEConstants.EHOLDING_PERPETUAL.equals(docFieldConfig.getName())) {
2560                                 globalEditEHoldingsFieldsFlagBO.setExtentOfOwnerShipEditFlag(true);
2561                                 globalEditEHoldingsFieldsFlagBO.setPerpetualAccessEditFlag(true);
2562                             } else if (OLEConstants.HOLDINGS_NOTE.equals(docFieldConfig.getName())) {
2563                                 globalEditEHoldingsFieldsFlagBO.seteHoldingsNoteEditFlag(true);
2564                             } else if (OLEConstants.DONOR_CODE_DISPLAY.equals(docFieldConfig.getName())) {
2565                                 globalEditEHoldingsFieldsFlagBO.setDonorCodeEditFlag(true);
2566                             } else if (OLEConstants.EHOLDING_DONOR_PUBLIC_DISPLAY.equals(docFieldConfig.getName())) {
2567                                 globalEditEHoldingsFieldsFlagBO.setDonorPublicDisplayEditFlag(true);
2568                             } else if (OLEConstants.EHOLDING_DONOR_NOTE.equals(docFieldConfig.getName())) {
2569                                 globalEditEHoldingsFieldsFlagBO.setDonorNoteEditFlag(true);
2570                             }
2571                         }
2572                     }
2573 
2574                     // TODO -  need to do for E-holdings for global edit
2575 
2576                 } else if (DocType.ITEM.getCode().equals(docType)) {
2577 
2578                     GlobalEditItemFieldsFlagBO globalEditItemFieldsFlagBO = editorForm.getGlobalEditItemFieldsFlagBO();
2579                     for (DocFieldConfig docFieldConfig : docFieldConfigList) {
2580                         if (docFieldConfig.isGloballyEditable()) {
2581 
2582                             if (OLEConstants.CALL_NUMBER.equals(docFieldConfig.getName())) {
2583                                 globalEditItemFieldsFlagBO.setCallNumberEditFlag(true);
2584                             } else if (OLEConstants.CALL_NUMBER_PREFIX.equals(docFieldConfig.getName())) {
2585                                 globalEditItemFieldsFlagBO.setCallNumberPrefixEditFlag(true);
2586                             } else if (OLEConstants.CALL_NUMBER_TYPE_CODE.equals(docFieldConfig.getName())) {
2587                                 globalEditItemFieldsFlagBO.setCallNumberTypeEditFlag(true);
2588                             } else if (OLEConstants.SHELVING_ORDER.equals(docFieldConfig.getName())) {
2589                                 globalEditItemFieldsFlagBO.setShelvingOrderEditFlag(true);
2590                             } else if (OLEConstants.LOCATION_LEVEL.equals(docFieldConfig.getName())) {
2591                                 globalEditItemFieldsFlagBO.setLocationEditFlag(true);
2592                             } else if (OLEConstants.ITEM_STATUS_CODE_VALUE.equals(docFieldConfig.getName())) {
2593                                 globalEditItemFieldsFlagBO.setItemStatusEditFlag(true);
2594                                 globalEditItemFieldsFlagBO.setAccessInfoEditFlag(true);
2595                             } else if (OLEConstants.PO_LINE_ITEM_IDENTIFIER.equals(docFieldConfig.getName())) {
2596                                 globalEditItemFieldsFlagBO.setCallNumberTypeEditFlag(true);
2597                             } else if (OLEConstants.VENDOR_LINE_ITEM_IDENTIFIER.equals(docFieldConfig.getName())) {
2598                                 globalEditItemFieldsFlagBO.setVendorLineItemIDEditFlag(true);
2599                             } else if (OLEConstants.BAR_CODE_ARSL.equals(docFieldConfig.getName())) {
2600                                 globalEditItemFieldsFlagBO.setBarcodeARSLEditFlag(true);
2601                             } else if (OLEConstants.STATISTICAL_SEARCH_CODE.equals(docFieldConfig.getName())) {
2602                                 globalEditItemFieldsFlagBO.setStatisticalSearchingCodesEditFlag(true);
2603                             } else if (OLEConstants.ITEM_TYPE_CODE_VALUE.equals(docFieldConfig.getName())) {
2604                                 globalEditItemFieldsFlagBO.setItemTypeEditFlag(true);
2605                             } else if (OLEConstants.COPY_NUMBER_LABEL.equals(docFieldConfig.getName())) {
2606                                 globalEditItemFieldsFlagBO.setCopyNumberEditFlag(true);
2607                             } else if (OLEConstants.VOLUME_NUMBER.equals(docFieldConfig.getName()) || OLEConstants.VOLUME_NUMBER_LABEL.equals(docFieldConfig.getName())) {
2608                                 //globalEditItemFieldsFlagBO.set(true);
2609                             } else if (OLEConstants.ENUMARATION.equals(docFieldConfig.getName())) {
2610                                 globalEditItemFieldsFlagBO.setEnumerationEditFlag(true);
2611                             } else if (OLEConstants.CHRONOLOGY.equals(docFieldConfig.getName())) {
2612                                 globalEditItemFieldsFlagBO.setChronologyEditFlag(true);
2613                             } else if (OLEConstants.DONORPUBLIC_DISPLAY.equals(docFieldConfig.getName())) {
2614                                 globalEditItemFieldsFlagBO.setDonorPublicDisplayEditFlag(true);
2615                             } else if (OLEConstants.DONORNOTE_DISPLAY.equals(docFieldConfig.getName())) {
2616                                 globalEditItemFieldsFlagBO.setDonorNoteEditFlag(true);
2617                             } else if (OLEConstants.ITEMNOTE_TYPE_DISPLAY.equals(docFieldConfig.getName()) ) {
2618                                 globalEditItemFieldsFlagBO.setExtndInfoEditFlag(true);
2619                             } else if (OLEConstants.ITEMBARCODE_DISPLAY.equals(docFieldConfig.getName()) || OLEConstants.ITEMBARCODE_SEARCH.equals(docFieldConfig.getName())) {
2620                                 globalEditItemFieldsFlagBO.setBarcodeEditFlag(true);
2621                             } else if (OLEConstants.TEMPITEMTYPE_DISPLAY.equals(docFieldConfig.getName())) {
2622                                 globalEditItemFieldsFlagBO.setTempItemTypeEditFlag(true);
2623                             } else if (OLEConstants.DONORCODE_DISPLAY.equals(docFieldConfig.getName())) {
2624                                 globalEditItemFieldsFlagBO.setDonorCodeEditFlag(true);
2625                             } else if (OLEConstants.FORMERIDENTIFIER_DISPLAY.equals(docFieldConfig.getName())) {
2626                                 globalEditItemFieldsFlagBO.setFormerIdentifiersEditFlag(true);
2627                             } else if (OLEConstants.FASTADD_DISPLAY.equals(docFieldConfig.getName())) {
2628                                 globalEditItemFieldsFlagBO.setFastAddEditFlag(true);
2629                             } else if (OLEConstants.PIECES_DISPLAY.equals(docFieldConfig.getName())) {
2630                                 globalEditItemFieldsFlagBO.setNumberOfPiecesEditFlag(true);
2631                             } else if (OLEConstants.ITEMSTATUSDATE_DISPLAY.equals(docFieldConfig.getName())) {
2632                                 globalEditItemFieldsFlagBO.setItemStatusDateEditFlag(true);
2633                             } else if (OLEConstants.CHECKINNOTE_DISPLAY.equals(docFieldConfig.getName())) {
2634                                 globalEditItemFieldsFlagBO.setCheckinNoteEditFlag(true);
2635                             } else if (OLEConstants.DUEDATETIME_DISPLAY.equals(docFieldConfig.getName())) {
2636                                 globalEditItemFieldsFlagBO.setDueDatetimeEditFlag(true);
2637                             } else if (OLEConstants.CLAIMSRETURNFLAG_DISPLAY.equals(docFieldConfig.getName())) {
2638                                 globalEditItemFieldsFlagBO.setClaimsReturnEditFlag(true);
2639                             } else if (OLEConstants.MISSINGPIECEFLAG_DISPLAY.equals(docFieldConfig.getName())) {
2640                                 globalEditItemFieldsFlagBO.setMissingPieceEditFlag(true);
2641                             } else if (OLEConstants.ITEMDAMAGEDSTATUS_DISPLAY.equals(docFieldConfig.getName())) {
2642                                 globalEditItemFieldsFlagBO.setItemDamagedStatusEditFlag(true);
2643                             }
2644 
2645                             // TODO - need to do for other fields in ITEM
2646                         }
2647                     }
2648                 }
2649             }
2650 
2651 
2652         }
2653 
2654 
2655     }
2656 
2657 
2658     @RequestMapping(params = "methodToCall=cancel")
2659     public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2660                                HttpServletRequest request, HttpServletResponse response) {
2661         String docCategory = request.getParameter("docCategory");
2662         String docType = request.getParameter("docType");
2663         String docFormat = request.getParameter("docFormat");
2664         String docId = request.getParameter("docId");
2665         String bibId = request.getParameter("bibId");
2666         String instanceId = request.getParameter("instanceId");
2667         String editable = request.getParameter("editable");
2668 
2669         String requestUrl="/ole-kr-krad/editorcontroller?viewId=EditorView&methodToCall=load&docCategory="+docCategory+"&docType="+docType+"&docFormat="+docFormat+"&docId="+docId+"&bibId="+bibId+"&instanceId="+instanceId+"&editable="+editable;
2670         String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
2671         String url = baseUrl + requestUrl;
2672         Properties props = new Properties();
2673         props.put(UifParameters.METHOD_TO_CALL, "load");
2674         if (org.apache.commons.lang.StringUtils.isNotBlank(form.getReturnFormKey())) {
2675             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
2676         }
2677 
2678 
2679         return performRedirect(form, url, props);
2680     }
2681     /**
2682      * This method prints the bib information in to a PDF.
2683      * @param form
2684      * @param result
2685      * @param request
2686      * @param response
2687      */
2688     @RequestMapping(params = "methodToCall=printBib")
2689     public void printBib(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
2690         String formKey = request.getParameter("formKey");
2691         EditorForm editorForm = (EditorForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
2692         generateBibPdfView(editorForm, response);
2693     }
2694 
2695     /**
2696      * This method generates the pdf with bib information.
2697      * @param editorForm
2698      * @param response
2699      */
2700     private void generateBibPdfView(EditorForm editorForm, HttpServletResponse response) {
2701         LOG.debug("Creating Bib PDF");
2702         String fileName = "Bib" + "_" + editorForm.getDocId() + ".pdf";
2703 
2704         Bib bib = null;
2705         WorkBibMarcForm documentForm = null;
2706         if (null != editorForm.getDocumentForm() && editorForm.getDocumentForm() instanceof WorkBibMarcForm) {
2707             documentForm = (WorkBibMarcForm) editorForm.getDocumentForm();
2708             if (CollectionUtils.isNotEmpty(documentForm.getBibTreeList())) {
2709                 bib = documentForm.getBibTreeList().get(0).getBib();
2710             }
2711         }
2712 
2713         try {
2714             Document document = this.getDocument(0, 0, 5, 5);
2715             OutputStream outputStream = null;
2716             response.setContentType("application/pdf");
2717             response.setHeader("Content-Disposition", "inline;filename=" + fileName);
2718             outputStream = response.getOutputStream();
2719             PdfWriter.getInstance(document, outputStream);
2720             Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
2721             document.open();
2722             document.newPage();
2723 
2724             PdfPTable pdfTable = new PdfPTable(3);
2725             pdfTable.setWidths(new int[]{15, 2, 30});
2726 
2727             Paragraph paraGraph = new Paragraph();
2728             paraGraph.setAlignment(Element.ALIGN_CENTER);
2729             paraGraph.add(new Chunk("Bibliographic Record", boldFont));
2730             paraGraph.add(Chunk.NEWLINE);
2731             paraGraph.add(Chunk.NEWLINE);
2732             paraGraph.add(Chunk.NEWLINE);
2733 
2734             pdfTable.addCell(getPdfPCellInJustified("Bib Id"));
2735             pdfTable.addCell(getPdfPCellInLeft(":"));
2736             pdfTable.addCell(getPdfPCellInJustified((bib != null && bib.getId() != null) ? bib.getId() : ""));
2737 
2738             pdfTable.addCell(getPdfPCellInJustified("Bib Record Status"));
2739             pdfTable.addCell(getPdfPCellInLeft(":"));
2740             pdfTable.addCell(getPdfPCellInJustified((bib != null && bib.getStatus() != null) ? bib.getStatus() : ""));
2741 
2742             pdfTable.addCell(getPdfPCellInJustified("Leader"));
2743             pdfTable.addCell(getPdfPCellInLeft(":"));
2744             pdfTable.addCell(getPdfPCellInJustified((documentForm != null && documentForm.getLeader() != null) ? documentForm.getLeader() : ""));
2745 
2746             if (null != documentForm && null != documentForm.getMarcControlFields()) {
2747                 List<ControlField006Text> controlFields006List = documentForm.getMarcControlFields().getControlFields006List();
2748                 if (CollectionUtils.isNotEmpty(controlFields006List)) {
2749                     if (StringUtils.isNotBlank(controlFields006List.get(0).getRawText())) {
2750                         pdfTable.addCell(getPdfPCellInJustified("006"));
2751                         pdfTable.addCell(getPdfPCellInLeft(":"));
2752                         if (controlFields006List.size() == 1) {
2753                             pdfTable.addCell(getPdfPCellInJustified(controlFields006List.get(0).getRawText()));
2754                         } else if (controlFields006List.size() > 1) {
2755                             StringBuilder textBuilder = new StringBuilder();
2756                             for (ControlField006Text controlField006Text : controlFields006List) {
2757                                 if (null != controlField006Text.getRawText()) {
2758                                     textBuilder.append(controlField006Text.getRawText());
2759                                     textBuilder.append(System.lineSeparator());
2760                                 }
2761                             }
2762                             pdfTable.addCell(getPdfPCellInJustified(textBuilder.toString()));
2763                         }
2764                     }
2765                 }
2766 
2767                 List<ControlField007Text> controlFields007List = documentForm.getMarcControlFields().getControlFields007List();
2768                 if (CollectionUtils.isNotEmpty(controlFields007List)) {
2769                     if (StringUtils.isNotBlank(controlFields007List.get(0).getRawText())) {
2770                         pdfTable.addCell(getPdfPCellInJustified("007"));
2771                         pdfTable.addCell(getPdfPCellInLeft(":"));
2772                         if (controlFields007List.size() == 1) {
2773                             pdfTable.addCell(getPdfPCellInJustified(controlFields007List.get(0).getRawText()));
2774                         } else if (controlFields007List.size() > 1) {
2775                             StringBuilder textBuilder = new StringBuilder();
2776                             for (ControlField007Text controlField007Text : controlFields007List) {
2777                                 if (null != controlField007Text.getRawText()) {
2778                                     textBuilder.append(controlField007Text.getRawText());
2779                                     textBuilder.append(System.lineSeparator());
2780                                 }
2781                             }
2782                             pdfTable.addCell(getPdfPCellInJustified(textBuilder.toString()));
2783                         }
2784                     }
2785                 }
2786             }
2787 
2788             BibMarcRecord bibMarcRecord = null;
2789             String controlField008Value = null;
2790             if (null != bib) {
2791                 BibMarcRecordProcessor recordProcessor = new BibMarcRecordProcessor();
2792                 BibMarcRecords bibMarcRecords = recordProcessor.fromXML(bib.getContent());
2793                 if (null != bibMarcRecords && CollectionUtils.isNotEmpty(bibMarcRecords.getRecords())) {
2794                     bibMarcRecord = bibMarcRecords.getRecords().get(0);
2795                     List<ControlField> controlFields = bibMarcRecord.getControlFields();
2796                     for (ControlField controlField : controlFields) {
2797                         if (controlField.getTag().equals(ControlFields.CONTROL_FIELD_008)) {
2798                             controlField008Value = controlField.getValue();
2799                         }
2800                     }
2801                 }
2802             }
2803 
2804             pdfTable.addCell(getPdfPCellInJustified("008"));
2805             pdfTable.addCell(getPdfPCellInLeft(":"));
2806             if (StringUtils.isNotBlank(controlField008Value)) {
2807                 pdfTable.addCell(getPdfPCellInJustified(controlField008Value.replaceAll(" ", "#")));
2808             } else {
2809                 pdfTable.addCell(getPdfPCellInJustified(""));
2810             }
2811 
2812             Paragraph dataFieldsParaGraph = new Paragraph(new Paragraph("Data Fields : ", new Font(Font.TIMES_ROMAN, 13, Font.BOLD)));
2813             dataFieldsParaGraph.setIndentationLeft(60);
2814             dataFieldsParaGraph.add(Chunk.NEWLINE);
2815             dataFieldsParaGraph.add(Chunk.NEWLINE);
2816 
2817             PdfPTable dataFieldsTable = new PdfPTable(4);
2818 
2819             float[] columnWidths = new float[] {10f, 5f, 5f, 100f};
2820             dataFieldsTable.setWidths(columnWidths);
2821 
2822             if (null != bib && null != bibMarcRecord) {
2823                 StringBuffer value = new StringBuffer();
2824                 for (DataField dataField : bibMarcRecord.getDataFields()) {
2825                     dataFieldsTable.addCell(getPdfPCellInLeft(dataField.getTag()));
2826                     dataFieldsTable.addCell(getPdfPCellInLeft(StringUtils.isNotBlank(dataField.getInd1()) ? dataField.getInd1() : "#"));
2827                     dataFieldsTable.addCell(getPdfPCellInLeft(StringUtils.isNotBlank(dataField.getInd2()) ? dataField.getInd2() : "#"));
2828                     for (SubField subField : dataField.getSubFields()) {
2829                         value.append("|" + subField.getCode());
2830                         value.append(" ");
2831                         value.append(subField.getValue());
2832                     }
2833                     dataFieldsTable.addCell(getPdfPCellInLeft(value.toString()));
2834                     value.delete(0, value.length());
2835                 }
2836             }
2837 
2838             document.add(paraGraph);
2839             document.add(pdfTable);
2840             document.add(Chunk.NEWLINE);
2841             document.add(dataFieldsParaGraph);
2842             document.add(dataFieldsTable);
2843             document.close();
2844             outputStream.flush();
2845             outputStream.close();
2846         } catch (Exception e) {
2847             LOG.error(e, e);
2848         }
2849     }
2850 
2851 
2852 }