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();
}
}
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;
}
Aggregations