1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.action;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.kuali.rice.core.api.util.RiceConstants;
22 import org.kuali.rice.kim.api.identity.Person;
23 import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizer;
24 import org.kuali.rice.kns.document.authorization.TransactionalDocumentPresentationController;
25 import org.kuali.rice.kns.service.KNSServiceLocator;
26 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
27 import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
28 import org.kuali.rice.krad.document.Copyable;
29 import org.kuali.rice.krad.document.Document;
30 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
31 import org.kuali.rice.krad.util.GlobalVariables;
32 import org.kuali.rice.krad.util.KRADConstants;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.Set;
39
40
41
42
43 public class KualiTransactionalDocumentActionBase extends KualiDocumentActionBase {
44
45
46
47
48
49 public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
50 KualiTransactionalDocumentFormBase tmpForm = (KualiTransactionalDocumentFormBase) form;
51
52 Document document = tmpForm.getDocument();
53
54 if (!tmpForm.getDocumentActions().containsKey(KRADConstants.KUALI_ACTION_CAN_COPY)) {
55 throw buildAuthorizationException("copy", document);
56 }
57
58 ((Copyable) tmpForm.getTransactionalDocument()).toCopy();
59
60 return mapping.findForward(RiceConstants.MAPPING_BASIC);
61 }
62
63 @SuppressWarnings("unchecked")
64 protected void populateAuthorizationFields(KualiDocumentFormBase formBase){
65 super.populateAuthorizationFields(formBase);
66 Document document = formBase.getDocument();
67 Map editMode = new HashMap();
68
69 if (formBase.isFormDocumentInitialized()) {
70 Person user = GlobalVariables.getUserSession().getPerson();
71
72 TransactionalDocumentPresentationController documentPresentationController = (TransactionalDocumentPresentationController) getDocumentHelperService().getDocumentPresentationController(document);
73 TransactionalDocumentAuthorizer documentAuthorizer = (TransactionalDocumentAuthorizer) KNSServiceLocator
74 .getDocumentHelperService().getDocumentAuthorizer(document);
75 Set<String> editModes = documentAuthorizer.getEditModes(document, user, documentPresentationController.getEditModes(document));
76 editMode = this.convertSetToMap(editModes);
77 if (getDataDictionaryService().getDataDictionary().getDocumentEntry(document.getClass().getName()).getUsePessimisticLocking()) {
78 editMode = getPessimisticLockService().establishLocks(document, editMode, user);
79 }
80 }
81 formBase.setEditingMode(editMode);
82 }
83 }