001/*
002 *  Copyright 2016 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 org.ametys.cms.content.indexing.solr.SolrFieldNames;
019
020/**
021 * Represents a {@link Query} testing if a document is allowed to anonymous (i.e. public and does not have any restriction).
022 */
023public class AclReadAllowAnonymousQuery implements Query
024{
025    private boolean _allowAnonymous;
026    
027    /**
028     * Create a AllowAnonymousQuery all documents restricted to anonymous (public documents).
029     */
030    public AclReadAllowAnonymousQuery()
031    {
032        this(true);
033    }
034    
035    /**
036     * Create a PublicPageQuery.
037     * @param allowAnonymous <code>true</code> to get only documents
038     * which are restricted to anonymous, <code>false</code> otherwise.
039     */
040    public AclReadAllowAnonymousQuery(boolean allowAnonymous)
041    {
042        this._allowAnonymous = allowAnonymous;
043    }
044    
045    @Override
046    public String build() throws QuerySyntaxException
047    {
048        return SolrFieldNames.ACL_READ_ALLOW_ANONYMOUS + ":" + (_allowAnonymous ? "true" : "false");
049    }
050    
051}