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 restricted to any connected user.
022 */
023public class AclReadAllowAnyConnectedUserQuery implements Query
024{
025    private boolean _allowAnyConnectedUser;
026    
027    /**
028     * Create a query getting all documents restricted to any connected user.
029     */
030    public AclReadAllowAnyConnectedUserQuery()
031    {
032        this(true);
033    }
034    
035    /**
036     * Create a AllowAnyConnectedUserQuery.
037     * @param allowAnyConnectedUser <code>true</code> to get only documents
038     * which are restricted to any connected user, <code>false</code> otherwise.
039     */
040    public AclReadAllowAnyConnectedUserQuery(boolean allowAnyConnectedUser)
041    {
042        this._allowAnyConnectedUser = allowAnyConnectedUser;
043    }
044    
045    @Override
046    public String build() throws QuerySyntaxException
047    {
048        return SolrFieldNames.ACL_READ_ALLOW_ANY_CONNECTED_USER + ":" + (_allowAnyConnectedUser ? "true" : "false");
049    }
050    
051}