catalogue-util-library/src/main/java/org/gcube/datacatalogue/ckanutillibrary/gcat/GCatCaller.java

70 lines
1.9 KiB
Java

package org.gcube.datacatalogue.ckanutillibrary.gcat;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import org.gcube.datacatalogue.ckanutillibrary.ckan.SimpleExtendCkanClient;
import org.gcube.gcat.client.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import eu.trentorise.opendata.jackan.model.CkanDataset;
import eu.trentorise.opendata.jackan.model.CkanLicense;
// TODO: Auto-generated Javadoc
/**
* The Class GCatCaller.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* May 29, 2020
*/
public class GCatCaller {
private SimpleExtendCkanClient jackanCkanClient;
private String catalogueURL;
private static final Logger LOG = LoggerFactory.getLogger(GCatCaller.class);
/**
* Instantiates a new g cat caller.
*/
public GCatCaller(String catalogueURL) {
this.catalogueURL = catalogueURL;
this.jackanCkanClient = new SimpleExtendCkanClient(catalogueURL);
}
/**
* Gets the dataset for name.
*
* @param datasetIdOrName the dataset id or name
* @return the dataset for name
* @throws JsonParseException the json parse exception
* @throws JsonMappingException the json mapping exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public CkanDataset getDatasetForName(String datasetIdOrName) throws JsonParseException, JsonMappingException, IOException {
LOG.debug("Get dataset for name "+datasetIdOrName+ "called");
String json = new Item().read(datasetIdOrName);
return SimpleExtendCkanClient.getObjectMapper().readValue(json, CkanDataset.class);
}
/**
* TODO gCAT missing
* @return
* @throws MalformedURLException
*/
public List<CkanLicense> getLicenseList() {
LOG.debug("Get linces list called");
return jackanCkanClient.getLicenseList();
}
}