AriadnePlus/dnet-ariadneplus-graphdb-pu.../src/main/java/eu/dnetlib/ariadneplus/reader/json/ParseRDFJSON.java

98 lines
2.5 KiB
Java
Raw Normal View History

package eu.dnetlib.ariadneplus.reader.json;
import java.util.Iterator;
import java.util.LinkedHashMap;
2020-06-16 02:36:16 +02:00
import eu.dnetlib.ariadneplus.reader.RunSPARQLQueryService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
@Service
public class ParseRDFJSON {
2020-06-16 02:36:16 +02:00
private static final Log log = LogFactory.getLog(ParseRDFJSON.class);
static JSONObject map ;
@Value("${catalog.entry.path}")
2020-06-10 19:39:53 +02:00
private String catalogEntryJsonPath;
2020-06-16 02:36:16 +02:00
@Value("${catalog.entry.collection.path}")
private String catalogEntryCollectionJsonPath;
private boolean isCollection = false;
private String json;
private Iterator<Object> it ;
public String getJson() {
return json;
}
public void setJson(String json) throws ParseException {
this.json = json;
}
private void fillMap() throws ParseException {
map = (JSONObject)(new JSONParser(JSONParser.MODE_PERMISSIVE).parse(json));
}
public void parse(String json) throws ParseException {
setJson(json);
fillMap();
DocumentContext jsonContext = JsonPath.parse(json);
2020-06-10 19:39:53 +02:00
JSONArray entries = jsonContext.read(getCatalogEntryJsonPath());
int size = entries.size();
it = entries.iterator();
}
public boolean hasNextElement(){
return it.hasNext();
}
public LinkedHashMap getNextElement(){
return (LinkedHashMap)it.next();
}
public static JSONObject get(String key){
return (JSONObject) map.get(key);
}
2020-06-10 19:39:53 +02:00
public String getCatalogEntryJsonPath() {
2020-06-16 02:36:16 +02:00
if (isCollection) {
return catalogEntryCollectionJsonPath;
}
2020-06-10 19:39:53 +02:00
return catalogEntryJsonPath;
}
2020-06-10 19:39:53 +02:00
public void setCatalogEntryJsonPath(String catalogEntryJsonPath) {
this.catalogEntryJsonPath = catalogEntryJsonPath;
}
2020-06-16 02:36:16 +02:00
public void setCatalogEntryCollectionJsonPath(String catalogEntryCollectionJsonPath) {
this.catalogEntryCollectionJsonPath = catalogEntryCollectionJsonPath;
}
2020-06-16 02:36:16 +02:00
public boolean isCollection() {
return isCollection;
}
public void setCollection(boolean collection) {
isCollection = collection;
}
}