use of org.cristalise.kernel.common.CannotManageException 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.CannotManageException 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.CannotManageException in project kernel by cristal-ise.
the class CreateAgentFromDescription method createAgentAddRoles.
/**
* @param newAgentPath
* @param roles
* @return
* @throws CannotManageException
* @throws ObjectCannotBeUpdated
* @throws ObjectAlreadyExistsException
*/
protected ActiveEntity createAgentAddRoles(AgentPath newAgentPath, String[] roles, String pwd) throws CannotManageException, ObjectCannotBeUpdated, ObjectAlreadyExistsException {
// create the Agent object
Logger.msg(3, "CreateAgentFromDescription.createAgentAddRoles() - Creating Agent");
CorbaServer factory = Gateway.getCorbaServer();
if (factory == null)
throw new CannotManageException("This process cannot create new Items");
ActiveEntity newAgent = factory.createAgent(newAgentPath);
Gateway.getLookupManager().add(newAgentPath);
try {
if (StringUtils.isNotBlank(pwd))
Gateway.getLookupManager().setAgentPassword(newAgentPath, pwd);
for (String roleName : roles) {
RolePath role = Gateway.getLookupManager().getRolePath(roleName);
Gateway.getLookupManager().addRole(newAgentPath, role);
}
} catch (ObjectNotFoundException | NoSuchAlgorithmException e) {
Logger.error(e);
Gateway.getLookupManager().delete(newAgentPath);
}
return newAgent;
}
use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.
the class RemoveAgent method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
Logger.msg(1, "RemoveAgent::request() - Starting.");
AgentPath targetAgent;
try {
targetAgent = new AgentPath(itemPath);
} catch (InvalidAgentPathException ex) {
throw new InvalidDataException("Could not resolve " + itemPath + " as an Agent.");
}
String agentName = targetAgent.getAgentName();
// remove from roles
for (RolePath role : targetAgent.getRoles()) {
try {
Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated | ObjectNotFoundException | CannotManageException e) {
Logger.error(e);
throw new InvalidDataException("Error removing " + agentName + " from Role " + role.getName() + " exceptoin message:" + e.getMessage());
}
}
return super.runActivityLogic(agent, itemPath, transitionID, requestData, locker);
}
use of org.cristalise.kernel.common.CannotManageException in project kernel by cristal-ise.
the class BulkImport method importAgentPath.
public AgentPath importAgentPath(ItemPath item, Object locker) throws PersistencyException {
try {
AgentPath agentPath = (AgentPath) importCluster.get(item, PATH + "/Item");
Gateway.getLookupManager().add(agentPath);
Gateway.getLookupManager().setAgentPassword(agentPath, "aaa");
return agentPath;
} catch (ObjectCannotBeUpdated | ObjectAlreadyExistsException | CannotManageException | ObjectNotFoundException | NoSuchAlgorithmException e) {
Logger.error(e);
throw new PersistencyException(e.getMessage());
}
}
Aggregations