Search in sources :

Example 1 with JSONException

use of com.bakdata.conquery.models.exceptions.JSONException in project conquery by bakdata.

the class FilterTest method importConcepts.

private void importConcepts(StandaloneSupport support) throws JSONException, IOException {
    Dataset dataset = support.getDataset();
    concept = new TreeConcept();
    concept.setLabel("concept");
    concept.setValidator(support.getValidator());
    concept.setDataset(support.getDataset());
    rawConnector.put("name", "connector");
    rawConnector.put("table", "table");
    ((ObjectNode) rawConnector.get("filters")).put("name", "filter");
    connector = parseSubTree(support, rawConnector, ConceptTreeConnector.class, conn -> conn.setConcept(concept));
    concept.setConnectors(Collections.singletonList((ConceptTreeConnector) connector));
    support.getDatasetsProcessor().addConcept(dataset, concept);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Setter(lombok.Setter) Getter(lombok.Getter) RequiredData(com.bakdata.conquery.integration.common.RequiredData) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) JSONException(com.bakdata.conquery.models.exceptions.JSONException) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) Range(com.bakdata.conquery.models.common.Range) ResourceFile(com.bakdata.conquery.integration.common.ResourceFile) CPSType(com.bakdata.conquery.io.cps.CPSType) IOException(java.io.IOException) NotNull(javax.validation.constraints.NotNull) LoadingUtil(com.bakdata.conquery.integration.common.LoadingUtil) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) AbstractQueryEngineTest(com.bakdata.conquery.integration.json.AbstractQueryEngineTest) Dataset(com.bakdata.conquery.models.datasets.Dataset) FilterValue(com.bakdata.conquery.apiv1.query.concept.filter.FilterValue) CQDateRestriction(com.bakdata.conquery.apiv1.query.concept.specific.CQDateRestriction) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) LocalDate(java.time.LocalDate) Query(com.bakdata.conquery.apiv1.query.Query) Jackson(com.bakdata.conquery.io.jackson.Jackson) ConqueryTestSpec(com.bakdata.conquery.integration.json.ConqueryTestSpec) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) Collections(java.util.Collections) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dataset(com.bakdata.conquery.models.datasets.Dataset) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)

Example 2 with JSONException

use of com.bakdata.conquery.models.exceptions.JSONException in project conquery by bakdata.

the class ConqueryTestSpec method parseSubTreeList.

public static <T> List<T> parseSubTreeList(StandaloneSupport support, ArrayNode node, Class<?> expectedType, Consumer<T> modifierBeforeValidation) throws IOException, JSONException {
    ObjectMapper mapper = support.getDataset().injectIntoNew(new SingletonNamespaceCollection(support.getNamespace().getStorage().getCentralRegistry()).injectIntoNew(Jackson.MAPPER.copy().addHandler(new DatasetPlaceHolderFiller(support))));
    List<T> result = new ArrayList<>(node.size());
    for (var child : node) {
        T value;
        try {
            value = mapper.readerFor(expectedType).readValue(child);
        } catch (Exception e) {
            if (child.isValueNode()) {
                String potentialPath = child.textValue();
                try {
                    value = mapper.readerFor(expectedType).readValue(IntegrationTest.class.getResource(potentialPath));
                } catch (Exception e2) {
                    throw new RuntimeException("Could not parse value " + potentialPath, e2);
                }
            } else {
                throw e;
            }
        }
        if (modifierBeforeValidation != null) {
            modifierBeforeValidation.accept(value);
        }
        result.add(value);
        ValidatorHelper.failOnError(log, support.getValidator().validate(value));
    }
    return result;
}
Also used : SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) ArrayList(java.util.ArrayList) IntegrationTest(com.bakdata.conquery.integration.IntegrationTest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JSONException(com.bakdata.conquery.models.exceptions.JSONException) IOException(java.io.IOException)

Aggregations

JSONException (com.bakdata.conquery.models.exceptions.JSONException)2 IOException (java.io.IOException)2 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)1 Query (com.bakdata.conquery.apiv1.query.Query)1 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)1 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)1 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 CQDateRestriction (com.bakdata.conquery.apiv1.query.concept.specific.CQDateRestriction)1 IntegrationTest (com.bakdata.conquery.integration.IntegrationTest)1 LoadingUtil (com.bakdata.conquery.integration.common.LoadingUtil)1 RequiredData (com.bakdata.conquery.integration.common.RequiredData)1 ResourceFile (com.bakdata.conquery.integration.common.ResourceFile)1 AbstractQueryEngineTest (com.bakdata.conquery.integration.json.AbstractQueryEngineTest)1 ConqueryTestSpec (com.bakdata.conquery.integration.json.ConqueryTestSpec)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 Jackson (com.bakdata.conquery.io.jackson.Jackson)1 Range (com.bakdata.conquery.models.common.Range)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)1 ConceptTreeConnector (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)1