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

com.infilos.spring.track.aop.AuditSpec Maven / Gradle / Ivy

There is a newer version: 2.7.18-0
Show newest version
package com.infilos.spring.track.aop;

import com.infilos.spring.track.api.Audit;
import com.infilos.spring.track.api.AuditAttri;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class AuditSpec {
    private AuditSpec() {
    }

    /**
     * Should add more composite check conditions.
     */
    public static boolean isValid(AuditAttri attri) {
        return attri.from() != Audit.Nowhere;
    }

    public static boolean isEquals(AuditAttri left, AuditAttri right) {
        return left.from() == right.from()
            && left.name().equals(right.name())
            && left.locate().equals(right.locate())
            && left.value().equals(right.value())
            && left.alias().equals(right.alias());
    }

    public static AuditAttri create(Audit from, Map attributes) {
        return new AuditAttri() {

            @Override
            public Class annotationType() {
                return AuditAttri.class;
            }

            @Override
            public Audit from() {
                return from;
            }

            @Override
            public String name() {
                return Optional.ofNullable(attributes.get("name")).orElse("");
            }

            @Override
            public String locate() {
                return Optional.ofNullable(attributes.get("locate")).orElse("");
            }

            @Override
            public String value() {
                return Optional.ofNullable(attributes.get("value")).orElse("");
            }

            @Override
            public String alias() {
                return Optional.ofNullable(attributes.get("alias")).orElse("");
            }
        };
    }

    public static AuditAttri patch(AuditAttri origin, Map updates) {
        return create(
            origin.from(),
            new HashMap() {
                {
                    put("name", origin.name());
                    put("locate", origin.locate());
                    put("value", origin.value());
                    put("alias", origin.alias());
                    putAll(updates);
                }
            });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy