View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.actions;
18  
19  import java.util.List;
20  
21  import org.apache.log4j.MDC;
22  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
23  import org.kuali.rice.kew.actiontaken.ActionTakenValue;
24  import org.kuali.rice.kew.exception.InvalidActionTakenException;
25  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
26  import org.kuali.rice.kew.util.KEWConstants;
27  import org.kuali.rice.kew.util.Utilities;
28  import org.kuali.rice.kim.bo.entity.KimPrincipal;
29  
30  
31  /**
32   * Simply records an action taken with an annotation.  
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class LogDocumentActionAction extends ActionTakenEvent {
37  
38      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LogDocumentActionAction.class);
39  
40      /**
41       * @param rh RouteHeader for the document upon which the action is taken.
42       * @param principal User taking the action.
43       */
44      public LogDocumentActionAction(DocumentRouteHeaderValue rh, KimPrincipal principal) {
45          super(KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, rh, principal);
46      }
47  
48      /**
49       * @param rh RouteHeader for the document upon which the action is taken.
50       * @param principal User taking the action.
51       * @param annotation User comment on the action taken
52       */
53      public LogDocumentActionAction(DocumentRouteHeaderValue rh, KimPrincipal principal, String annotation) {
54          super(KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, rh, principal, annotation);
55      }
56  
57      /* (non-Javadoc)
58       * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
59       */
60      @Override
61      public String validateActionRules() {
62          // log action is always valid so return no error message
63          return "";
64      }
65  
66      /**
67       * Records the non-routed document action. - Checks to make sure the document status allows the action. Records the action.
68       * 
69       * @throws InvalidActionTakenException
70       */
71      public void recordAction() throws InvalidActionTakenException {
72          MDC.put("docId", getRouteHeader().getRouteHeaderId());
73  
74          String errorMessage = validateActionRules();
75          if (!Utilities.isEmpty(errorMessage)) {
76              throw new InvalidActionTakenException(errorMessage);
77          }
78  
79          LOG.debug("Logging document action");
80          ActionTakenValue actionTaken = saveActionTaken(Boolean.FALSE);
81          // LogDocumentAction should not contact the PostProcessor which is why we don't call notifyActionTaken
82         
83      }
84  
85  	@Override
86  	public String validateActionRules(List<ActionRequestValue> actionRequests) {
87          // log action is always valid so return no error message
88  		return "";
89  	}
90  }