Search in sources :

Example 1 with ObjectField

use of org.drools.workbench.services.verifier.api.client.index.ObjectField in project drools-wb by kiegroup.

the class ConditionsInspectorTest method testSubsume003.

@Test
public void testSubsume003() throws Exception {
    final Field nameField = new Field(new ObjectField("Person", "String", "name", configurationMock), "Person", "String", "name", configurationMock);
    final Field lastNameField = new Field(new ObjectField("Person", "String", "lastName", configurationMock), "Person", "String", "lastName", configurationMock);
    final ConditionsInspectorMultiMap a = getConditions(new ComparableConditionInspector<String>(new FieldCondition(nameField, mock(Column.class), "==", new Values<>("Toni"), configurationMock), configurationMock));
    final ConditionsInspectorMultiMap b = getConditions(new ComparableConditionInspector<Integer>(new FieldCondition(field, mock(Column.class), "==", new Values<>(12), configurationMock), configurationMock), new ComparableConditionInspector<String>(new FieldCondition(nameField, mock(Column.class), "==", new Values<>("Toni"), configurationMock), configurationMock), new ComparableConditionInspector<String>(new FieldCondition(lastNameField, mock(Column.class), "==", new Values<>("Rikkola"), configurationMock), configurationMock));
    assertFalse(a.subsumes(b));
    assertTrue(b.subsumes(a));
}
Also used : ObjectField(org.drools.workbench.services.verifier.api.client.index.ObjectField) Field(org.drools.workbench.services.verifier.api.client.index.Field) FieldCondition(org.drools.workbench.services.verifier.api.client.index.FieldCondition) ConditionsInspectorMultiMap(org.drools.workbench.services.verifier.core.cache.inspectors.condition.ConditionsInspectorMultiMap) Column(org.drools.workbench.services.verifier.api.client.index.Column) ObjectField(org.drools.workbench.services.verifier.api.client.index.ObjectField) Test(org.junit.Test)

Example 2 with ObjectField

use of org.drools.workbench.services.verifier.api.client.index.ObjectField in project drools-wb by kiegroup.

the class FieldInspectorUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    configurationMock = new AnalyzerConfigurationMock();
    final Field field = spy(new Field(objectField, "org.Person", "String", "name", configurationMock));
    fieldCondition = makeCondition(field);
    fieldAction = makeAction(field);
    new FieldInspector(field, ruleInspectorUpdater, new AnalyzerConfigurationMock());
}
Also used : ObjectField(org.drools.workbench.services.verifier.api.client.index.ObjectField) Field(org.drools.workbench.services.verifier.api.client.index.Field) AnalyzerConfigurationMock(org.drools.workbench.services.verifier.core.checks.AnalyzerConfigurationMock) Before(org.junit.Before)

Example 3 with ObjectField

use of org.drools.workbench.services.verifier.api.client.index.ObjectField in project drools-wb by kiegroup.

the class Utils method resolveObjectField.

public static ObjectField resolveObjectField(final ObjectType objectType, final String fieldType, final String factField, final AnalyzerConfiguration configuration) {
    final ObjectField first = objectType.getFields().where(Field.name().is(factField)).select().first();
    if (first == null) {
        final ObjectField objectField = new ObjectField(objectType.getType(), fieldType, factField, configuration);
        objectType.getFields().add(objectField);
        return objectField;
    } else {
        return first;
    }
}
Also used : ObjectField(org.drools.workbench.services.verifier.api.client.index.ObjectField)

Example 4 with ObjectField

use of org.drools.workbench.services.verifier.api.client.index.ObjectField in project drools-wb by kiegroup.

the class SingleRangeCheck method partition.

private Map<PartitionKey, List<RuleInspector>> partition(Collection<ObjectField> partitionFields, Collection<RuleInspector> rules, int conditionIndex) {
    List<PartitionKey> keysWithNull = new ArrayList<>();
    Map<PartitionKey, List<RuleInspector>> partitions = new HashMap<>();
    for (RuleInspector rule : rules) {
        PartitionKey key = getPartitionKey(partitionFields, rule, conditionIndex);
        partitions.computeIfAbsent(key, k -> {
            if (k.hasNulls()) {
                keysWithNull.add(k);
            }
            return new ArrayList<>();
        }).add(rule);
    }
    for (PartitionKey key : keysWithNull) {
        for (Map.Entry<PartitionKey, List<RuleInspector>> partition : partitions.entrySet()) {
            if (key.subsumes(partition.getKey())) {
                partition.getValue().addAll(partitions.get(key));
            }
        }
    }
    keysWithNull.forEach(partitions::remove);
    return partitions;
}
Also used : IntStream(java.util.stream.IntStream) Operator(org.drools.workbench.services.verifier.api.client.relations.Operator) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) CheckBase(org.drools.workbench.services.verifier.core.checks.base.CheckBase) Issue(org.drools.workbench.services.verifier.api.client.reporting.Issue) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) AnalyzerConfiguration(org.drools.workbench.services.verifier.api.client.configuration.AnalyzerConfiguration) ObjectField(org.drools.workbench.services.verifier.api.client.index.ObjectField) Function(java.util.function.Function) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Severity(org.drools.workbench.services.verifier.api.client.reporting.Severity) HashSet(java.util.HashSet) RuleInspector(org.drools.workbench.services.verifier.core.cache.inspectors.RuleInspector) FieldCondition(org.drools.workbench.services.verifier.api.client.index.FieldCondition) Operator.resolve(org.drools.workbench.services.verifier.api.client.relations.Operator.resolve) Map(java.util.Map) CheckType(org.drools.workbench.services.verifier.api.client.reporting.CheckType) Collectors.toSet(java.util.stream.Collectors.toSet) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) ConditionInspector(org.drools.workbench.services.verifier.core.cache.inspectors.condition.ConditionInspector) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) HashMap(java.util.HashMap) RuleInspector(org.drools.workbench.services.verifier.core.cache.inspectors.RuleInspector) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ObjectField

use of org.drools.workbench.services.verifier.api.client.index.ObjectField in project drools-wb by kiegroup.

the class SingleRangeCheck method checkRanges.

private void checkRanges(Collection<ObjectField> rangeFields, Map<PartitionKey, List<RuleInspector>> partitions, int conditionIndex) {
    for (Map.Entry<PartitionKey, List<RuleInspector>> partition : partitions.entrySet()) {
        List<List<? extends Range<?>>> dimensions = new ArrayList<>();
        for (ObjectField field : rangeFields) {
            if ("Integer".equals(field.getFieldType())) {
                checkMonodimensionalRange(partition, dimensions, field, conditionIndex, IntegerRange::new, Integer.MIN_VALUE, Integer.MAX_VALUE);
            } else {
                checkMonodimensionalRange(partition, dimensions, field, conditionIndex, NumericRange::new, Double.MIN_VALUE, Double.MAX_VALUE);
            }
        }
        checkBidimensionalRanges(partition, dimensions);
    }
}
Also used : ArrayList(java.util.ArrayList) ObjectField(org.drools.workbench.services.verifier.api.client.index.ObjectField) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ObjectField (org.drools.workbench.services.verifier.api.client.index.ObjectField)7 Field (org.drools.workbench.services.verifier.api.client.index.Field)4 AnalyzerConfigurationMock (org.drools.workbench.services.verifier.core.checks.AnalyzerConfigurationMock)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 FieldCondition (org.drools.workbench.services.verifier.api.client.index.FieldCondition)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1