use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection 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;
}
use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.
the class LoadingUtil method importPreviousQueries.
public static void importPreviousQueries(StandaloneSupport support, RequiredData content, User user) throws IOException {
// Load previous query results if available
int id = 1;
for (ResourceFile queryResults : content.getPreviousQueryResults()) {
UUID queryId = new UUID(0L, id++);
final CsvParser parser = support.getConfig().getCsv().withParseHeaders(false).withSkipHeader(false).createParser();
String[][] data = parser.parseAll(queryResults.stream()).toArray(new String[0][]);
ConceptQuery q = new ConceptQuery(new CQExternal(Arrays.asList("ID", "DATE_SET"), data));
ManagedExecution<?> managed = support.getNamespace().getExecutionManager().createQuery(support.getNamespace().getNamespaces(), q, queryId, user, support.getNamespace().getDataset());
user.addPermission(managed.createPermission(AbilitySets.QUERY_CREATOR));
if (managed.getState() == ExecutionState.FAILED) {
fail("Query failed");
}
}
for (JsonNode queryNode : content.getPreviousQueries()) {
ObjectMapper mapper = new SingletonNamespaceCollection(support.getNamespaceStorage().getCentralRegistry()).injectIntoNew(Jackson.MAPPER);
mapper = support.getDataset().injectIntoNew(mapper);
Query query = mapper.readerFor(Query.class).readValue(queryNode);
UUID queryId = new UUID(0L, id++);
ManagedExecution<?> managed = support.getNamespace().getExecutionManager().createQuery(support.getNamespace().getNamespaces(), query, queryId, user, support.getNamespace().getDataset());
user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managed.getId()));
if (managed.getState() == ExecutionState.FAILED) {
fail("Query failed");
}
}
// wait only if we actually did anything
if (!content.getPreviousQueryResults().isEmpty()) {
support.waitUntilWorkDone();
}
}
use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.
the class IdRefrenceTest method testListReferences.
@Test
public void testListReferences() throws IOException {
CentralRegistry registry = new CentralRegistry();
Dataset dataset = new Dataset();
dataset.setName("dataset");
Table table = new Table();
table.setDataset(dataset);
table.setName("table");
registry.register(dataset);
registry.register(table);
final CentralRegistry metaRegistry = new CentralRegistry();
User user = new User("usermail", "userlabel", mock(MetaStorage.class));
metaRegistry.register(user);
String json = Jackson.MAPPER.writeValueAsString(new ListHolder(Collections.singletonList(table), Collections.singletonList(user)));
assertThat(json).contains("\"user.usermail\"").contains("\"dataset.table\"");
ListHolder holder = new SingletonNamespaceCollection(registry, metaRegistry).injectIntoNew(Jackson.MAPPER.readerFor(ListHolder.class)).readValue(json);
assertThat(holder.getUsers().get(0)).isSameAs(user);
assertThat(holder.getTables().get(0)).isSameAs(table);
}
use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.
the class SerializationTestUtil method test.
private void test(T value, T expected, ObjectMapper mapper) throws IOException {
if (registry != null) {
mapper = new SingletonNamespaceCollection(registry, registry).injectIntoNew(mapper);
}
for (Injectable injectable : injectables) {
mapper = injectable.injectIntoNew(mapper);
}
ObjectWriter writer = mapper.writerFor(type).withView(InternalOnly.class);
ObjectReader reader = mapper.readerFor(type).withView(InternalOnly.class);
ValidatorHelper.failOnError(log, validator.validate(value));
byte[] src = writer.writeValueAsBytes(value);
T copy = reader.readValue(src);
if (expected == null && copy == null) {
return;
}
ValidatorHelper.failOnError(log, validator.validate(copy));
// because IdentifiableImp cashes the hash
if (value instanceof IdentifiableImpl) {
assertThat(copy.hashCode()).isEqualTo(value.hashCode());
}
RecursiveComparisonAssert<?> ass = assertThat(copy).as("Unequal after copy.").usingRecursiveComparison();
ass.isEqualTo(expected);
}
use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.
the class ConqueryTestSpec method parseSubTree.
public static <T> T parseSubTree(StandaloneSupport support, JsonNode node, JavaType expectedType, Consumer<T> modifierBeforeValidation) throws IOException, JSONException {
ObjectMapper mapper = support.getDataset().injectIntoNew(new SingletonNamespaceCollection(support.getNamespace().getStorage().getCentralRegistry(), support.getMetaStorage().getCentralRegistry()).injectIntoNew(Jackson.MAPPER.copy().addHandler(new DatasetPlaceHolderFiller(support))));
T result = mapper.readerFor(expectedType).readValue(node);
if (modifierBeforeValidation != null) {
modifierBeforeValidation.accept(result);
}
ValidatorHelper.failOnError(log, support.getValidator().validate(result));
return result;
}
Aggregations