View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.util.GlobalVariables;
31  import org.kuali.rice.krad.util.KRADConstants;
32  
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  import java.util.HashMap;
36  import java.util.Map;
37  import java.util.Set;
38  
39  /**
40   * This class handles UI actions for all shared methods of transactional documents.
41   *
42   * @deprecated Use {@link org.kuali.rice.krad.document.TransactionalDocumentControllerBase}.
43   */
44  @Deprecated
45  public class KualiTransactionalDocumentActionBase extends KualiDocumentActionBase {
46  //    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiTransactionalDocumentActionBase.class);
47  
48      /**
49       * Method that will take the current document and call its copy method if Copyable.
50       */
51      public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
52          KualiTransactionalDocumentFormBase tmpForm = (KualiTransactionalDocumentFormBase) form;
53  
54          Document document = tmpForm.getDocument();
55          
56          if (!tmpForm.getDocumentActions().containsKey(KRADConstants.KUALI_ACTION_CAN_COPY)) {
57              throw buildAuthorizationException("copy", document);
58          }
59  
60          ((Copyable) tmpForm.getTransactionalDocument()).toCopy();
61  
62          return mapping.findForward(RiceConstants.MAPPING_BASIC);
63      }
64  
65      @SuppressWarnings("unchecked")
66  	protected void populateAuthorizationFields(KualiDocumentFormBase formBase){
67      	super.populateAuthorizationFields(formBase);
68      	Document document = formBase.getDocument();
69      	Map editMode = new HashMap();
70      	
71      	if (formBase.isFormDocumentInitialized()) {
72          	Person user = GlobalVariables.getUserSession().getPerson();
73          	
74          	TransactionalDocumentPresentationController documentPresentationController = (TransactionalDocumentPresentationController) getDocumentHelperService().getDocumentPresentationController(document);
75              TransactionalDocumentAuthorizer documentAuthorizer = (TransactionalDocumentAuthorizer) KNSServiceLocator
76                      .getDocumentHelperService().getDocumentAuthorizer(document);
77              Set<String> editModes = documentAuthorizer.getEditModes(document, user, documentPresentationController.getEditModes(document));
78              editMode = this.convertSetToMap(editModes);
79              if (getDataDictionaryService().getDataDictionary().getDocumentEntry(document.getClass().getName()).getUsePessimisticLocking()) {
80                  editMode = getPessimisticLockService().establishLocks(document, editMode, user);
81              }            
82      	}
83      	formBase.setEditingMode(editMode);
84      }
85  }