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