Search in sources :

Example 1 with Duration

use of org.kie.api.definition.type.Duration in project drools by kiegroup.

the class TypeDeclarationUtil method createTypeDeclaration.

public static TypeDeclaration createTypeDeclaration(Class<?> cls) {
    TypeDeclaration typeDeclaration = createTypeDeclarationForBean(cls);
    Duration duration = cls.getAnnotation(Duration.class);
    if (duration != null) {
        wireDurationAccessor(duration.value(), typeDeclaration);
    }
    Timestamp timestamp = cls.getAnnotation(Timestamp.class);
    if (timestamp != null) {
        wireDurationAccessor(timestamp.value(), typeDeclaration);
    }
    return typeDeclaration;
}
Also used : Duration(org.kie.api.definition.type.Duration) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Timestamp(org.kie.api.definition.type.Timestamp)

Example 2 with Duration

use of org.kie.api.definition.type.Duration in project drools by kiegroup.

the class TypeDeclarationConfigurator method wireDurationAccessor.

private static void wireDurationAccessor(KnowledgeBuilderImpl kbuilder, Annotated annotated, TypeDeclaration type, PackageRegistry pkgRegistry) {
    Duration duration = annotated.getTypedAnnotation(Duration.class);
    if (duration != null) {
        BaseDescr typeDescr = annotated instanceof BaseDescr ? ((BaseDescr) annotated) : new BaseDescr();
        String durationField;
        try {
            durationField = duration.value();
        } catch (Exception e) {
            kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, e.getMessage()));
            return;
        }
        type.setDurationAttribute(durationField);
        InternalKnowledgePackage pkg = pkgRegistry.getPackage();
        MVELAnalysisResult results = getMvelAnalysisResult(kbuilder, typeDescr, type, pkgRegistry, durationField, pkg);
        if (results != null) {
            type.setDurationExtractor(getFieldExtractor(type, durationField, pkg, results));
        } else {
            kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, "Error processing @duration for TypeDeclaration '" + type.getFullName() + "': cannot access the field '" + durationField + "'"));
        }
    }
}
Also used : TypeDeclarationError(org.drools.compiler.compiler.TypeDeclarationError) MVELAnalysisResult(org.drools.compiler.rule.builder.dialect.mvel.MVELAnalysisResult) Duration(org.kie.api.definition.type.Duration) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

Duration (org.kie.api.definition.type.Duration)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TypeDeclarationError (org.drools.compiler.compiler.TypeDeclarationError)1 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)1 MVELAnalysisResult (org.drools.compiler.rule.builder.dialect.mvel.MVELAnalysisResult)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 TypeDeclaration (org.drools.core.rule.TypeDeclaration)1 Timestamp (org.kie.api.definition.type.Timestamp)1