
io.vertigo.dynamo.impl.collections.CollectionsManagerImpl Maven / Gradle / Ivy
/**
* vertigo - simple java starter
*
* Copyright (C) 2013, KleeGroup, [email protected] (http://www.kleegroup.com)
* KleeGroup, Centre d'affaire la Boursidiere - BP 159 - 92357 Le Plessis Robinson Cedex - France
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vertigo.dynamo.impl.collections;
import io.vertigo.dynamo.collections.CollectionsManager;
import io.vertigo.dynamo.collections.DtListProcessor;
import io.vertigo.dynamo.collections.IndexDtListFunctionBuilder;
import io.vertigo.dynamo.collections.ListFilter;
import io.vertigo.dynamo.collections.model.Facet;
import io.vertigo.dynamo.collections.model.FacetValue;
import io.vertigo.dynamo.collections.model.FacetedQuery;
import io.vertigo.dynamo.collections.model.FacetedQueryResult;
import io.vertigo.dynamo.domain.metamodel.DtField;
import io.vertigo.dynamo.domain.model.DtList;
import io.vertigo.dynamo.domain.model.DtObject;
import io.vertigo.dynamo.impl.collections.facet.model.FacetFactory;
import io.vertigo.lang.Assertion;
import io.vertigo.lang.Option;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
/**
* Implémentation du gestionnaire de la manipulation des collections.
*
* @author pchretien
*/
public final class CollectionsManagerImpl implements CollectionsManager {
private final Option indexPlugin;
private final FacetFactory facetFactory;
private final DtListProcessor listProcessor;
/**
* Constructeur.
* @param indexPlugin Plugin optionnel d'index
*/
@Inject
public CollectionsManagerImpl(final Option indexPlugin) {
Assertion.checkNotNull(indexPlugin);
//-----
this.indexPlugin = indexPlugin;
facetFactory = new FacetFactory(this);
listProcessor = new DtListProcessorImpl();
}
/** {@inheritDoc} */
@Override
public FacetedQueryResult> facetList(final DtList dtList, final FacetedQuery facetedQuery) {
Assertion.checkNotNull(dtList);
Assertion.checkNotNull(facetedQuery);
//-----
//1- on applique les filtres
final DtList filteredDtList = filter(dtList, facetedQuery);
//2- on facette
final List facets = facetFactory.createFacets(facetedQuery.getDefinition(), filteredDtList);
//TODO 2b- cluster vide
final Map> resultCluster = Collections.emptyMap();
//TODO 2c- mise en valeur vide
final Map> highlights = Collections.emptyMap();
//3- on construit le résultat
return new FacetedQueryResult<>(Option.some(facetedQuery), filteredDtList.size(), filteredDtList, facets, resultCluster, highlights, dtList);
}
//=========================================================================
//=======================Filtrage==========================================
//=========================================================================
private DtList filter(final DtList dtList, final FacetedQuery facetedQuery) {
final List listFilters = facetedQuery.getListFilters();
DtListProcessor dtListProcessor = createDtListProcessor();
for (final ListFilter listFilter : listFilters) {
dtListProcessor = dtListProcessor.filter(listFilter);
}
return dtListProcessor.apply(dtList);
}
/** {@inheritDoc} */
@Override
public DtListProcessor createDtListProcessor() {
return listProcessor;
}
/** {@inheritDoc} */
@Override
public IndexDtListFunctionBuilder createIndexDtListFunctionBuilder() {
Assertion.checkNotNull(indexPlugin.isDefined(), "An IndexPlugin is required to use this function");
//-----
return new IndexDtListFunctionBuilderImpl<>(indexPlugin.get());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy