1 package org.kuali.ole.service;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.select.bo.OleCheckListBo;
5 import org.kuali.rice.kew.api.exception.WorkflowException;
6 import org.kuali.rice.krad.exception.DocumentTypeAuthorizationException;
7 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
8 import org.kuali.rice.krad.service.impl.MaintenanceDocumentServiceImpl;
9 import org.kuali.rice.krad.util.GlobalVariables;
10 import org.kuali.rice.krad.util.KRADConstants;
11 import org.kuali.rice.krad.util.ObjectUtils;
12
13 import java.io.Serializable;
14 import java.util.Map;
15
16
17
18
19 public class OleCheckListMaintenanceDocumentServiceImpl extends MaintenanceDocumentServiceImpl implements OleCheckListMaintenanceDocumentService {
20
21 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleCheckListMaintenanceDocumentServiceImpl.class);
22
23
24
25
26
27
28
29
30 @Override
31 public MaintenanceDocument setupNewMaintenanceDocument(String objectClassName, String documentTypeName,
32 String maintenanceAction) {
33 if (StringUtils.isEmpty(objectClassName) && StringUtils.isEmpty(documentTypeName)) {
34 throw new IllegalArgumentException("Document type name or bo class not given!");
35 }
36
37
38 if (StringUtils.isEmpty(documentTypeName)) {
39 try {
40 documentTypeName =
41 getDocumentDictionaryService().getMaintenanceDocumentTypeName(Class.forName(objectClassName));
42 } catch (ClassNotFoundException e) {
43 throw new RuntimeException(e);
44 }
45
46 if (StringUtils.isEmpty(documentTypeName)) {
47 throw new RuntimeException(
48 "documentTypeName is empty; does this Business Object have a maintenance document definition? " +
49 objectClassName);
50 }
51 }
52
53
54 if (KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) ||
55 KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) {
56 Class<?> boClass =
57 getDocumentDictionaryService().getMaintenanceDataObjectClass(documentTypeName);
58 boolean allowsNewOrCopy = getDataObjectAuthorizationService()
59 .canCreate(boClass, GlobalVariables.getUserSession().getPerson(), documentTypeName);
60 if (!allowsNewOrCopy) {
61 LOG.error("Document type " + documentTypeName + " does not allow new or copy actions.");
62 throw new DocumentTypeAuthorizationException(
63 GlobalVariables.getUserSession().getPerson().getPrincipalId(), "newOrCopy", documentTypeName);
64 }
65 }
66
67
68 try {
69 return (MaintenanceDocument) getDocumentService().getNewDocument(documentTypeName);
70 } catch (WorkflowException e) {
71 LOG.error("Cannot get new maintenance document instance for doc type: " + documentTypeName, e);
72 throw new RuntimeException("Cannot get new maintenance document instance for doc type: " + documentTypeName,
73 e);
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86 public void setupMaintenanceObjectForDelete(MaintenanceDocument document, String maintenanceAction,
87 Map<String, String[]> requestParameters) {
88 document.getNewMaintainableObject().setMaintenanceAction(maintenanceAction);
89 document.getOldMaintainableObject().setMaintenanceAction(maintenanceAction);
90
91 Object oldDataObject = retrieveObjectForMaintenance(document, requestParameters);
92 Object newDataObject = ObjectUtils.deepCopy((Serializable) oldDataObject);
93
94 document.getOldMaintainableObject().setDataObject(oldDataObject);
95 document.getNewMaintainableObject().setDataObject(newDataObject);
96 }
97
98 @Override
99 public void setupMaintenanceObject(MaintenanceDocument document, String maintenanceAction,
100 Map<String, String[]> requestParameters) {
101
102 super.setupMaintenanceObject(document,maintenanceAction,requestParameters);
103
104
105 OleCheckListBo oldDataObject = (OleCheckListBo) document.getOldMaintainableObject().getDataObject();
106 OleCheckListBo newDataObject = (OleCheckListBo) ObjectUtils.deepCopy((Serializable) oldDataObject);
107
108 document.getOldMaintainableObject().setDataObject(oldDataObject);
109 document.getNewMaintainableObject().setDataObject(newDataObject);
110 }
111 }