open search record id generated with sha-256 function

master
Enrico Ottonello 2 years ago
parent 8b2b703c6f
commit 0d0ca09983

@ -4,6 +4,8 @@ import eu.dnetlib.ariadneplus.elasticsearch.model.AriadnePlusEntry;
import eu.dnetlib.ariadneplus.elasticsearch.model.AriadneResource;
import eu.dnetlib.ariadneplus.elasticsearch.model.Spatial;
import eu.dnetlib.ariadneplus.reader.ResourceManager;
import eu.dnetlib.ariadneplus.reader.utils.ESUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -28,7 +30,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -188,12 +193,13 @@ public class BulkUpload {
ace.getSpatial().clear();
ace.setSpatial(dedupSpatials);
}
String[] splits = ace.getIdentifier().split("/");
log.debug("JSON >>>> "+ace.toJson());
String idES = splits[splits.length-1];
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] encodedhash = digest.digest(
ace.getIdentifier().getBytes(StandardCharsets.UTF_8));
String idES = ESUtils.bytesToHex(encodedhash);
log.debug("indexing " + ace.getIdentifier() + " > " + idES);
request.add(new IndexRequest(elasticSearchIndexName).id(idES)
.source(ace.toJson(),XContentType.JSON));
long start = System.currentTimeMillis();

@ -61,4 +61,16 @@ public class ESUtils {
ZonedDateTime zd = ZonedDateTime.parse(BSTDate, BST_FORMATTER);
return zd.format(elasticSearchDateFormatter);
}
public static String bytesToHex(byte[] hash) {
StringBuilder hexString = new StringBuilder(2 * hash.length);
for (int i = 0; i < hash.length; i++) {
String hex = Integer.toHexString(0xff & hash[i]);
if(hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}

Loading…
Cancel
Save