Search in sources :

Example 6 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class FieldConstraintDescrVisitor method visit.

/**
 * End
 *
 * @param descr
 */
private void visit(QualifiedIdentifierRestrictionDescr descr) {
    String text = descr.getText();
    String base = text.substring(0, text.indexOf("."));
    String fieldName = text.substring(text.indexOf("."));
    Variable patternVariable = data.getVariableByRuleAndVariableName(pattern.getRuleName(), base);
    if (patternVariable != null) {
        QualifiedIdentifierRestriction restriction = new QualifiedIdentifierRestriction(pattern);
        restriction.setPatternIsNot(pattern.isPatternNot());
        restriction.setFieldPath(field.getPath());
        restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
        restriction.setVariablePath(patternVariable.getPath());
        restriction.setVariableName(base);
        restriction.setVariablePath(fieldName);
        restriction.setOrderNumber(orderNumber);
        restriction.setParentPath(pattern.getPath());
        restriction.setParentType(pattern.getVerifierComponentType());
        // Set field value, if it is not set.
        field.setFieldType(Field.VARIABLE);
        data.add(restriction);
        solvers.addPatternComponent(restriction);
    } else {
        EnumField enumField = (EnumField) data.getFieldByObjectTypeAndFieldName(base, fieldName);
        if (enumField == null) {
            ObjectType objectType = data.getObjectTypeByFullName(base);
            if (objectType == null) {
                Import objectImport = data.getImportByName(base);
                if (objectImport != null) {
                    objectType = ObjectTypeFactory.createObjectType(descr, objectImport);
                } else {
                    objectType = ObjectTypeFactory.createObjectType(descr, base);
                }
                data.add(objectType);
            }
            enumField = new EnumField(descr);
            enumField.setObjectTypePath(objectType.getPath());
            enumField.setObjectTypeName(objectType.getName());
            enumField.setName(fieldName);
            objectType.getFields().add(enumField);
            data.add(enumField);
        }
        EnumRestriction restriction = new EnumRestriction(pattern);
        restriction.setPatternIsNot(pattern.isPatternNot());
        restriction.setFieldPath(field.getPath());
        restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
        restriction.setEnumBasePath(enumField.getPath());
        restriction.setEnumBase(base);
        restriction.setEnumName(fieldName);
        restriction.setOrderNumber(orderNumber);
        restriction.setParentPath(pattern.getPath());
        restriction.setParentType(pattern.getVerifierComponentType());
        // Set field value, if it is not set.
        field.setFieldType(Field.ENUM);
        data.add(restriction);
        solvers.addPatternComponent(restriction);
    }
}
Also used : EnumField(org.drools.verifier.components.EnumField) ObjectType(org.drools.verifier.components.ObjectType) Variable(org.drools.verifier.components.Variable) PatternVariable(org.drools.verifier.components.PatternVariable) Import(org.drools.verifier.components.Import) EnumRestriction(org.drools.verifier.components.EnumRestriction) QualifiedIdentifierRestriction(org.drools.verifier.components.QualifiedIdentifierRestriction)

Example 7 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class ObjectTypeFactory method createObjectType.

static ObjectType createObjectType(BaseDescr descr, Import objectImport) {
    ObjectType objectType = new ObjectType(descr);
    objectType.setName(objectImport.getShortName());
    objectType.setFullName(objectImport.getName());
    return objectType;
}
Also used : ObjectType(org.drools.verifier.components.ObjectType)

Example 8 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class ObjectTypeFactory method createObjectType.

static ObjectType createObjectType(BaseDescr descr, String shortName) {
    ObjectType objectType = new ObjectType(descr);
    objectType.setName(shortName);
    objectType.setFullName(shortName);
    return objectType;
}
Also used : ObjectType(org.drools.verifier.components.ObjectType)

Example 9 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class VerifierTest method testFactTypesFromJarAndDeclarations.

@Test
public void testFactTypesFromJarAndDeclarations() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    Verifier verifier = vBuilder.newVerifier();
    try {
        JarInputStream jar = new JarInputStream(this.getClass().getResourceAsStream("model.jar"));
        verifier.addObjectModel(jar);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    verifier.addResourcesToVerify(new ClassPathResource("importsAndDeclarations.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    Collection<ObjectType> objectTypes = result.getVerifierData().getAll(VerifierComponentType.OBJECT_TYPE);
    for (ObjectType objectType : objectTypes) {
        if (objectType.getName().equals("VoiceCall")) {
            assertEquals(4, objectType.getMetadata().keySet().size());
        }
    }
    assertNotNull(objectTypes);
    assertEquals(4, objectTypes.size());
    Collection<Field> fields = result.getVerifierData().getAll(VerifierComponentType.FIELD);
    assertNotNull(fields);
    assertEquals(11, fields.size());
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) JarInputStream(java.util.jar.JarInputStream) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) IOException(java.io.IOException) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 10 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class VerifierDataMapsTest method testSavePatternAndGet.

@Test
public void testSavePatternAndGet() {
    VerifierData data = VerifierReportFactory.newVerifierData();
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    assertNotNull(rule.getName());
    assertEquals("testRule1", rule.getName());
    ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    assertNotNull(pattern.getRulePath());
    assertEquals(rule.getPath(), pattern.getRulePath());
    assertNotNull(pattern.getName());
    assertEquals(rule.getName(), pattern.getRuleName());
    pattern.setObjectTypePath(objectType.getPath());
    assertNotNull(pattern.getObjectTypePath());
    assertEquals(objectType.getPath(), pattern.getObjectTypePath());
    data.add(rule);
    data.add(objectType);
    data.add(pattern);
    Collection<VerifierComponent> all = data.getAll();
    assertEquals(3, all.size());
    assertTrue(all.contains(pattern));
    assertTrue(all.contains(objectType));
    assertTrue(all.contains(rule));
    Collection<VerifierComponent> components = data.getAll(pattern.getVerifierComponentType());
    assertEquals(1, components.size());
    assertEquals(pattern, components.toArray()[0]);
    VerifierComponent objectType2 = data.getVerifierObject(objectType.getVerifierComponentType(), objectType.getPath());
    assertNotNull(objectType2);
    assertEquals(objectType, objectType2);
    VerifierComponent rule2 = data.getVerifierObject(rule.getVerifierComponentType(), rule.getPath());
    assertNotNull(rule2);
    assertEquals(rule, rule2);
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) VerifierRule(org.drools.verifier.components.VerifierRule) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Aggregations

ObjectType (org.drools.verifier.components.ObjectType)14 Field (org.drools.verifier.components.Field)7 VerifierRule (org.drools.verifier.components.VerifierRule)5 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 Test (org.junit.Test)4 Import (org.drools.verifier.components.Import)3 VerifierReport (org.drools.verifier.data.VerifierReport)3 IOException (java.io.IOException)2 JarInputStream (java.util.jar.JarInputStream)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)2 EnumField (org.drools.verifier.components.EnumField)2 Pattern (org.drools.verifier.components.Pattern)2 PatternVariable (org.drools.verifier.components.PatternVariable)2 SubPattern (org.drools.verifier.components.SubPattern)2 VerifierData (org.drools.verifier.data.VerifierData)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1