Search in sources :

Example 1 with SpecException

use of com.bazaarvoice.jolt.exception.SpecException in project nifi by apache.

the class TransformFactory method getChainrJoltTransformations.

protected static List<JoltTransform> getChainrJoltTransformations(ClassLoader classLoader, Object specJson) throws Exception {
    if (!(specJson instanceof List)) {
        throw new SpecException("JOLT Chainr expects a JSON array of objects - Malformed spec.");
    } else {
        List operations = (List) specJson;
        if (operations.isEmpty()) {
            throw new SpecException("JOLT Chainr passed an empty JSON array.");
        } else {
            ArrayList<JoltTransform> entries = new ArrayList<JoltTransform>(operations.size());
            for (Object chainrEntryObj : operations) {
                if (!(chainrEntryObj instanceof Map)) {
                    throw new SpecException("JOLT ChainrEntry expects a JSON map - Malformed spec");
                } else {
                    Map chainrEntryMap = (Map) chainrEntryObj;
                    String opString = (String) chainrEntryMap.get("operation");
                    String operationClassName;
                    if (opString == null) {
                        throw new SpecException("JOLT Chainr \'operation\' must implement Transform or ContextualTransform");
                    } else {
                        if (ChainrEntry.STOCK_TRANSFORMS.containsKey(opString)) {
                            operationClassName = ChainrEntry.STOCK_TRANSFORMS.get(opString);
                        } else {
                            operationClassName = opString;
                        }
                        entries.add(getCustomTransform(classLoader, operationClassName, chainrEntryMap.get("spec")));
                    }
                }
            }
            return entries;
        }
    }
}
Also used : SpecException(com.bazaarvoice.jolt.exception.SpecException) JoltTransform(com.bazaarvoice.jolt.JoltTransform) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

JoltTransform (com.bazaarvoice.jolt.JoltTransform)1 SpecException (com.bazaarvoice.jolt.exception.SpecException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1