Search in sources :

Example 1 with PortableParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition in project drools by kiegroup.

the class ActionWorkItemCol52 method diff.

@Override
public List<BaseColumnFieldDiff> diff(BaseColumn otherColumn) {
    if (otherColumn == null) {
        return null;
    }
    List<BaseColumnFieldDiff> result = super.diff(otherColumn);
    ActionWorkItemCol52 other = (ActionWorkItemCol52) otherColumn;
    // Field: Work Item definition.
    final PortableWorkDefinition thisDefinition = this.getWorkItemDefinition();
    final PortableWorkDefinition otherDefinition = other.getWorkItemDefinition();
    // for differences between the two WorkItemDefinitions
    if (thisDefinition == null && otherDefinition == null) {
        return result;
    } else if (thisDefinition != null && otherDefinition == null) {
        result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_NAME, thisDefinition.getName(), null));
        for (PortableParameterDefinition parameter : thisDefinition.getParameters()) {
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_NAME, parameter.getName(), null));
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, parameter.asString(), null));
        }
    } else if (thisDefinition == null && otherDefinition != null) {
        result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_NAME, null, otherDefinition.getName()));
        for (PortableParameterDefinition parameter : otherDefinition.getParameters()) {
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_NAME, null, parameter.getName()));
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, null, parameter.asString()));
        }
    } else {
        if (!thisDefinition.getName().equals(otherDefinition.getName())) {
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_NAME, thisDefinition.getName(), otherDefinition.getName()));
        }
        final List<String> thisDefinitionParameterNames = Arrays.asList(thisDefinition.getParameterNames());
        final List<String> otherDefinitionParameterNames = Arrays.asList(otherDefinition.getParameterNames());
        // Some Parameters have been deleted
        final List<String> parameterNamesDeleted = new ArrayList<String>(thisDefinitionParameterNames);
        parameterNamesDeleted.removeAll(otherDefinitionParameterNames);
        for (String parameterName : parameterNamesDeleted) {
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_NAME, thisDefinition.getParameter(parameterName).getName(), null));
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, thisDefinition.getParameter(parameterName).asString(), null));
        }
        // Some Parameters have been added
        final List<String> parameterNamesAdded = new ArrayList<String>(otherDefinitionParameterNames);
        parameterNamesAdded.removeAll(thisDefinitionParameterNames);
        for (String parameterName : parameterNamesAdded) {
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_NAME, null, otherDefinition.getParameter(parameterName).getName()));
            result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, null, otherDefinition.getParameter(parameterName).asString()));
        }
        // Some Parameters have been updated
        final List<String> parameterNamesUpdated = new ArrayList<String>(thisDefinitionParameterNames);
        parameterNamesUpdated.retainAll(otherDefinitionParameterNames);
        for (String parameterName : parameterNamesUpdated) {
            boolean parameterNamesDiffer = false;
            if (!isEqualOrNull(thisDefinition.getParameter(parameterName).getName(), otherDefinition.getParameter(parameterName).getName())) {
                result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_NAME, thisDefinition.getParameter(parameterName).getName(), otherDefinition.getParameter(parameterName).getName()));
                parameterNamesDiffer = true;
            }
            if (!isEqualOrNull(thisDefinition.getParameter(parameterName).asString(), otherDefinition.getParameter(parameterName).asString())) {
                if (!parameterNamesDiffer) {
                    result.add(new WorkItemColumnParameterValueDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, thisDefinition.getParameter(parameterName).getName(), thisDefinition.getParameter(parameterName).asString(), otherDefinition.getParameter(parameterName).asString()));
                } else {
                    result.add(new BaseColumnFieldDiffImpl(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, thisDefinition.getParameter(parameterName).asString(), otherDefinition.getParameter(parameterName).asString()));
                }
            }
        }
    }
    return result;
}
Also used : PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) ArrayList(java.util.ArrayList) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition)

Example 2 with PortableParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition in project kie-wb-common by kiegroup.

the class WorkItemParametersWidget method setParameters.

public void setParameters(Collection<PortableParameterDefinition> parameters) {
    this.clear();
    this.parameters = sort(parameters);
    for (PortableParameterDefinition ppd : this.parameters) {
        WorkItemParameterWidget pw = WorkItemParameterWidgetFactory.getWidget(ppd, bindingProvider, isReadOnly);
        add(pw);
    }
}
Also used : PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition)

Example 3 with PortableParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition in project drools-wb by kiegroup.

the class WorkItemsEditorServiceImpl method convertWorkItemParameters.

