Package com.bazaarvoice.jolt.exception

Examples of com.bazaarvoice.jolt.exception.SpecException


    private final Traversr traversr;

    public PathEvaluatingTraversal( String dotNotation ) {

        if ( dotNotation.contains("*") || dotNotation.contains("$")) {
            throw new SpecException("DotNotation (write key) can not contain '*' or '$'.");
        }

        List<PathElement> paths;
        Traversr trav;

        if ( StringTools.isNotBlank( dotNotation ) ) {

            // Compute the path elements.
            paths = ShiftrSpec.parseDotNotationRHS( dotNotation );

            // Use the canonical versions of the path elements to create the Traversr
            List<String> traversrPaths = new ArrayList<String>( paths.size() );
            for ( PathElement pe : paths ) {
                traversrPaths.add( pe.getCanonicalForm() );
            }
            trav = createTraversr( traversrPaths );
        }
        else {
            paths = Collections.emptyList();
            trav = createTraversr( Arrays.asList( "" ) );
        }

        List<EvaluatablePathElement> evalPaths = new ArrayList<EvaluatablePathElement>( paths.size() );
        for( PathElement pe : paths ) {
            if ( ! ( pe instanceof EvaluatablePathElement ) ) {
                throw new SpecException( "RHS key=" + pe.getRawKey() + " is not a valid RHS key." );
            }

            evalPaths.add( (EvaluatablePathElement) pe );
        }

View Full Code Here


     * @param index the index of the chainrEntryObj, used in reporting errors
     */
    public ChainrEntry( int index, Object chainrEntryObj ) {

        if ( ! (chainrEntryObj instanceof Map ) ) {
            throw new SpecException( "JOLT ChainrEntry expects a JSON map - Malformed spec" + getErrorMessageIndexSuffix() );
        }

        @SuppressWarnings( "unchecked" ) // We know it is a Map due to the check above
        Map<String,Object> chainrEntryMap = (Map<String, Object>) chainrEntryObj;

        this.index = index;

        String opString = extractOperationString( ChainrEntry.OPERATION_KEY, chainrEntryMap );

        if ( opString == null ) {
            throw new SpecException( "JOLT Chainr 'operation' must implement Transform or ContextualTransform" + getErrorMessageIndexSuffix() );
        }

        if ( STOCK_TRANSFORMS.containsKey( opString ) ) {
            operationClassName = STOCK_TRANSFORMS.get( opString );
        }
        else {
            operationClassName = opString;
        }

        joltTransformClass = loadJoltTransformClass();

        spec = chainrEntryMap.get( ChainrEntry.SPEC_KEY );

        isSpecDriven = SpecDriven.class.isAssignableFrom( joltTransformClass );
        if ( isSpecDriven && ! chainrEntryMap.containsKey( SPEC_KEY ) ) {
            throw new SpecException( "JOLT Chainr - Transform className:" + joltTransformClass.getCanonicalName() + " requires a spec" + getErrorMessageIndexSuffix() );
        }
    }
View Full Code Here

        if ( operationNameObj == null ) {
            return null;
        }
        else if ( operationNameObj instanceof String) {
            if ( StringTools.isBlank((String) operationNameObj) ) {
                throw new SpecException( "JOLT Chainr '" + ChainrEntry.OPERATION_KEY + "' should not be blank" + getErrorMessageIndexSuffix() );
            }
            return (String) operationNameObj;
        }
        else {
            throw new SpecException( "JOLT Chainr needs a '" + ChainrEntry.OPERATION_KEY + "' of type String" + getErrorMessageIndexSuffix() );
        }
    }
View Full Code Here

        try {
            Class opClass = Class.forName( operationClassName );

            if ( Chainr.class.isAssignableFrom( opClass ) ) {
                throw new SpecException( "Attempt to nest Chainr inside itself" + getErrorMessageIndexSuffix() );
            }

            if ( ! JoltTransform.class.isAssignableFrom( opClass ) )
            {
                throw new SpecException( "JOLT Chainr class:" + operationClassName + " does not implement the JoltTransform interface" + getErrorMessageIndexSuffix() );
            }

            @SuppressWarnings( "unchecked" ) // We know it is some type of Transform due to the check above
            Class<? extends JoltTransform> transformClass = (Class<? extends JoltTransform>) opClass;

            return transformClass;

        } catch ( ClassNotFoundException e ) {
            throw new SpecException( "JOLT Chainr could not find transform class:" + operationClassName + getErrorMessageIndexSuffix(), e );
        }
    }
