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());
}
}
}
}
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;
}
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);
}
}
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 + "'");
}
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());
}
}
Aggregations