Convert TPF from Gson to Jackson
This commit is contained in:
parent
93884142b4
commit
69c4f5460c
7 changed files with 52 additions and 35 deletions
|
@ -1,12 +1,14 @@
|
|||
package org.linkeddatafragments.config;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.linkeddatafragments.datasource.IDataSourceType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -18,7 +20,7 @@ import java.util.Map.Entry;
|
|||
*/
|
||||
public class ConfigReader {
|
||||
private final Map<String, IDataSourceType> dataSourceTypes = new HashMap<>();
|
||||
private final Map<String, JsonObject> dataSources = new HashMap<>();
|
||||
private final Map<String, JsonNode> dataSources = new HashMap<>();
|
||||
private final Map<String, String> prefixes = new HashMap<>();
|
||||
private final String baseURL;
|
||||
|
||||
|
@ -28,19 +30,34 @@ public class ConfigReader {
|
|||
* @param configReader the configuration
|
||||
*/
|
||||
public ConfigReader(Reader configReader) {
|
||||
JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
|
||||
this.baseURL = root.has("baseURL") ? root.getAsJsonPrimitive("baseURL").getAsString() : null;
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root = null;
|
||||
try {
|
||||
root = mapper.readTree(configReader);
|
||||
this.baseURL = root.has("baseURL") ? root.get("baseURL").asText() : null;
|
||||
|
||||
for (Entry<String, JsonElement> entry : root.getAsJsonObject("datasourcetypes").entrySet()) {
|
||||
final String className = entry.getValue().getAsString();
|
||||
Iterator<Entry<String, JsonNode>> iterator;
|
||||
|
||||
iterator = root.get("datasourcetypes").fields();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<String, JsonNode> entry = iterator.next();
|
||||
final String className = entry.getValue().asText();
|
||||
dataSourceTypes.put(entry.getKey(), initDataSouceType(className) );
|
||||
}
|
||||
for (Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
|
||||
JsonObject dataSource = entry.getValue().getAsJsonObject();
|
||||
this.dataSources.put(entry.getKey(), dataSource);
|
||||
|
||||
iterator = root.get("datasources").fields();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<String, JsonNode> entry = iterator.next();
|
||||
this.dataSources.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet()) {
|
||||
this.prefixes.put(entry.getKey(), entry.getValue().getAsString());
|
||||
|
||||
iterator = root.get("prefixes").fields();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<String, JsonNode> entry = iterator.next();
|
||||
this.prefixes.put(entry.getKey(), entry.getValue().asText());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +75,7 @@ public class ConfigReader {
|
|||
*
|
||||
* @return the data sources
|
||||
*/
|
||||
public Map<String, JsonObject> getDataSources() {
|
||||
public Map<String, JsonNode> getDataSources() {
|
||||
return dataSources;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.linkeddatafragments.datasource;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.linkeddatafragments.exceptions.DataSourceCreationException;
|
||||
import org.linkeddatafragments.exceptions.UnknownDataSourceTypeException;
|
||||
|
||||
|
@ -18,12 +18,12 @@ public class DataSourceFactory {
|
|||
* @return datasource interface
|
||||
* @throws DataSourceCreationException
|
||||
*/
|
||||
public static IDataSource create(JsonObject config) throws DataSourceCreationException {
|
||||
String title = config.getAsJsonPrimitive("title").getAsString();
|
||||
String description = config.getAsJsonPrimitive("description").getAsString();
|
||||
String typeName = config.getAsJsonPrimitive("type").getAsString();
|
||||
public static IDataSource create(JsonNode config) throws DataSourceCreationException {
|
||||
String title = config.get("title").asText();
|
||||
String description = config.get("description").asText();
|
||||
String typeName = config.get("type").asText();
|
||||
|
||||
JsonObject settings = config.getAsJsonObject("settings");
|
||||
JsonNode settings = config.get("settings");
|
||||
|
||||
final IDataSourceType type = DataSourceTypesRegistry.getType(typeName);
|
||||
if ( type == null )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.linkeddatafragments.datasource;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.linkeddatafragments.exceptions.DataSourceCreationException;
|
||||
|
||||
/**
|
||||
|
@ -28,6 +28,6 @@ public interface IDataSourceType
|
|||
*/
|
||||
IDataSource createDataSource(final String title,
|
||||
final String description,
|
||||
final JsonObject settings)
|
||||
final JsonNode settings)
|
||||
throws DataSourceCreationException;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.linkeddatafragments.datasource.tdb;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.linkeddatafragments.datasource.IDataSource;
|
||||
import org.linkeddatafragments.datasource.IDataSourceType;
|
||||
import org.linkeddatafragments.exceptions.DataSourceCreationException;
|
||||
|
@ -18,10 +18,10 @@ public class JenaTDBDataSourceType implements IDataSourceType
|
|||
@Override
|
||||
public IDataSource createDataSource( final String title,
|
||||
final String description,
|
||||
final JsonObject settings )
|
||||
final JsonNode settings )
|
||||
throws DataSourceCreationException
|
||||
{
|
||||
final String dname = settings.getAsJsonPrimitive("directory").getAsString();
|
||||
final String dname = settings.get("directory").asText();
|
||||
final File dir = new File( dname );
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.linkeddatafragments.servlet;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.apache.jena.riot.Lang;
|
||||
import org.linkeddatafragments.config.ConfigReader;
|
||||
import org.linkeddatafragments.datasource.DataSourceFactory;
|
||||
|
@ -89,7 +89,7 @@ public class LinkedDataFragmentServlet extends HttpServlet {
|
|||
}
|
||||
|
||||
// register data sources
|
||||
for (Entry<String, JsonObject> dataSource : config.getDataSources().entrySet()) {
|
||||
for (Entry<String, JsonNode> dataSource : config.getDataSources().entrySet()) {
|
||||
dataSources.put(dataSource.getKey(), DataSourceFactory.create(dataSource.getValue()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.vivoweb.linkeddatafragments.datasource.rdfservice;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.linkeddatafragments.datasource.IDataSource;
|
||||
import org.linkeddatafragments.datasource.IDataSourceType;
|
||||
import org.linkeddatafragments.exceptions.DataSourceCreationException;
|
||||
|
@ -16,7 +16,7 @@ public class RDFServiceDataSourceType implements IDataSourceType
|
|||
@Override
|
||||
public IDataSource createDataSource( final String title,
|
||||
final String description,
|
||||
final JsonObject settings )
|
||||
final JsonNode settings )
|
||||
throws DataSourceCreationException
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.vivoweb.linkeddatafragments.servlet;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
|
@ -90,7 +90,7 @@ public class VitroLinkedDataFragmentServlet extends VitroHttpServlet {
|
|||
}
|
||||
|
||||
// register data sources
|
||||
for (Entry<String, JsonObject> dataSource : config.getDataSources().entrySet()) {
|
||||
for (Entry<String, JsonNode> dataSource : config.getDataSources().entrySet()) {
|
||||
dataSources.put(dataSource.getKey(), DataSourceFactory.create(dataSource.getValue()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue