1 /**
2 * Copyright 2005-2012 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.kew.actions;
17
18 import org.apache.log4j.MDC;
19 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
20 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
21 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
22 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
23 import org.kuali.rice.kew.api.KewApiConstants;
24 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
25
26 import java.util.List;
27
28
29 /**
30 * Simply records an action taken with an annotation.
31 *
32 * @author Kuali Rice Team (rice.collab@kuali.org)
33 */
34 public class LogDocumentActionAction extends ActionTakenEvent {
35
36 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LogDocumentActionAction.class);
37
38 /**
39 * @param rh RouteHeader for the document upon which the action is taken.
40 * @param principal User taking the action.
41 */
42 public LogDocumentActionAction(DocumentRouteHeaderValue rh, PrincipalContract principal) {
43 super(KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, rh, principal);
44 }
45
46 /**
47 * @param rh RouteHeader for the document upon which the action is taken.
48 * @param principal User taking the action.
49 * @param annotation User comment on the action taken
50 */
51 public LogDocumentActionAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) {
52 super(KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, rh, principal, annotation);
53 }
54
55 /* (non-Javadoc)
56 * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
57 */
58 @Override
59 public String validateActionRules() {
60 // log action is always valid so return no error message
61 return "";
62 }
63
64 /**
65 * Records the non-routed document action. - Checks to make sure the document status allows the action. Records the action.
66 *
67 * @throws InvalidActionTakenException
68 */
69 public void recordAction() throws InvalidActionTakenException {
70 MDC.put("docId", getRouteHeader().getDocumentId());
71
72 String errorMessage = validateActionRules();
73 if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
74 throw new InvalidActionTakenException(errorMessage);
75 }
76
77 LOG.debug("Logging document action");
78 ActionTakenValue actionTaken = saveActionTaken(Boolean.TRUE);
79 // LogDocumentAction should not contact the PostProcessor which is why we don't call notifyActionTaken
80
81 }
82
83 @Override
84 public String validateActionRules(List<ActionRequestValue> actionRequests) {
85 // log action is always valid so return no error message
86 return "";
87 }
88 }