Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension point to preprocess data before indexing #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.indexing.indexer.IndexDocumentCreator;
import org.wso2.carbon.registry.indexing.indexer.IndexerException;
import org.wso2.carbon.registry.indexing.indexer.IndexerPreProcessor;
import org.wso2.carbon.registry.indexing.solr.SolrClient;
import org.wso2.carbon.utils.WaitBeforeShutdownObserver;

Expand Down Expand Up @@ -240,6 +241,12 @@ private void createIndexDocument(File2Index file2Index) {
Resource resource;
//Check whether resource exists before indexing the resource
if (registry.resourceExists(resourcePath) && (resource = registry.get(resourcePath)) != null) {

// Process resource before index document is created
if (Utils.getIndexerPreprocessor() != null) {
IndexerPreProcessor preprocessor = Utils.getIndexerPreprocessor();
preprocessor.processResource(resource);
}
// Create the IndexDocument
IndexDocumentCreator indexDocumentCreator = new IndexDocumentCreator(file2Index, resource);
indexDocumentCreator.createIndexDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.wso2.carbon.registry.core.config.RegistryConfigurationProcessor;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.registry.indexing.indexer.IndexerPreProcessor;
import org.wso2.carbon.registry.indexing.internal.IndexingServiceComponent;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.WaitBeforeShutdownObserver;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class Utils {
private static String remoteTopicHeaderNS;

private static String remoteSubscriptionStoreContext;

private static IndexerPreProcessor preprocessor;

public static void setRegistryService(RegistryService service) {
registryService = service;
Expand Down Expand Up @@ -180,4 +183,12 @@ public static boolean isIndexingConfigAvailable() throws RegistryException {
}
return false;
}

public static IndexerPreProcessor getIndexerPreprocessor() {
return preprocessor;
}

public static void setIndexerPreprocessor(IndexerPreProcessor preprocessor) {
Utils.preprocessor = preprocessor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024, WSO2 LLc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLc. licenses this file to you 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 org.wso2.carbon.registry.indexing.indexer;


import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.exceptions.RegistryException;

/**
* Interface is provided to manupilate registry resource before it is indexed
*/
public interface IndexerPreProcessor {

public void processResource(Resource resource) throws RegistryException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.wso2.carbon.registry.indexing.IndexingManager;
import org.wso2.carbon.registry.indexing.Utils;
import org.wso2.carbon.registry.indexing.indexer.IndexerException;
import org.wso2.carbon.registry.indexing.indexer.IndexerPreProcessor;
import org.wso2.carbon.registry.indexing.service.*;
import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
Expand Down Expand Up @@ -311,5 +312,20 @@ public void loadTenantIndex(int tenantId) {
public static boolean canIndexTenant(int tenantId) {
return tenantId == MultitenantConstants.SUPER_TENANT_ID || initializedTenants.containsKey(tenantId);
}

@Reference(
name = "registry.indexer.preprocessor",
service = org.wso2.carbon.registry.indexing.indexer.IndexerPreProcessor.class,
cardinality = ReferenceCardinality.OPTIONAL,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetIndexerPreProcessor")
protected void setIndexerPreProcessor(IndexerPreProcessor preprocesor) {
Utils.setIndexerPreprocessor(preprocesor);
}

protected void unsetIndexerPreProcessor(IndexerPreProcessor preprocesor) {
stopIndexing();
Utils.setIndexerPreprocessor(null);
}
}