Commit fccb5c7f authored by Jeroen Hoffman's avatar Jeroen Hoffman

CMS-10098 add a Reconfigurable daemon module that registers the SearchServiceFactory

parent 8b6473b5
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2013-2015 Hippo B.V. (http://www.onehippo.com)
Copyright 2013-2016 Hippo B.V. (http://www.onehippo.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -49,6 +49,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-services</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
......
/*
* Copyright 2016 Hippo B.V. (http://www.onehippo.com)
*/
package org.onehippo.cms7.services.search.jcr.service;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.onehippo.cms7.services.HippoServiceRegistry;
import org.onehippo.cms7.services.search.service.QueryPersistService;
import org.onehippo.cms7.services.search.service.SearchService;
import org.onehippo.cms7.services.search.service.SearchServiceException;
import org.onehippo.cms7.services.search.service.SearchServiceFactory;
import org.onehippo.repository.modules.AbstractReconfigurableDaemonModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Reconfigurable daemon module that registers the SearchServiceFactory.
*/
public class SearchServiceModule extends AbstractReconfigurableDaemonModule {
private static final Logger log = LoggerFactory.getLogger(SearchServiceModule.class);
private SearchServiceFactory searchServiceFactory;
private boolean wildcardPostfixEnabled;
private int wildcardPostfixMinLength;
@Override
protected void doInitialize(final Session session) throws RepositoryException {
log.info("Initializing search service module");
}
private void register() {
log.debug("Registering search service factory");
searchServiceFactory = new SearchServiceFactory() {
@Override
public SearchService createSearchService(final Object clientObject) throws SearchServiceException {
if (!(clientObject instanceof Session)) {
throw new SearchServiceException("Search service argument must be of type javax.jcr.Session");
}
return new HippoJcrSearchService((Session) clientObject, wildcardPostfixEnabled, wildcardPostfixMinLength);
}
@Override
public QueryPersistService createQueryPersistService(final Object clientObject) throws SearchServiceException {
if (!(clientObject instanceof Session)) {
throw new SearchServiceException("Search service argument must be of type javax.jcr.Session");
}
return new HippoJcrSearchService((Session) clientObject, wildcardPostfixEnabled, wildcardPostfixMinLength);
}
};
HippoServiceRegistry.registerService(searchServiceFactory, SearchServiceFactory.class, SearchServiceFactory.class.getName());
}
@Override
protected void doShutdown() {
unregister();
}
@Override
protected void doConfigure(final Node node) throws RepositoryException {
unregister();
this.wildcardPostfixEnabled = getBoolean(node, "wildcard.postfix.enabled", HippoJcrSearchService.DEFAULT_WILDCARD_POSTFIX_ENABLED);
this.wildcardPostfixMinLength = getInteger(node, "wildcard.postfix.minlength", HippoJcrSearchService.DEFAULT_WILDCARD_POSTFIX_MINLENGTH);
log.info("SearchServiceModule configured at wildcardPostfixEnabled={} and wildcardPostfixMinLength={}",
this.wildcardPostfixEnabled, this.wildcardPostfixMinLength);
register();
}
private void unregister() {
log.debug("Unregistering search service factory {}", searchServiceFactory);
if (searchServiceFactory != null) {
HippoServiceRegistry.unregisterService(searchServiceFactory, SearchServiceFactory.class, SearchServiceFactory.class.getName());
}
}
private int getInteger(final Node config, final String property, final int defaultValue) throws RepositoryException {
if (config.hasProperty(property)) {
return (int)config.getProperty(property).getLong();
}
return defaultValue;
}
private boolean getBoolean(final Node config, final String property, final boolean defaultValue) throws RepositoryException {
if (config.hasProperty(property)) {
return config.getProperty(property).getBoolean();
}
return defaultValue;
}
}
......@@ -25,4 +25,19 @@
</sv:property>
</sv:node>
<sv:node sv:name="hippo-configuration-hippo-modules-search-service">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>1009</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>search-service.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/hippo:configuration/hippo:modules</sv:value>
</sv:property>
</sv:node>
</sv:node>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 Hippo B.V. (http://www.onehippo.com)
-->
<sv:node sv:name="search-service" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hipposys:module</sv:value>
</sv:property>
<sv:property sv:name="hipposys:className" sv:type="String">
<sv:value>org.onehippo.cms7.services.search.jcr.service.SearchServiceModule</sv:value>
</sv:property>
<sv:property sv:name="hipposys:cmsonly" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:node sv:name="hippo:moduleconfig">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hipposys:moduleconfig</sv:value>
</sv:property>
<sv:property sv:name="wildcard.postfix.enabled" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:property sv:name="wildcard.postfix.minlength" sv:type="Long">
<sv:value>3</sv:value>
</sv:property>
</sv:node>
</sv:node>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012-2015 Hippo B.V. (http://www.onehippo.com)
Copyright 2012-2016 Hippo B.V. (http://www.onehippo.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -55,6 +55,7 @@
<cglib.version>2.2.2</cglib.version>
<hippo.repository.version>4.1.0-SNAPSHOT</hippo.repository.version>
<hippo.services.version>3.1.0-SNAPSHOT</hippo.services.version>
<hippo.utilities.version>3.1.0-SNAPSHOT</hippo.utilities.version>
<maven.plugin.site.version>3.0-beta-3</maven.plugin.site.version>
......@@ -102,6 +103,13 @@
<version>${hippo.utilities.version}</version>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-services</artifactId>
<version>${hippo.services.version}</version>
<scope>provided</scope>
</dependency>
<!-- Apache Commons -->
<dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment