mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
SEARCH-56: Altering CoreDescriptorDecorator to allow for limited property substitution
This commit is contained in:
+1
-1
@@ -1851,7 +1851,7 @@ public class AlfrescoSolrDataModel implements QueryConstants
|
||||
parser.setSearchParameters(searchParameters);
|
||||
parser.setAllowLeadingWildcard(true);
|
||||
|
||||
Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getCoreProperties();
|
||||
Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties();
|
||||
int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000"));
|
||||
parser.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit);
|
||||
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ public class EnsureModelsComponent extends SearchComponent
|
||||
public void prepare(ResponseBuilder rb) throws IOException
|
||||
{
|
||||
SolrQueryRequest req = rb.req;
|
||||
Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getCoreProperties();
|
||||
Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties();
|
||||
|
||||
boolean isTrackingEnabled = Boolean.parseBoolean(props.getProperty("enable.alfresco.tracking", "false"));
|
||||
|
||||
@@ -90,7 +90,7 @@ public class EnsureModelsComponent extends SearchComponent
|
||||
SolrResourceLoader loader = core.getLatestSchema().getResourceLoader();
|
||||
SolrKeyResourceLoader keyResourceLoader = new SolrKeyResourceLoader(loader);
|
||||
SOLRAPIClientFactory clientFactory = new SOLRAPIClientFactory();
|
||||
Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getCoreProperties();
|
||||
Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getProperties();
|
||||
SOLRAPIClient repositoryClient = clientFactory.getSOLRAPIClient(props, keyResourceLoader,
|
||||
AlfrescoSolrDataModel.getInstance().getDictionaryService(CMISStrictDictionaryService.DEFAULT),
|
||||
AlfrescoSolrDataModel.getInstance().getNamespaceDAO());
|
||||
|
||||
+3
-1
@@ -36,6 +36,8 @@ public class ConfigUtil {
|
||||
protected final static Logger log = LoggerFactory.getLogger(ConfigUtil.class);
|
||||
|
||||
private static final String JNDI_PREFIX = "java:comp/env/";
|
||||
private static final String ENV_PREFIX = "SOLR_";
|
||||
|
||||
/**
|
||||
* Finds the property based on looking up the value in one of three places (in order of preference):
|
||||
* <ol>
|
||||
@@ -107,6 +109,6 @@ public class ConfigUtil {
|
||||
protected static String convertPropertyNameToEnvironmentParam(String propertyName)
|
||||
{
|
||||
if (propertyName == null) propertyName = "";
|
||||
return propertyName.replace('.','_').toUpperCase();
|
||||
return ENV_PREFIX+propertyName.replace('.','_').toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class Lucene4QueryBuilderContextSolrImpl implements LuceneQueryBuilderCon
|
||||
// lqp.setAllowLeadingWildcard(true);
|
||||
// this.namespacePrefixResolver = namespacePrefixResolver;
|
||||
|
||||
Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getCoreProperties();
|
||||
Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties();
|
||||
int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000"));
|
||||
lqp.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit);
|
||||
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ public class CoreWatcherJob implements Job
|
||||
private void registerForCore(AlfrescoCoreAdminHandler adminHandler, CoreContainer coreContainer, SolrCore core,
|
||||
String coreName, TrackerRegistry trackerRegistry) throws JobExecutionException
|
||||
{
|
||||
Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getCoreProperties();
|
||||
Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getProperties();
|
||||
boolean testcase = Boolean.parseBoolean(System.getProperty("alfresco.test", "false"));
|
||||
if (Boolean.parseBoolean(props.getProperty("enable.alfresco.tracking", "false")))
|
||||
{
|
||||
|
||||
+22
-5
@@ -18,22 +18,39 @@
|
||||
*/
|
||||
package org.apache.solr.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.alfresco.solr.config.ConfigUtil;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* This class was created solely for the purpose of exposing the coreProperties of the CoreDescriptor
|
||||
* This class was created solely for the purpose of exposing the coreProperties of the CoreDescriptor.
|
||||
* It is now possible to substitute a sub-set of properties using the rules specified here @see ConfigUtil#locateProperty()
|
||||
*
|
||||
* The Substitutable Properties are defined in the substitutableProperties list.
|
||||
* @author Ahmed Owian
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class CoreDescriptorDecorator {
|
||||
private CoreDescriptor descriptor;
|
||||
private final Properties properties = new Properties();
|
||||
|
||||
public static ImmutableList<String> substitutableProperties = ImmutableList.of(
|
||||
"alfresco.host",
|
||||
"alfresco.port",
|
||||
"alfresco.baseUrl",
|
||||
"alfresco.port.ssl"
|
||||
);
|
||||
|
||||
public CoreDescriptorDecorator(CoreDescriptor descriptor)
|
||||
{
|
||||
this.descriptor = descriptor;
|
||||
properties.putAll(descriptor.coreProperties);
|
||||
substitutableProperties.forEach(prop ->
|
||||
properties.put(prop, ConfigUtil.locateProperty(prop,properties.getProperty(prop)))
|
||||
);
|
||||
}
|
||||
|
||||
public Properties getCoreProperties()
|
||||
public Properties getProperties()
|
||||
{
|
||||
return this.descriptor.coreProperties;
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,10 +1,7 @@
|
||||
#
|
||||
# solrcore.properties - used in solrconfig.xml
|
||||
#
|
||||
# data is in ${data.dir.root}/${data.dir.store}
|
||||
|
||||
data.dir.root=@@ALFRESCO_SOLR4_DATA_DIR@@
|
||||
data.dir.store=workspace/SpacesStore
|
||||
enable.alfresco.tracking=true
|
||||
|
||||
#
|
||||
@@ -12,6 +9,12 @@ enable.alfresco.tracking=true
|
||||
#
|
||||
alfresco.version=5.1
|
||||
|
||||
#
|
||||
#These are replaced by the admin handler
|
||||
#
|
||||
#data.dir.root=DATA_DIR
|
||||
#data.dir.store=workspace/SpacesStore
|
||||
#alfresco.stores=workspace://SpacesStore
|
||||
|
||||
#
|
||||
# Properties loaded during alfresco tracking
|
||||
@@ -22,7 +25,7 @@ alfresco.port=8080
|
||||
alfresco.port.ssl=8443
|
||||
alfresco.baseUrl=/alfresco
|
||||
alfresco.cron=0/15 * * * * ? *
|
||||
alfresco.stores=workspace://SpacesStore
|
||||
|
||||
#alfresco.index.transformContent=false
|
||||
#alfresco.ignore.datatype.1=d:content
|
||||
alfresco.lag=1000
|
||||
|
||||
+6
-5
@@ -1,17 +1,18 @@
|
||||
#
|
||||
# solrcore.properties - used in solrconfig.xml
|
||||
#
|
||||
# data is in ${data.dir.root}/${data.dir.store}
|
||||
|
||||
data.dir.root=@@ALFRESCO_SOLR4_DATA_DIR@@
|
||||
data.dir.store=workspace/SpacesStore
|
||||
enable.alfresco.tracking=true
|
||||
#
|
||||
|
||||
#
|
||||
# Alfresco version
|
||||
#
|
||||
alfresco.version=5.1
|
||||
|
||||
#These are replaced by the admin handler
|
||||
#
|
||||
#data.dir.root=DATA_DIR
|
||||
#data.dir.store=workspace/SpacesStore
|
||||
#alfresco.stores=workspace://SpacesStore
|
||||
|
||||
#
|
||||
# Properties loaded during alfresco tracking
|
||||
|
||||
+4
-7
@@ -43,9 +43,6 @@ public class ConfigUtilTest {
|
||||
System.setProperty("find.me", "iamfoundagain");
|
||||
assertEquals("iamfoundagain", ConfigUtil.locateProperty("find.me", "king"));
|
||||
System.clearProperty("find.me");
|
||||
|
||||
//Assumes there is always a PATH environment variable
|
||||
assertNotEquals("king", ConfigUtil.locateProperty("PATH", "king"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,10 +56,10 @@ public class ConfigUtilTest {
|
||||
|
||||
@Test
|
||||
public void convertPropertyNameToEnvironmentParam() throws Exception {
|
||||
assertEquals("GETHIN",ConfigUtil.convertPropertyNameToEnvironmentParam("gethin"));
|
||||
assertEquals("SOLR_CONTENT_DIR",ConfigUtil.convertPropertyNameToEnvironmentParam("solr.content.dir"));
|
||||
assertEquals("SOLR_MODEL_DIR",ConfigUtil.convertPropertyNameToEnvironmentParam("solr.model.dir"));
|
||||
assertEquals("SOLR_HOST",ConfigUtil.convertPropertyNameToEnvironmentParam("solr.host"));
|
||||
assertEquals("SOLR_GETHIN",ConfigUtil.convertPropertyNameToEnvironmentParam("gethin"));
|
||||
assertEquals("SOLR_SOLR_CONTENT_DIR",ConfigUtil.convertPropertyNameToEnvironmentParam("solr.content.dir"));
|
||||
assertEquals("SOLR_SOLR_MODEL_DIR",ConfigUtil.convertPropertyNameToEnvironmentParam("solr.model.dir"));
|
||||
assertEquals("SOLR_SOLR_HOST",ConfigUtil.convertPropertyNameToEnvironmentParam("solr.host"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user