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);
}
}
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;
}
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;
}
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());
}
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);
}
Aggregations