added the method "deleteResource"
This commit is contained in:
parent
ed7a5f64e2
commit
2db8bd6a2c
|
@ -11,6 +11,7 @@ import org.gcube.gcat.client.Resource;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class GCatCaller.
|
||||
*
|
||||
|
@ -63,14 +64,27 @@ public class GCatCaller {
|
|||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
* @param datasetID the dataset ID
|
||||
* @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 {
|
||||
public String addResourceToDataset(String datasetId, String jsonValueResource) throws MalformedURLException {
|
||||
LOG.debug("Create resource called");
|
||||
return new Resource().create(datasetID, jsonValueResource);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,7 +103,7 @@ public class GCatCaller {
|
|||
*
|
||||
* @param jsonGroup the json group
|
||||
* @return the string
|
||||
* @throws MalformedURLException
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String createGroup(String jsonGroup) throws MalformedURLException {
|
||||
LOG.debug("Create group called");
|
||||
|
|
|
@ -271,11 +271,11 @@ public interface DataCatalogue {
|
|||
String addResourceToDataset(ResourceBean resource) throws Exception;
|
||||
|
||||
/**
|
||||
* Remove the resource with id resourceId from the dataset in which it is.
|
||||
* Remove the resource with id resourceId from dataset in which it is.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
* @return true on success, false otherwise.
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
boolean deleteResourceFromDataset(String resourceId) throws Exception;
|
||||
|
||||
|
|
|
@ -811,14 +811,15 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
|
||||
// try to create
|
||||
String jsonValueDataset = MarshUnmarshCkanObject.toJsonValueDataset(dataset);
|
||||
LOG.info("Serialized dataset is: " + jsonValueDataset);
|
||||
LOG.debug("Serialized dataset is: " + jsonValueDataset);
|
||||
jsonValueDataset = gCatCaller.createDataset(jsonValueDataset,true);
|
||||
LOG.debug("Created dataset is: " + jsonValueDataset);
|
||||
|
||||
if(jsonValueDataset != null){
|
||||
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset);
|
||||
LOG.debug("Dataset with name " + toCkanDataset.getName() + " has been created. Setting visibility");
|
||||
LOG.info("Dataset with name " + toCkanDataset.getName() + " has been created correctly");
|
||||
|
||||
//TODO FOLLOWING OPERATIONS ARE NO LONGER NEEDED
|
||||
// set visibility
|
||||
/*boolean visibilitySet = directCkanCaller.setDatasetPrivate(
|
||||
!setPublic, // swap to private
|
||||
|
@ -829,15 +830,16 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
LOG.info("Was visibility set to " + (setPublic ? "public" : "private") + "? " + visibilitySet);
|
||||
*/
|
||||
|
||||
// //set searchable to true if dataset visibility is private
|
||||
// if(!setPublic){ // (swap to private)
|
||||
// boolean searchableSet = directCkanCaller.setSearchableField(toCkanDataset.getId(), setSearchable, CKAN_TOKEN_SYS);
|
||||
// LOG.info("Was searchable set to True? " + searchableSet);
|
||||
// }
|
||||
//set searchable to true if dataset visibility is private
|
||||
/*if(!setPublic){ // (swap to private)
|
||||
boolean searchableSet = directCkanCaller.setSearchableField(toCkanDataset.getId(), setSearchable, CKAN_TOKEN_SYS);
|
||||
LOG.info("Was searchable set to True? " + searchableSet);
|
||||
}
|
||||
|
||||
LOG.info("Setting searchable to? " + setSearchable);
|
||||
boolean searchableSet = directCkanCaller.setSearchableField(toCkanDataset.getId(), setSearchable, CKAN_TOKEN_SYS);
|
||||
LOG.info("Was searchable set to? " + searchableSet);
|
||||
*/
|
||||
return toCkanDataset.getId();
|
||||
}
|
||||
|
||||
|
@ -851,7 +853,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
|
||||
@Override
|
||||
public String addResourceToDataset(ResourceBean resourceBean) throws Exception {
|
||||
LOG.debug("Request to add a resource described by this bean " + resourceBean);
|
||||
LOG.info("Request to add a resource described by this bean " + resourceBean);
|
||||
|
||||
// checks
|
||||
checkNotNull(resourceBean);
|
||||
|
@ -893,7 +895,22 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
|
||||
@Override
|
||||
public boolean deleteResourceFromDataset(String resourceId) throws Exception {
|
||||
throw new Exception("Method not implemented");
|
||||
LOG.info("Request to delete a resource with id " + resourceId);
|
||||
|
||||
// checks
|
||||
checkNotNull(resourceId);
|
||||
checkArgument(!resourceId.isEmpty());
|
||||
|
||||
try{
|
||||
CkanResource theResource = ckanCaller.getResource(resourceId);
|
||||
gCatCaller.deleteResource(theResource.getPackageId(), resourceId);
|
||||
return true;
|
||||
|
||||
}catch(Exception e){
|
||||
LOG.error("Unable to delete resource whose id is " + resourceId, e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue