use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.
the class ImportAgent method create.
@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
if (roles.isEmpty())
throw new ObjectNotFoundException("Agent '" + name + "' must declare at least one Role ");
AgentPath newAgent = new AgentPath(getItemPath(), name);
ActiveEntity newAgentEnt = Gateway.getCorbaServer().createAgent(newAgent);
Gateway.getLookupManager().add(newAgent);
// assemble properties
properties.add(new Property(NAME, name, true));
properties.add(new Property(TYPE, "Agent", false));
try {
if (StringUtils.isNotBlank(password))
Gateway.getLookupManager().setAgentPassword(newAgent, password);
newAgentEnt.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Error initialising new agent name:" + name);
}
for (ImportRole role : roles) {
RolePath thisRole = (RolePath) role.create(agentPath, reset);
Gateway.getLookupManager().addRole(newAgent, thisRole);
}
return newAgent;
}
use of org.cristalise.kernel.common.ObjectNotFoundException 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.ObjectNotFoundException in project kernel by cristal-ise.
the class ItemProxy method getProperty.
/**
* Retrieves the values of a named property
*
* @param name of the Item Property
* @return the value of the property
* @throws ObjectNotFoundException property was not found
*/
public String getProperty(String name) throws ObjectNotFoundException {
Logger.msg(5, "ItemProxy.getProperty() - " + name + " from item " + mItemPath);
Property prop = (Property) getObject(ClusterType.PROPERTY + "/" + name);
if (prop != null)
return prop.getValue();
else
throw new ObjectNotFoundException("ItemProxy.getProperty() - COULD not find property " + name + " from item " + mItemPath);
}
use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.
the class ItemProxy method queryData.
/**
* Query data of the Item located by the ClusterStorage path
*
* @param path the ClusterStorage path
* @return the data in XML form
* @throws ObjectNotFoundException path was not correct
*/
public String queryData(String path) throws ObjectNotFoundException {
try {
Logger.msg(7, "ItemProxy.queryData() - " + mItemPath + "/" + path);
if (path.endsWith("all")) {
Logger.msg(7, "ItemProxy.queryData() - listing contents");
String[] result = Gateway.getStorage().getClusterContents(mItemPath, path.substring(0, path.length() - 3));
StringBuffer retString = new StringBuffer();
for (int i = 0; i < result.length; i++) {
retString.append(result[i]);
if (i < result.length - 1)
retString.append(",");
}
Logger.msg(7, "ItemProxy.queryData() - " + retString.toString());
return retString.toString();
} else {
C2KLocalObject target = Gateway.getStorage().get(mItemPath, path, null);
return Gateway.getMarshaller().marshall(target);
}
} catch (ObjectNotFoundException e) {
throw e;
} catch (Exception e) {
Logger.error(e);
return "<ERROR>" + e.getMessage() + "</ERROR>";
}
}
use of org.cristalise.kernel.common.ObjectNotFoundException 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