Search in sources :

Example 76 with InvalidDataException

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

the class Activity method updateItemProperties.

private void updateItemProperties(ItemPath itemPath, Outcome outcome, Object locker) throws InvalidDataException, PersistencyException, ObjectCannotBeUpdated, ObjectNotFoundException {
    for (java.util.Map.Entry<String, Object> entry : getProperties().entrySet()) {
        if (entry.getKey().startsWith("ItemProperty.")) {
            String propName = entry.getKey().substring(13);
            if (StringUtils.isNotBlank(propName)) {
                String propValue = entry.getValue().toString();
                // FIXME: use DataHelper if possible, because it will make code more general
                if (StringUtils.isNotBlank(propValue) && propValue.startsWith(XPATH_TOKEN)) {
                    try {
                        propValue = outcome.getFieldByXPath(propValue.substring(6));
                    } catch (XPathExpressionException e) {
                        throw new InvalidDataException(e.getMessage());
                    }
                }
                if (StringUtils.isNotBlank(propValue)) {
                    Logger.msg(5, "Activity.updateItemProperties() - propName:" + propName + " propValue:" + propValue);
                    WriteProperty.write(itemPath, propName, propValue, locker);
                }
            } else {
                throw new InvalidDataException("Incomplete vertex property name:" + entry.getKey());
            }
        }
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Map(java.util.Map) WfCastorHashMap(org.cristalise.kernel.lifecycle.WfCastorHashMap)

Example 77 with InvalidDataException

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

the class Split method calculateNexts.

public String[] calculateNexts(ItemPath itemPath, Object locker) throws InvalidDataException {
    String nexts;
    String expr = (String) getBuiltInProperty(ROUTING_EXPR);
    String scriptName = (String) getBuiltInProperty(ROUTING_SCRIPT_NAME);
    Integer scriptVersion = deriveVersionNumber(getBuiltInProperty(ROUTING_SCRIPT_VERSION));
    if (expr != null && expr.length() > 0) {
        try {
            nexts = (String) DataHelperUtility.evaluateValue(itemPath, expr, getActContext(), locker);
        } catch (Exception e) {
            Logger.error(e);
            throw new InvalidDataException("XORSplit expression evaulation failed: " + expr + " with " + e.getMessage());
        }
    } else if (scriptName != null && scriptName.length() > 0) {
        try {
            nexts = evaluateScript(scriptName, scriptVersion, itemPath, locker).toString();
        } catch (ScriptingEngineException e) {
            Logger.error(e);
            throw new InvalidDataException("Error running routing script " + scriptName + " v" + scriptVersion);
        }
    } else
        throw new InvalidDataException("Split is invalid without valid routing script or expression");
    StringTokenizer tok = new StringTokenizer(nexts, ",");
    String[] nextsTab = new String[tok.countTokens()];
    for (int i = 0; i < nextsTab.length; i++) nextsTab[i] = tok.nextToken();
    return nextsTab;
}
Also used : StringTokenizer(java.util.StringTokenizer) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException)

Example 78 with InvalidDataException

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

the class Outcome method setMetaDataFromPath.

/**
 * Retrieves the SchemaName, Version, EevetnId triplet from the path. Check getClusterPath() implementation
 *
 * @param path the ClusterPath to work with
 * @throws PersistencyException path was incorrect
 * @throws InvalidDataException Schema was not found or the Path has incorrect data
 */
protected void setMetaDataFromPath(String path) throws PersistencyException, InvalidDataException {
    StringTokenizer tok = new StringTokenizer(path, "/");
    if (tok.countTokens() != 3 && !(tok.nextToken().equals(OUTCOME.getName())))
        throw new PersistencyException("Outcome() - Outcome path must have three components:" + path);
    String schemaName = tok.nextToken();
    String verString = tok.nextToken();
    String objId = tok.nextToken();
    try {
        Integer schemaVersion = Integer.valueOf(verString);
        mSchema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
        mID = Integer.valueOf(objId);
    } catch (NumberFormatException ex) {
        throw new InvalidDataException("Outcome() - Version or EventID was an invalid number version:" + verString + " eventID:" + objId);
    } catch (ObjectNotFoundException e) {
        Logger.error(e);
        throw new InvalidDataException("Outcome() - problem loading schema:" + schemaName + " version:" + verString);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 79 with InvalidDataException

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

the class Outcome method setField.

/**
 * Sets the textNode value of the named Element of the given Element. It only updates existing Element.
 *
 * @param element Element to use
 * @param name the name of the Element
 * @param data the data to be set
 * @param remove flag to remove the element if the data is null
 * @throws InvalidDataException the name was not found or there were more Elements with the given name
 */
public void setField(Element element, String name, String data, boolean remove) throws InvalidDataException {
    NodeList elements = element.getElementsByTagName(name);
    if (hasSingleField(elements)) {
        if (data == null && remove) {
            Logger.msg(7, "Outcome.setField() - removing name:" + name);
            element.removeChild(elements.item(0));
            return;
        }
        // Setting nodeValue to null could corrupt document
        if (data == null)
            data = "";
        setNodeValue(elements.item(0), data);
    } else
        throw new InvalidDataException("Invalid name:'" + name + "'");
}
Also used : NodeList(org.w3c.dom.NodeList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 80 with InvalidDataException

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

the class Outcome method appendXmlFragment.

/**
 * Append the new Node created from xmlFragment as a child of the Node selected by the XPath
 *
 * @param xpath the selected parent node
 * @param xmlFragment string containing the xml fragment
 * @return the Node just added
 */
public Node appendXmlFragment(String xpath, String xmlFragment) throws InvalidDataException {
    try {
        Node parentNode = getNodeByXPath(xpath);
        Node newNode = parse(xmlFragment).getDocumentElement();
        return parentNode.appendChild(mDOM.importNode(newNode, true));
    } catch (SAXException | IOException | XPathExpressionException e) {
        Logger.error(e);
        throw new InvalidDataException(e.getMessage());
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

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