improved addResource
This commit is contained in:
parent
6419fced4b
commit
331f1e2a9f
|
@ -5,6 +5,8 @@ package org.gcube.datacatalogue.ckanutillibrary.gcat;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
|
||||||
import org.gcube.gcat.client.Group;
|
import org.gcube.gcat.client.Group;
|
||||||
import org.gcube.gcat.client.Item;
|
import org.gcube.gcat.client.Item;
|
||||||
import org.gcube.gcat.client.Resource;
|
import org.gcube.gcat.client.Resource;
|
||||||
|
@ -40,9 +42,10 @@ public class GCatCaller {
|
||||||
*
|
*
|
||||||
* @param datasetIdOrName the dataset id or name
|
* @param datasetIdOrName the dataset id or name
|
||||||
* @return the jsonValue
|
* @return the jsonValue
|
||||||
|
* @throws WebApplicationException
|
||||||
* @throws MalformedURLException the malformed URL exception
|
* @throws MalformedURLException the malformed URL exception
|
||||||
*/
|
*/
|
||||||
public String getDatasetForName(String datasetIdOrName) throws MalformedURLException {
|
public String getDatasetForName(String datasetIdOrName) throws WebApplicationException, MalformedURLException {
|
||||||
LOG.debug("Get dataset for name "+datasetIdOrName+ "called");
|
LOG.debug("Get dataset for name "+datasetIdOrName+ "called");
|
||||||
return new Item().read(datasetIdOrName);
|
return new Item().read(datasetIdOrName);
|
||||||
}
|
}
|
||||||
|
@ -54,9 +57,10 @@ public class GCatCaller {
|
||||||
* @param jsonDataset the json dataset
|
* @param jsonDataset the json dataset
|
||||||
* @param socialPost if true sends the social post
|
* @param socialPost if true sends the social post
|
||||||
* @return the jsonValue
|
* @return the jsonValue
|
||||||
|
* @throws WebApplicationException
|
||||||
* @throws MalformedURLException the malformed URL exception
|
* @throws MalformedURLException the malformed URL exception
|
||||||
*/
|
*/
|
||||||
public String createDataset(String jsonDataset, boolean socialPost) throws MalformedURLException {
|
public String createDataset(String jsonDataset, boolean socialPost) throws WebApplicationException, MalformedURLException {
|
||||||
LOG.debug("Create dataset called");
|
LOG.debug("Create dataset called");
|
||||||
return new Item().create(jsonDataset,socialPost);
|
return new Item().create(jsonDataset,socialPost);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +87,7 @@ public class GCatCaller {
|
||||||
* @param resourceId the resource id
|
* @param resourceId the resource id
|
||||||
* @throws MalformedURLException the malformed URL exception
|
* @throws MalformedURLException the malformed URL exception
|
||||||
*/
|
*/
|
||||||
public void deleteResource(String datasetId, String resourceId) throws MalformedURLException {
|
public void deleteResource(String datasetId, String resourceId) throws MalformedURLException {
|
||||||
LOG.debug("Delete resource called");
|
LOG.debug("Delete resource called");
|
||||||
new Resource().delete(datasetId, resourceId);
|
new Resource().delete(datasetId, resourceId);
|
||||||
}
|
}
|
||||||
|
@ -106,31 +110,26 @@ public class GCatCaller {
|
||||||
* @return the string
|
* @return the string
|
||||||
* @throws MalformedURLException the malformed URL exception
|
* @throws MalformedURLException the malformed URL exception
|
||||||
*/
|
*/
|
||||||
public String createGroup(String jsonGroup) throws MalformedURLException {
|
public String createGroup(String jsonGroup) throws MalformedURLException {
|
||||||
LOG.debug("Create group called");
|
LOG.debug("Create group called");
|
||||||
return new Group().create(jsonGroup);
|
return new Group().create(jsonGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* TODO MUST BE COMPLETED
|
|
||||||
*
|
|
||||||
* Patch dataset.
|
* Patch dataset.
|
||||||
*
|
*
|
||||||
* @param datasetId the dataset id
|
* @param datasetName the dataset name
|
||||||
* @param jsonObj the json obj
|
* @param jsonObj the json obj
|
||||||
|
* @return the string
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws WebApplicationException
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public void patchDataset(String datasetId, JSONObject jsonObj) throws Exception {
|
public String patchDataset(String datasetName, JSONObject jsonObj) throws WebApplicationException, MalformedURLException {
|
||||||
|
LOG.debug("Patch dataset called");
|
||||||
//String searchableAsString = searchable ? "True" : "False";
|
return new Item().patch(datasetName, jsonObj.toJSONString());
|
||||||
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
jsonObj.put("id", datasetId); //just to be sure
|
|
||||||
//obj.put("searchable", searchableAsString);
|
|
||||||
|
|
||||||
throw new Exception("Method patchDataset is missing by gCat CL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -970,24 +970,30 @@ public class DataCatalogueImpl implements DataCatalogue {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean patchFieldsForDataset(String datasetId, Map<String, String> mapFields) throws Exception {
|
public boolean patchFieldsForDataset(String datasetIdOrName, Map<String, String> mapFields) throws Exception {
|
||||||
LOG.info("Called patch the fields " + mapFields + " for dataset id: " + datasetId);
|
LOG.info("Called patch the fields " + mapFields + " for dataset id/name: " + datasetIdOrName);
|
||||||
|
|
||||||
checkNotNull(datasetId);
|
checkNotNull(datasetIdOrName);
|
||||||
checkNotNull(mapFields);
|
checkNotNull(mapFields);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
CkanDataset dataset = ckanCaller.getDataset(datasetIdOrName);
|
||||||
|
String datasetId = dataset.getId();
|
||||||
|
|
||||||
JSONObject jsonObj = new JSONObject();
|
JSONObject jsonObj = new JSONObject();
|
||||||
for (String key : mapFields.keySet()) {
|
for (String key : mapFields.keySet()) {
|
||||||
jsonObj.put(key, mapFields.get(key));
|
jsonObj.put(key, mapFields.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonObj.put("id", datasetId);
|
||||||
|
|
||||||
LOG.debug("Json Dataset is: " + jsonObj);
|
LOG.debug("Json Dataset is: " + jsonObj);
|
||||||
gCatCaller.patchDataset(datasetId, jsonObj);
|
gCatCaller.patchDataset(dataset.getName(), jsonObj);
|
||||||
LOG.info("Patch operation for dataset " + datasetId + " terminates without errors");
|
LOG.info("Patch operation for dataset " + datasetId + " terminates without errors");
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error occurred trying to patch the dataset with id: " + datasetId, e.getMessage());
|
LOG.error("Error occurred trying to patch the dataset with id: " + datasetIdOrName, e);
|
||||||
throw new Exception("Unable to patch the dataset. Error: " + e.getMessage());
|
throw new Exception("Unable to patch the dataset. Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,9 +1029,21 @@ public class DataCatalogueImpl implements DataCatalogue {
|
||||||
|
|
||||||
// checks
|
// checks
|
||||||
checkNotNull(resourceBean);
|
checkNotNull(resourceBean);
|
||||||
|
checkNotNull(resourceBean.getUrl());
|
||||||
|
|
||||||
|
boolean isAccessibleURL = false;
|
||||||
|
try {
|
||||||
|
isAccessibleURL = CatalogueUtilMethods.resourceExists(resourceBean.getUrl());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception("It seems the resource at this url " + resourceBean.getUrl()+" is not reachable. Error: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
if (CatalogueUtilMethods.resourceExists(resourceBean.getUrl())) {
|
if(!isAccessibleURL){
|
||||||
|
throw new Exception("It seems there is no resource at this url " + resourceBean.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
CkanResource resource = CKANConveter.toCkanResource(CKAN_CATALOGUE_URL, resourceBean);
|
CkanResource resource = CKANConveter.toCkanResource(CKAN_CATALOGUE_URL, resourceBean);
|
||||||
|
|
||||||
String jsonValueResource = MarshUnmarshCkanObject.toJsonValueResource(resource, METHOD.TO_CREATE);
|
String jsonValueResource = MarshUnmarshCkanObject.toJsonValueResource(resource, METHOD.TO_CREATE);
|
||||||
|
@ -1039,9 +1057,9 @@ public class DataCatalogueImpl implements DataCatalogue {
|
||||||
LOG.debug("Resource " + createdRes.getName() + " added correclty");
|
LOG.debug("Resource " + createdRes.getName() + " added correclty");
|
||||||
return createdRes.getId();
|
return createdRes.getId();
|
||||||
}
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
} else
|
LOG.error("Unable to add the resource "+resourceBean, e);
|
||||||
throw new Exception("It seems there is no is no resource at this url " + resourceBean.getUrl());
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1276,7 +1294,4 @@ public class DataCatalogueImpl implements DataCatalogue {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,22 +101,37 @@ public class CatalogueUtilMethods {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to check if a something at this url actually exists
|
* Utility method to check if a something at this url actually exists
|
||||||
* @param URLName
|
* @param urlName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean resourceExists(String URLName){
|
public static boolean resourceExists(String urlName){
|
||||||
|
|
||||||
if(URLName == null || URLName.isEmpty())
|
if(urlName == null || urlName.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// replace https
|
// replace https
|
||||||
String urlToTest = URLName.replace(HTTPS, HTTP);
|
//String urlToTest = urlName.replace(HTTPS, HTTP);
|
||||||
|
String urlToTest = urlName;
|
||||||
HttpURLConnection.setFollowRedirects(true);
|
HttpURLConnection.setFollowRedirects(true);
|
||||||
HttpURLConnection con = (HttpURLConnection) new URL(urlToTest).openConnection();
|
HttpURLConnection con = (HttpURLConnection) new URL(urlToTest).openConnection();
|
||||||
con.setRequestMethod("HEAD");
|
con.setRequestMethod("HEAD");
|
||||||
logger.debug("Return code is " + con.getResponseCode());
|
int responseCode = con.getResponseCode();
|
||||||
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
|
logger.debug("Trying HEAD request to: " + urlToTest);
|
||||||
|
logger.debug("HEAD response code is " + responseCode);
|
||||||
|
//2×× Success
|
||||||
|
boolean exists = (200 <= responseCode) && (responseCode <= 208);
|
||||||
|
if(!exists) {
|
||||||
|
con = (HttpURLConnection) new URL(urlToTest).openConnection();
|
||||||
|
logger.debug("Trying GET request to: " + urlToTest);
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
responseCode = con.getResponseCode();
|
||||||
|
logger.debug("GET response code is " + responseCode);
|
||||||
|
//2×× Success
|
||||||
|
exists = (200 <= responseCode) && (responseCode <= 208);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exists;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logger.error("Exception while checking url", e);
|
logger.error("Exception while checking url", e);
|
||||||
|
@ -136,4 +151,5 @@ public class CatalogueUtilMethods {
|
||||||
return key.concat(scope);
|
return key.concat(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,10 @@ public class TestDataCatalogueLib {
|
||||||
//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 = "";
|
private String authorizationToken = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
|
||||||
String subjectId = "aa_father4";
|
String subjectId = "aa_father4";
|
||||||
String objectId = "bb_son4";
|
String objectId = "bb_son4";
|
||||||
|
String productName = "adatasetcreatedbycatalogue-util-library-873805063";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before.
|
* Before.
|
||||||
|
@ -293,447 +294,32 @@ public class TestDataCatalogueLib {
|
||||||
LOG.info("Created the group: "+ckanGroup);
|
LOG.info("Created the group: "+ckanGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void testAddResource() throws Exception{
|
public void addResource() throws Exception {
|
||||||
|
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
SecurityTokenProvider.instance.set(authorizationToken);
|
SecurityTokenProvider.instance.set(authorizationToken);
|
||||||
|
|
||||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
CkanDataset dataset = instance.getDataset("adatasetcreatedbycatalogue-util-library-873805063", null);
|
|
||||||
|
|
||||||
for (int i = 0; i < 1; i++) {
|
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||||
ResourceBean resourceBean = new ResourceBean("https://google.com", "resouce "+i, "description "+i, null, testUser, dataset.getId(), null);
|
CkanDataset dataset = instance.getDataset(productName, null);
|
||||||
|
|
||||||
|
for (int i = 1; i < 3; i++) {
|
||||||
|
ResourceBean resourceBean = new ResourceBean("https://data-dev.d4science.net/ie8Y", "resouce " + i,
|
||||||
|
"description " + i, null, testUser, dataset.getId(), null);
|
||||||
instance.addResourceToDataset(resourceBean);
|
instance.addResourceToDataset(resourceBean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// //@Test
|
//@Test
|
||||||
// public void getSysadminEmail() throws Exception{
|
public void patchFieldsForDataset() throws Exception{
|
||||||
// DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
|
||||||
// System.out.println(utils.getCatalogueEmail());
|
ScopeProvider.instance.set(scope);
|
||||||
// }
|
SecurityTokenProvider.instance.set(authorizationToken);
|
||||||
//
|
|
||||||
// //@Test
|
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||||
// public void getStatistics() throws Exception{
|
Map<String, String> customFieldsToChange = new HashMap<String, String>();
|
||||||
//
|
customFieldsToChange.put("key-random-0", "patched");
|
||||||
// DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
instance.patchFieldsForDataset(productName, customFieldsToChange);
|
||||||
// logger.debug("Statistics " + utils.getStatistics());
|
}
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getGroupForName() throws Exception{
|
|
||||||
//
|
|
||||||
// String groupName = "ariadne";
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// CkanGroup org = utils.getGroupByName(groupName);
|
|
||||||
//
|
|
||||||
// logger.debug("The "+CkanGroup.class.getSimpleName()+" is: "+org.getName());
|
|
||||||
// logger.debug("LandingPages of "+CkanGroup.class.getSimpleName()+" for name " + utils.getLandingPages());
|
|
||||||
// if(org.getUsers()!=null) {
|
|
||||||
//
|
|
||||||
// for (CkanUser user : org.getUsers()) {
|
|
||||||
// logger.debug("User: "+user.getName());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getDatasetIdsFromDB() throws Exception{
|
|
||||||
// DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
|
||||||
// List<String> ids = utils.getProductsIdsInGroupOrOrg("aquamaps", true, 0, Integer.MAX_VALUE);
|
|
||||||
// logger.debug("Size is " + ids.size());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void searchInOrganization() throws Exception{
|
|
||||||
// DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
|
||||||
// String apiKey = utils.getApiKeyFromUsername(testUser);
|
|
||||||
// List<CkanDataset> matches = utils.searchForPackageInOrganization(apiKey, "\"asfis:HMC+eez:AGO;FAO+grsf-org:INT+eez:AGO;RFB+iso3:AGO+isscfg:01.1.1\"", 0, 10, "grsf_admin");
|
|
||||||
// logger.debug("Size is " + matches.size());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void search() throws Exception{
|
|
||||||
// DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
|
||||||
// String apiKey = utils.getApiKeyFromUsername(testUser);
|
|
||||||
// List<CkanDataset> matches = utils.searchForPackage(apiKey, "\"asfis:HMC+eez:AGO;FAO+grsf-org:INT+eez:AGO;RFB+iso3:AGO+isscfg:01.1.1\"", 0, 10);
|
|
||||||
// logger.debug("Size is " + matches.size());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // @Test
|
|
||||||
// public void testManageProduct() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl catalogue = factory.getUtilsPerScope(scope);
|
|
||||||
// String apiKey = catalogue.getApiKeyFromUsername("costantino_perciante");
|
|
||||||
// //Map<String, List<String>> map = new HashMap<String, List<String>>();
|
|
||||||
// //map.put("a new custom field", Arrays.asList("a new custom field 2"));
|
|
||||||
// //catalogue.patchProductCustomFields("test-searchable-504043", apiKey, map);
|
|
||||||
// catalogue.removeCustomField("test-searchable-504043", "a new custom field", "a new custom field", apiKey);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getRole() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// instance.getOrganizationsAndRolesByUser(testUser, Arrays.asList(RolesCkanGroupOrOrg.ADMIN, RolesCkanGroupOrOrg.EDITOR, RolesCkanGroupOrOrg.MEMBER
|
|
||||||
// ));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void datasetsRelationshipCreate() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// DatasetRelationships relation = DatasetRelationships.parent_of;
|
|
||||||
//
|
|
||||||
// boolean resC = instance.createDatasetRelationship(subjectId, objectId, relation, "Comment for this relationship", instance.getApiKeyFromUsername(testUser));
|
|
||||||
//
|
|
||||||
// logger.debug("Res is " + resC);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void datasetsRelationshipDelete() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// DatasetRelationships relation = DatasetRelationships.child_of;
|
|
||||||
//
|
|
||||||
// boolean resD = instance.deleteDatasetRelationship(subjectId, objectId, relation, instance.getApiKeyFromUsername(testUser));
|
|
||||||
//
|
|
||||||
// logger.debug("ResD is " + resD);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void datasetRelationshipRetrieve() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// List<CkanDatasetRelationship> res = instance.getRelationshipDatasets(subjectId, objectId, instance.getApiKeyFromUsername(testUser));
|
|
||||||
//
|
|
||||||
// logger.debug("Relationships " + res);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testgetApiKeyFromUser() throws Exception {
|
|
||||||
//
|
|
||||||
// logger.debug("Testing getApiKeyFromUser");
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// String username = "francescomangiacrapa";
|
|
||||||
// String key = instance.getApiKeyFromUsername(username);
|
|
||||||
//
|
|
||||||
// System.out.println("key for " + username + " is " + key);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testgetUserFromApiKey() throws Exception {
|
|
||||||
//
|
|
||||||
// logger.debug("Testing getApiKeyFromUser");
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// String key = "put-your-key-here";
|
|
||||||
// CKanUserWrapper user = instance.getUserFromApiKey(key);
|
|
||||||
//
|
|
||||||
// System.out.println("user for " + key + " is " + user);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getOrganizationsByUser() throws Exception {
|
|
||||||
//
|
|
||||||
// System.out.println("Testing getOrganizationsByUser");
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// String username = "francescomangiacrapa";
|
|
||||||
// List<CkanO)rganization> organizations = instance.getOrganizationsByUser(username);
|
|
||||||
//
|
|
||||||
// System.out.println("organizations for user " + username + " are: ");
|
|
||||||
//
|
|
||||||
// for (CkanOrganization ckanOrganization : organizations) {
|
|
||||||
// System.out.println("-" + ckanOrganization.getName());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getGroupsAndRolesByUser() throws Exception {
|
|
||||||
//
|
|
||||||
// logger.debug("Testing getGroupsAndRolesByUser");
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// String username = "andrea.rossi";
|
|
||||||
// instance = new DataCatalogueImpl("/gcube");
|
|
||||||
// List<RolesCkanGroupOrOrg> rolesToMatch = new ArrayList<RolesCkanGroupOrOrg>();
|
|
||||||
// rolesToMatch.add(RolesCkanGroupOrOrg.ADMIN);
|
|
||||||
// rolesToMatch.add(RolesCkanGroupOrOrg.MEMBER);
|
|
||||||
// rolesToMatch.add(RolesCkanGroupOrOrg.EDITOR);
|
|
||||||
// Map<String, List<RolesCkanGroupOrOrg>> map = instance.getOrganizationsAndRolesByUser(username, rolesToMatch);
|
|
||||||
//
|
|
||||||
// System.out.println("organizations for user " + username + " are " + map);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getUsers() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
//
|
|
||||||
// List<RolesCkanGroupOrOrg> rolesToMatch = new ArrayList<RolesCkanGroupOrOrg>();
|
|
||||||
// rolesToMatch.add(RolesCkanGroupOrOrg.ADMIN);
|
|
||||||
// rolesToMatch.add(RolesCkanGroupOrOrg.EDITOR);
|
|
||||||
//
|
|
||||||
// Map<String, List<RolesCkanGroupOrOrg>> orgs = instance.getOrganizationsAndRolesByUser("costantino_perciante", rolesToMatch);
|
|
||||||
//
|
|
||||||
// Iterator<Entry<String, List<RolesCkanGroupOrOrg>>> iterator = orgs.entrySet().iterator();
|
|
||||||
//
|
|
||||||
// while (iterator.hasNext()) {
|
|
||||||
// Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg>> entry = (Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg>>) iterator
|
|
||||||
// .next();
|
|
||||||
//
|
|
||||||
// logger.debug("Org is " + entry.getKey() + " and role is " + entry.getValue().get(0));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void createUsers() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl 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);
|
|
||||||
// CkanUser memberUser = new CkanUser("user_member_devvre", "user_member_devvre@test.it", "");
|
|
||||||
// client.createUser(memberUser);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void createAsEditor() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE");
|
|
||||||
// boolean checkedEditor = instance.checkRoleIntoOrganization("user_editor_devvre", "devvre", RolesCkanGroupOrOrg.MEMBER);
|
|
||||||
// if(checkedEditor){
|
|
||||||
// logger.debug("Created editor in devvre? " + checkedEditor);
|
|
||||||
// }
|
|
||||||
// boolean checkedAdmin = instance.checkRoleIntoOrganization("user_admin_devvre", "devvre", RolesCkanGroupOrOrg.MEMBER);
|
|
||||||
// if(checkedAdmin){
|
|
||||||
// logger.debug("Created admin in devvre? " + checkedAdmin);
|
|
||||||
// }
|
|
||||||
// boolean checkedMember = instance.checkRoleIntoOrganization("user_member_devvre", "devvre", RolesCkanGroupOrOrg.MEMBER);
|
|
||||||
// if(checkedMember){
|
|
||||||
// logger.debug("Created member in devvre? " + checkedMember);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void adminCreateDataset() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl 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", null, "devvre", null, null, null, null, 1, null, null, null, null, null, false);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void adminChangeVisibility() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl 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"));
|
|
||||||
//
|
|
||||||
// boolean res = instance.setDatasetPrivate(false, "3571cca5-b0ae-4dc6-b791-434a8e062ce5", "33bbdcb1-929f-441f-8718-a9e5134f517d", instance.getApiKeyFromUsername("user_admin_devvre"));
|
|
||||||
// logger.debug(""+res);
|
|
||||||
//
|
|
||||||
// // 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());
|
|
||||||
// //
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testInvalidOrgRole() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// boolean res = instance.isRoleAlreadySet("francesco_mangiacrapa", "devvre_group", RolesCkanGroupOrOrg.ADMIN, true);
|
|
||||||
// logger.debug(""+res);
|
|
||||||
//
|
|
||||||
// // set to editor
|
|
||||||
// instance.checkRoleIntoGroup("francesco_mangiacrapa", "devvre_group", RolesCkanGroupOrOrg.EDITOR);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void existProductWithNameOrId() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// boolean res = instance.existProductWithNameOrId("notification_portlet_2");
|
|
||||||
// logger.debug(""+res);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testGroupAssociation() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// String datasetId = "test_grsf_group_stock_groups_sadsad";
|
|
||||||
// String groupName = "assessment-unit";
|
|
||||||
// instance.assignDatasetToGroup(groupName, datasetId, instance.getApiKeyFromUsername("costantino_perciante"));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
// //@Test
|
|
||||||
// public void checkGroupRole() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// String role = instance.getRoleOfUserInGroup("francesco.mangiacrapa", "test-by-francesco", instance.getApiKeyFromUsername("francesco.mangiacrapa"));
|
|
||||||
// logger.debug("Role is " + role);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getURL() throws Exception{
|
|
||||||
// DataCatalogueImpl util = factory.getUtilsPerScope("/gcube/devNext/NextNext");
|
|
||||||
//
|
|
||||||
// CkanDataset dataset = new CkanDataset();
|
|
||||||
// CheckedCkanClient client = new CheckedCkanClient(util.getCatalogueUrl(), util.getApiKeyFromUsername("costantino_perciante"));
|
|
||||||
//
|
|
||||||
// dataset.setName("random-test-" + UUID.randomUUID().toString().substring(0, 5));
|
|
||||||
// dataset.setOwnerOrg(client.getOrganization("devvre").getId());
|
|
||||||
// dataset.setOpen(true);
|
|
||||||
// dataset.setPriv(true);
|
|
||||||
// //CkanDataset id = client.createDataset(dataset);
|
|
||||||
//
|
|
||||||
// // util.setDatasetPrivate(true, client.getOrganization("devvre").getId(), id.getId(), util.getApiKeyFromUsername("costantino_perciante"));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void deleteAndPurgeDataset() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl util = factory.getUtilsPerScope("/gcube/devNext/NextNext");
|
|
||||||
// boolean deleted = util.deleteProduct("random-test-56sadadsfsdf", util.getApiKeyFromUsername("user_admin_devvre"), true);
|
|
||||||
// logger.debug("Deleted ? " + deleted);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // @Test
|
|
||||||
// public void testSearchableSet() throws Exception{
|
|
||||||
//
|
|
||||||
// DataCatalogueImpl util = factory.getUtilsPerScope("/gcube/devNext/NextNext");
|
|
||||||
// boolean setSearchability = util.setSearchableField("1b261d07-9f9c-414f-ad8d-c5aa429548fc", false);
|
|
||||||
// logger.debug("Searchability set? " + setSearchability);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testNameConversion(){
|
|
||||||
//
|
|
||||||
// logger.debug(CatalogueUtilMethods.fromCKanUsernameToUsername("costantino_perciante"));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getGroupsRoles() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// Map<RolesCkanGroupOrOrg, List<String>> res = instance.getRolesAndUsersGroup("abundance-level");
|
|
||||||
// logger.debug(res.toString());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testResourcePatch() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// String id = "858f5e77-80c2-4cb2-bcfc-77529693dc9a";
|
|
||||||
// instance.patchResource(id, "http://ftp.d4science.org/previews/69cc0769-de6f-45eb-a842-7be2807e8887.jpg", "new_name_for_testing_patch.csv", "description test", "", instance.getApiKeyFromUsername("costantino_perciante"));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testPatchProduct() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// Map<String, List<String>> customFieldsToChange = new HashMap<String, List<String>>();
|
|
||||||
// customFieldsToChange.put("Status", Arrays.asList("Pending"));
|
|
||||||
// instance.patchProductCustomFields("a-test-to-ignore", instance.getApiKeyFromUsername("costantino_perciante"), customFieldsToChange, false);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void addTag()throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// instance.addTag("test-after-tags-editing", instance.getApiKeyFromUsername("costantino_perciante"), "api add tag to test");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void removeTag()throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// instance.removeTag("test-after-tags-editing", instance.getApiKeyFromUsername("costantino_perciante"), "api add tag to test");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void removeGroup()throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// instance.removeDatasetFromGroup("pending", "test-after-tags-editing", instance.getApiKeyFromUsername("costantino_perciante"));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getGroups() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// instance.getParentGroups("abundance-level", instance.getApiKeyFromUsername("costantino_perciante"));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void testBelongsToGroup() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// boolean checked = instance.isDatasetInGroup("assessment-unit", "test-after-updates-17-1654");
|
|
||||||
// logger.debug("Result is " + checked);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // @Test
|
|
||||||
// public void getDatasetsInGroup() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// List<CkanDataset> result = instance.getProductsInGroup("assessment-unit");
|
|
||||||
// for (CkanDataset ckanDataset : result) {
|
|
||||||
// logger.debug("Dataset name is " + ckanDataset.getName());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getHigher(){
|
|
||||||
// logger.debug("Max is " + RolesCkanGroupOrOrg.getHigher(RolesCkanGroupOrOrg.ADMIN, RolesCkanGroupOrOrg.ADMIN));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getUrlProduct() throws Exception{
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
// String datasetName = "test_from_andrea_rossi";
|
|
||||||
// String url = instance.getUrlFromDatasetIdOrName(datasetName);
|
|
||||||
// logger.debug("url is " + url);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //@Test
|
|
||||||
// public void getCatalogueURLs() throws Exception{
|
|
||||||
// DataCatalogueImpl util = factory.getUtilsPerScope("/gcube/devNext/NextNext");
|
|
||||||
// logger.debug("MAP ACCESS URL TO CATALOGUE:" +util.getMapAccessURLToCatalogue());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue