use of org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition 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;
}
use of org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testRHSExecuteWorkItem.
@Test
public void testRHSExecuteWorkItem() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "true" };
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
List<ActionCol52> cols = new ArrayList<ActionCol52>();
ActionWorkItemCol52 awi = new ActionWorkItemCol52();
PortableWorkDefinition pwd = new PortableWorkDefinition();
pwd.setName("work-item");
awi.setWorkItemDefinition(pwd);
PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
p1.setName("BooleanParameter");
p1.setValue(Boolean.TRUE);
pwd.addParameter(p1);
PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
p2.setName("FloatParameter");
p2.setValue(123.456f);
pwd.addParameter(p2);
PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
p3.setName("IntegerParameter");
p3.setValue(123);
pwd.addParameter(p3);
PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
p4.setName("StringParameter");
p4.setValue("hello");
pwd.addParameter(p4);
cols.add(awi);
RuleModel rm = new RuleModel();
allColumns.addAll(cols);
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
assertEquals(1, rm.rhs.length);
// Examine RuleModel action
ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
assertNotNull(aw);
PortableWorkDefinition mpwd = aw.getWorkDefinition();
assertNotNull(mpwd);
assertEquals(4, mpwd.getParameters().size());
PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getParameter("BooleanParameter");
assertNotNull(mp1);
assertEquals(Boolean.TRUE, mp1.getValue());
PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getParameter("FloatParameter");
assertNotNull(mp2);
assertEquals(new Float(123.456f), mp2.getValue());
PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getParameter("IntegerParameter");
assertNotNull(mp3);
assertEquals(new Integer(123), mp3.getValue());
PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getParameter("StringParameter");
assertNotNull(mp4);
assertEquals("hello", mp4.getValue());
}
use of org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testRHSExecuteWorkItemWithBindings.
@Test
public void testRHSExecuteWorkItemWithBindings() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "true" };
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
List<ActionCol52> cols = new ArrayList<ActionCol52>();
ActionWorkItemCol52 awi = new ActionWorkItemCol52();
PortableWorkDefinition pwd = new PortableWorkDefinition();
pwd.setName("work-item");
awi.setWorkItemDefinition(pwd);
PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
p1.setName("BooleanParameter");
p1.setValue(Boolean.TRUE);
p1.setBinding("$b");
pwd.addParameter(p1);
PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
p2.setName("FloatParameter");
p2.setValue(123.456f);
p2.setBinding("$f");
pwd.addParameter(p2);
PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
p3.setName("IntegerParameter");
p3.setValue(123);
p3.setBinding("$i");
pwd.addParameter(p3);
PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
p4.setName("StringParameter");
p4.setValue("hello");
p4.setBinding("$s");
pwd.addParameter(p4);
cols.add(awi);
RuleModel rm = new RuleModel();
allColumns.addAll(cols);
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
assertEquals(1, rm.rhs.length);
// Examine RuleModel action
ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
assertNotNull(aw);
PortableWorkDefinition mpwd = aw.getWorkDefinition();
assertNotNull(mpwd);
assertEquals(4, mpwd.getParameters().size());
PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getParameter("BooleanParameter");
assertNotNull(mp1);
assertEquals(Boolean.TRUE, mp1.getValue());
assertEquals("$b", mp1.getBinding());
PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getParameter("FloatParameter");
assertNotNull(mp2);
assertEquals(new Float(123.456f), mp2.getValue());
assertEquals("$f", mp2.getBinding());
PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getParameter("IntegerParameter");
assertNotNull(mp3);
assertEquals(new Integer(123), mp3.getValue());
assertEquals("$i", mp3.getBinding());
PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getParameter("StringParameter");
assertNotNull(mp4);
assertEquals("hello", mp4.getValue());
assertEquals("$s", mp4.getBinding());
}
use of org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition in project drools by kiegroup.
the class ActionWorkItemCol52Test method testDiffAll.
@Test
public void testDiffAll() {
PortableWorkDefinition def1 = new PortableWorkDefinition();
def1.setName("def1name");
column1.setWorkItemDefinition(def1);
column1.setHeader("header1");
column1.setHideColumn(false);
column1.setDefaultValue(new DTCellValue52("default1"));
PortableWorkDefinition def2 = new PortableWorkDefinition();
def2.setName("def2name");
column2.setWorkItemDefinition(def2);
column2.setHeader("header2");
column2.setHideColumn(true);
column2.setDefaultValue(new DTCellValue52("default2"));
List<BaseColumnFieldDiff> diff = column1.diff(column2);
assertNotNull(diff);
assertEquals(4, diff.size());
assertEquals(FIELD_HIDE_COLUMN, diff.get(0).getFieldName());
assertEquals(false, diff.get(0).getOldValue());
assertEquals(true, diff.get(0).getValue());
assertEquals(FIELD_DEFAULT_VALUE, diff.get(1).getFieldName());
assertEquals("default1", diff.get(1).getOldValue());
assertEquals("default2", diff.get(1).getValue());
assertEquals(FIELD_HEADER, diff.get(2).getFieldName());
assertEquals("header1", diff.get(2).getOldValue());
assertEquals("header2", diff.get(2).getValue());
assertEquals(FIELD_WORKITEM_DEFINITION_NAME, diff.get(3).getFieldName());
assertEquals("def1name", diff.get(3).getOldValue());
assertEquals("def2name", diff.get(3).getValue());
}
use of org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition in project drools by kiegroup.
the class ActionWorkItemCol52Test method testWorkItemDefinition_ParamAndNull.
@Test
public void testWorkItemDefinition_ParamAndNull() {
PortableWorkDefinition def1 = new PortableWorkDefinition();
def1.setName("def1name");
PortableStringParameterDefinition param1 = new PortableStringParameterDefinition();
param1.setName("param1");
param1.setValue("value1");
def1.addParameter(param1);
column1.setWorkItemDefinition(null);
column2.setWorkItemDefinition(def1);
List<BaseColumnFieldDiff> diff = column1.diff(column2);
assertNotNull(diff);
assertEquals(3, diff.size());
assertEquals(FIELD_WORKITEM_DEFINITION_NAME, diff.get(0).getFieldName());
assertEquals(null, diff.get(0).getOldValue());
assertEquals("def1name", diff.get(0).getValue());
assertEquals(FIELD_WORKITEM_DEFINITION_PARAMETER_NAME, diff.get(1).getFieldName());
assertEquals(null, diff.get(1).getOldValue());
assertEquals("param1", diff.get(1).getValue());
assertEquals(FIELD_WORKITEM_DEFINITION_PARAMETER_VALUE, diff.get(2).getFieldName());
assertEquals(null, diff.get(2).getOldValue());
assertEquals("\"value1\"", diff.get(2).getValue());
}
Aggregations