View Full Code Here

     */
    @Inject
    public Shiftr( Object spec ) {

        if ( spec == null ){
            throw new SpecException( "Shiftr expected a spec of Map type, got 'null'." );
        }
        if ( ! ( spec instanceof Map ) ) {
            throw new SpecException( "Shiftr expected a spec of Map type, got " + spec.getClass().getSimpleName() );
        }

        rootSpec = new ShiftrCompositeSpec( ROOT_KEY, (Map<String, Object>) spec );
    }
View Full Code Here

    private final RemovrCompositeSpec rootSpec;

    @Inject
    public Removr( Object spec ) {
        if ( spec == null ){
            throw new SpecException( "Removr expected a spec of Map type, got 'null'." );
        }
        if ( ! ( spec instanceof Map ) ) {
            throw new SpecException( "Removr expected a spec of Map type, got " + spec.getClass().getSimpleName() );
        }
        rootSpec = new RemovrCompositeSpec( ROOT_KEY, (Map<String, Object>) spec );
        this.spec = (Map<String, Object>) spec;
    }
View Full Code Here

    public ShiftrSpec(String rawJsonKey) {

        PathElement pe = parseSingleKeyLHS( rawJsonKey );

        if ( ! ( pe instanceof MatchablePathElement ) ) {
            throw new SpecException( "Spec LHS key=" + rawJsonKey + " is not a valid LHS key." );
        }

        this.pathElement = (MatchablePathElement) pe;
    }
View Full Code Here

    public RemovrSpec(String rawJsonKey) {
        List<PathElement> pathElements = parse(rawJsonKey);

        if (pathElements.size() != 1) {
            throw new SpecException("Removr invalid LHS:" + rawJsonKey + " can not contain '.'");
        }

        PathElement pe = pathElements.get(0);
        if (!(pe instanceof MatchablePathElement)) {
            throw new SpecException("Spec LHS key=" + rawJsonKey + " is not a valid LHS key.");
        }

        this.pathElement = (MatchablePathElement) pe;
    }
View Full Code Here

        }
        else if ( key.startsWith("@") || key.contains( "@(" ) ) {
            return TransposePathElement.parse( key );
        }
        else if ( key.contains( "@" ) ) {
            throw new SpecException( "Invalid key:" + key  + " can not have an @ other than at the front." );
        }
        else if ( key.contains("$") ) {
            return new DollarPathElement( key );
        }
        else if ( key.contains("[") ) {

            if ( StringTools.countMatches(key, "[") != 1 || StringTools.countMatches(key, "]") != 1 ) {
                throw new SpecException( "Invalid key:" + key + " has too many [] references.");
            }

            return new ArrayPathElement( key );
        }
        else if ( key.contains( "&" ) ) {

            if ( key.contains("*") )
            {
                throw new SpecException("Can't mix * with & ) ");
            }
            return new AmpPathElement( key );
        }
        else if ( "*".equals( key ) ) {
            return new StarAllPathElement( key );
View Full Code Here

        if ( c == '(' ) {
            isParensAt = true;
            atParensCount++;
        }
        else if ( c == '.' ) {
            throw new SpecException( "Unable to parse dotNotation, invalid TransposePathElement : " + dotNotationRef );
        }

        sb.append( c );

        while( iter.hasNext() ) {
            c = iter.next();
            sb.append( c );

            // Parsing "@(a.b.[&2])"
            if ( isParensAt ) {
                if ( c == '(' ) {
                    throw new SpecException( "Unable to parse dotNotation, too many open parens '(' : " + dotNotationRef );
                }
                else if ( c == ')' ) {
                    atParensCount--;
                }

                if ( atParensCount == 0 ) {
                    return sb.toString();
                }
                else if ( atParensCount < 0 ) {
                    throw new SpecException( "Unable to parse dotNotation, specifically the '@()' part : " + dotNotationRef );
                }
            }
            // Parsing "@abc.def
            else if ( c == '.' ) {
                return sb.toString();
            }
        }

        // if we got to the end of the String and we have mismatched parenthesis throw an exception.
        if ( isParensAt && atParensCount != 0 ) {
            throw new SpecException( "Invalid @() pathElement from : " + dotNotationRef );
        }
        // Parsing "@abc"
        return sb.toString();
    }
View Full Code Here

TOP

Related Classes of com.bazaarvoice.jolt.exception.SpecException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.