Search in sources :

Example 1 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData in project kie-wb-common by kiegroup.

the class BeanPropertiesProviderTest method testGetModelProperties.

protected void testGetModelProperties(String... columns) {
    field = new MultipleSubFormFieldDefinition();
    for (String column : columns) {
        field.getColumnMetas().add(new TableColumnMeta(column, column));
    }
    List<String> bannedColumns = new ArrayList<>(Arrays.asList(columns));
    if (!StringUtils.isEmpty(currentEditedMeta.getProperty())) {
        bannedColumns.remove(currentEditedMeta.getProperty());
    }
    field.setStandaloneClassName(TYPE_NAME);
    parentContext = new FormEditorRenderingContext(path);
    parentContext.setModel(field);
    context.setParentContext(parentContext);
    expectedFields = DATA_OBJECT_VALID_FIELDS - bannedColumns.size();
    SelectorData data = provider.getSelectorData(context);
    verify(service).getDataObjectProperties(any(), any());
    assertNotNull(data);
    assertNotNull(data.getValues());
    assertNull(data.getSelectedValue());
    assertFalse(data.getValues().isEmpty());
    assertEquals(expectedFields, data.getValues().size());
    for (String column : bannedColumns) {
        assertNull(data.getValues().get(column));
    }
    assertNull(data.getValues().get(DataObjectFormModelHandler.SERIAL_VERSION_UID));
    assertNull(data.getValues().get(PERSISTENCE_ID_PROPERTY));
}
Also used : FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) ArrayList(java.util.ArrayList) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Example 2 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData in project kie-wb-common by kiegroup.

the class BeanPropertiesProviderTest method testWithoutParentContext.

@Test
public void testWithoutParentContext() {
    SelectorData data = provider.getSelectorData(context);
    verify(service, never()).getDataObjectProperties(any(), any());
    assertNotNull(data);
    assertNotNull(data.getValues());
    assertTrue(data.getValues().isEmpty());
    assertNull(data.getSelectedValue());
}
Also used : SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) Test(org.junit.Test) AbstractDataObjectFinderTest(org.kie.workbench.common.forms.data.modeller.service.impl.AbstractDataObjectFinderTest)

Example 3 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData in project kie-wb-common by kiegroup.

the class SelectorOptionsProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    SelectorData data = new SelectorData<>();
    Map<Object, String> values = new HashMap<>();
    Object selectedValue = null;
    if (context.getModel() instanceof SelectorFieldBaseDefinition) {
        SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel();
        selectedValue = selector.getDefaultValue();
        List<SelectorOption> options = selector.getOptions();
        options.forEach(option -> values.put(option.getValue(), option.getText()));
        if (!values.containsKey(selectedValue)) {
            selectedValue = null;
            selector.setDefaultValue(null);
        }
    }
    data.setValues(values);
    data.setSelectedValue(selectedValue);
    return data;
}
Also used : SelectorOption(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorOption) HashMap(java.util.HashMap) SelectorFieldBaseDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorFieldBaseDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Example 4 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData in project kie-wb-common by kiegroup.

the class AbstractProcessFilteredNodeProviderBaseTest method testGetSelectorDataWithNoValues.

@Test
public void testGetSelectorDataWithNoValues() {
    @SuppressWarnings("unchecked") Iterable<Element> nodes = mock(Iterable.class);
    when(graph.nodes()).thenReturn(nodes);
    when(nodes.spliterator()).thenReturn(Spliterators.emptySpliterator());
    SelectorData selectorData = provider.getSelectorData(renderingContext);
    Map values = selectorData.getValues();
    assertTrue(values.isEmpty());
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Map(java.util.Map) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) Test(org.junit.Test)

Example 5 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData in project kie-wb-common by kiegroup.

the class DefaultRouteFormProviderTest method testGetSelectorDataWithValues.

@Test
public void testGetSelectorDataWithValues() {
    List<Element> nodes = mockModes();
    when(graph.nodes()).thenReturn(nodes);
    // add the desired edges to the selected node.
    when(selectedNode.getOutEdges()).thenReturn(outEdges);
    SelectorData selectorData = provider.getSelectorData(renderingContext);
    Map values = selectorData.getValues();
    verifyValues(values);
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Map(java.util.Map) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) Test(org.junit.Test)

Aggregations

SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)12 Test (org.junit.Test)7 Map (java.util.Map)5 Element (org.kie.workbench.common.stunner.core.graph.Element)5 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TableColumnMeta (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DataObjectFinderService (org.kie.workbench.common.forms.data.modeller.service.DataObjectFinderService)1 AbstractDataObjectFinderTest (org.kie.workbench.common.forms.data.modeller.service.impl.AbstractDataObjectFinderTest)1 SystemSelectorDataProvider (org.kie.workbench.common.forms.dynamic.model.config.SystemSelectorDataProvider)1 FormRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext)1 SelectorFieldBaseDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorFieldBaseDefinition)1