Search in sources :

Example 26 with ObjectNotFoundException

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;
}
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 27 with ObjectNotFoundException

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;
}
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 28 with ObjectNotFoundException

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);
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Property(org.cristalise.kernel.property.Property)

Example 29 with ObjectNotFoundException

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>";
    }
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) 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)

Example 30 with ObjectNotFoundException

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;
        }
    }
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ActivityDef(org.cristalise.kernel.lifecycle.ActivityDef)

Aggregations

ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)59 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)38 PersistencyException (org.cristalise.kernel.common.PersistencyException)27 DomainPath (org.cristalise.kernel.lookup.DomainPath)12 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)12 ItemPath (org.cristalise.kernel.lookup.ItemPath)12 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 AgentPath (org.cristalise.kernel.lookup.AgentPath)11 CannotManageException (org.cristalise.kernel.common.CannotManageException)9 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)8 IOException (java.io.IOException)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)7 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)6 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)6 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)5 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)5 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)5 Property (org.cristalise.kernel.property.Property)5 MappingException (org.exolab.castor.mapping.MappingException)5 MarshalException (org.exolab.castor.xml.MarshalException)5