Search in sources :

Example 1 with ActionFieldList

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()]);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FieldAccessorsAndMutators(org.kie.soup.project.datamodel.oracle.FieldAccessorsAndMutators) ActionFieldList(org.drools.workbench.models.datamodel.rule.ActionFieldList) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ArrayList(java.util.ArrayList)

Example 2 with ActionFieldList

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]);
}
Also used : ActionFieldList(org.drools.workbench.models.datamodel.rule.ActionFieldList) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) Test(org.junit.Test)

Aggregations

ActionFieldList (org.drools.workbench.models.datamodel.rule.ActionFieldList)2 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)2 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 Test (org.junit.Test)1 FieldAccessorsAndMutators (org.kie.soup.project.datamodel.oracle.FieldAccessorsAndMutators)1