use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ImportItem method create.
/**
*/
@Override
public Path create(AgentPath agentPath, boolean reset) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification, PersistencyException {
domainPath = new DomainPath(new DomainPath(initialPath), name);
if (domainPath.exists()) {
ItemPath domItem = domainPath.getItemPath();
if (!getItemPath().equals(domItem)) {
throw new CannotManageException("Item " + domainPath + " was found with the wrong itemPath (" + domainPath.getItemPath() + " vs " + getItemPath() + ")");
}
} else
isDOMPathExists = false;
TraceableEntity newItem = getTraceableEntitiy();
// (re)initialise the new item with properties, workflow and collections
try {
newItem.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(createItemProperties()), Gateway.getMarshaller().marshall(createCompositeActivity()), Gateway.getMarshaller().marshall(createCollections()));
} catch (Exception ex) {
Logger.error("Error initialising new item " + ns + "/" + name);
Logger.error(ex);
if (isNewItem)
Gateway.getLookupManager().delete(itemPath);
throw new CannotManageException("Problem initialising new item. See server log:" + ex.getMessage());
}
History hist = new History(getItemPath(), null);
// import outcomes
for (ImportOutcome thisOutcome : outcomes) {
String outcomeData = thisOutcome.getData(ns);
// load schema and state machine
Schema schema = LocalObjectLoader.getSchema(thisOutcome.schema, thisOutcome.version);
// parse new outcome and validate
Outcome newOutcome = new Outcome(-1, outcomeData, schema);
newOutcome.validateAndCheck();
Viewpoint impView;
try {
impView = (Viewpoint) Gateway.getStorage().get(getItemPath(), ClusterType.VIEWPOINT + "/" + thisOutcome.schema + "/" + thisOutcome.viewname, null);
if (newOutcome.isIdentical(impView.getOutcome())) {
Logger.msg(5, "ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name + " identical, no update required");
continue;
} else {
Logger.msg("ImportItem.create() - Difference found in view " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name);
if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
Logger.msg("ImportItem.create() - Last edit was not done by import, and reset not requested. Not overwriting.");
continue;
}
}
} catch (ObjectNotFoundException ex) {
Logger.msg("ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " not found in " + ns + "/" + name + ". Creating.");
impView = new Viewpoint(getItemPath(), schema, thisOutcome.viewname, -1);
}
// write new view/outcome/event
Event newEvent = hist.addEvent(agentPath, null, "Admin", "Import", "Import", "Import", schema, Bootstrap.getPredefSM(), PredefinedStep.DONE, thisOutcome.viewname);
newOutcome.setID(newEvent.getID());
impView.setEventId(newEvent.getID());
Gateway.getStorage().put(getItemPath(), newOutcome, null);
Gateway.getStorage().put(getItemPath(), impView, null);
}
// register domain path (before collections in case of recursive collections)
if (!isDOMPathExists) {
domainPath.setItemPath(getItemPath());
Gateway.getLookupManager().add(domainPath);
}
return domainPath;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class AgentProxy method callScript.
@SuppressWarnings("rawtypes")
private ErrorInfo callScript(ItemProxy item, Job job) throws ScriptingEngineException, InvalidDataException, ObjectNotFoundException {
Script script = job.getScript();
if (script.getOutputParams().size() == 1) {
Parameter p = script.getOutputParams().values().iterator().next();
if (p.getType() == ErrorInfo.class) {
script.setActExecEnvironment(item, this, job);
Object returnVal = script.execute();
if (returnVal instanceof Map)
return (ErrorInfo) ((Map) returnVal).get(p.getName());
else
return (ErrorInfo) returnVal;
}
}
throw new InvalidDataException("Script " + script.getName() + " must define single output of type org.cristalise.kernel.scripting.ErrorInfo");
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ItemProxy method setProperty.
/**
* Sets the vlaue of the given Property
*
* @param agent the Agent who is setting the Property
* @param name the name of the Property
* @param value the value of the Property
* @throws AccessRightsException Agent does not the rights to execute this operation
* @throws PersistencyException there was a database problems during this operations
* @throws InvalidDataException data was invalid
*/
public void setProperty(AgentProxy agent, String name, String value) throws AccessRightsException, PersistencyException, InvalidDataException {
try {
String[] params = { name, value };
agent.execute(this, "WriteProperty", params);
} catch (AccessRightsException | PersistencyException | InvalidDataException e) {
throw (e);
} catch (Exception e) {
Logger.error(e);
throw new PersistencyException("Could not store property:" + e.getMessage());
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ProxyClientConnection method run.
/**
* Main loop. Reads proxy commands from the client and acts on them.
*/
@Override
public void run() {
Thread.currentThread().setName(getName() + ": " + clientSocket.getInetAddress());
Logger.msg(7, "ProxyClientConnection.run() - clientID:" + thisClientId + " - Setting up proxy client connection with " + clientSocket.getInetAddress());
try {
request = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String input = null;
ProxyMessage thisMessage;
while (clientSocket != null) {
try {
input = request.readLine();
Logger.msg(9, "ProxyClientConnection.run() - " + thisClientId + " - received " + input);
thisMessage = new ProxyMessage(input);
processMessage(thisMessage);
} catch (InterruptedIOException ex) {
// timeout
} catch (InvalidDataException ex) {
// invalid proxy message
Logger.error("ProxyClientConnection.run() - clientID:" + thisClientId + " - Invalid proxy message: " + input);
}
}
} catch (IOException ex) {
if (!closing) {
if (Logger.doLog(8))
Logger.error(ex);
Logger.error("ProxyClientConnection.run() - clientID:" + thisClientId + " - Error reading from socket.");
}
}
closeSocket();
Logger.msg(1, "ProxyClientConnection.run() - clientID:" + thisClientId + " closed.");
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Dependency method addToVertexProperties.
/**
* Add Dependency specific values to VertexProperties (CastorHashMap). First checks if there is a Script
* to be executed, if no Script defined it will use the default conversion implemented for BuiltInCollections
*
* @param props the current list of VertexProperties
* @throws InvalidDataException inconsistent data was provided
* @throws ObjectNotFoundException objects were not found while reading the properties
*/
public void addToVertexProperties(CastorHashMap props) throws InvalidDataException, ObjectNotFoundException {
Logger.msg(2, "Dependency.addToVertexProperties(" + getName() + ") - Starting ...");
BuiltInCollections builtInColl = BuiltInCollections.getValue(getName());
for (DependencyMember member : getMembers().list) {
String memberUUID = member.getChildUUID();
Integer memberVer = LocalObjectLoader.deriveVersionNumber(member.getBuiltInProperty(VERSION));
if (memberVer == null) {
throw new InvalidDataException("Version is null for Collection:" + getName() + ", DependencyMember:" + memberUUID);
}
// - or this is not a BuiltInCollection
if (convertToVertextPropsByScript(props, member) || builtInColl == null)
continue;
Logger.msg(5, "Dependency.addToVertexProperties() - Dependency:" + getName() + " memberUUID:" + memberUUID);
// LocalObjectLoader checks if data is valid and loads object to cache
switch(builtInColl) {
// ***************************************************************************************************
case SCHEMA:
try {
LocalObjectLoader.getSchema(memberUUID, memberVer);
props.setBuiltInProperty(SCHEMA_NAME, memberUUID);
props.setBuiltInProperty(SCHEMA_VERSION, memberVer);
} catch (ObjectNotFoundException e) {
// Schema dependency could be defined in Properties
if (props.containsKey(SCHEMA_NAME)) {
Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
String uuid = LocalObjectLoader.getSchema(props).getItemPath().getUUID().toString();
props.setBuiltInProperty(SCHEMA_NAME, uuid);
}
}
break;
// ***************************************************************************************************
case SCRIPT:
try {
LocalObjectLoader.getScript(memberUUID, memberVer);
props.setBuiltInProperty(SCRIPT_NAME, memberUUID);
props.setBuiltInProperty(SCRIPT_VERSION, memberVer);
} catch (ObjectNotFoundException e) {
// Backward compability: Script dependency could be defined in Properties
if (props.containsKey(SCRIPT_NAME)) {
Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
String uuid = LocalObjectLoader.getScript(props).getItemPath().getUUID().toString();
props.setBuiltInProperty(SCRIPT_NAME, uuid);
}
}
break;
// ***************************************************************************************************
case QUERY:
try {
LocalObjectLoader.getQuery(memberUUID, memberVer);
props.setBuiltInProperty(QUERY_NAME, memberUUID);
props.setBuiltInProperty(QUERY_VERSION, memberVer);
} catch (ObjectNotFoundException e) {
// Backward compability: Query dependency could be defined in Properties
if (props.containsKey(QUERY_NAME)) {
Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
String uuid = LocalObjectLoader.getQuery(props).getItemPath().getUUID().toString();
props.setBuiltInProperty(QUERY_NAME, uuid);
}
}
break;
// ***************************************************************************************************
case STATE_MACHINE:
try {
LocalObjectLoader.getStateMachine(memberUUID, memberVer);
props.setBuiltInProperty(STATE_MACHINE_NAME, memberUUID);
props.setBuiltInProperty(STATE_MACHINE_VERSION, memberVer);
} catch (ObjectNotFoundException e) {
if (props.containsKey(STATE_MACHINE_NAME)) {
Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
String uuid = LocalObjectLoader.getStateMachine(props).getItemPath().getUUID().toString();
props.setBuiltInProperty(STATE_MACHINE_NAME, uuid);
}
}
break;
// ***************************************************************************************************
case ACTIVITY:
ActivityDef actDef = LocalObjectLoader.getActDef(memberUUID, memberVer);
CastorHashMap chm = null;
if (props.containsKey(ACTIVITY_DEF_URN)) {
chm = (CastorHashMap) props.getBuiltInProperty(ACTIVITY_DEF_URN);
} else {
chm = new CastorHashMap();
props.setBuiltInProperty(ACTIVITY_DEF_URN, chm);
}
Logger.msg(8, "Dependency.addToVertexProperties(" + getName() + ") - actDef:" + actDef.getActName());
chm.put(actDef.getActName(), memberUUID + "~" + memberVer);
break;
// ***************************************************************************************************
default:
Logger.msg(8, "Dependency.addToVertexProperties() - Cannot handle BuiltIn Dependency:" + getName());
break;
}
}
}
Aggregations