All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cds.impl.parser.CqnParser Maven / Gradle / Ivy

There is a newer version: 3.6.1
Show newest version
/*******************************************************************
 * © 2019 SAP SE or an SAP affiliate company. All rights reserved. *
 *******************************************************************/
package com.sap.cds.impl.parser;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.sap.cds.ql.cqn.CqnSyntaxException;

public abstract class CqnParser {

	private static final ObjectMapper mapper = new ObjectMapper().enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
			.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);

	private static final Configuration CONFIG = Configuration.defaultConfiguration()
			.addOptions(Option.SUPPRESS_EXCEPTIONS).mappingProvider(new JacksonMappingProvider(mapper))
			.jsonProvider(new JacksonJsonNodeJsonProvider(mapper));

	protected final DocumentContext cqn;

	protected CqnParser(DocumentContext cqn) {
		this.cqn = cqn;
	}

	protected static DocumentContext getDocumentContext(String cqn) {
		try {
			return JsonPath.using(CONFIG).parse(cqn);
		} catch (InvalidJsonException ex) {
			throw new CqnSyntaxException("Invalid CQN: " + cqn, ex);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy