org.openbp.server.context.TokenContextServiceBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openbp-server Show documentation
Show all versions of openbp-server Show documentation
The OpenBP process engine (main module)
package org.openbp.server.context;
import java.util.Iterator;
import org.openbp.common.util.ToStringHelper;
import org.openbp.core.model.modelmgr.ModelMgr;
import org.openbp.server.persistence.PersistenceContext;
import org.openbp.server.persistence.PersistenceContextProvider;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Abstract base class for token context service implementations.
*
* @author Heiko Erhardt
*/
public abstract class TokenContextServiceBase
implements TokenContextService
{
@Autowired
private PersistenceContextProvider persistenceContextProvider;
@Autowired
private ModelMgr modelMgr;
/**
* Default constructor.
*/
public TokenContextServiceBase()
{
}
/**
* Returns a string represenation of this object.
*
* @return Debug string containing the most important properties of this object
*/
public String toString()
{
return ToStringHelper.toString(this);
}
/**
* Gets the persistence context provider.
*/
public PersistenceContextProvider getPersistenceContextProvider()
{
return persistenceContextProvider;
}
/**
* Sets the persistence context provider.
*/
public void setPersistenceContextProvider(final PersistenceContextProvider persistenceContextProvider)
{
this.persistenceContextProvider = persistenceContextProvider;
}
/**
* Gets the model mgr.
*/
public ModelMgr getModelMgr()
{
return modelMgr;
}
/**
* Sets the model mgr.
*/
public void setModelMgr(ModelMgr modelMgr)
{
this.modelMgr = modelMgr;
}
/**
* Retrieves a token context by its id.
*
* @param id Context id
* @return The context or null if no such context exists
*/
public TokenContext getContextById(Object id)
{
TokenContextCriteria criteria = new TokenContextCriteria();
criteria.setId(id);
Iterator it = getContexts(criteria, 0);
if (it.hasNext())
return (TokenContext) it.next();
return null;
}
/**
* Creates a new child context.
*
* @return The context
*/
public TokenContext createChildContext(TokenContext parentContext)
{
TokenContext childContext = createContext();
childContext.setDebuggerId(parentContext.getDebuggerId());
childContext.setCurrentSocket(parentContext.getCurrentSocket());
childContext.setExecutingModel(parentContext.getExecutingModel());
parentContext.addChildContext(childContext);
return childContext;
}
/**
* Creates a context.
* However, the context is not added to the context list.
*
* @return The new context
*/
public TokenContext createContext()
{
PersistenceContext pc = getPersistenceContextProvider().obtainPersistenceContext();
return (TokenContext) pc.createEntity(TokenContext.class);
}
/**
* Creates a workflow task. However, the workflow task is not added to the * workflow task list.
*
* @param context Token context to associate with the workflow task @return
* The new workflow task
*/
public WorkflowTask createWorkflowTask(final TokenContext context)
{
PersistenceContext pc = getPersistenceContextProvider().obtainPersistenceContext();
WorkflowTask workflowTask = (WorkflowTask) pc.createEntity(WorkflowTask.class);
// Link workflow task and context
workflowTask.setTokenContext(context);
return workflowTask;
}
}