Search in sources :

Example 6 with FormRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext in project kie-wb-common by kiegroup.

the class ProcessCompensationRefProvider method getSelectorData.

@Override
@SuppressWarnings("unchecked")
public SelectorData getSelectorData(FormRenderingContext context) {
    final Diagram diagram = sessionManager.getCurrentSession().getCanvasHandler().getDiagram();
    final String rootUUID = diagram.getMetadata().getCanvasRootUUID();
    final Node<?, ? extends Edge> selectedNode = getSelectedNode(diagram, sessionManager.getCurrentSession());
    final Map<Object, String> values = new TreeMap<>(SafeComparator.TO_STRING_COMPARATOR);
    if (selectedNode != null) {
        Node<?, ? extends Edge> currentNode = selectedNode;
        final List<Node> compensableNodes = new ArrayList<>();
        Node<?, ? extends Edge> parentNode;
        int levels = 0;
        do {
            parentNode = GraphUtils.getParent(currentNode).asNode();
            compensableNodes.addAll(getCompensableNodes(parentNode));
            if (rootUUID.equals(parentNode.getUUID())) {
                levels = 2;
            } else if (isSubProcess(parentNode)) {
                currentNode = parentNode;
                levels++;
            } else if (isLane(parentNode)) {
                currentNode = parentNode;
            }
        } while (levels < 2);
        compensableNodes.stream().map(node -> buildPair(node.getUUID(), (BPMNDefinition) (((View) node.getContent()).getDefinition()))).forEach(pair -> values.put(pair.getK1(), pair.getK2()));
        ActivityRef currentActivityRef = null;
        if (isEndCompensationEvent(selectedNode)) {
            currentActivityRef = ((EndCompensationEvent) ((View) selectedNode.getContent()).getDefinition()).getExecutionSet().getActivityRef();
        } else if (isIntermediateCompensationEventThrowing(selectedNode)) {
            currentActivityRef = ((IntermediateCompensationEventThrowing) ((View) selectedNode.getContent()).getDefinition()).getExecutionSet().getActivityRef();
        }
        if (currentActivityRef != null && !isEmpty(currentActivityRef.getValue()) && !values.containsKey(currentActivityRef.getValue())) {
            Node configured = diagram.getGraph().getNode(currentActivityRef.getValue());
            if (configured != null) {
                Pair<Object, String> pair = buildPair(configured.getUUID(), (BPMNDefinition) ((View) configured.getContent()).getDefinition());
                values.put(pair.getK1(), pair.getK2());
            }
        }
    }
    return new SelectorData(values, null);
}
Also used : IntermediateCompensationEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEventThrowing) Edge(org.kie.workbench.common.stunner.core.graph.Edge) SelectorDataProvider(org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) IntermediateCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEvent) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) Map(java.util.Map) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Pair(org.uberfire.commons.data.Pair) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) StringUtils.isEmpty(org.kie.workbench.common.stunner.core.util.StringUtils.isEmpty) BPMNDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition) Collectors(java.util.stream.Collectors) BaseSubprocess(org.kie.workbench.common.stunner.bpmn.definition.BaseSubprocess) List(java.util.List) TreeMap(java.util.TreeMap) BaseTask(org.kie.workbench.common.stunner.bpmn.definition.BaseTask) ClientUtils.getSelectedNode(org.kie.workbench.common.stunner.core.client.util.ClientUtils.getSelectedNode) ActivityRef(org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.ActivityRef) SafeComparator(org.kie.workbench.common.stunner.core.util.SafeComparator) Node(org.kie.workbench.common.stunner.core.graph.Node) ClientUtils.getSelectedNode(org.kie.workbench.common.stunner.core.client.util.ClientUtils.getSelectedNode) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) ActivityRef(org.kie.workbench.common.stunner.bpmn.definition.property.event.compensation.ActivityRef) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent)

Example 7 with FormRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext in project kie-wb-common by kiegroup.

the class BeanPropertiesProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    HashMap<String, String> values = new HashMap<>();
    if (context instanceof FormEditorRenderingContext && context.getParentContext() != null) {
        if (context.getParentContext().getModel() instanceof MultipleSubFormFieldDefinition) {
            FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
            if (context.getParentContext() != null) {
                MultipleSubFormFieldDefinition subForm = (MultipleSubFormFieldDefinition) context.getParentContext().getModel();
                Path path = editorContext.getFormPath();
                String typeName = subForm.getStandaloneClassName();
                final TableColumnMeta currentMeta = (TableColumnMeta) context.getModel();
                Set<String> unavailableProperties = subForm.getColumnMetas().stream().map(TableColumnMeta::getProperty).collect(Collectors.toSet());
                if (currentMeta != null && !StringUtils.isEmpty(currentMeta.getProperty())) {
                    unavailableProperties.remove(currentMeta.getProperty());
                }
                modelFinderService.getModel(typeName, path).getProperties().stream().filter(property -> !unavailableProperties.contains(property.getName())).forEachOrdered(property -> values.put(property.getName(), property.getName()));
            }
        }
    }
    return new SelectorData(values, null);
}
Also used : Path(org.uberfire.backend.vfs.Path) ModelFinderService(org.kie.workbench.common.forms.data.modeller.service.shared.ModelFinderService) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) Set(java.util.Set) HashMap(java.util.HashMap) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) Dependent(javax.enterprise.context.Dependent) SystemSelectorDataProvider(org.kie.workbench.common.forms.dynamic.model.config.SystemSelectorDataProvider) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) Path(org.uberfire.backend.vfs.Path) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) HashMap(java.util.HashMap) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Example 8 with FormRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext in project kie-wb-common by kiegroup.

the class RuleFlowGroupFormProviderTest method testGroupWithSameProject.

@Test
public void testGroupWithSameProject() {
    RuleFlowGroup group1 = new RuleFlowGroup("g1");
    group1.setPathUri("default://main@MySpace/Project1/src/main/resources/com/myspace/project1/RulesFile.rdrl");
    RuleFlowGroup group2 = new RuleFlowGroup("g1");
    group2.setPathUri("default://main@MySpace/Project1/src/main/resources/com/myspace/RulesFile2.rdrl".replace('/', '\\'));
    RuleFlowGroup group3 = new RuleFlowGroup("g1");
    group3.setPathUri("default://main@MySpace/Project2/src/main/resources/com/myspace/project1/RulesFile.rdrl");
    List<RuleFlowGroup> groups = Arrays.asList(group1, group2, group3);
    when(dataProvider.getRuleFlowGroupNames()).thenReturn(groups);
    FormRenderingContext context = mock(FormRenderingContext.class);
    SelectorData<String> data = tested.getSelectorData(context);
    Map<String, String> values = data.getValues();
    assertNotNull(values);
    assertEquals(1, values.size());
    assertEquals("g1 [Project1, Project2]", values.get(group1.getName()));
    verify(requestRuleFlowGroupDataEvent, times(1)).fire(any(RequestRuleFlowGroupDataEvent.class));
}
Also used : RuleFlowGroup(org.kie.workbench.common.stunner.bpmn.definition.property.task.RuleFlowGroup) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) RequestRuleFlowGroupDataEvent(org.kie.workbench.common.stunner.bpmn.forms.dataproviders.RequestRuleFlowGroupDataEvent) Test(org.junit.Test)

Example 9 with FormRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext in project kie-wb-common by kiegroup.

the class RuleFlowGroupFormProviderTest method testGetSelectorData.

@Test
@SuppressWarnings("unchecked")
public void testGetSelectorData() {
    RuleFlowGroup group1 = new RuleFlowGroup("g1");
    group1.setPathUri("default://main@MySpace/Project1/src/main/resources/com/myspace/project1/RulesFile.rdrl");
    RuleFlowGroup group2 = new RuleFlowGroup("g2");
    group2.setPathUri("default://main@MySpace/Project1/src/main/resources/com/myspace/RulesFile2.rdrl".replace('/', '\\'));
    RuleFlowGroup group3 = new RuleFlowGroup("g1");
    group3.setPathUri("default://main@MySpace/Project2/src/main/resources/com/myspace/project1/RulesFile.rdrl");
    List<RuleFlowGroup> groups = Arrays.asList(group1, group2, group3);
    when(dataProvider.getRuleFlowGroupNames()).thenReturn(groups);
    FormRenderingContext context = mock(FormRenderingContext.class);
    SelectorData data = tested.getSelectorData(context);
    Map<String, String> values = data.getValues();
    assertNotNull(values);
    assertEquals(2, values.size());
    assertEquals("g2 [Project1]", values.get(group2.getName()));
    assertEquals("g1 [Project1, Project2]", values.get(group1.getName()));
    verify(requestRuleFlowGroupDataEvent, times(1)).fire(any(RequestRuleFlowGroupDataEvent.class));
}
Also used : RuleFlowGroup(org.kie.workbench.common.stunner.bpmn.definition.property.task.RuleFlowGroup) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) RequestRuleFlowGroupDataEvent(org.kie.workbench.common.stunner.bpmn.forms.dataproviders.RequestRuleFlowGroupDataEvent) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) Test(org.junit.Test)

Aggregations

FormRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext)9 Test (org.junit.Test)4 SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)4 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)2 RuleFlowGroup (org.kie.workbench.common.stunner.bpmn.definition.property.task.RuleFlowGroup)2 RequestRuleFlowGroupDataEvent (org.kie.workbench.common.stunner.bpmn.forms.dataproviders.RequestRuleFlowGroupDataEvent)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Dependent (javax.enterprise.context.Dependent)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ModelFinderService (org.kie.workbench.common.forms.data.modeller.service.shared.ModelFinderService)1 AbstractNestedFormFormGroup (org.kie.workbench.common.forms.dynamic.client.rendering.formGroups.impl.nestedForm.AbstractNestedFormFormGroup)1 SelectorDataProvider (org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider)1 SystemSelectorDataProvider (org.kie.workbench.common.forms.dynamic.model.config.SystemSelectorDataProvider)1