fix date/time regex hashes
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.inteligr8.alfresco.asie.service;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -9,6 +12,7 @@ import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.codec.digest.MurmurHash3;
|
||||
import org.joda.time.ReadablePartial;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -70,7 +74,20 @@ public class SolrShardHashService {
|
||||
}
|
||||
|
||||
this.logger.trace("Discovered node property for sharding: {} => {}", nodeRef, fullPropertyValue);
|
||||
String hashableValue = fullPropertyValue.toString();
|
||||
|
||||
String hashableValue = null;
|
||||
if (fullPropertyValue instanceof TemporalAccessor) {
|
||||
Instant instant = Instant.from((TemporalAccessor) fullPropertyValue);
|
||||
hashableValue = instant.toString();
|
||||
} else if (fullPropertyValue instanceof ReadablePartial) {
|
||||
hashableValue = ((ReadablePartial) fullPropertyValue).toString();
|
||||
} else if (fullPropertyValue instanceof Date) {
|
||||
Instant instant = ((Date) fullPropertyValue).toInstant();
|
||||
hashableValue = instant.toString();
|
||||
} else {
|
||||
hashableValue = fullPropertyValue.toString();
|
||||
}
|
||||
|
||||
if (shardset.getRegex() != null) {
|
||||
Matcher matcher = shardset.getRegex().matcher(hashableValue);
|
||||
if (!matcher.find()) {
|
||||
@@ -84,6 +101,7 @@ public class SolrShardHashService {
|
||||
int shardHash = this.hash(hashableValue, shardset.getShards().intValue());
|
||||
this.logger.debug("Hash shardable value to shard instance ID: {}: {} => {}", nodeRef, hashableValue, shardHash);
|
||||
return shardHash;
|
||||
// TODO replicate hash algorithm for other shard methods
|
||||
default:
|
||||
this.logger.trace("Unable to determine shard instance ID due to shard method: {}", shardset.getMethod());
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user