use of com.bakdata.conquery.io.storage.MetaStorage in project conquery by bakdata.
the class GroupHandlingTest method execute.
@Override
public void execute(StandaloneSupport conquery) throws Exception {
MetaStorage storage = conquery.getMetaStorage();
Group group1 = new Group("company", "company", storage);
User user1 = new User("user", "user", storage);
User user1copy = new User("user", "user", storage);
User user2 = new User("user2", "user2", storage);
try {
storage.addGroup(group1);
storage.addUser(user1);
group1.addMember(user1);
group1.addMember(user1copy);
assertThat(group1.getMembers()).containsExactlyInAnyOrder(user1.getId());
group1.addMember(user2);
assertThat(group1.getMembers()).containsExactlyInAnyOrder(user1.getId(), user2.getId());
group1.removeMember(user2);
assertThat(group1.getMembers()).containsExactlyInAnyOrder(user1.getId());
} finally {
storage.removeUser(user1.getId());
storage.removeUser(user2.getId());
storage.removeGroup(group1.getId());
}
}
use of com.bakdata.conquery.io.storage.MetaStorage in project conquery by bakdata.
the class ImportUpdateTest method execute.
@Override
public void execute(String name, TestConquery testConquery) throws Exception {
final StandaloneSupport conquery = testConquery.getSupport(name);
MetaStorage storage = conquery.getMetaStorage();
String testJson = In.resource("/tests/query/UPDATE_IMPORT_TESTS/SIMPLE_TREECONCEPT_Query.json").withUTF8().readAll();
final Dataset dataset = conquery.getDataset();
final Namespace namespace = conquery.getNamespace();
final ImportId importId1 = ImportId.Parser.INSTANCE.parse(dataset.getName(), "table1", "table1");
final ImportId importId2 = ImportId.Parser.INSTANCE.parse(dataset.getName(), "table2", "table2");
QueryTest test = (QueryTest) JsonIntegrationTest.readJson(dataset, testJson);
final List<RequiredTable> tables = test.getContent().getTables();
assertThat(tables.size()).isEqualTo(2);
List<File> cqpps;
// Manually import data, so we can do our own work.
{
ValidatorHelper.failOnError(log, conquery.getValidator().validate(test));
importSecondaryIds(conquery, test.getContent().getSecondaryIds());
conquery.waitUntilWorkDone();
LoadingUtil.importTables(conquery, tables);
conquery.waitUntilWorkDone();
LoadingUtil.importConcepts(conquery, test.getRawConcepts());
conquery.waitUntilWorkDone();
cqpps = LoadingUtil.generateCqpp(conquery, tables);
conquery.waitUntilWorkDone();
assertThat(cqpps.size()).isEqualTo(tables.size());
LoadingUtil.importCqppFiles(conquery, List.of(cqpps.get(0)));
conquery.waitUntilWorkDone();
}
final Query query = IntegrationUtils.parseQuery(conquery, test.getRawQuery());
// State before update.
{
log.info("Checking state before update");
assertThat(namespace.getStorage().getAllImports()).hasSize(1);
// Must contain the import.
assertThat(namespace.getStorage().getAllImports()).filteredOn(imp -> imp.getId().equals(importId1)).isNotEmpty();
assertThat(namespace.getStorage().getCentralRegistry().getOptional(importId1)).isNotEmpty();
for (ShardNode node : conquery.getShardNodes()) {
for (Worker worker : node.getWorkers().getWorkers().values()) {
if (!worker.getInfo().getDataset().equals(dataset.getId())) {
continue;
}
final ModificationShieldedWorkerStorage workerStorage = worker.getStorage();
assertThat(workerStorage.getAllCBlocks()).describedAs("CBlocks for Worker %s", worker.getInfo().getId()).filteredOn(block -> block.getBucket().getId().getDataset().equals(dataset.getId())).isNotEmpty();
assertThat(workerStorage.getAllBuckets()).filteredOn(bucket -> bucket.getId().getDataset().equals(dataset.getId())).describedAs("Buckets for Worker %s", worker.getInfo().getId()).isNotEmpty();
// Must contain the import.
assertThat(workerStorage.getImport(importId1)).isNotNull();
}
}
assertThat(namespace.getNumberOfEntities()).isEqualTo(4);
// assert that the query can be executed after the import
IntegrationUtils.assertQueryResult(conquery, query, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
}
// Try to update an import that does not exist should throw a Not-Found Webapplication Exception
LoadingUtil.updateCqppFile(conquery, cqpps.get(1), Response.Status.Family.CLIENT_ERROR, "Not Found");
conquery.waitUntilWorkDone();
// Load manually new data for import and update the concerned import
{
log.info("Manually loading new data for import");
final RequiredTable importTable = test.getContent().getTables().stream().filter(table -> table.getName().equalsIgnoreCase(importId1.getTable().getTable())).findFirst().orElseThrow();
final String csvName = importTable.getCsv().getName();
final String path = importTable.getCsv().getPath();
// copy new content of the importTable into the csv-File used by the preprocessor to avoid creating multiple files withe same names
FileUtils.copyInputStreamToFile(In.resource(path.substring(0, path.lastIndexOf('/')) + "/" + csvName.replace(".csv", ".update.csv")).asStream(), new File(conquery.getTmpDir(), csvName));
File descriptionFile = new File(conquery.getTmpDir(), importTable.getName() + ConqueryConstants.EXTENSION_DESCRIPTION);
File newPreprocessedFile = new File(conquery.getTmpDir(), importTable.getName() + ConqueryConstants.EXTENSION_PREPROCESSED);
// create import descriptor
{
TableImportDescriptor desc = new TableImportDescriptor();
desc.setName(importTable.getName());
desc.setTable(importTable.getName());
TableInputDescriptor input = new TableInputDescriptor();
{
input.setPrimary(importTable.getPrimaryColumn().createOutput());
input.setSourceFile(csvName);
input.setOutput(new OutputDescription[importTable.getColumns().length]);
for (int i = 0; i < importTable.getColumns().length; i++) {
input.getOutput()[i] = importTable.getColumns()[i].createOutput();
}
}
desc.setInputs(new TableInputDescriptor[] { input });
Jackson.MAPPER.writeValue(descriptionFile, desc);
}
// preprocess
conquery.preprocessTmp(conquery.getTmpDir(), List.of(descriptionFile));
log.info("updating import");
// correct update of the import
LoadingUtil.updateCqppFile(conquery, newPreprocessedFile, Response.Status.Family.SUCCESSFUL, "No Content");
conquery.waitUntilWorkDone();
}
// State after update.
{
log.info("Checking state after update");
assertThat(namespace.getStorage().getAllImports()).hasSize(1);
// Must contain the import.
assertThat(namespace.getStorage().getAllImports()).filteredOn(imp -> imp.getId().equals(importId1)).isNotEmpty();
assertThat(namespace.getStorage().getCentralRegistry().getOptional(importId1)).isNotEmpty();
for (ShardNode node : conquery.getShardNodes()) {
for (Worker worker : node.getWorkers().getWorkers().values()) {
if (!worker.getInfo().getDataset().equals(dataset.getId())) {
continue;
}
final ModificationShieldedWorkerStorage workerStorage = worker.getStorage();
assertThat(workerStorage.getAllCBlocks()).describedAs("CBlocks for Worker %s", worker.getInfo().getId()).filteredOn(block -> block.getBucket().getId().getDataset().equals(dataset.getId())).isNotEmpty();
assertThat(workerStorage.getAllBuckets()).filteredOn(bucket -> bucket.getId().getDataset().equals(dataset.getId())).describedAs("Buckets for Worker %s", worker.getInfo().getId()).isNotEmpty();
// Must contain the import.
assertThat(workerStorage.getImport(importId1)).isNotNull();
}
}
assertThat(namespace.getNumberOfEntities()).isEqualTo(9);
// Issue a query and assert that it has more content.
IntegrationUtils.assertQueryResult(conquery, query, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
}
}
use of com.bakdata.conquery.io.storage.MetaStorage in project conquery by bakdata.
the class PermissionRoleHandlingTest method execute.
/**
* This is a longer test that plays through different scenarios of permission
* and role adding/deleting. Creating many objects here to avoid side effects.
*/
@Override
public void execute(StandaloneSupport conquery) throws Exception {
MetaStorage storage = conquery.getMetaStorage();
Role mandator1 = new Role("company", "company", storage);
TestUser user1 = new TestUser(storage);
Dataset dataset = conquery.getDataset();
try {
storage.addRole(mandator1);
storage.addUser(user1);
user1.addRole(mandator1);
user1.addPermission(dataset.createPermission(Ability.READ.asSet()));
mandator1.addPermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isTrue();
// Delete permission from mandator
mandator1.removePermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
assertThat(mandator1.getPermissions()).isEmpty();
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
// Add permission to user
user1.addPermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isTrue();
// Delete permission from mandator
user1.removePermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
// Add permission to mandator, remove mandator from user
mandator1.addPermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
user1.removeRole(mandator1);
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
// Add mandator back to user
user1.addRole(mandator1);
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isTrue();
// Delete all permissions from mandator and user
user1.removePermission(dataset.createPermission(Ability.READ.asSet()));
mandator1.removePermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isFalse();
assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
} finally {
storage.removeUser(user1.getId());
storage.removeRole(mandator1.getId());
}
}
use of com.bakdata.conquery.io.storage.MetaStorage in project conquery by bakdata.
the class RoleHandlingTest method execute.
@Override
public void execute(StandaloneSupport conquery) throws Exception {
Dataset dataset1 = new Dataset();
dataset1.setLabel("dataset1");
MetaStorage storage = conquery.getMetaStorage();
Role mandator1 = new Role("company", "company", storage);
Role mandator1Copy = new Role("company", "company", storage);
Role mandator2 = new Role("company2", "company2", storage);
User user1 = new User("user", "user", storage);
try {
storage.addRole(mandator1);
storage.addRole(mandator2);
storage.addUser(user1);
// // ADDING
user1.addRole(mandator1);
assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId());
user1.addRole(mandator1Copy);
assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId());
user1.addRole(mandator2);
assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId(), mandator2.getId());
// // REMOVING
user1.removeRole(mandator2);
assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId());
user1.removeRole(mandator1);
assertThat(user1.getRoles()).isEmpty();
} finally {
storage.removeUser(user1.getId());
storage.removeRole(mandator1.getId());
storage.removeRole(mandator2.getId());
}
}
use of com.bakdata.conquery.io.storage.MetaStorage in project conquery by bakdata.
the class RoleUITest method execute.
@Override
public void execute(StandaloneSupport conquery) throws Exception {
MetaStorage storage = conquery.getMetaStorage();
Role mandator = new Role("testMandatorName", "testMandatorLabel", storage);
RoleId mandatorId = mandator.getId();
User user = new User("testUser@test.de", "testUserName", storage);
UserId userId = user.getId();
try {
ConqueryPermission permission = DatasetPermission.onInstance(Ability.READ.asSet(), new DatasetId("testDatasetId"));
storage.addRole(mandator);
storage.addUser(user);
// override permission object, because it might have changed by the subject
// owning the permission
mandator.addPermission(permission);
user.addRole(mandator);
URI classBase = HierarchyHelper.hierarchicalPath(conquery.defaultAdminURIBuilder(), RoleUIResource.class, "getRole").buildFromMap(Map.of(ROLE_ID, mandatorId.toString()));
Response response = conquery.getClient().target(classBase).request().get();
assertThat(response.getStatus()).isEqualTo(200);
// Check for Freemarker Errors
assertThat(response.readEntity(String.class).toLowerCase()).doesNotContain(List.of("freemarker", "debug"));
} finally {
storage.removeRole(mandatorId);
storage.removeUser(userId);
}
}
Aggregations