Search in sources :

Example 21 with InvalidDataException

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);
    }
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 22 with InvalidDataException

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);
    }
}
Also used : OutcomeValidator(org.cristalise.kernel.persistency.outcome.OutcomeValidator) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 23 with InvalidDataException

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()));
}
Also used : CollectionMember(org.cristalise.kernel.collection.CollectionMember) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 24 with InvalidDataException

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;
}
Also used : HashMap(java.util.HashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 25 with InvalidDataException

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.");
    }
}
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

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