001/* 002 * Copyright 2020 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.plugins.workspaces.members.solr; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020import org.quartz.JobExecutionContext; 021 022import org.ametys.cms.content.indexing.solr.SolrIndexer; 023import org.ametys.cms.repository.Content; 024import org.ametys.cms.repository.ContentQueryHelper; 025import org.ametys.cms.repository.ContentTypeExpression; 026import org.ametys.core.schedule.progression.ContainerProgressionTracker; 027import org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable; 028import org.ametys.plugins.repository.AmetysObjectIterable; 029import org.ametys.plugins.repository.AmetysObjectResolver; 030import org.ametys.plugins.repository.query.expression.Expression.Operator; 031import org.ametys.plugins.workspaces.WorkspacesConstants; 032 033/** 034 * Schedulable to re-index all existing members 035 */ 036public class ReindexMembersSchedulable extends AbstractStaticSchedulable 037{ 038 /** The Solr indexer */ 039 protected SolrIndexer _solrIndexer; 040 041 /** The ametys object resolver */ 042 protected AmetysObjectResolver _resolver; 043 044 @Override 045 public void service(ServiceManager manager) throws ServiceException 046 { 047 super.service(manager); 048 _solrIndexer = (SolrIndexer) manager.lookup(SolrIndexer.ROLE); 049 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 050 } 051 052 @Override 053 public void execute(JobExecutionContext context, ContainerProgressionTracker progressionTracker) throws Exception 054 { 055 String xpathQuery = ContentQueryHelper.getContentXPathQuery(new ContentTypeExpression(Operator.EQ, WorkspacesConstants.MEMBER_CONTENT_TYPE_ID)); 056 AmetysObjectIterable<Content> searchResults = _resolver.query(xpathQuery); 057 058 _solrIndexer.indexContents(searchResults, progressionTracker); // This indexes on all workspaces 059 } 060}