managing swith of scope in the deleteResourceFromDataset
This commit is contained in:
parent
7fc5fab646
commit
96b4fc0732
|
@ -339,10 +339,11 @@ public interface DataCatalogue {
|
||||||
* Remove the resource with id resourceId from dataset in which it is.
|
* Remove the resource with id resourceId from dataset in which it is.
|
||||||
*
|
*
|
||||||
* @param resourceId the resource id
|
* @param resourceId the resource id
|
||||||
|
* @param username the username
|
||||||
* @return true on success, false otherwise.
|
* @return true on success, false otherwise.
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
boolean deleteResourceFromDataset(String resourceId) throws Exception;
|
boolean deleteResourceFromDataset(String resourceId, String username) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a CkanGroup.
|
* Create a CkanGroup.
|
||||||
|
|
|
@ -1205,21 +1205,32 @@ public class DataCatalogueImpl implements DataCatalogue {
|
||||||
* @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#deleteResourceFromDataset(java.lang.String)
|
* @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#deleteResourceFromDataset(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteResourceFromDataset(String resourceId) throws Exception {
|
public boolean deleteResourceFromDataset(String resourceId, String username) throws Exception {
|
||||||
LOG.info("Called deleteResourceFromDataset - resource with id " + resourceId);
|
LOG.info("Called deleteResourceFromDataset - resource with id " + resourceId);
|
||||||
|
|
||||||
// checks
|
// checks
|
||||||
checkNotNull(resourceId);
|
checkNotNull(resourceId);
|
||||||
checkArgument(!resourceId.isEmpty());
|
checkArgument(!resourceId.isEmpty());
|
||||||
|
|
||||||
|
GcubeContext gcubeContext = null;
|
||||||
try{
|
try{
|
||||||
CkanResource theResource = ckanCaller.getResource(resourceId);
|
CkanResource theResource = ckanCaller.getResource(resourceId);
|
||||||
|
|
||||||
|
CkanDataset theDataset = getDataset(theResource.getPackageId(), username);
|
||||||
|
|
||||||
|
//Switch the context if needed
|
||||||
|
gcubeContext = GCubeUtils.detectTheOrgNameContexts(theDataset.getOrganization().getName(), username, true);
|
||||||
|
|
||||||
gCatCaller.deleteResource(theResource.getPackageId(), resourceId);
|
gCatCaller.deleteResource(theResource.getPackageId(), resourceId);
|
||||||
LOG.info("Resource with id: " + resourceId + " deleted correclty");
|
LOG.info("Resource with id: " + resourceId + " deleted correclty");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LOG.error("Unable to delete resource whose id is " + resourceId, e);
|
LOG.error("Unable to delete resource whose id is " + resourceId, e);
|
||||||
|
}finally {
|
||||||
|
//revert the context if needed
|
||||||
|
if(gcubeContext!=null)
|
||||||
|
GCubeUtils.revertToSourceContext(gcubeContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class GCubeUtils {
|
||||||
String destinationTokenForUser = pContext.getCurrentUserToken(destinationScopeForOrg, username);
|
String destinationTokenForUser = pContext.getCurrentUserToken(destinationScopeForOrg, username);
|
||||||
LOG.debug("Destination token detected: "
|
LOG.debug("Destination token detected: "
|
||||||
+ destinationTokenForUser.substring(0, destinationTokenForUser.length() - 12) + "XXXXX"
|
+ destinationTokenForUser.substring(0, destinationTokenForUser.length() - 12) + "XXXXX"
|
||||||
+ "for user: " + username);
|
+ " for user: " + username);
|
||||||
|
|
||||||
if (destinationScopeForOrg != null && destinationTokenForUser != null) {
|
if (destinationScopeForOrg != null && destinationTokenForUser != null) {
|
||||||
gcubeContext.setTargetScope(destinationScopeForOrg);
|
gcubeContext.setTargetScope(destinationScopeForOrg);
|
||||||
|
|
|
@ -35,13 +35,14 @@ public class TestDataCatalogueLib {
|
||||||
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueLib.class);
|
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueLib.class);
|
||||||
|
|
||||||
private DataCatalogueFactory factory;
|
private DataCatalogueFactory factory;
|
||||||
private String scope = "/gcube/devsec/devVRE";
|
//private String scope = "/gcube/devsec/devVRE";
|
||||||
|
private String scope = "/gcube";
|
||||||
//private String scope = "/pred4s/preprod/preVRE";
|
//private String scope = "/pred4s/preprod/preVRE";
|
||||||
//private String scope = "/d4science.research-infrastructures.eu/SoBigData/Catalogue-TerritoriAperti";
|
//private String scope = "/d4science.research-infrastructures.eu/SoBigData/Catalogue-TerritoriAperti";
|
||||||
//private String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
|
//private String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
|
||||||
//private String testUser = "costantino_perciante";
|
//private String testUser = "costantino_perciante";
|
||||||
private String testUser = "francesco.mangiacrapa";
|
private String testUser = "francesco.mangiacrapa";
|
||||||
private String authorizationToken = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
|
private String authorizationToken = "";
|
||||||
String subjectId = "aa_father4";
|
String subjectId = "aa_father4";
|
||||||
String objectId = "bb_son4";
|
String objectId = "bb_son4";
|
||||||
String productName = "adatasetcreatedbycatalogue-util-library-873805063";
|
String productName = "adatasetcreatedbycatalogue-util-library-873805063";
|
||||||
|
@ -325,6 +326,19 @@ public class TestDataCatalogueLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void deleteResource() throws Exception {
|
||||||
|
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
SecurityTokenProvider.instance.set(authorizationToken);
|
||||||
|
|
||||||
|
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||||
|
String resourceId = "ce7295cf-47db-4faf-901f-4fec2d3fae7a";
|
||||||
|
boolean deleted = instance.deleteResourceFromDataset(resourceId, testUser);
|
||||||
|
|
||||||
|
LOG.info("Deleted the resource? "+deleted);
|
||||||
|
}
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void patchFieldsForDataset() throws Exception{
|
public void patchFieldsForDataset() throws Exception{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue