Search in sources :

Example 1 with Expires

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

the class TypeDeclaration method configureExpirationOffset.

private static void configureExpirationOffset(TypeDeclaration type, Annotated annotated) {
    Expires expires = annotated.getTypedAnnotation(Expires.class);
    if (expires != null) {
        String expiration = expires.value();
        long offset = TimeIntervalParser.parseSingle(expiration);
        // @Expires( -1 ) means never expire
        type.setExpirationOffset(offset == -1L ? Long.MAX_VALUE : offset);
        type.setExpirationType(expires.policy());
    }
}
Also used : Expires(org.kie.api.definition.type.Expires)

Example 2 with Expires

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

the class TypeDeclarationUtil method createTypeDeclaration.

public static TypeDeclaration createTypeDeclaration(KnowledgePackageImpl pkg, TypeMetaData metaType) {
    try {
        Class<?> typeClass = pkg.getTypeResolver().resolveType(metaType.getPackage() + "." + metaType.getName());
        TypeDeclaration typeDeclaration = createTypeDeclarationForBean(typeClass);
        for (Map.Entry<String, AnnotationValue[]> ann : metaType.getAnnotations().entrySet()) {
            switch(ann.getKey()) {
                case "role":
                    for (AnnotationValue annVal : ann.getValue()) {
                        if (annVal.getKey().equals("value") && annVal.getValue().equals("event")) {
                            typeDeclaration.setRole(Role.Type.EVENT);
                        }
                    }
                    break;
                case "duration":
                    for (AnnotationValue annVal : ann.getValue()) {
                        if (annVal.getKey().equals("value")) {
                            wireDurationAccessor(annVal.getValue().toString(), typeDeclaration);
                        }
                    }
                    break;
                case "timestamp":
                    for (AnnotationValue annVal : ann.getValue()) {
                        if (annVal.getKey().equals("value")) {
                            wireTimestampAccessor(annVal.getValue().toString(), typeDeclaration);
                        }
                    }
                    break;
                case "expires":
                    for (AnnotationValue annVal : ann.getValue()) {
                        if (annVal.getKey().equals("value")) {
                            long offset = TimeIntervalParser.parseSingle(annVal.getValue().toString());
                            typeDeclaration.setExpirationOffset(offset == -1L ? Long.MAX_VALUE : offset);
                        } else if (annVal.getKey().equals("policy")) {
                            typeDeclaration.setExpirationType(Enum.valueOf(Expires.Policy.class, annVal.getValue().toString()));
                        }
                    }
                    break;
                case "propertyReactive":
                    typeDeclaration.setPropertyReactive(true);
                    break;
                case "classReactive":
                    typeDeclaration.setPropertyReactive(false);
                    break;
                default:
                    throw new UnsupportedOperationException("Unknown annotation: " + ann.getKey());
            }
        }
        return typeDeclaration;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : AnnotationValue(org.drools.model.AnnotationValue) Expires(org.kie.api.definition.type.Expires) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Map(java.util.Map)

Aggregations

Expires (org.kie.api.definition.type.Expires)2 Map (java.util.Map)1 TypeDeclaration (org.drools.core.rule.TypeDeclaration)1 AnnotationValue (org.drools.model.AnnotationValue)1