Commit dec5c76a authored by dietricf's avatar dietricf
Browse files

Introduce BPMN Engine

parent 85dc2a8b
This diff is collapsed.
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base;
public class ProcessException extends Exception {
public ProcessException( String msg ) {
super( msg );
}
public ProcessException( String msg, Throwable throwable) {
super( msg, throwable );
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base;
import lombok.extern.log4j.Log4j2;
import java.util.HashMap;
import java.util.Map;
@Log4j2
public abstract class ProcessGrid {
public static class Recoverable<T extends ProcessSubject> {
private final T subject;
private final ProcessGrid instance;
public Recoverable( T subject, ProcessGrid instance ) {
this.subject = subject;
this.instance = instance;
}
public void start(StateResolver resolver ) throws ProcessException {
ProcessTask t = instance.resolve( resolver.resolveState());
t.recover(subject);
}
}
private Map<ProcessState, ProcessTask> gridMap = new HashMap<>();
public <T extends ProcessSubject> Recoverable<T> recover(T subject) {
return new Recoverable<>( subject, this);
}
protected <P extends ProcessTask> P register(ProcessState state, P step ) {
gridMap.put( state, step );
return step;
}
protected ProcessTask resolve(ProcessState state ) throws ProcessException {
if( !gridMap.containsKey(state) ) {
log.error("State" + state.toString() + " is not resolvable!");
throw new ProcessException("State " + state.toString() + " is not resolvable!");
}
else {
return gridMap.get(state);
}
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base;
public interface ProcessState {
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base;
public interface ProcessSubject {
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base;
public interface ProcessTask {
void enterStep(ProcessSubject model) throws ProcessException;
void leaveStep(ProcessSubject model) throws ProcessException;
void connectOutputTo(ProcessTask step) throws ProcessException;
void recover(ProcessSubject model) throws ProcessException;
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base;
public interface StateResolver {
ProcessState resolveState() throws ProcessException;
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
@Log4j2
public abstract class BaseTask<T extends ProcessSubject> implements ProcessTask {
private ProcessTask outputStep;
private String description;
protected BaseTask(String description ) {
this.description = description;
}
public String getDescription() {
return description;
}
@Override
public void leaveStep(ProcessSubject model) throws ProcessException {
log.debug("On Leave: \""+description+"\"");
onLeaveStep( (T)model );
if(outputStep==null) {
log.debug(description+": firing unconnected Output!");
}
else {
log.debug("Left step: \""+description+"\"");
outputStep.enterStep(model);
}
}
@Override
public void enterStep(ProcessSubject model ) throws ProcessException {
log.debug("Enter: \""+description+"\"");
onEnterStep((T)model);
}
@Override
public void recover(ProcessSubject model) throws ProcessException {
log.debug("Recover: \""+description+"\"");
onRecover((T)model);
}
protected abstract void onLeaveStep(T model) throws ProcessException;
protected abstract void onEnterStep(T model) throws ProcessException;
protected abstract void onRecover(T model) throws ProcessException;
@Override
public void connectOutputTo(ProcessTask step) throws ProcessException {
this.outputStep = step;
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
import java.util.EnumMap;
import java.util.Map;
@Log4j2
public abstract class DecisionTask<T extends ProcessSubject> extends BaseTask<T> {
public enum OutputPort {PORT1, PORT2, PORT3, PORT4, PORT5, YES, NO}
private Map<OutputPort, ProcessTask> outputMap = new EnumMap<>(OutputPort.class);
protected DecisionTask(String description) {
super(description);
}
public void connectOutputTo(OutputPort port, ProcessTask step ) {
outputMap.put(port, step);
}
public abstract OutputPort decide( T model ) throws ProcessException;
@Override
public void enterStep(ProcessSubject model) throws ProcessException {
log.debug("Enter: \""+getDescription()+"\"");
OutputPort port = decide((T)model);
if( !outputMap.containsKey(port) ){
throw new ProcessException(getDescription()+": Usage of unconnected output "+port.name());
}
else {
outputMap.get(port).enterStep(model);
}
}
@Override
protected void onLeaveStep(T model) throws ProcessException {
throw new ProcessException("onLeaveStep must not be called on a decision task object");
}
@Override
protected void onEnterStep(T model) throws ProcessException {
}
@Override
protected void onRecover(T model) throws ProcessException {
// Entry-point is enter!
enterStep(model);
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
@Log4j2
public class EndPointTask implements ProcessTask {
private final String description;
public EndPointTask(String description ) {
this.description = description;
}
@Override
public void enterStep(ProcessSubject model) throws ProcessException {
log.debug("Endpoint: \""+description+"\"");
}
@Override
public void leaveStep(ProcessSubject model) throws ProcessException {
throw new ProcessException("Cannot leave Endpoint: " + description);
}
@Override
public void connectOutputTo(ProcessTask step) throws ProcessException {
throw new ProcessException("Cannot connect to an Endpoint: "+description);
}
@Override
public void recover(ProcessSubject model) throws ProcessException {
throw new ProcessException("Cannot recover at an Endpoint: "+description);
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
@Log4j2
public abstract class ServiceTask <T extends ProcessSubject> extends BaseTask<T> {
protected ServiceTask(String description) {
super(description);
}
@Override
public void enterStep(ProcessSubject model) throws ProcessException {
log.debug("Enter: \""+getDescription()+"\"");
this.leaveStep( model );
}
@Override
protected void onEnterStep(ProcessSubject model) throws ProcessException {
// implement empty
}
@Override
protected void onRecover(T model) throws ProcessException {
enterStep( model );
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
@Log4j2
public abstract class UserInteractionTask<T extends ProcessSubject> extends BaseTask<T> {
protected UserInteractionTask(String description) {
super(description);
}
protected boolean isStayInThisTask(T model){ // NOSONAR Parameter needed, if overridden
return false;
}
protected void onStayInTask(T model) throws ProcessException {
}
@Override
protected void onRecover(T model) throws ProcessException {
leaveStep( model );
}
@Override
public void leaveStep(ProcessSubject model) throws ProcessException {
if( !isStayInThisTask((T)model)) {
super.leaveStep(model);
}
else {
log.debug("Stay In this task valid! -> staying!");
onStayInTask((T)model);
}
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessGrid;
import org.springframework.stereotype.Component;
@Log4j2
@Component
public class GfiGrid extends ProcessGrid {
public GfiGrid() {
try {
init();
}
catch( ProcessException e ) {
log.fatal("Invalid process grid configuration", e );
throw new RuntimeException("Invalid process grid configuration"); // NOSONAR _fd
}
}
private void init() throws ProcessException {
// TODO: Create the Grid here
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessState;
@Log4j2
public enum GfiProcessState implements ProcessState {
NEW (0),
APPLIED (1),
CANCELED (2),
UNDEFINED_ (-1); // NOSONAR
private final int statusValue;
GfiProcessState(int statusValue ) {
this.statusValue = statusValue;
}
public int getStatusValue() {
return statusValue;
}
public static ProcessState fromValue( int statusValue ) { // NOSONAR complexity high but simple
switch( statusValue ) {
case 0:
return NEW;
case 1: