You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ba...@apache.org on 2024/03/06 12:44:41 UTC
(jackrabbit-oak) branch issue/oak-6769 updated: OAK-6769: Convert oak-search-mt to OSGi R7 annotations
This is an automated email from the ASF dual-hosted git repository.
baedke pushed a commit to branch issue/oak-6769
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/issue/oak-6769 by this push:
new 83796728a3 OAK-6769: Convert oak-search-mt to OSGi R7 annotations
83796728a3 is described below
commit 83796728a38a2133e28ec1184cb9d4932094b1cf
Author: Manfred Baedke <ma...@gmail.com>
AuthorDate: Wed Mar 6 13:43:37 2024 +0100
OAK-6769: Convert oak-search-mt to OSGi R7 annotations
Done.
---
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 dc3113cb0e..b6d4ace64b 100644
--- a/oak-search-mt/pom.xml
+++ b/oak-search-mt/pom.xml
@@ -84,8 +84,8 @@
<dependencies>
<!-- Optional OSGi dependencies, used only when running within OSGi -->
<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();