001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.actions;
017
018 import org.apache.log4j.MDC;
019 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
020 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
021 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
022 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
023 import org.kuali.rice.kew.api.KewApiConstants;
024 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
025
026 import java.util.List;
027
028
029 /**
030 * Simply records an action taken with an annotation.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 public class LogDocumentActionAction extends ActionTakenEvent {
035
036 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LogDocumentActionAction.class);
037
038 /**
039 * @param rh RouteHeader for the document upon which the action is taken.
040 * @param principal User taking the action.
041 */
042 public LogDocumentActionAction(DocumentRouteHeaderValue rh, PrincipalContract principal) {
043 super(KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, rh, principal);
044 }
045
046 /**
047 * @param rh RouteHeader for the document upon which the action is taken.
048 * @param principal User taking the action.
049 * @param annotation User comment on the action taken
050 */
051 public LogDocumentActionAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) {
052 super(KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, rh, principal, annotation);
053 }
054
055 /* (non-Javadoc)
056 * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
057 */
058 @Override
059 public String validateActionRules() {
060 // log action is always valid so return no error message
061 return "";
062 }
063
064 /**
065 * Records the non-routed document action. - Checks to make sure the document status allows the action. Records the action.
066 *
067 * @throws InvalidActionTakenException
068 */
069 public void recordAction() throws InvalidActionTakenException {
070 MDC.put("docId", getRouteHeader().getDocumentId());
071
072 String errorMessage = validateActionRules();
073 if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
074 throw new InvalidActionTakenException(errorMessage);
075 }
076
077 LOG.debug("Logging document action");
078 ActionTakenValue actionTaken = saveActionTaken(Boolean.TRUE);
079 // LogDocumentAction should not contact the PostProcessor which is why we don't call notifyActionTaken
080
081 }
082
083 @Override
084 public String validateActionRules(List<ActionRequestValue> actionRequests) {
085 // log action is always valid so return no error message
086 return "";
087 }
088 }