private Set<PortableParameterDefinition> convertWorkItemParameters(final Set<ParameterDefinition> parameters) {
    final Set<PortableParameterDefinition> pps = new HashSet<PortableParameterDefinition>();
    for (ParameterDefinition pd : parameters) {
        final DataType pdt = pd.getType();
        PortableParameterDefinition ppd = null;
        if (pdt instanceof BooleanDataType) {
            ppd = new PortableBooleanParameterDefinition();
        } else if (pdt instanceof FloatDataType) {
            ppd = new PortableFloatParameterDefinition();
        } else if (pdt instanceof IntegerDataType) {
            ppd = new PortableIntegerParameterDefinition();
        } else if (pdt instanceof ObjectDataType) {
            ppd = new PortableObjectParameterDefinition();
            final PortableObjectParameterDefinition oppd = (PortableObjectParameterDefinition) ppd;
            final ObjectDataType odt = (ObjectDataType) pdt;
            oppd.setClassName(odt.getClassName());
        } else if (pd.getType() instanceof StringDataType) {
            ppd = new PortableStringParameterDefinition();
        }
        if (ppd != null) {
            ppd.setName(pd.getName());
            pps.add(ppd);
        }
    }
    return pps;
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) PortableObjectParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableObjectParameterDefinition) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) DataType(org.jbpm.process.core.datatype.DataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) HashSet(java.util.HashSet) PortableObjectParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableObjectParameterDefinition) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)

Example 4 with PortableParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition in project drools-wb by kiegroup.

the class ActionWorkItemSetFieldPluginTest method testSetWorkItem.

@Test
public void testSetWorkItem() throws Exception {
    final String workItemKey = "workItem";
    final PortableWorkDefinition workDefinition = mock(PortableWorkDefinition.class);
    final PortableParameterDefinition parameterDefinition = mock(PortableParameterDefinition.class);
    final ActionWorkItemSetFieldPlugin.WorkItemParameter parameter = mock(ActionWorkItemSetFieldPlugin.WorkItemParameter.class);
    final HashMap<String, ActionWorkItemSetFieldPlugin.WorkItemParameter> workItems = new HashMap<String, ActionWorkItemSetFieldPlugin.WorkItemParameter>() {

        {
            put(workItemKey, parameter);
        }
    };
    final List<ActionInsertFactCol52> actions = new ArrayList<ActionInsertFactCol52>() {

        {
            add(mock(ActionInsertFactCol52.class));
        }
    };
    doReturn(model).when(presenter).getModel();
    doReturn(actions).when(model).getActionCols();
    doReturn("workName").when(workDefinition).getName();
    doReturn("parameterName").when(parameterDefinition).getName();
    doReturn("parameterClassName").when(parameterDefinition).getClassName();
    doReturn(workItems).when(plugin).getWorkItems();
    doReturn(workDefinition).when(parameter).getWorkDefinition();
    doReturn(parameterDefinition).when(parameter).getWorkParameterDefinition();
    plugin.setWorkItem(workItemKey);
    assertEquals(workItemKey, plugin.getWorkItem());
    verify(editingWrapper).setWorkItemName("workName");
    verify(editingWrapper).setWorkItemResultParameterName("parameterName");
    verify(editingWrapper).setParameterClassName("parameterClassName");
    verify(plugin).fireChangeEvent(workItemPage);
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) HashMap(java.util.HashMap) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) ArrayList(java.util.ArrayList) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 5 with PortableParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition in project drools-wb by kiegroup.

the class ActionWorkItemSetFieldPluginTest method firstFakeWorkItem.

private ActionWorkItemCol52 firstFakeWorkItem() {
    final ActionWorkItemCol52 workItemCol52 = new ActionWorkItemCol52();
    final PortableWorkDefinition portableWorkDefinition = new PortableWorkDefinition();
    final PortableParameterDefinition portableStringParameterDefinition = new PortableStringParameterDefinition();
    portableStringParameterDefinition.setName("StringResult");
    portableWorkDefinition.setResults(Collections.singleton(portableStringParameterDefinition));
    portableWorkDefinition.setName("StringWorkItemName");
    portableWorkDefinition.setDisplayName("StringWorkItemDisplayName");
    workItemCol52.setWorkItemDefinition(portableWorkDefinition);
    return workItemCol52;
}
Also used : PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition)

Aggregations

PortableParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition)9 PortableWorkDefinition (org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition)6 PortableFloatParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)3 PortableStringParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition)3 ArrayList (java.util.ArrayList)2 PortableBooleanParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition)2 PortableIntegerParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition)2 PortableObjectParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableObjectParameterDefinition)2 ActionWorkItemCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 HasBinding (org.drools.workbench.models.datamodel.workitems.HasBinding)1 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)1 ParameterDefinition (org.jbpm.process.core.ParameterDefinition)1 DataType (org.jbpm.process.core.datatype.DataType)1 BooleanDataType (org.jbpm.process.core.datatype.impl.type.BooleanDataType)1 FloatDataType (org.jbpm.process.core.datatype.impl.type.FloatDataType)1 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)1 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)1 StringDataType (org.jbpm.process.core.datatype.impl.type.StringDataType)1