Search in sources :

Example 1 with InvalidAgentPathException

use of org.cristalise.kernel.lookup.InvalidAgentPathException in project kernel by cristal-ise.

the class ItemImplementation method delegatedAction.

@Override
public String delegatedAction(SystemKey agentId, SystemKey delegateId, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException, InvalidCollectionModification {
    Workflow lifeCycle = null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        Logger.msg(1, "ItemImplementation::request(" + mItemPath + ") - Transition " + transitionID + " on " + stepPath + " by " + (delegate == null ? "" : delegate + " on behalf of ") + agent);
        // TODO: check if delegate is allowed valid for agent
        lifeCycle = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
        String finalOutcome = lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, transitionID, requestData);
        // store the workflow if we've changed the state of the domain wf
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        // remove entity path if transaction was successful
        if (stepPath.equals("workflow/predefined/Erase")) {
            Logger.msg("Erasing item path " + mItemPath.toString());
            Gateway.getLookupManager().delete(mItemPath);
        }
        mStorage.commit(lifeCycle);
        return finalOutcome;
    } catch (AccessRightsException | InvalidTransitionException | ObjectNotFoundException | PersistencyException | InvalidDataException | ObjectAlreadyExistsException | InvalidCollectionModification ex) {
        if (Logger.doLog(8))
            Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw ex;
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException ex) {
        if (Logger.doLog(8))
            Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw new InvalidDataException(ex.getClass().getName() + " - " + ex.getMessage());
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    } catch (Exception ex) {
        // non-CORBA exception hasn't been caught!
        Logger.error("Unknown Error: requestAction on " + mItemPath + " by " + agentId + " executing " + stepPath);
        Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw new InvalidDataException("Extraordinary Exception during execution:" + ex.getClass().getName() + " - " + ex.getMessage());
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    }
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) MarshalException(org.exolab.castor.xml.MarshalException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 2 with InvalidAgentPathException

use of org.cristalise.kernel.lookup.InvalidAgentPathException in project kernel by cristal-ise.

the class ItemImplementation method handleError.

/**
 * @param agentId
 * @param delegateId
 * @param stepPath
 * @param ex
 * @return
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 * @throws AccessRightsException
 * @throws InvalidTransitionException
 * @throws InvalidDataException
 * @throws ObjectAlreadyExistsException
 * @throws InvalidCollectionModification
 */
private String handleError(SystemKey agentId, SystemKey delegateId, String stepPath, Workflow lifeCycle, Exception ex) throws PersistencyException, ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, InvalidCollectionModification {
    if (!Gateway.getProperties().getBoolean("StateMachine.enableErrorHandling", false))
        return null;
    int errorTransId = ((Activity) lifeCycle.search(stepPath)).getErrorTransitionId();
    if (errorTransId == -1)
        return null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        String errorOutcome = Gateway.getMarshaller().marshall(new ErrorInfo(ex));
        lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, errorTransId, errorOutcome);
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        return errorOutcome;
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException | MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        return "";
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo) Activity(org.cristalise.kernel.lifecycle.instance.Activity) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) IOException(java.io.IOException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) MappingException(org.exolab.castor.mapping.MappingException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 3 with InvalidAgentPathException

use of org.cristalise.kernel.lookup.InvalidAgentPathException in project kernel by cristal-ise.

the class CorbaServer method getAgent.

/**
 * Returns a CORBA servant for a pre-existing entity
 *
 * @param agentPath the AgentPath representing the Agent
 * @return the servant
 * @throws InvalidAgentPathException agentPath was not Agent
 * @throws ObjectNotFoundException agentPath was not found
 */
public ActiveEntity getAgent(AgentPath agentPath) throws InvalidAgentPathException, ObjectNotFoundException {
    Servant agent = null;
    if (!agentPath.exists())
        throw new ObjectNotFoundException(agentPath + " does not exist");
    synchronized (mItemCache) {
        agent = mItemCache.get(agentPath);
        if (agent == null) {
            Logger.msg(7, "Creating new servant for " + agentPath);
            agent = new ActiveEntity(agentPath, mAgentPOA);
            mItemCache.put(agentPath, agent);
        } else if (!(agent instanceof ActiveEntity))
            throw new InvalidAgentPathException("Item " + agentPath + " was not an agent");
    }
    return (ActiveEntity) agent;
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Servant(org.omg.PortableServer.Servant) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity)

Example 4 with InvalidAgentPathException

use of org.cristalise.kernel.lookup.InvalidAgentPathException 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)

Aggregations

InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)4 CannotManageException (org.cristalise.kernel.common.CannotManageException)3 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 IOException (java.io.IOException)2 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)1 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)1 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)1 Activity (org.cristalise.kernel.lifecycle.instance.Activity)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1