Search in sources :

Example 1 with Timestamp

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

the class TypeDeclarationConfigurator method wireTimestampAccessor.

private static void wireTimestampAccessor(KnowledgeBuilderImpl kbuilder, Annotated annotated, TypeDeclaration type, PackageRegistry pkgRegistry) {
    Timestamp timestamp = annotated.getTypedAnnotation(Timestamp.class);
    if (timestamp != null) {
        BaseDescr typeDescr = annotated instanceof BaseDescr ? ((BaseDescr) annotated) : new BaseDescr();
        String timestampField;
        try {
            timestampField = timestamp.value();
        } catch (Exception e) {
            kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, e.getMessage()));
            return;
        }
        type.setTimestampAttribute(timestampField);
        InternalKnowledgePackage pkg = pkgRegistry.getPackage();
        MVELAnalysisResult results = getMvelAnalysisResult(kbuilder, typeDescr, type, pkgRegistry, timestampField, pkg);
        if (results != null) {
            type.setTimestampExtractor(getFieldExtractor(type, timestampField, pkg, results));
        } else {
            kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, "Error creating field accessors for timestamp field '" + timestamp + "' for type '" + type.getTypeName() + "'"));
        }
    }
}
Also used : TypeDeclarationError(org.drools.compiler.compiler.TypeDeclarationError) MVELAnalysisResult(org.drools.compiler.rule.builder.dialect.mvel.MVELAnalysisResult) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) Timestamp(org.kie.api.definition.type.Timestamp) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 2 with Timestamp

use of org.kie.api.definition.type.Timestamp 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)

Aggregations

Timestamp (org.kie.api.definition.type.Timestamp)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 Duration (org.kie.api.definition.type.Duration)1