Search in sources :

Example 46 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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 47 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class AgentProxy method callScript.

@SuppressWarnings("rawtypes")
private ErrorInfo callScript(ItemProxy item, Job job) throws ScriptingEngineException, InvalidDataException, ObjectNotFoundException {
    Script script = job.getScript();
    if (script.getOutputParams().size() == 1) {
        Parameter p = script.getOutputParams().values().iterator().next();
        if (p.getType() == ErrorInfo.class) {
            script.setActExecEnvironment(item, this, job);
            Object returnVal = script.execute();
            if (returnVal instanceof Map)
                return (ErrorInfo) ((Map) returnVal).get(p.getName());
            else
                return (ErrorInfo) returnVal;
        }
    }
    throw new InvalidDataException("Script " + script.getName() + " must define single output of type org.cristalise.kernel.scripting.ErrorInfo");
}
Also used : Script(org.cristalise.kernel.scripting.Script) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Parameter(org.cristalise.kernel.scripting.Parameter) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) Map(java.util.Map)

Example 48 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ItemProxy method setProperty.

/**
 * Sets the vlaue of the given Property
 *
 * @param agent the Agent who is setting the Property
 * @param name the name of the Property
 * @param value the value of the Property
 * @throws AccessRightsException Agent does not the rights to execute this operation
 * @throws PersistencyException there was a database problems during this operations
 * @throws InvalidDataException data was invalid
 */
public void setProperty(AgentProxy agent, String name, String value) throws AccessRightsException, PersistencyException, InvalidDataException {
    try {
        String[] params = { name, value };
        agent.execute(this, "WriteProperty", params);
    } catch (AccessRightsException | PersistencyException | InvalidDataException e) {
        throw (e);
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException("Could not store property:" + e.getMessage());
    }
}
Also used : AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) 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 49 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ProxyClientConnection method run.

/**
 * Main loop. Reads proxy commands from the client and acts on them.
 */
@Override
public void run() {
    Thread.currentThread().setName(getName() + ": " + clientSocket.getInetAddress());
    Logger.msg(7, "ProxyClientConnection.run() - clientID:" + thisClientId + " - Setting up proxy client connection with " + clientSocket.getInetAddress());
    try {
        request = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String input = null;
        ProxyMessage thisMessage;
        while (clientSocket != null) {
            try {
                input = request.readLine();
                Logger.msg(9, "ProxyClientConnection.run() - " + thisClientId + " - received " + input);
                thisMessage = new ProxyMessage(input);
                processMessage(thisMessage);
            } catch (InterruptedIOException ex) {
            // timeout
            } catch (InvalidDataException ex) {
                // invalid proxy message
                Logger.error("ProxyClientConnection.run() - clientID:" + thisClientId + " - Invalid proxy message: " + input);
            }
        }
    } catch (IOException ex) {
        if (!closing) {
            if (Logger.doLog(8))
                Logger.error(ex);
            Logger.error("ProxyClientConnection.run() - clientID:" + thisClientId + " - Error reading from socket.");
        }
    }
    closeSocket();
    Logger.msg(1, "ProxyClientConnection.run() - clientID:" + thisClientId + " closed.");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 50 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5