2018-12-04 12:06:22 +01:00
|
|
|
package org.gcube.gcat.persistence.ckan;
|
|
|
|
|
2022-04-28 10:47:52 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2021-12-06 17:45:15 +01:00
|
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
2022-02-28 15:43:40 +01:00
|
|
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
2022-02-17 17:35:07 +01:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
2018-12-04 12:06:22 +01:00
|
|
|
import org.gcube.gcat.ContextTest;
|
2022-02-17 17:35:07 +01:00
|
|
|
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
|
2021-12-06 17:45:15 +01:00
|
|
|
import org.junit.Ignore;
|
2018-12-04 12:06:22 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class CKANOrganizationTest extends ContextTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(CKANOrganizationTest.class);
|
|
|
|
|
2019-09-12 14:26:24 +02:00
|
|
|
/*
|
2018-12-04 12:06:22 +01:00
|
|
|
@Test
|
|
|
|
public void getUserRole() throws Exception {
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI());
|
|
|
|
ckanOrganization.setName(CKANOrganization.getCKANOrganizationName());
|
|
|
|
String ret = ckanOrganization.getUserRole("luca.frosini");
|
|
|
|
logger.debug("{}", ret);
|
|
|
|
}
|
2019-09-12 14:26:24 +02:00
|
|
|
*/
|
2018-12-04 12:06:22 +01:00
|
|
|
|
2019-05-20 17:23:49 +02:00
|
|
|
@Test
|
2021-02-03 21:55:32 +01:00
|
|
|
public void countOrganizations() throws Exception {
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
int count = ckanOrganization.count();
|
|
|
|
logger.debug("The organizations are {}", count);
|
|
|
|
}
|
|
|
|
|
2022-04-28 10:47:52 +02:00
|
|
|
public static List<String> listOrg() throws Exception {
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
String ret = ckanOrganization.list(1000, 0);
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
String[] groupArray = objectMapper.readValue(ret, String[].class);
|
|
|
|
return Arrays.asList(groupArray);
|
|
|
|
}
|
|
|
|
|
2021-02-03 21:55:32 +01:00
|
|
|
@Test
|
|
|
|
public void listOrganizations() throws Exception {
|
2019-05-20 17:23:49 +02:00
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
String ret = ckanOrganization.list(1000, 0);
|
|
|
|
logger.debug("{}", ret);
|
|
|
|
}
|
2021-12-06 17:45:15 +01:00
|
|
|
|
|
|
|
@Ignore
|
|
|
|
@Test
|
|
|
|
public void deleteOrganization() throws Exception {
|
|
|
|
ContextTest.setContextByName("/gcube");
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI());
|
|
|
|
String name = "aquamaps1";
|
|
|
|
ckanOrganization.setName(name);
|
|
|
|
logger.debug("Going to delete {}", name);
|
|
|
|
// ckanOrganization.delete(true);
|
|
|
|
}
|
|
|
|
|
2022-02-17 17:35:07 +01:00
|
|
|
|
|
|
|
@Ignore
|
|
|
|
@Test
|
|
|
|
public void createOrganization() throws Exception {
|
|
|
|
ContextTest.setContextByName("/gcube/devNext/NextNext");
|
2022-02-28 15:43:40 +01:00
|
|
|
String context = SecretManagerProvider.instance.get().getContext();
|
2022-02-17 17:35:07 +01:00
|
|
|
ScopeBean scopeBean = new ScopeBean(context);
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI());
|
|
|
|
String name = CatalogueConfiguration.getOrganizationName(scopeBean);
|
|
|
|
ckanOrganization.setName(name);
|
|
|
|
String json = "{\"display_name\": \"" + scopeBean.name() + "\",\"description\": \"" + context + " Organization\",\"name\": \"" + name + "\"}";
|
|
|
|
logger.info("Going to create Organization {} : {}", name, json);
|
|
|
|
// ckanOrganization.create(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-13 16:35:21 +01:00
|
|
|
//@Ignore
|
|
|
|
@Test
|
2021-12-06 17:45:15 +01:00
|
|
|
public void deleteAllOrganizations() throws Exception {
|
|
|
|
ContextTest.setContextByName("/gcube");
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI());
|
|
|
|
String ret = ckanOrganization.list(1000, 0);
|
|
|
|
logger.debug("{}", ret);
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
JsonNode organizations = (ArrayNode) mapper.readTree(ret);
|
|
|
|
for(JsonNode jn : organizations) {
|
|
|
|
ckanOrganization.setName(jn.asText());
|
2021-12-07 17:18:09 +01:00
|
|
|
logger.debug("Going to delete organization '{}'", jn.asText());
|
2021-12-06 17:45:15 +01:00
|
|
|
try {
|
|
|
|
// ckanOrganization.delete(true);
|
|
|
|
}catch (Exception e) {
|
|
|
|
// A not empty organization cannot be deleted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 12:06:22 +01:00
|
|
|
}
|