001 /*
002 * Copyright 2005-2007 The Kuali Foundation
003 *
004 *
005 * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
006 * compliance with the License. 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 distributed under the License is distributed on an "AS
011 * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
012 * language governing permissions and limitations under the License.
013 */
014 package org.kuali.rice.kew.messaging.exceptionhandling;
015
016 import org.apache.commons.lang.StringUtils;
017 import org.kuali.rice.kew.api.WorkflowRuntimeException;
018 import org.kuali.rice.kew.service.KEWServiceLocator;
019 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
020 import org.kuali.rice.ksb.messaging.exceptionhandling.DefaultMessageExceptionHandler;
021 import org.kuali.rice.ksb.messaging.exceptionhandling.MessageExceptionHandler;
022 import org.kuali.rice.ksb.service.KSBServiceLocator;
023
024 /**
025 * A {@link MessageExceptionHandler} which handles putting documents into
026 * exception routing.
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030 public class DocumentMessageExceptionHandler extends DefaultMessageExceptionHandler {
031
032 @Override
033 protected void placeInException(Throwable throwable, PersistedMessageBO message) throws Exception {
034 KEWServiceLocator.getExceptionRoutingService().placeInExceptionRouting(throwable, message, getDocumentId(message));
035 }
036
037
038
039 @Override
040 public void handleExceptionLastDitchEffort(Throwable throwable, PersistedMessageBO message, Object service) throws Exception {
041 KEWServiceLocator.getExceptionRoutingService().placeInExceptionRoutingLastDitchEffort(throwable, message, getDocumentId(message));
042 }
043
044
045
046 @Override
047 protected void scheduleExecution(Throwable throwable, PersistedMessageBO message) throws Exception {
048 String description = "DocumentId: " + getDocumentId(message);
049 KSBServiceLocator.getExceptionRoutingService().scheduleExecution(throwable, message, description);
050 }
051
052 protected String getDocumentId(PersistedMessageBO message) {
053 if (!StringUtils.isEmpty(message.getValue1())) {
054 return message.getValue1();
055 }
056 throw new WorkflowRuntimeException("Unable to put this message in exception routing service name " + message.getServiceName());
057 }
058 }