This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/1.22 by this push:
     new 8f5d7b4012 OAK-6769: Convert oak-search-mt to OSGi R7 annotations
8f5d7b4012 is described below

commit 8f5d7b40129bbe214d971ed19d93aac5231e01d9
Author: mbaedke <manfred.bae...@gmail.com>
AuthorDate: Wed Mar 6 13:54:58 2024 +0100

    OAK-6769: Convert oak-search-mt to OSGi R7 annotations
---
 oak-search-mt/pom.xml                              |  4 +-
 .../mt/MTFulltextQueryTermsProviderFactory.java    | 71 ++++++++++++++--------
 2 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/oak-search-mt/pom.xml b/oak-search-mt/pom.xml
index 77238c4c9b..063d74a74d 100644
--- a/oak-search-mt/pom.xml
+++ b/oak-search-mt/pom.xml
@@ -99,8 +99,8 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
             <scope>provided</scope>
         </dependency>
 
diff --git 
a/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java
 
b/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java
index 7107b8e8f5..d2cc5313d6 100644
--- 
a/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java
+++ 
b/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java
@@ -22,14 +22,15 @@ import java.io.File;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.AttributeType;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.apache.jackrabbit.oak.commons.PropertiesUtil;
 import 
org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -45,36 +46,52 @@ import org.slf4j.LoggerFactory;
  * Factory for {@link MTFulltextQueryTermsProvider}
  */
 @Component(
-        name = 
"org.apache.jackrabbit.oak.plugins.index.mt.MTFulltextQueryTermsProviderFactory",
-        label = "Apache Jackrabbit Oak Machine Translation Fulltext Query 
Terms Provider",
-        configurationFactory = true,
-        metatype = true,
-        policy = ConfigurationPolicy.REQUIRE
+        service = { FulltextQueryTermsProvider.class },
+        configurationPolicy = ConfigurationPolicy.REQUIRE
 )
-@Service(FulltextQueryTermsProvider.class)
+@Designate(
+        ocd = MTFulltextQueryTermsProviderFactory.Configuration.class,
+        factory = true )
 public class MTFulltextQueryTermsProviderFactory implements 
FulltextQueryTermsProvider {
 
-    private static final float DEFAULT_MIN_SCORE = 0.5f;
+    @ObjectClassDefinition(
+            id = 
"org.apache.jackrabbit.oak.plugins.index.mt.MTFulltextQueryTermsProviderFactory",
+            name = "Apache Jackrabbit Oak Machine Translation Fulltext Query 
Terms Provider"
+    )
+    @interface Configuration {
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
+        @AttributeDefinition(
+                name = "Joshua Config Path",
+                description = "The absolute filesystem path to Apache Joshua 
configuration file"
+        )
+        String path_to_config();
+
+        @AttributeDefinition(
+                name = "Node types",
+                description = "List of node types for which expanding the 
query via MT",
+                cardinality = 10
+        )
+        String[] node_types();
 
-    @Property(label = "Joshua Config Path", description = "The absolute 
filesystem path to Apache Joshua configuration file")
-    private static final String CONFIG_PATH = "path.to.config";
+        @AttributeDefinition(
+                name = "Minimum score",
+                description = "Minimum allowed score for a translated 
phrase/term to be used for expansion",
+                type = AttributeType.FLOAT
+        )
+        float min_score() default DEFAULT_MIN_SCORE;
+    }
 
-    @Property(label = "Node types", description = "List of node types for 
which expanding the query via MT", cardinality = 10)
-    private static final String NODE_TYPES = "node.types";
+    private static final float DEFAULT_MIN_SCORE = 0.5f;
 
-    @Property(label = "Minimum score", description = "Minimum allowed score 
for a translated phrase/term to be used for expansion",
-            floatValue = DEFAULT_MIN_SCORE)
-    private static final String MIN_SCORE = "min.score";
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
     private MTFulltextQueryTermsProvider queryTermsProvider;
 
     @Activate
-    public void activate(Map<String, ?> config) throws Exception {
-        String pathToJoshuaConfig = 
PropertiesUtil.toString(config.get(CONFIG_PATH), ".");
-        String[] nts = PropertiesUtil.toStringArray(config.get(NODE_TYPES), 
new String[]{"Oak:unstructured"});
-        float minScore = (float) 
PropertiesUtil.toDouble(config.get(MIN_SCORE), DEFAULT_MIN_SCORE);
+    public void activate(Configuration config) {
+        String pathToJoshuaConfig = 
PropertiesUtil.toString(config.path_to_config(), ".");
+        String[] nts = PropertiesUtil.toStringArray(config.node_types(), new 
String[]{"Oak:unstructured"});
+        float minScore = (float) PropertiesUtil.toDouble(config.min_score(), 
DEFAULT_MIN_SCORE);
         log.info("activating MT FulltextQueryTermProvider from Joshua config 
at {} on {} nodetypes, minScore {}", pathToJoshuaConfig, nts, minScore);
         Decoder decoder = null;
         try {
@@ -97,7 +114,7 @@ public class MTFulltextQueryTermsProviderFactory implements 
FulltextQueryTermsPr
     }
 
     @Deactivate
-    public void deactivate() throws Exception {
+    public void deactivate() {
         if (queryTermsProvider != null) {
             log.debug("clearing resources");
             queryTermsProvider.clearResources();

Reply via email to