Search in sources :

Example 1 with FormConfigAPI

use of com.bakdata.conquery.apiv1.forms.FormConfigAPI in project conquery by bakdata.

the class FormConfigTest method addConfigWithoutTranslation.

@Test
public void addConfigWithoutTranslation() {
    user.addPermission(dataset.createPermission(Ability.READ.asSet()));
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(mapper.valueToTree(form)).build();
    processor.addConfig(user, dataset, formConfig);
    assertThat(storage.getAllFormConfigs()).containsExactly(FormConfigAPI.intern(formConfig, user, dataset));
}
Also used : FormConfigAPI(com.bakdata.conquery.apiv1.forms.FormConfigAPI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 2 with FormConfigAPI

use of com.bakdata.conquery.apiv1.forms.FormConfigAPI in project conquery by bakdata.

the class FormConfigTest method getConfigs.

@Test
public void getConfigs() {
    // PREPARE
    user.addPermission(dataset.createPermission(Ability.READ.asSet()));
    user.addPermission(FormPermission.onInstance(Ability.CREATE, form.getFormType()));
    ExportForm form2 = new ExportForm();
    RelativeMode mode3 = new RelativeMode();
    form2.setTimeMode(mode3);
    mode3.setForm(form);
    mode3.setFeatures(List.of(new CQConcept()));
    mode3.setOutcomes(List.of(new CQConcept()));
    TestForm form3 = new TestForm();
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(mapper.valueToTree(form)).build();
    FormConfigAPI formConfig2 = FormConfigAPI.builder().formType(form2.getFormType()).values(mapper.valueToTree(form2)).build();
    // This should not be retrieved by the user because it does not hold the Permission to create TestForms
    FormConfigAPI formConfig3 = FormConfigAPI.builder().formType(form3.getFormType()).values(mapper.valueToTree(form2)).build();
    FormConfigId formId = processor.addConfig(user, dataset, formConfig).getId();
    FormConfigId formId2 = processor.addConfig(user, dataset, formConfig2).getId();
    FormConfigId _formId3 = processor.addConfig(user, dataset, formConfig3).getId();
    FormScanner.FRONTEND_FORM_CONFIGS = Map.of(form.getFormType(), new FormType(form.getFormType(), new TextNode("dummy")));
    // EXECUTE
    Stream<FormConfigOverviewRepresentation> response = processor.getConfigsByFormType(user, dataset, Collections.emptySet());
    // CHECK
    assertThat(response).containsExactlyInAnyOrder(FormConfigOverviewRepresentation.builder().formType(form.getClass().getAnnotation(CPSType.class).id()).id(formId).label(formConfig.getLabel()).own(true).ownerName(user.getLabel()).shared(false).system(false).tags(formConfig.getTags()).createdAt(formConfig.getCreationTime().atZone(ZoneId.systemDefault())).build(), FormConfigOverviewRepresentation.builder().formType(form2.getClass().getAnnotation(CPSType.class).id()).id(formId2).label(formConfig2.getLabel()).own(true).ownerName(user.getLabel()).shared(false).system(false).tags(formConfig2.getTags()).createdAt(formConfig2.getCreationTime().atZone(ZoneId.systemDefault())).build());
}
Also used : FormConfigAPI(com.bakdata.conquery.apiv1.forms.FormConfigAPI) FormConfigOverviewRepresentation(com.bakdata.conquery.models.forms.configs.FormConfig.FormConfigOverviewRepresentation) FormType(com.bakdata.conquery.models.forms.frontendconfiguration.FormType) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) TextNode(com.fasterxml.jackson.databind.node.TextNode) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) FormConfigId(com.bakdata.conquery.models.identifiable.ids.specific.FormConfigId) RelativeMode(com.bakdata.conquery.apiv1.forms.export_form.RelativeMode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 3 with FormConfigAPI

use of com.bakdata.conquery.apiv1.forms.FormConfigAPI in project conquery by bakdata.

the class FormConfigTest method patchConfig.

@Test
public void patchConfig() {
    // PREPARE
    user.addPermission(DatasetPermission.onInstance(Ability.READ, datasetId));
    Group group1 = new Group("test1", "test1", storage);
    storage.addGroup(group1);
    Group group2 = new Group("test2", "test2", storage);
    storage.addGroup(group2);
    group1.addMember(user);
    group2.addMember(user);
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    JsonNode values = mapper.valueToTree(form);
    FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(values).build();
    FormConfig config = processor.addConfig(user, dataset, formConfig);
    // EXECUTE PART 1
    processor.patchConfig(user, config, FormConfigPatch.builder().label("newTestLabel").tags(new String[] { "tag1", "tag2" }).groups(List.of(group1.getId())).values(new ObjectNode(mapper.getNodeFactory(), Map.of("test-Node", new TextNode("test-text")))).build());
    // CHECK PART 1
    FormConfig patchedFormExpected = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), values);
    patchedFormExpected.setDataset(dataset);
    patchedFormExpected.setFormId(config.getFormId());
    patchedFormExpected.setLabel("newTestLabel");
    patchedFormExpected.setShared(true);
    patchedFormExpected.setTags(new String[] { "tag1", "tag2" });
    patchedFormExpected.setOwner(user);
    patchedFormExpected.setValues(new ObjectNode(mapper.getNodeFactory(), Map.of("test-Node", new TextNode("test-text"))));
    final FormConfigId formId = config.getId();
    assertThat(storage.getFormConfig(formId)).usingRecursiveComparison().ignoringFields("cachedId", FormConfig.Fields.creationTime).isEqualTo(patchedFormExpected);
    assertThat(storage.getGroup(group1.getId()).getPermissions()).contains(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
    assertThat(storage.getGroup(group2.getId()).getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
    // EXECUTE PART 2 (Unshare)
    processor.patchConfig(user, config, FormConfigPatch.builder().groups(List.of()).build());
    // CHECK PART 2
    patchedFormExpected.setShared(false);
    assertThat(storage.getFormConfig(formId)).usingRecursiveComparison().ignoringFields("cachedId", FormConfig.Fields.creationTime).isEqualTo(patchedFormExpected);
    assertThat(storage.getGroup(group1.getId()).getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
    assertThat(storage.getGroup(group2.getId()).getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
}
Also used : Group(com.bakdata.conquery.models.auth.entities.Group) FormConfigAPI(com.bakdata.conquery.apiv1.forms.FormConfigAPI) FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) FormConfigId(com.bakdata.conquery.models.identifiable.ids.specific.FormConfigId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

FormConfigAPI (com.bakdata.conquery.apiv1.forms.FormConfigAPI)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Test (org.junit.jupiter.api.Test)3 FormConfigId (com.bakdata.conquery.models.identifiable.ids.specific.FormConfigId)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)1 RelativeMode (com.bakdata.conquery.apiv1.forms.export_form.RelativeMode)1 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 Group (com.bakdata.conquery.models.auth.entities.Group)1 FormConfig (com.bakdata.conquery.models.forms.configs.FormConfig)1 FormConfigOverviewRepresentation (com.bakdata.conquery.models.forms.configs.FormConfig.FormConfigOverviewRepresentation)1 FormType (com.bakdata.conquery.models.forms.frontendconfiguration.FormType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1