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

dk.apaq.framework.criteria.mongo.interpreter.CompareRuleInterpreter Maven / Gradle / Ivy

/*
 * Rule
 * Copyright (C) 2011 by Apaq
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package dk.apaq.framework.criteria.mongo.interpreter;


import dk.apaq.framework.criteria.rules.CompareRule;
import org.springframework.data.mongodb.core.query.Criteria;

/**
 *
 * @author michael
 */
public class CompareRuleInterpreter implements Interpreter {

    public boolean interpret(Criteria clause, CompareRule filter) {
        
        Criteria c = clause.and(filter.getPropertyId());//Criteria.where(filter.getPropertyId());
        
        switch (filter.getCompareType()) {
            case Equals:
                c.is(filter.getValue());
                break;
            case GreaterOrEqual:
                c.gte(filter.getValue());
                break;
            case GreaterThan:
                c.gt(filter.getValue());
                break;
            case LessOrEqual:
                c.lte(filter.getValue());
                break;
            case LessThan:
                c.lt(filter.getValue());
                break;
        }
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy