1 package org.kuali.ole.deliver.service;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.rice.kew.api.exception.WorkflowException;
5 import org.kuali.rice.krad.exception.DocumentTypeAuthorizationException;
6 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7 import org.kuali.rice.krad.service.impl.MaintenanceDocumentServiceImpl;
8 import org.kuali.rice.krad.util.GlobalVariables;
9 import org.kuali.rice.krad.util.KRADConstants;
10 import org.kuali.rice.krad.util.ObjectUtils;
11
12 import java.io.Serializable;
13 import java.util.Map;
14
15
16
17
18
19
20
21
22 public class OleDeliverRequestMaintenanceDocumentServiceImpl extends MaintenanceDocumentServiceImpl {
23 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDeliverRequestMaintenanceDocumentServiceImpl.class);
24
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 LOG.error("Exception", e);
47 throw new RuntimeException(e);
48 }
49
50 if (StringUtils.isEmpty(documentTypeName)) {
51 throw new RuntimeException(
52 "documentTypeName is empty; does this Business Object have a maintenance document definition? " +
53 objectClassName);
54 }
55 }
56
57
58 if (KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) ||
59 KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) {
60 Class<?> boClass =
61 getDocumentDictionaryService().getMaintenanceDataObjectClass(documentTypeName);
62 boolean allowsNewOrCopy = getDataObjectAuthorizationService()
63 .canCreate(boClass, GlobalVariables.getUserSession().getPerson(), documentTypeName);
64 if (!allowsNewOrCopy) {
65 LOG.error("Document type " + documentTypeName + " does not allow new or copy actions.");
66 throw new DocumentTypeAuthorizationException(
67 GlobalVariables.getUserSession().getPerson().getPrincipalId(), "newOrCopy", documentTypeName);
68 }
69 }
70
71
72 try {
73 return (MaintenanceDocument) getDocumentService().getNewDocument(documentTypeName);
74 } catch (WorkflowException e) {
75 LOG.error("Cannot get new maintenance document instance for doc type: " + documentTypeName, e);
76 throw new RuntimeException("Cannot get new maintenance document instance for doc type: " + documentTypeName,
77 e);
78 }
79 }
80
81
82
83
84
85
86
87
88
89
90
91 public void setupMaintenanceObjectForDelete(MaintenanceDocument document, String maintenanceAction,
92 Map<String, String[]> requestParameters) {
93 document.getNewMaintainableObject().setMaintenanceAction(maintenanceAction);
94 document.getOldMaintainableObject().setMaintenanceAction(maintenanceAction);
95
96 Object oldDataObject = retrieveObjectForMaintenance(document, requestParameters);
97 Object newDataObject = ObjectUtils.deepCopy((Serializable) oldDataObject);
98
99 document.getOldMaintainableObject().setDataObject(oldDataObject);
100 document.getNewMaintainableObject().setDataObject(newDataObject);
101 }
102
103 }