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

136 lines
3.4 KiB
Java

/*
*
*/
package org.gcube.datacatalogue.utillibrary.gcat;
import java.net.MalformedURLException;
import javax.ws.rs.WebApplicationException;
import org.gcube.gcat.client.Group;
import org.gcube.gcat.client.Item;
import org.gcube.gcat.client.Resource;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class GCatCaller.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* May 29, 2020
*/
public class GCatCaller {
private String catalogueURL;
private static final Logger LOG = LoggerFactory.getLogger(GCatCaller.class);
/**
* Instantiates a new g cat caller.
*
* @param catalogueURL the catalogue URL
*/
public GCatCaller(String catalogueURL) {
this.catalogueURL = catalogueURL;
}
/**
* Gets the dataset for name.
*
* @param datasetIdOrName the dataset id or name
* @return the jsonValue
* @throws WebApplicationException
* @throws MalformedURLException the malformed URL exception
*/
public String getDatasetForName(String datasetIdOrName) throws WebApplicationException, MalformedURLException {
LOG.debug("Get dataset for name "+datasetIdOrName+ "called");
return new Item().read(datasetIdOrName);
}
/**
* Creates the dataset.
*
* @param jsonDataset the json dataset
* @param socialPost if true sends the social post
* @return the jsonValue
* @throws WebApplicationException
* @throws MalformedURLException the malformed URL exception
*/
public String createDataset(String jsonDataset, boolean socialPost) throws WebApplicationException, MalformedURLException {
LOG.debug("Create dataset called");
return new Item().create(jsonDataset,socialPost);
}
/**
* Adds the resource to dataset.
*
* @param datasetId the dataset id
* @param jsonValueResource the json value resource
* @return the string
* @throws MalformedURLException the malformed URL exception
*/
public String addResourceToDataset(String datasetId, String jsonValueResource) throws MalformedURLException {
LOG.debug("Create resource called");
return new Resource().create(datasetId, jsonValueResource);
}
/**
* Delete resource.
*
* @param datasetId the dataset id
* @param resourceId the resource id
* @throws MalformedURLException the malformed URL exception
*/
public void deleteResource(String datasetId, String resourceId) throws MalformedURLException {
LOG.debug("Delete resource called");
new Resource().delete(datasetId, resourceId);
}
/**
* Gets the catalogue URL.
*
* @return the catalogue URL
*/
public String getCatalogueURL() {
return catalogueURL;
}
/**
* Creates the group.
*
* @param jsonGroup the json group
* @return the string
* @throws MalformedURLException the malformed URL exception
*/
public String createGroup(String jsonGroup) throws MalformedURLException {
LOG.debug("Create group called");
return new Group().create(jsonGroup);
}
/**
* Patch dataset.
*
* @param datasetName the dataset name
* @param jsonObj the json obj
* @return the string
* @throws MalformedURLException
* @throws WebApplicationException
* @throws Exception the exception
*/
public String patchDataset(String datasetName, JSONObject jsonObj) throws WebApplicationException, MalformedURLException {
LOG.debug("Patch dataset called");
return new Item().patch(datasetName, jsonObj.toJSONString());
}
}