2020-06-03 14:39:41 +02:00
|
|
|
package org.gcube.datacatalogue.ckanutillibrary.ckan;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonParseException;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
|
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
2020-08-27 17:25:56 +02:00
|
|
|
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
2020-06-03 16:29:47 +02:00
|
|
|
import eu.trentorise.opendata.jackan.model.CkanResource;
|
2020-06-03 14:39:41 +02:00
|
|
|
|
2020-06-03 16:29:47 +02:00
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
/**
|
|
|
|
* The Class MarshUnmarshCkanObject.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
|
|
|
|
* Jun 3, 2020
|
|
|
|
*/
|
2020-06-03 14:39:41 +02:00
|
|
|
public class MarshUnmarshCkanObject {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To ckan dataset.
|
|
|
|
*
|
|
|
|
* @param jsonDataset the json dataset
|
|
|
|
* @return the ckan dataset
|
2020-06-03 16:29:47 +02:00
|
|
|
* @throws JsonParseException the json parse exception
|
|
|
|
* @throws JsonMappingException the json mapping exception
|
|
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
2020-06-03 14:39:41 +02:00
|
|
|
*/
|
|
|
|
public static CkanDataset toCkanDataset(String jsonDataset) throws JsonParseException, JsonMappingException, IOException {
|
|
|
|
return ExtendCkanClient.getObjectMapper().readValue(jsonDataset, CkanDataset.class);
|
|
|
|
}
|
2020-06-03 16:29:47 +02:00
|
|
|
|
2020-08-27 17:25:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To ckan group.
|
|
|
|
*
|
|
|
|
* @param jsonGroup the json group
|
|
|
|
* @return the ckan group
|
|
|
|
* @throws JsonParseException the json parse exception
|
|
|
|
* @throws JsonMappingException the json mapping exception
|
|
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
|
|
|
*/
|
|
|
|
public static CkanGroup toCkanGroup(String jsonGroup) throws JsonParseException, JsonMappingException, IOException {
|
|
|
|
return ExtendCkanClient.getObjectMapper().readValue(jsonGroup, CkanGroup.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 16:29:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* To ckan resource.
|
|
|
|
*
|
|
|
|
* @param jsonResource the json resource
|
|
|
|
* @return the ckan resource
|
|
|
|
* @throws JsonParseException the json parse exception
|
|
|
|
* @throws JsonMappingException the json mapping exception
|
|
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
|
|
|
*/
|
|
|
|
public static CkanResource toCkanResource(String jsonResource) throws JsonParseException, JsonMappingException, IOException {
|
|
|
|
return ExtendCkanClient.getObjectMapper().readValue(jsonResource, CkanResource.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To json value resource.
|
|
|
|
*
|
|
|
|
* @param resource the resource
|
|
|
|
* @return the string
|
|
|
|
* @throws JsonProcessingException the json processing exception
|
|
|
|
*/
|
|
|
|
public static String toJsonValueResource(CkanResource resource) throws JsonProcessingException{
|
|
|
|
return ExtendCkanClient.getObjectMapper().writeValueAsString(resource);
|
|
|
|
}
|
2020-06-03 14:39:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To json value dataset.
|
|
|
|
*
|
|
|
|
* @param dataset the dataset
|
|
|
|
* @return the string
|
2020-06-03 16:29:47 +02:00
|
|
|
* @throws JsonProcessingException the json processing exception
|
2020-06-03 14:39:41 +02:00
|
|
|
*/
|
|
|
|
public static String toJsonValueDataset(CkanDataset dataset) throws JsonProcessingException {
|
|
|
|
return ExtendCkanClient.getObjectMapper().writeValueAsString(dataset);
|
|
|
|
}
|
2020-08-27 17:25:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To json value group.
|
|
|
|
*
|
|
|
|
* @param group the group
|
|
|
|
* @return the string
|
|
|
|
* @throws JsonProcessingException the json processing exception
|
|
|
|
*/
|
|
|
|
public static String toJsonValueGroup(CkanGroup group) throws JsonProcessingException {
|
|
|
|
return ExtendCkanClient.getObjectMapper().writeValueAsString(group);
|
|
|
|
}
|
2020-06-03 14:39:41 +02:00
|
|
|
|
|
|
|
}
|