Search in sources :

Example 1 with FormConfig

use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.

the class FormConfigProcessor method addConfig.

/**
 * Adds the provided config to the desired dataset and the datasets that the
 * subject has access to (has the READ ability on the Dataset), if the config is
 * translatable to those.
 */
public FormConfig addConfig(Subject subject, Dataset targetDataset, FormConfigAPI config) {
    // TODO clear this up
    final Namespace namespace = datasetRegistry.get(targetDataset.getId());
    subject.authorize(namespace.getDataset(), Ability.READ);
    FormConfig internalConfig = FormConfigAPI.intern(config, storage.getUser(subject.getId()), targetDataset);
    // Add the config immediately to the submitted dataset
    addConfigToDataset(internalConfig);
    return internalConfig;
}
Also used : FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 2 with FormConfig

use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.

the class FormConfigAPI method intern.

public static FormConfig intern(FormConfigAPI extern, User owner, Dataset dataset) {
    FormConfig intern = new FormConfig();
    intern.setFormId(extern.formId);
    intern.setFormType(extern.formType);
    intern.setLabel(extern.label);
    intern.setTags(extern.tags);
    intern.setValues(extern.values);
    intern.setCreationTime(extern.creationTime);
    intern.setOwner(owner);
    intern.setDataset(dataset);
    return intern;
}
Also used : FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig)

Example 3 with FormConfig

use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.

the class SerializationTests method formConfig.

@Test
public void formConfig() throws JSONException, IOException {
    final CentralRegistry registry = new CentralRegistry();
    final Dataset dataset = new Dataset("test-dataset");
    registry.register(dataset);
    ExportForm form = new ExportForm();
    AbsoluteMode mode = new AbsoluteMode();
    form.setTimeMode(mode);
    mode.setForm(form);
    mode.setFeatures(List.of(new CQConcept()));
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    JsonNode values = mapper.valueToTree(form);
    FormConfig formConfig = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), values);
    formConfig.setDataset(dataset);
    SerializationTestUtil.forType(FormConfig.class).registry(registry).test(formConfig);
}
Also used : FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig) AbsoluteMode(com.bakdata.conquery.apiv1.forms.export_form.AbsoluteMode) Dataset(com.bakdata.conquery.models.datasets.Dataset) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) JsonNode(com.fasterxml.jackson.databind.JsonNode) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 4 with FormConfig

use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.

the class FormConfigTest method deleteConfig.

@Test
public void deleteConfig() {
    // PREPARE
    user.addPermission(DatasetPermission.onInstance(Ability.READ, datasetId));
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    FormConfig formConfig = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), mapper.valueToTree(form));
    formConfig.setDataset(dataset);
    user.addPermission(formConfig.createPermission(AbilitySets.FORM_CONFIG_CREATOR));
    storage.addFormConfig(formConfig);
    // EXECUTE
    processor.deleteConfig(user, formConfig);
    // CHECK
    assertThat(storage.getAllFormConfigs()).doesNotContain(formConfig);
    assertThat(user.getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.FORM_CONFIG_CREATOR, formConfig.getId()));
}
Also used : FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 5 with FormConfig

use of com.bakdata.conquery.models.forms.configs.FormConfig 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

FormConfig (com.bakdata.conquery.models.forms.configs.FormConfig)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Test (org.junit.jupiter.api.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 FormConfigAPI (com.bakdata.conquery.apiv1.forms.FormConfigAPI)1 AbsoluteMode (com.bakdata.conquery.apiv1.forms.export_form.AbsoluteMode)1 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)1 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 Group (com.bakdata.conquery.models.auth.entities.Group)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 FormConfigFullRepresentation (com.bakdata.conquery.models.forms.configs.FormConfig.FormConfigFullRepresentation)1 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)1 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)1 FormConfigId (com.bakdata.conquery.models.identifiable.ids.specific.FormConfigId)1 Namespace (com.bakdata.conquery.models.worker.Namespace)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1