From ff6df173847f751a4e3a39d42dbafeeca0a75f00 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Wed, 14 Sep 2016 14:23:30 +0000 Subject: [PATCH] minor fixes git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@131353 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ckanutillibrary/CKanUtils.java | 2 +- .../ckanutillibrary/TestCKanLib.java | 66 ++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/CKanUtils.java b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/CKanUtils.java index 35ffb5c..137eee1 100644 --- a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/CKanUtils.java +++ b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/CKanUtils.java @@ -158,7 +158,7 @@ public interface CKanUtils { boolean isSysAdmin(String username, String apiKey); /** - * Check if this role is present for this user in that organization. If it is not present we need to add it with the given role. + * Check if this role is present for this user in the organization. If he/she is not present we need to add it with the given role. * @param username * @param organizationName * @param correspondentRoleToCheck diff --git a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/TestCKanLib.java b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/TestCKanLib.java index 67ad6d2..faa05d8 100644 --- a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/TestCKanLib.java +++ b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/TestCKanLib.java @@ -13,7 +13,9 @@ import org.gcube.datacatalogue.ckanutillibrary.models.DatasetRelationships; import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization; import org.slf4j.LoggerFactory; +import eu.trentorise.opendata.jackan.CheckedCkanClient; import eu.trentorise.opendata.jackan.model.CkanOrganization; +import eu.trentorise.opendata.jackan.model.CkanUser; public class TestCKanLib { @@ -168,10 +170,70 @@ public class TestCKanLib { String url = "https://dev4.d4science.org/group/devvre/ckan"; String scopeToUse = new ApplicationProfileScopePerUrlReader().getScopePerUrl(url); logger.debug("Retrieved scope is " + scopeToUse); - - ScopeProvider.instance.reset(); // the sysout should print null + + ScopeProvider.instance.reset(); // the following sysout should print null String url2 = "https://dev4.d4science.org/group/devvre/ckan"; String scopeToUse2 = new ApplicationProfileScopePerUrlReader().getScopePerUrl(url2); logger.debug("Retrieved scope is " + scopeToUse2); } + + //@Test + public void createUsers() throws Exception{ + + CKanUtilsImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE"); + CheckedCkanClient client = new CheckedCkanClient(instance.getCatalogueUrl(), instance.getApiKeyFromUsername("costantino_perciante")); + CkanUser editorUser = new CkanUser("user_editor_devvre", "user_editor_devvre@test.it", ""); + client.createUser(editorUser); + CkanUser adminUser = new CkanUser("user_admin_devvre", "user_admin_devvre@test.it", ""); + client.createUser(adminUser); + + } + + //@Test + public void createAsEditor() throws Exception{ + CKanUtilsImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE"); + boolean checkedEditor = instance.checkRole("user_editor_devvre", "devvre", RolesIntoOrganization.EDITOR); + if(checkedEditor){ + logger.debug("Created editor in devvre? " + checkedEditor); + } + boolean checkedAdmin = instance.checkRole("user_admin_devvre", "devvre", RolesIntoOrganization.ADMIN); + if(checkedAdmin){ + logger.debug("Created admin in devvre? " + checkedAdmin); + } + } + + //@Test + public void editorCreateDataset() throws Exception{ + + CKanUtilsImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE"); + instance.createCKanDataset(instance.getApiKeyFromUsername("user_editor_devvre"), "dataset_as_editor_devvre_private", "devvre", null, null, null, null, 1, null, null, null, null, null, false); + + } + + //@Test + public void adminCreateDataset() throws Exception{ + + CKanUtilsImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE"); + //instance.createCKanDataset(instance.getApiKeyFromUsername("user_admin_devvre"), "dataset_as_admin_devvre", "devvre", null, null, null, null, 1, null, null, null, null, null, false); + instance.createCKanDataset(instance.getApiKeyFromUsername("user_admin_devvre"), "dataset_as_admin_devvre_private", "devvre", null, null, null, null, 1, null, null, null, null, null, false); + } + + //@Test + public void adminChangeVisibility() throws Exception{ + + CKanUtilsImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE"); + //instance.createCKanDataset(instance.getApiKeyFromUsername("user_editor_devvre"), "dataset_as_editor_devvre", "devvre", null, null, null, null, 1, null, null, null, null, null, false); + //instance.setDatasetPrivate(true, "3571cca5-b0ae-4dc6-b791-434a8e062ce5", "dataset_as_admin_devvre_public", instance.getApiKeyFromUsername("user_admin_devvre")); + + instance.setDatasetPrivate(true, "3571cca5-b0ae-4dc6-b791-434a8e062ce5", "33bbdcb1-929f-441f-8718-a9e5134f517d", instance.getApiKeyFromUsername("user_editor_devvre")); + + // CheckedCkanClient client = new CheckedCkanClient(instance.getCatalogueUrl(), instance.getApiKeyFromUsername("user_admin_devvre")); + // CkanDataset dataset = client.getDataset("dataset_as_admin_devvre_private"); + // logger.debug("Current value for private: " + dataset.isPriv()); + // dataset.setPriv(!dataset.isPriv()); + // CkanDataset datasetUpd = client.updateDataset(dataset); + // logger.debug("Private value is " + datasetUpd.isPriv()); + // + + } }