Search in sources :

Example 6 with CannotManageException

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;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Property(org.cristalise.kernel.property.Property) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CannotManageException(org.cristalise.kernel.common.CannotManageException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 7 with CannotManageException

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;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) Schema(org.cristalise.kernel.persistency.outcome.Schema) History(org.cristalise.kernel.events.History) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Event(org.cristalise.kernel.events.Event) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 8 with CannotManageException

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;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CorbaServer(org.cristalise.kernel.entity.CorbaServer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 9 with CannotManageException

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);
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 10 with CannotManageException

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());
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) PersistencyException(org.cristalise.kernel.common.PersistencyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Aggregations

CannotManageException (org.cristalise.kernel.common.CannotManageException)12 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)8 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)7 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 CorbaServer (org.cristalise.kernel.entity.CorbaServer)3 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 RolePath (org.cristalise.kernel.lookup.RolePath)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)2 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2