001/* 002 * Copyright 2017 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.indexing.explorer; 017 018import org.ametys.cms.content.indexing.solr.SolrFieldNames; 019import org.ametys.plugins.explorer.resources.Resource; 020import org.ametys.plugins.explorer.resources.ResourceCollection; 021import org.ametys.plugins.repository.AmetysObject; 022import org.ametys.plugins.repository.RepositoryConstants; 023 024/** 025 * Observer in charge of indexing explorer resources when created, modified, moved... 026 */ 027public class SolrIndexResourceObserver extends AbstractSolrIndexResourceObserver 028{ 029 @Override 030 protected String[] getWorkspacesToIndex() 031 { 032 return new String[] {RepositoryConstants.DEFAULT_WORKSPACE}; 033 } 034 035 @Override 036 protected boolean isHandledResource(AmetysObject object) 037 { 038 return object != null && object.getPath().startsWith("/" + RepositoryConstants.NAMESPACE_PREFIX + ":resources"); 039 } 040 041 @Override 042 protected void onResourceCreated(Resource resource, String workspaceName) throws Exception 043 { 044 _solrIndexer.indexResource(resource, SolrFieldNames.TYPE_RESOURCE, workspaceName); 045 } 046 047 @Override 048 protected void onResourceUpdated(Resource resource, String workspaceName) throws Exception 049 { 050 _solrIndexer.indexResource(resource, SolrFieldNames.TYPE_RESOURCE, workspaceName); 051 } 052 053 @Override 054 protected void onCollectionRenamedOrMoved(ResourceCollection resourceCollection, String workspaceName) throws Exception 055 { 056 _solrIndexer.indexResources(resourceCollection.getChildren(), SolrFieldNames.TYPE_RESOURCE, workspaceName); 057 } 058}