| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| package org.eclipse.osbp.bpm.api; |
| |
| import org.drools.runtime.process.ProcessContext; |
| import org.eclipse.osbp.dsl.common.datatypes.IDto; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| /** |
| * Base class for blip function groups. It provides basic functions to handle blips. |
| */ |
| public abstract class BlipBaseFunctionGroup { |
| |
| private static IBlipBPMProcessProtocolCache protocolCache; |
| private final static Logger log = LoggerFactory.getLogger(BlipBaseFunctionGroup.class); |
| |
| @Deprecated |
| public final static void setProtocolCache(IBlipBPMProcessProtocolCache protocolCache) { |
| if (BlipBaseFunctionGroup.protocolCache == null) { |
| BlipBaseFunctionGroup.protocolCache = protocolCache; |
| } |
| else if (BlipBaseFunctionGroup.protocolCache != protocolCache) { |
| BlipBaseFunctionGroup.protocolCache = protocolCache; |
| } |
| } |
| |
| /** |
| * This method can be used as the default sequence flow on exclusive split gateways! |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @return <b>always</b> <code>true</code> |
| */ |
| public final static boolean defaultSequenceFlow(Object kcontext) { |
| return true; |
| } |
| |
| /** |
| * name of the function defaultSequenceFlow(kcontext) to be used in the blip grammar |
| */ |
| protected final static String DEFAULT_SEQUENCE_FLOW = "defaultSequenceFlow"; |
| |
| /** |
| * @see hints in {@link #getVariable(Object, String) |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @return the protocol of this process instance, which can be generated with appendProcessProtocol() |
| */ |
| public final static IBlipBPMProcessProtocol getProcessProtocol(Object kcontext) { |
| return protocolCache.mergeToProtocol(kcontext, (IBlipBPMProcessProtocol)getVariable(kcontext, IBlipBPMConstants.VARIABLE_PROCESS_PROTOCOL)); |
| } |
| |
| /** |
| * @see hints in {@link #getVariable(Object, String) |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @param line new line for the protocol |
| * @return the new protocol of this process instance |
| */ |
| public final static IBlipBPMProcessProtocol appendProcessProtocol(Object kcontext, String line) { |
| IBlipBPMProcessProtocol protocol = protocolCache.addToProtocol(kcontext, line, getProcessProtocol(kcontext)); |
| setVariable(kcontext, IBlipBPMConstants.VARIABLE_PROCESS_PROTOCOL, protocol); |
| return protocol; |
| } |
| |
| /** |
| * @see hints in {@link #getVariable(Object, String) |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @return the workload dto of this process instance |
| */ |
| public final static Object getWorkloadDto(Object kcontext) { |
| return getVariable(kcontext, IBlipBPMConstants.VARIABLE_PROCESS_WORKLOAD_DTO); |
| } |
| |
| /** |
| * @see hints in {@link #getVariable(Object, String) |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @param workloadDto the new/modified workload dto for this process instance |
| */ |
| public final static void setWorkloadDto(Object kcontext, IDto workloadDto) { |
| setVariable(kcontext, IBlipBPMConstants.VARIABLE_PROCESS_WORKLOAD_DTO, workloadDto); |
| } |
| |
| /** |
| * @see hints in {@link #getVariable(Object, String) |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @return the full qualified name for the workload dto used in this process instance |
| */ |
| public final static Object getWorkloadDtoFQN(Object kcontext) { |
| return getVariable(kcontext, IBlipBPMConstants.VARIABLE_PROCESS_WORKLOAD_DTO_FQN); |
| } |
| |
| /** |
| * Local process variables are available in |
| * <ul> |
| * <li>in <i>User Tasks</i> ony, if they are mapped from local process variables to task variables</li> |
| * <li>in <i>Script Tasks</i>, <i>Gateways</i>, etc. via (Java/mvel) scripts</li> |
| * </ul> |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @param variable name of the process instance variable |
| * @return the value of the process instance variable or <code>null</code> |
| */ |
| protected final static Object getVariable(Object kcontext, String variable) { |
| return getVariable(kcontext, variable, null); |
| } |
| |
| /** |
| * Local process variables are available in |
| * <ul> |
| * <li>in <i>User Tasks</i> ony, if they are mapped from local process variables to task variables</li> |
| * <li>in <i>Script Tasks</i>, <i>Gateways</i>, etc. via (Java/mvel) scripts</li> |
| * </ul> |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @param variable name of the process instance variable |
| * @param defaultValue default value, if the variable has not been set before |
| * @return the value of the process instance variable or <code>defaultValue</code> |
| */ |
| protected final static Object getVariable(Object kcontext, String variable, Object defaultValue) { |
| Object value = defaultValue; |
| if ((variable instanceof String) && (kcontext instanceof ProcessContext) && !variable.isEmpty()) { |
| try { |
| value = ((ProcessContext) kcontext).getVariable(variable); |
| } |
| catch (Exception e) { |
| log.error("getVariable(\""+variable+"\"): ", e); |
| } |
| } |
| else if (kcontext == null) { |
| log.error("getVariable(\""+variable+"\"): kcontext must be instance of ProcessContext, but is <null>"); |
| } |
| else if (!(kcontext instanceof ProcessContext)) { |
| log.error("getVariable(\""+variable+"\"): kcontext must be instance of ProcessContext, but is "+kcontext.getClass().getCanonicalName()); |
| } |
| return value; |
| } |
| |
| /** |
| * @see hints in {@link #getVariable(Object, String) |
| * @param kcontext should be the {@link org.drools.runtime.process.ProcessContext} available in BPM (Java/mvel) scripts |
| * @param variable name of the process instance variable to be set |
| * @param value the new value of the process instance variable |
| */ |
| protected final static void setVariable(Object kcontext, String variable, Object value) { |
| if ((variable instanceof String) && (kcontext instanceof ProcessContext) && !variable.isEmpty()) { |
| try { |
| ((ProcessContext) kcontext).setVariable(variable, value); |
| } |
| catch (Exception e) { |
| log.error("setVariable(\""+variable+"\",<value>): ", e); |
| } |
| } |
| else if (kcontext == null) { |
| log.error("getVariable(\""+variable+"\"): kcontext must be instance of ProcessContext, but is <null>"); |
| } |
| else if (!(kcontext instanceof ProcessContext)) { |
| log.error("getVariable(\""+variable+"\"): kcontext must be instance of ProcessContext, but is "+kcontext.getClass().getCanonicalName()); |
| } |
| } |
| } |