use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class Activity method request.
public String request(AgentPath agent, AgentPath delegate, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
// Find requested transition
Transition transition = getStateMachine().getTransition(transitionID);
// Check if the transition is possible
String usedRole = transition.getPerformingRole(this, agent);
// Verify outcome
boolean storeOutcome = false;
if (transition.hasOutcome(getProperties())) {
if (StringUtils.isNotBlank(requestData))
storeOutcome = true;
else if (transition.getOutcome().isRequired())
throw new InvalidDataException("Transition requires outcome data, but none was given");
}
// Get new state
State oldState = getStateMachine().getState(this.state);
State newState = getStateMachine().traverse(this, transition, agent);
// Run extra logic in predefined steps here
String outcome = runActivityLogic(agent, itemPath, transitionID, requestData, locker);
// set new state and reservation
setState(newState.getId());
setBuiltInProperty(AGENT_NAME, transition.getReservation(this, agent));
try {
History hist = getWf().getHistory(locker);
if (storeOutcome) {
Schema schema = transition.getSchema(getProperties());
Outcome newOutcome = new Outcome(-1, outcome, schema);
// TODO: if we were ever going to validate outcomes on storage, it would be here.
// newOutcome.validateAndCheck();
String viewpoint = resolveViewpointName(newOutcome);
int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint).getID();
newOutcome.setID(eventID);
Gateway.getStorage().put(itemPath, newOutcome, locker);
// update specific view if defined
if (!viewpoint.equals("last")) {
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
}
// update the default "last" view
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);
updateItemProperties(itemPath, newOutcome, locker);
} else {
hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
}
} catch (PersistencyException ex) {
Logger.error(ex);
throw ex;
}
if (newState.isFinished() && !(getBuiltInProperty(BREAKPOINT).equals(Boolean.TRUE) && !oldState.isFinished())) {
runNext(agent, itemPath, locker);
}
DateUtility.setToNow(mStateDate);
pushJobsToAgents(itemPath);
return outcome;
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class ClusterStorageManager method instantiateStores.
public ArrayList<ClusterStorage> instantiateStores(String allClusters) throws PersistencyException {
ArrayList<ClusterStorage> rootStores = new ArrayList<ClusterStorage>();
StringTokenizer tok = new StringTokenizer(allClusters, ",");
clusterPriority = new String[tok.countTokens()];
while (tok.hasMoreTokens()) {
ClusterStorage newStorage = null;
String newStorageClass = tok.nextToken();
try {
if (!newStorageClass.contains("."))
newStorageClass = "org.cristalise.storage." + newStorageClass;
newStorage = (ClusterStorage) (Class.forName(newStorageClass).newInstance());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
throw new PersistencyException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + " could not be found.");
}
rootStores.add(newStorage);
}
return rootStores;
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class RemoteMap method loadKeys.
protected void loadKeys() {
if (keyLock != null)
return;
clear();
keyLock = new Object();
synchronized (this) {
String[] keys;
try {
keys = storage.getClusterContents(mItemPath, mPath + mName);
for (String key : keys) super.put(key, null);
} catch (PersistencyException e) {
Logger.error(e);
}
}
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class Outcome method setMetaDataFromPath.
/**
* Retrieves the SchemaName, Version, EevetnId triplet from the path. Check getClusterPath() implementation
*
* @param path the ClusterPath to work with
* @throws PersistencyException path was incorrect
* @throws InvalidDataException Schema was not found or the Path has incorrect data
*/
protected void setMetaDataFromPath(String path) throws PersistencyException, InvalidDataException {
StringTokenizer tok = new StringTokenizer(path, "/");
if (tok.countTokens() != 3 && !(tok.nextToken().equals(OUTCOME.getName())))
throw new PersistencyException("Outcome() - Outcome path must have three components:" + path);
String schemaName = tok.nextToken();
String verString = tok.nextToken();
String objId = tok.nextToken();
try {
Integer schemaVersion = Integer.valueOf(verString);
mSchema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
mID = Integer.valueOf(objId);
} catch (NumberFormatException ex) {
throw new InvalidDataException("Outcome() - Version or EventID was an invalid number version:" + verString + " eventID:" + objId);
} catch (ObjectNotFoundException e) {
Logger.error(e);
throw new InvalidDataException("Outcome() - problem loading schema:" + schemaName + " version:" + verString);
}
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class QueryOutcomeInitiator method initOutcomeInstance.
@Override
public Outcome initOutcomeInstance(Job job) throws InvalidDataException {
if (job.hasQuery()) {
try {
Outcome o = new Outcome(-1, job.getItemProxy().executeQuery(job.getQuery()), job.getSchema());
o.validateAndCheck();
return o;
} catch (PersistencyException | ObjectNotFoundException | InvalidItemPathException e) {
throw new InvalidDataException("Error executing Query:" + e.getMessage());
}
} else
throw new InvalidDataException("No Query was defined for job:" + job);
}
Aggregations