All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.memority.toolkit.rule.api.RuleDefinitions Maven / Gradle / Ivy

Go to download

This artifact provides the API classes that are necessary to implement the contracts of Memority configuration Rules.

There is a newer version: 3.43.1
Show newest version
/*
 * Copyright (c) 2016-2023 Memority. All Rights Reserved.
 *
 * This file is part of Memority Toolkit API , a Memority project.
 *
 * This file is released under the Memority Public Artifacts End-User License Agreement,
 * see 
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 */
package com.memority.toolkit.rule.api;

import org.apache.commons.lang3.Validate;
import org.intellij.lang.annotations.Language;
import org.springframework.core.annotation.AnnotationUtils;

/**
 * Provide utility methods to instantiate {@link RuleDefinition}s
 */
public interface RuleDefinitions {


    @SuppressWarnings("rawtypes")
    static RuleDefinition forJavaRule(Class ruleClazz) {
        return forJavaRule(ruleClazz, null);
    }

    @SuppressWarnings("rawtypes")
    static RuleDefinition forJavaRule(Class ruleClazz, RuleConfiguration configuration) {
        Validate.notNull(ruleClazz);

        JavaRule javaRuleAnnot = AnnotationUtils.findAnnotation(ruleClazz, JavaRule.class);
        if (javaRuleAnnot == null) {
            throw new IllegalArgumentException("Cannot create rule definition from class that is not annotated with @JavaRule!");
        }
        return new RuleDefinition(
                null,
                javaRuleAnnot.label()[0],
                null,
                configuration);

    }

    static RuleDefinition forJavaRule(String classLabel, RuleConfiguration config) {
        Validate.notBlank(classLabel);
        return new RuleDefinition(
                null,
                classLabel,
                null,
                config);
    }

    static RuleDefinition forDelegateRule(String ruleId) {
        return new RuleDefinition(
                null,
                null,
                ruleId,
                null
        );
    }

    static RuleDefinition forGroovyRule(@Language("groovy") String script) {
        Validate.notBlank(script);
        return new RuleDefinition(
                script,
                null,
                null,
                null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy