Search in sources :

Example 6 with DatasetId

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;
}
Also used : AddWorker(com.bakdata.conquery.models.messages.network.specific.AddWorker) WebApplicationException(javax.ws.rs.WebApplicationException) NamespaceStorage(com.bakdata.conquery.io.storage.NamespaceStorage) InternalOnly(com.bakdata.conquery.io.jackson.InternalOnly) ShardNodeInformation(com.bakdata.conquery.models.worker.ShardNodeInformation) Namespace(com.bakdata.conquery.models.worker.Namespace) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) EntityIdMap(com.bakdata.conquery.models.identifiable.mapping.EntityIdMap)

Example 7 with DatasetId

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);
}
Also used : IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) Locale(java.util.Locale) ResultUtil(com.bakdata.conquery.io.result.ResultUtil) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ResultUtil.makeResponseWithFileName(com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName) Subject(com.bakdata.conquery.models.auth.entities.Subject) RequiredArgsConstructor(lombok.RequiredArgsConstructor) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ArrayList(java.util.ArrayList) Dataset(com.bakdata.conquery.models.datasets.Dataset) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Response(javax.ws.rs.core.Response) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Ability(com.bakdata.conquery.models.auth.permissions.Ability) Locale(java.util.Locale) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) I18n(com.bakdata.conquery.models.i18n.I18n) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) Namespace(com.bakdata.conquery.models.worker.Namespace) Dataset(com.bakdata.conquery.models.datasets.Dataset) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 8 with DatasetId

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;
}
Also used : Dataset(com.bakdata.conquery.models.datasets.Dataset) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)

Example 9 with DatasetId

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);
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) User(com.bakdata.conquery.models.auth.entities.User) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 10 with DatasetId

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());
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Group(com.bakdata.conquery.models.auth.entities.Group) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) Test(org.junit.jupiter.api.Test)

Aggregations

DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)31 Test (org.junit.jupiter.api.Test)18 DatasetPermission (com.bakdata.conquery.models.auth.permissions.DatasetPermission)9 Permission (org.apache.shiro.authz.Permission)8 User (com.bakdata.conquery.models.auth.entities.User)7 AdminPermission (com.bakdata.conquery.models.auth.permissions.AdminPermission)7 ExecutionPermission (com.bakdata.conquery.models.auth.permissions.ExecutionPermission)7 SuperPermission (com.bakdata.conquery.models.auth.permissions.SuperPermission)7 ConqueryTestSpec (com.bakdata.conquery.integration.json.ConqueryTestSpec)6 Role (com.bakdata.conquery.models.auth.entities.Role)6 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)5 Dataset (com.bakdata.conquery.models.datasets.Dataset)5 Group (com.bakdata.conquery.models.auth.entities.Group)4 ConceptId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptId)4 ConceptTreeChildId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptTreeChildId)4 DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)4 ConceptsProcessor (com.bakdata.conquery.resources.api.ConceptsProcessor)4 ResolvedConceptsResult (com.bakdata.conquery.resources.api.ConceptsProcessor.ResolvedConceptsResult)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 FilterTemplate (com.bakdata.conquery.apiv1.FilterTemplate)3