Search in sources :

Example 1 with FESecondaryId

use of com.bakdata.conquery.apiv1.frontend.FESecondaryId in project conquery by bakdata.

the class SecondaryIdEndpointTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    final SecondaryIdDescription description = new SecondaryIdDescription();
    description.setDescription("description-DESCRIPTION");
    description.setName("description-NAME");
    description.setLabel("description-LABEL");
    final SecondaryIdDescriptionId id = new SecondaryIdDescriptionId(conquery.getDataset().getId(), description.getName());
    final Response post = uploadDescription(conquery, description);
    log.info("{}", post);
    assertThat(post).describedAs("Response = `%s`", post).returns(Response.Status.Family.SUCCESSFUL, response -> response.getStatusInfo().getFamily());
    {
        final Set<FESecondaryId> secondaryIds = fetchSecondaryIdDescriptions(conquery);
        log.info("{}", secondaryIds);
        description.setDataset(conquery.getDataset());
        assertThat(secondaryIds).extracting(FESecondaryId::getId).containsExactly(description.getId().toString());
        // Upload Table referencing SecondaryId
        {
            // Build data manually so content is minmal (ie no dataset prefixes etc)
            ObjectNode tableNode = Jackson.MAPPER.createObjectNode();
            tableNode.put("name", "table");
            ObjectNode columnNode = Jackson.MAPPER.createObjectNode();
            columnNode.put("name", "column");
            columnNode.put("type", MajorTypeId.INTEGER.name());
            columnNode.put("secondaryId", description.getId().toStringWithoutDataset());
            tableNode.put("columns", columnNode);
            final Response response = uploadTable(conquery, tableNode);
            assertThat(response.getStatusInfo().getFamily()).isEqualTo(Response.Status.Family.SUCCESSFUL);
        }
    }
    {
        final URI uri = HierarchyHelper.hierarchicalPath(conquery.defaultAdminURIBuilder(), DatasetsUIResource.class, "getDataset").buildFromMap(Map.of("dataset", conquery.getDataset().getName()));
        final Response actual = conquery.getClient().target(uri).request().get();
        assertThat(actual).returns(Response.Status.Family.SUCCESSFUL, response -> response.getStatusInfo().getFamily());
    }
    {
        // First one fails because table depends on it
        assertThat(deleteDescription(conquery, id)).returns(Response.Status.Family.CLIENT_ERROR, response -> response.getStatusInfo().getFamily());
        deleteTable(conquery, new TableId(conquery.getDataset().getId(), "table"));
        // We've deleted the table, now it should be successful
        assertThat(deleteDescription(conquery, id)).returns(Response.Status.Family.SUCCESSFUL, response -> response.getStatusInfo().getFamily());
        final Set<FESecondaryId> secondaryIds = fetchSecondaryIdDescriptions(conquery);
        log.info("{}", secondaryIds);
        assertThat(secondaryIds).isEmpty();
    }
}
Also used : Response(javax.ws.rs.core.Response) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AdminTablesResource(com.bakdata.conquery.resources.admin.rest.AdminTablesResource) AdminDatasetResource(com.bakdata.conquery.resources.admin.rest.AdminDatasetResource) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) URI(java.net.URI) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MajorTypeId(com.bakdata.conquery.models.events.MajorTypeId) IntegrationTest(com.bakdata.conquery.integration.IntegrationTest) ResourceConstants(com.bakdata.conquery.resources.ResourceConstants) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) DatasetsUIResource(com.bakdata.conquery.resources.admin.ui.DatasetsUIResource) FESecondaryId(com.bakdata.conquery.apiv1.frontend.FESecondaryId) Entity(javax.ws.rs.client.Entity) DatasetResource(com.bakdata.conquery.resources.api.DatasetResource) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Jackson(com.bakdata.conquery.io.jackson.Jackson) HierarchyHelper(com.bakdata.conquery.resources.hierarchies.HierarchyHelper) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) Set(java.util.Set) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FESecondaryId(com.bakdata.conquery.apiv1.frontend.FESecondaryId) URI(java.net.URI) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Example 2 with FESecondaryId

use of com.bakdata.conquery.apiv1.frontend.FESecondaryId in project conquery by bakdata.

the class FrontEndConceptBuilder method createRoot.

public static FERoot createRoot(NamespaceStorage storage, Subject subject) {
    FERoot root = new FERoot();
    Map<IId<?>, FENode> roots = root.getConcepts();
    List<? extends Concept<?>> allConcepts = new ArrayList<>(storage.getAllConcepts());
    // Remove any hidden concepts
    allConcepts.removeIf(Concept::isHidden);
    if (allConcepts.isEmpty()) {
        log.warn("There are no displayable concepts in the dataset {}", storage.getDataset().getId());
    }
    // Submit all permissions to Shiro
    boolean[] isPermitted = subject.isPermitted(allConcepts, Ability.READ);
    for (int i = 0; i < allConcepts.size(); i++) {
        if (isPermitted[i]) {
            roots.put(allConcepts.get(i).getId(), createCTRoot(allConcepts.get(i), storage.getStructure()));
        }
    }
    if (roots.isEmpty()) {
        log.warn("No concepts could be collected for {} on dataset {}. The subject is possibly lacking the permission to use them.", subject.getId(), storage.getDataset().getId());
    } else {
        log.trace("Collected {} concepts for {} on dataset {}.", roots.size(), subject.getId(), storage.getDataset().getId());
    }
    // add the structure tree
    for (StructureNode sn : storage.getStructure()) {
        FENode node = createStructureNode(sn, roots);
        if (node == null) {
            log.trace("Did not create a structure node entry for {}. Contained no concepts.", sn.getId());
            continue;
        }
        roots.put(sn.getId(), node);
    }
    // add all secondary IDs
    root.getSecondaryIds().addAll(storage.getSecondaryIds().stream().map(sid -> new FESecondaryId(sid.getId().toString(), sid.getLabel(), sid.getDescription())).collect(Collectors.toSet()));
    return root;
}
Also used : IId(com.bakdata.conquery.models.identifiable.ids.IId) FENode(com.bakdata.conquery.apiv1.frontend.FENode) FERoot(com.bakdata.conquery.apiv1.frontend.FERoot) ArrayList(java.util.ArrayList) FESecondaryId(com.bakdata.conquery.apiv1.frontend.FESecondaryId)

Aggregations

FESecondaryId (com.bakdata.conquery.apiv1.frontend.FESecondaryId)2 FENode (com.bakdata.conquery.apiv1.frontend.FENode)1 FERoot (com.bakdata.conquery.apiv1.frontend.FERoot)1 IntegrationTest (com.bakdata.conquery.integration.IntegrationTest)1 Jackson (com.bakdata.conquery.io.jackson.Jackson)1 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)1 MajorTypeId (com.bakdata.conquery.models.events.MajorTypeId)1 IId (com.bakdata.conquery.models.identifiable.ids.IId)1 SecondaryIdDescriptionId (com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId)1 TableId (com.bakdata.conquery.models.identifiable.ids.specific.TableId)1 ResourceConstants (com.bakdata.conquery.resources.ResourceConstants)1 AdminDatasetResource (com.bakdata.conquery.resources.admin.rest.AdminDatasetResource)1 AdminTablesResource (com.bakdata.conquery.resources.admin.rest.AdminTablesResource)1 DatasetsUIResource (com.bakdata.conquery.resources.admin.ui.DatasetsUIResource)1 DatasetResource (com.bakdata.conquery.resources.api.DatasetResource)1 HierarchyHelper (com.bakdata.conquery.resources.hierarchies.HierarchyHelper)1 StandaloneSupport (com.bakdata.conquery.util.support.StandaloneSupport)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1