001/*
002 *  Copyright 2014 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.search.query;
017
018import java.util.Date;
019
020import org.ametys.cms.content.indexing.solr.SolrFieldNames;
021
022/**
023 * Represents a {@link Query} testing the last modification date of a content.
024 */
025public class LastModifiedQuery implements Query
026{
027    
028    /** The operator. */
029    protected Operator _operator;
030    /** The value to test. */
031    protected Date _value;
032    
033    /**
034     * Build a LastModifiedQuery.
035     * @param value the value.
036     */
037    public LastModifiedQuery(Date value)
038    {
039        this(Operator.EQ, value);
040    }
041    
042    /**
043     * Build a LastModifiedQuery.
044     * @param op the operator.
045     * @param value the value.
046     */
047    public LastModifiedQuery(Operator op, Date value)
048    {
049        _operator = op;
050        _value = value;
051    }
052    
053    /**
054     * Get the operator.
055     * @return the operator.
056     */
057    public Operator getOperator()
058    {
059        return _operator;
060    }
061    
062    /**
063     * Get the value.
064     * @return the value.
065     */
066    public Date getValue()
067    {
068        return _value;
069    }
070    
071    @Override
072    public String build() throws QuerySyntaxException
073    {
074        StringBuilder query = new StringBuilder();
075        
076        if (_operator == Operator.NE)
077        {
078            query.append('-');
079        }
080        
081        query.append(SolrFieldNames.LAST_MODIFIED).append(':');
082        
083        DateQuery.appendDateValue(query, _operator, _value);
084        
085        return query.toString();
086    }
087    
088}