Search in sources :

Example 1 with InvalidItemPathException

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

the class ItemImplementation method initialise.

@Override
public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, InvalidDataException, PersistencyException {
    Logger.msg(5, "Item::initialise(" + mItemPath + ") - agent:" + agentId);
    Object locker = new Object();
    AgentPath agentPath;
    try {
        agentPath = new AgentPath(agentId);
    } catch (InvalidItemPathException e) {
        throw new AccessRightsException("Invalid Agent Id:" + agentId);
    }
    // must supply properties
    if (propString == null || propString.length() == 0 || propString.equals("<NULL/>")) {
        throw new InvalidDataException("No properties supplied");
    }
    // store properties
    try {
        PropertyArrayList props = (PropertyArrayList) Gateway.getMarshaller().unmarshall(propString);
        for (Property thisProp : props.list) mStorage.put(mItemPath, thisProp, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Properties were invalid: " + propString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Properties were invalid");
    }
    // Store an event and the initial properties
    try {
        Schema initSchema = LocalObjectLoader.getSchema("ItemInitialization", 0);
        Outcome initOutcome = new Outcome(0, propString, initSchema);
        History hist = new History(mItemPath, locker);
        Event newEvent = hist.addEvent(new AgentPath(agentId), null, "", "Initialize", "", "", initSchema, Bootstrap.getPredefSM(), PredefinedStep.DONE, "last");
        initOutcome.setID(newEvent.getID());
        Viewpoint newLastView = new Viewpoint(mItemPath, initSchema, "last", newEvent.getID());
        mStorage.put(mItemPath, initOutcome, locker);
        mStorage.put(mItemPath, newLastView, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Could not store event and outcome.");
        Logger.error(ex);
        mStorage.abort(locker);
        throw new PersistencyException("Error storing event and outcome");
    }
    // init collections
    if (initCollsString != null && initCollsString.length() > 0 && !initCollsString.equals("<NULL/>")) {
        try {
            CollectionArrayList colls = (CollectionArrayList) Gateway.getMarshaller().unmarshall(initCollsString);
            for (Collection<?> thisColl : colls.list) {
                mStorage.put(mItemPath, thisColl, locker);
            }
        } catch (Throwable ex) {
            Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Collections were invalid: " + initCollsString);
            Logger.error(ex);
            mStorage.abort(locker);
            throw new InvalidDataException("Collections were invalid");
        }
    }
    // create wf
    Workflow lc = null;
    try {
        if (initWfString == null || initWfString.length() == 0 || initWfString.equals("<NULL/>")) {
            lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
        } else {
            lc = new Workflow((CompositeActivity) Gateway.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
        }
        mStorage.put(mItemPath, lc, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Workflow was invalid: " + initWfString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Workflow was invalid");
    }
    // All objects are in place, initialize the workflow to get the Item running
    lc.initialise(mItemPath, agentPath, locker);
    mStorage.put(mItemPath, lc, locker);
    mStorage.commit(locker);
    Logger.msg(3, "Initialisation of item " + mItemPath + " was successful");
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Schema(org.cristalise.kernel.persistency.outcome.Schema) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) History(org.cristalise.kernel.events.History) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Event(org.cristalise.kernel.events.Event) PersistencyException(org.cristalise.kernel.common.PersistencyException) Property(org.cristalise.kernel.property.Property)

Example 2 with InvalidItemPathException

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

the class ImportAggregation method create.

public org.cristalise.kernel.collection.Aggregation create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
    Aggregation newAgg = isDescription ? new AggregationDescription(name) : new AggregationInstance(name);
    if (version != null)
        newAgg.setVersion(version);
    for (ImportAggregationMember thisMem : aggregationMemberList) {
        StringBuffer classProps = new StringBuffer();
        ItemPath itemPath = null;
        if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length() > 0) {
            try {
                itemPath = new ItemPath(thisMem.itemDescriptionPath);
            } catch (InvalidItemPathException ex) {
                itemPath = new DomainPath(thisMem.itemDescriptionPath).getItemPath();
            }
            String descVer = thisMem.itemDescriptionVersion == null ? "last" : thisMem.itemDescriptionVersion;
            PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer, null);
            for (PropertyDescription pd : propList.list) {
                thisMem.props.put(pd.getName(), pd.getDefaultValue());
                if (pd.getIsClassIdentifier())
                    classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
            }
        }
        if (thisMem.itemPath != null && thisMem.itemPath.length() > 0) {
            try {
                itemPath = new ItemPath(thisMem.itemPath);
            } catch (InvalidItemPathException ex) {
                itemPath = new DomainPath(thisMem.itemPath).getItemPath();
            }
        }
        newAgg.addMember(itemPath, thisMem.props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
    }
    return newAgg;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) AggregationDescription(org.cristalise.kernel.collection.AggregationDescription) GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) AggregationInstance(org.cristalise.kernel.collection.AggregationInstance) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 3 with InvalidItemPathException

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

the class ImportDependency method create.

public Dependency create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
    Dependency newDep = isDescription ? new DependencyDescription(name) : new Dependency(name);
    if (version != null)
        newDep.setVersion(version);
    if (itemDescriptionPath != null && itemDescriptionPath.length() > 0) {
        ItemPath itemPath;
        try {
            itemPath = new ItemPath(itemDescriptionPath);
        } catch (InvalidItemPathException ex) {
            itemPath = new DomainPath(itemDescriptionPath).getItemPath();
        }
        String descVer = itemDescriptionVersion == null ? "last" : itemDescriptionVersion;
        PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer, null);
        StringBuffer classProps = new StringBuffer();
        for (PropertyDescription pd : propList.list) {
            props.put(pd.getName(), pd.getDefaultValue());
            if (pd.getIsClassIdentifier())
                classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
        }
        newDep.setProperties(props);
        newDep.setClassProps(classProps.toString());
    }
    for (ImportDependencyMember thisMem : dependencyMemberList) {
        ItemPath itemPath;
        try {
            itemPath = new ItemPath(thisMem.itemPath);
        } catch (InvalidItemPathException ex) {
            itemPath = new DomainPath(thisMem.itemPath).getItemPath();
        }
        org.cristalise.kernel.collection.DependencyMember newDepMem = newDep.addMember(itemPath);
        newDepMem.getProperties().putAll(thisMem.props);
    }
    return newDep;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) Dependency(org.cristalise.kernel.collection.Dependency) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) DependencyDescription(org.cristalise.kernel.collection.DependencyDescription) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 4 with InvalidItemPathException

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

the class Bootstrap method verifyBootDataItems.

/**
 * @param bootList
 * @param ns
 * @param reset
 * @throws InvalidItemPathException
 */
private static void verifyBootDataItems(String bootList, String ns, boolean reset) throws InvalidItemPathException {
    StringTokenizer str = new StringTokenizer(bootList, "\n\r");
    while (str.hasMoreTokens() && !shutdown) {
        String thisItem = str.nextToken();
        String[] idFilename = thisItem.split(",");
        String id = idFilename[0], filename = idFilename[1];
        ItemPath itemPath = new ItemPath(id);
        String[] fileParts = filename.split("/");
        String itemType = fileParts[0], itemName = fileParts[1];
        try {
            String location = "boot/" + filename + (itemType.equals("OD") ? ".xsd" : ".xml");
            verifyResource(ns, itemName, 0, itemType, itemPath, location, reset);
        } catch (Exception e) {
            Logger.error(e);
            Logger.die("Error importing bootstrap items. Unsafe to continue.");
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 5 with InvalidItemPathException

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

the class SetAgentPassword method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "SetAgentPassword: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("SetAgentPassword: Invalid parameters " + Arrays.toString(params));
    try {
        AgentPath targetAgent = new AgentPath(item);
        if (!targetAgent.equals(agent) && !agent.hasRole("Admin")) {
            throw new InvalidDataException("Agent passwords may only be set by those Agents or by an Administrator");
        }
        Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]);
        // censor password from outcome
        params[0] = "REDACTED";
        return bundleData(params);
    } catch (InvalidItemPathException ex) {
        Logger.error(ex);
        throw new InvalidDataException("Can only set password on an Agent. " + item + " is an Item.");
    } catch (NoSuchAlgorithmException e) {
        Logger.error(e);
        throw new InvalidDataException("Cryptographic libraries for password hashing not found.");
    }
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)15 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)11 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)10 PersistencyException (org.cristalise.kernel.common.PersistencyException)8 ItemPath (org.cristalise.kernel.lookup.ItemPath)8 DomainPath (org.cristalise.kernel.lookup.DomainPath)7 AgentPath (org.cristalise.kernel.lookup.AgentPath)6 Aggregation (org.cristalise.kernel.collection.Aggregation)3 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)3 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)3 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)3 Dependency (org.cristalise.kernel.collection.Dependency)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 Property (org.cristalise.kernel.property.Property)2 CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1