fix date parsing on es record creation

This commit is contained in:
Enrico Ottonello 2020-10-13 00:31:17 +02:00
parent 8f3722da13
commit 263c1beb7e
6 changed files with 21 additions and 4 deletions

View File

@ -57,6 +57,7 @@ public class BulkUpload {
try { try {
Object next = manager.next(); Object next = manager.next();
AriadneCatalogEntry ace = ((AriadneCatalogEntry) next); AriadneCatalogEntry ace = ((AriadneCatalogEntry) next);
// log.warn("ready to index: "+ace.toJson());
if (isCollection) { if (isCollection) {
ace.setResourceType("collection"); ace.setResourceType("collection");
if (ace.getSpatial()==null) { if (ace.getSpatial()==null) {
@ -138,6 +139,7 @@ public class BulkUpload {
esResponseCode = -3; esResponseCode = -3;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
log.error("Indexing "+e.getMessage()); log.error("Indexing "+e.getMessage());
return -1; return -1;
} }

View File

@ -32,6 +32,7 @@ public class AriadneCatalogEntry {
private String originalId; private String originalId;
private List<AgentInfo> owner; private List<AgentInfo> owner;
private String resourceType; private String resourceType;
private String rdfType;
private List<AgentInfo> scientificResponsible; private List<AgentInfo> scientificResponsible;
private List<Spatial> spatial; private List<Spatial> spatial;
// private List<SpatialRegion> spatialRegion; // private List<SpatialRegion> spatialRegion;
@ -381,4 +382,12 @@ public class AriadneCatalogEntry {
public void setAudience(String audience) { public void setAudience(String audience) {
this.audience = audience; this.audience = audience;
} }
public String getRdfType() {
return rdfType;
}
public void setRdfType(String rdfType) {
this.rdfType = rdfType;
}
} }

View File

@ -91,6 +91,7 @@ public class ResourceManager {
if (class_name.equals("Record") || class_name.equals("Collection")) { if (class_name.equals("Record") || class_name.equals("Collection")) {
class_name = "AriadneCatalogEntry"; class_name = "AriadneCatalogEntry";
} }
} }
} }
if (entry == null) { if (entry == null) {

View File

@ -153,6 +153,7 @@ public class RunSPARQLQueryService {
Rio.write(resultsModel, rdfRecordWriter); Rio.write(resultsModel, rdfRecordWriter);
parser.setCollection(isCollection); parser.setCollection(isCollection);
String bufferedRecord = recordWriter.toString(); String bufferedRecord = recordWriter.toString();
// log.debug(bufferedRecord);
int size = parser.parse(bufferedRecord); int size = parser.parse(bufferedRecord);
log.debug("json elements: "+size); log.debug("json elements: "+size);
if (size==-1) { if (size==-1) {

View File

@ -14,7 +14,7 @@ public class ESUtils {
.parseDefaulting(ChronoField.DAY_OF_MONTH, 1) .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
.toFormatter(); .toFormatter();
public static String getESFormatDate(String originalDate) { public static String getESFormatDate(String originalDate) {
try{ try{
LocalDate parsedDate = LocalDate.parse(originalDate, elasticSearchDateFormatter); LocalDate parsedDate = LocalDate.parse(originalDate, elasticSearchDateFormatter);
return parsedDate.format(elasticSearchDateFormatter); return parsedDate.format(elasticSearchDateFormatter);
@ -23,8 +23,12 @@ public class ESUtils {
LocalDate parsedDate = LocalDate.parse(originalDate, originalRecordDateFormatter); LocalDate parsedDate = LocalDate.parse(originalDate, originalRecordDateFormatter);
return parsedDate.format(elasticSearchDateFormatter); return parsedDate.format(elasticSearchDateFormatter);
} catch (Exception e1) { } catch (Exception e1) {
LocalDate parsedDate = LocalDate.parse(originalDate, yearOnlyDateFormatter); try {
return parsedDate.format(yearOnlyDateFormatter); LocalDate parsedDate = LocalDate.parse(originalDate.substring(0, 10), elasticSearchDateFormatter);
return parsedDate.format(elasticSearchDateFormatter);
} catch (Exception e2) {
return "0000";
}
} }
} }

View File

@ -56,7 +56,7 @@ public class GraphDbReaderAndESIndexTest {
runSPQRLQuery.setBulkUpload(bulkUpload); runSPQRLQuery.setBulkUpload(bulkUpload);
String recordId; String recordId;
final ClassPathResource queryTemplateResource; final ClassPathResource queryTemplateResource;
boolean testRecord = false; boolean testRecord = true;
if (testRecord) { if (testRecord) {
recordId = "https://ariadne-infrastructure.eu/aocat/Resource/3037F979-F94F-380B-A6A6-3972ED10E61C"; recordId = "https://ariadne-infrastructure.eu/aocat/Resource/3037F979-F94F-380B-A6A6-3972ED10E61C";
queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql"); queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql");