use of com.bakdata.conquery.models.identifiable.ids.specific.DatasetId in project conquery by bakdata.
the class AdminDatasetProcessor method addDataset.
/**
* Creates and initializes a new dataset if it does not already exist.
*/
public synchronized Dataset addDataset(Dataset dataset) {
final String name = dataset.getName();
if (datasetRegistry.get(new DatasetId(name)) != null) {
throw new WebApplicationException("Dataset already exists", Response.Status.CONFLICT);
}
NamespaceStorage datasetStorage = new NamespaceStorage(validator, "dataset_" + name);
datasetStorage.openStores(config.getStorage());
datasetStorage.loadData();
datasetStorage.setMetaStorage(storage);
datasetStorage.updateDataset(dataset);
datasetStorage.updateIdMapping(new EntityIdMap());
Namespace ns = new Namespace(datasetStorage, config.isFailOnError(), config.configureObjectMapper(Jackson.copyMapperAndInjectables(Jackson.BINARY_MAPPER)).writerWithView(InternalOnly.class));
datasetRegistry.add(ns);
// for now we just add one worker to every ShardNode
for (ShardNodeInformation node : datasetRegistry.getShardNodes().values()) {
node.send(new AddWorker(dataset));
}
return dataset;
}
use of com.bakdata.conquery.models.identifiable.ids.specific.DatasetId in project conquery by bakdata.
the class ResultExcelProcessor method getExcelResult.
public <E extends ManagedExecution<?> & SingleTableResult> Response getExcelResult(Subject subject, E exec, DatasetId datasetId, boolean pretty) {
ConqueryMDC.setLocation(subject.getName());
final Namespace namespace = datasetRegistry.get(datasetId);
Dataset dataset = namespace.getDataset();
subject.authorize(dataset, Ability.READ);
subject.authorize(dataset, Ability.DOWNLOAD);
subject.authorize(exec, Ability.READ);
IdPrinter idPrinter = config.getFrontend().getQueryUpload().getIdPrinter(subject, exec, namespace);
final Locale locale = I18n.LOCALE.get();
PrintSettings settings = new PrintSettings(pretty, locale, datasetRegistry, config, idPrinter::createId);
ExcelRenderer excelRenderer = new ExcelRenderer(config.getExcel(), settings);
StreamingOutput out = output -> excelRenderer.renderToStream(config.getFrontend().getQueryUpload().getIdResultInfos(), (ManagedExecution<?> & SingleTableResult) exec, output);
return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), "xlsx", MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.DatasetId in project conquery by bakdata.
the class IdDeserializer method findDatasetName.
private static String findDatasetName(DeserializationContext ctx) throws JsonMappingException {
Dataset dataset = Jackson.findInjectable(ctx, Dataset.class);
if (dataset != null) {
return dataset.getName();
}
// Sometimes injected via @PathParam
DatasetId id = Jackson.findInjectable(ctx, DatasetId.class);
if (id != null) {
return id.getName();
}
return null;
}
use of com.bakdata.conquery.models.identifiable.ids.specific.DatasetId in project conquery by bakdata.
the class SerializationTests method user.
/*
* Only way to add permission without a storage.
*/
@Test
public void user() throws IOException, JSONException {
User user = new User("user", "user", STORAGE);
user.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("test")));
user.addPermission(ExecutionPermission.onInstance(Ability.READ, new ManagedExecutionId(new DatasetId("dataset"), UUID.randomUUID())));
Role role = new Role("company", "company", STORAGE);
user.addRole(role);
CentralRegistry registry = new CentralRegistry();
registry.register(role);
SerializationTestUtil.forType(User.class).registry(registry).injectables(STORAGE).test(user);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.DatasetId in project conquery by bakdata.
the class CopyUserTest method testUserCopy.
@Test
void testUserCopy() {
final DatasetRegistry registry = new DatasetRegistry(0);
MetaStorage storage = new NonPersistentStoreFactory().createMetaStorage();
registry.setMetaStorage(storage);
// Create test role
Role role = new Role("role", "role", storage);
storage.addRole(role);
role.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset0")));
// Create test group
Group group = new Group("group", "group", storage);
storage.addGroup(group);
group.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset1")));
// Create original user with role and group mapping
User originUser = new User("user", "user", storage);
storage.addUser(originUser);
originUser.addRole(role);
group.addMember(originUser);
// Do copy
User copy = AuthorizationController.flatCopyUser(originUser, "copytest", storage);
// Check that it is not the same user
assertThat(copy).usingRecursiveComparison().isNotEqualTo(originUser);
// Check that the copy does not have any mappings
assertThat(group.containsMember(copy)).isFalse();
assertThat(copy.getRoles()).isEmpty();
// Check that the flat map worked
assertThat(copy.getPermissions()).containsExactlyInAnyOrderElementsOf(originUser.getEffectivePermissions());
}
Aggregations