use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ViewpointDataHelper method get.
/**
* dataPath syntax is used for search : viewpoint:/xpath/to/field
*/
@Override
public String get(ItemPath itemPath, String actContext, String dataPath, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
String[] paths = dataPath.split(":");
if (paths.length != 2)
throw new InvalidDataException("Invalid path: '" + dataPath + "' should have only one colon (:)");
String viewpoint = paths[0];
String xpath = paths[1];
// Leading dot now no longer necessary - remove if present
if (viewpoint.startsWith("./")) {
Logger.warning("Removing leading dot on viewpoint data helper path at " + actContext + " in " + itemPath.getUUID().toString() + ". Definition should be migrated.");
viewpoint = viewpoint.substring(2);
}
// load Viewpoint and Outcome
Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath, ClusterType.VIEWPOINT + "/" + viewpoint, locker);
Outcome outcome = (Outcome) view.getOutcome(locker);
// apply the XPath to its outcome
try {
return outcome.getFieldByXPath(xpath);
} catch (XPathExpressionException e) {
throw new InvalidDataException("Invalid XPath: " + xpath);
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Query method validateXML.
public void validateXML(String xml) throws InvalidDataException, ObjectNotFoundException {
Schema querySchema;
if (Gateway.getLookup() == null)
querySchema = new Schema("Query", 0, Gateway.getResource().getTextResource(null, "boot/OD/Query.xsd"));
else
querySchema = LocalObjectLoader.getSchema("Query", 0);
OutcomeValidator validator = new OutcomeValidator(querySchema);
String error = validator.validate(xml);
if (StringUtils.isBlank(error)) {
Logger.msg(5, "Query.validateXML() - DONE");
} else {
Logger.error("Query.validateXML() - $error");
Logger.error("\n============== XML ==============\n" + xml + "\n=================================\n");
throw new InvalidDataException(error);
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ModuleActivity method getDescRef.
public ModuleDescRef getDescRef(ItemProxy child, BuiltInCollections collection) throws ObjectNotFoundException, InvalidDataException {
Collection<?> coll = child.getCollection(collection.getName(), version);
if (coll.size() == 1)
throw new InvalidDataException("Too many members in " + collection + " collection in " + name);
CollectionMember collMem = coll.getMembers().list.get(0);
return new ModuleDescRef(null, collMem.getChildUUID(), Integer.valueOf(collMem.getProperties().get("Version").toString()));
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class PropertyDescriptionList method instantiate.
/**
* Before instantiating checks that supplied initial Properties exist in description list
*
* @param initProps initial list of Properties
* @return instantiated PropertyArrayList for Item
* @throws InvalidDataException data was inconsistent
*/
public PropertyArrayList instantiate(PropertyArrayList initProps) throws InvalidDataException {
HashMap<String, String> validatedInitProps = new HashMap<String, String>();
for (Property initProp : initProps.list) {
if (!definesProperty(initProp.getName()))
throw new InvalidDataException("Property " + initProp.getName() + " has not been declared in the property descriptions");
else
validatedInitProps.put(initProp.getName(), initProp.getValue());
}
PropertyArrayList propInst = new PropertyArrayList();
for (int i = 0; i < list.size(); i++) {
PropertyDescription pd = list.get(i);
String propName = pd.getName();
String propVal = pd.getDefaultValue();
if (validatedInitProps.containsKey(propName))
propVal = validatedInitProps.get(propName);
propInst.list.add(new Property(propName, propVal, pd.getIsMutable()));
}
return propInst;
}
use of org.cristalise.kernel.common.InvalidDataException 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.");
}
}
Aggregations