use of org.drools.workbench.models.datamodel.rule.ActionFieldList in project drools-wb by kiegroup.
the class ModelFieldUtil method getAvailableFieldCompletions.
/**
* Returns an array of ModelFields not consumed by the ActionFieldList; i.e. an array of available ModelFields.
*
* @param fieldCompletions The complete collection of ModelFields
* @param afl The model of ModelFields already used
* @return An array of unused ModelFields
*/
public static ModelField[] getAvailableFieldCompletions(final ModelField[] fieldCompletions, final ActionFieldList afl) {
if (fieldCompletions == null || fieldCompletions.length == 0) {
return fieldCompletions;
}
if (afl == null || afl.getFieldValues().length == 0) {
return fieldCompletions;
}
final List<ModelField> availableModelFields = new ArrayList<>();
availableModelFields.addAll(Arrays.asList(fieldCompletions));
for (ActionFieldValue afv : afl.getFieldValues()) {
final List<ModelField> usedModelFields = availableModelFields.stream().filter(m -> m.getName().equals(afv.getField())).collect(Collectors.toList());
availableModelFields.removeAll(usedModelFields);
}
return availableModelFields.toArray(new ModelField[availableModelFields.size()]);
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldList in project drools-wb by kiegroup.
the class ModelFieldUtilTest method filtering.
@Test
public void filtering() {
when(field1.getName()).thenReturn("field1");
when(field2.getName()).thenReturn("field2");
final ActionFieldList afl = new ActionInsertFact();
final ActionFieldValue afv = new ActionFieldValue();
afv.setField("field1");
afl.addFieldValue(afv);
final ModelField[] result = ModelFieldUtil.getAvailableFieldCompletions(new ModelField[] { field1, field2 }, afl);
assertEquals(1, result.length);
assertEquals(field2, result[0]);
}
Aggregations