use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Import method runActivityLogic.
/**
* Params: Schemaname_version:Viewpoint (optional), Outcome, Timestamp (optional)
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "Import: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
int split1 = params[0].indexOf('_');
int split2 = params[0].indexOf(':');
if (split1 == -1)
throw new InvalidDataException("Import: Invalid parameters " + Arrays.toString(params));
requestData = params[1];
Schema schema;
String viewpoint = null;
String schemaName = params[0].substring(0, split1);
int schemaVersion;
if (split2 > -1) {
schemaVersion = Integer.parseInt(params[0].substring(split1 + 1, split2));
viewpoint = params[0].substring(split2 + 1);
} else
schemaVersion = Integer.parseInt(params[0].substring(split1 + 1));
schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
String timestamp;
if (params.length == 3)
timestamp = params[2];
else
timestamp = DateUtility.timeToString(DateUtility.getNow());
// write event, outcome and viewpoints to storage
TransactionManager storage = Gateway.getStorage();
History hist = getWf().getHistory();
Event event = hist.addEvent(agent, null, getCurrentAgentRole(), getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint, timestamp);
try {
storage.put(item, new Outcome(event.getID(), requestData, schema), locker);
storage.put(item, new Viewpoint(item, schema, viewpoint, event.getID()), locker);
if (!"last".equals(viewpoint))
storage.put(item, new Viewpoint(item, schema, "last", event.getID()), locker);
} catch (PersistencyException e) {
storage.abort(locker);
throw e;
}
storage.commit(locker);
return requestData;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class RemoveDomainPath method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "RemoveDomainPath: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 1)
throw new InvalidDataException("RemoveDomainPath: Invalid parameters " + Arrays.toString(params));
DomainPath domainPath = new DomainPath(params[0]);
if (!domainPath.exists()) {
throw new ObjectNotFoundException("RemoveDomainPath: Domain path " + domainPath + " does not exist.");
}
if (!domainPath.getItemPath().equals(item)) {
throw new InvalidDataException("RemoveDomainPath: Domain path " + domainPath + " is not an alias of the current Item " + item);
}
Gateway.getLookupManager().delete(domainPath);
return requestData;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ReplaceDomainWorkflow method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException {
Workflow lifeCycle = getWf();
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "ReplaceDomainWorkflow: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 1)
throw new InvalidDataException("ReplaceDomainWorkflow: Invalid parameters " + Arrays.toString(params));
lifeCycle.getChildrenGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
CompositeActivity domain;
try {
domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("ReplaceDomainWorkflow: Could not unmarshall new workflow: " + e.getMessage());
}
domain.setName("domain");
lifeCycle.initChild(domain, true, new GraphPoint(150, 100));
// if new workflow, activate it, otherwise refresh the jobs
if (!domain.active)
lifeCycle.run(agent, item, locker);
else
lifeCycle.refreshJobs(item);
// store new wf
try {
Gateway.getStorage().put(item, lifeCycle, locker);
} catch (PersistencyException e) {
throw new PersistencyException("ReplaceDomainWorkflow: Could not write new workflow to storage: " + e.getMessage());
}
return requestData;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class WriteViewpoint method write.
public static void write(ItemPath item, String schemaName, String viewName, int eventId, Object locker) throws PersistencyException, ObjectNotFoundException, InvalidDataException {
Event event = (Event) Gateway.getStorage().get(item, ClusterType.HISTORY + "/" + eventId, locker);
if (StringUtils.isBlank(event.getSchemaName())) {
throw new InvalidDataException("Event " + eventId + " does not reference an Outcome, so cannot be assigned to a Viewpoint.");
}
// checks Schema name/version
Schema thisSchema = LocalObjectLoader.getSchema(schemaName, event.getSchemaVersion());
if (!event.getSchemaName().equals(thisSchema.getItemID())) {
throw new InvalidDataException("Event outcome schema is " + event.getSchemaName() + ", and cannot be used for a " + schemaName + " Viewpoint");
}
Gateway.getStorage().put(item, new Viewpoint(item, thisSchema, viewName, eventId), locker);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class WriteViewpoint method runActivityLogic.
/**
* SchemaName, name and event Id. Event and Outcome should be checked so schema version should be discovered.
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "WriteViewpoint: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 3) {
throw new InvalidDataException("WriteViewpoint: Invalid parameters " + Arrays.toString(params));
}
String schemaName = params[0];
String viewName = params[1];
int eventId;
try {
eventId = Integer.parseInt(params[2]);
} catch (NumberFormatException ex) {
throw new InvalidDataException("WriteViewpoint: Parameter 3 (EventId) must be an integer");
}
write(item, schemaName, viewName, eventId, locker);
return requestData;
}
Aggregations