|
|
|
@ -104,7 +104,18 @@ public class GRSFUtilities extends ContextTest {
|
|
|
|
|
return modified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
public static final String GROUP_SUFFIX = "_group";
|
|
|
|
|
|
|
|
|
|
public static String getGroupId(String name) {
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
|
stringBuffer.append(getGroupNameOnCkan(name));
|
|
|
|
|
if(!name.endsWith(GROUP_SUFFIX)) {
|
|
|
|
|
stringBuffer.append(GROUP_SUFFIX);
|
|
|
|
|
}
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGroupName() {
|
|
|
|
|
String[] groupNames = new String[] {
|
|
|
|
|
"GRSF", "Legacy", "Fishery", "Stock", "FIRMS", "FishSource", "RAM",
|
|
|
|
@ -115,11 +126,13 @@ public class GRSFUtilities extends ContextTest {
|
|
|
|
|
"GRSF SDG Flag", "GRSF Traceability Flag"
|
|
|
|
|
};
|
|
|
|
|
for(String name : groupNames) {
|
|
|
|
|
String ckanGroupName = getGroupNameOnCkan(name);
|
|
|
|
|
String groupName = CKANGroup.fromGroupTitleToName(name);
|
|
|
|
|
String ckanGroupName = getGroupId(name);
|
|
|
|
|
String groupName = CKANGroup.fromGroupTitleToName(name) + GROUP_SUFFIX;
|
|
|
|
|
logger.info("{} -> {}", name, ckanGroupName, groupName);
|
|
|
|
|
Assert.assertTrue(ckanGroupName.compareTo(groupName)==0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
@ -141,11 +154,12 @@ public class GRSFUtilities extends ContextTest {
|
|
|
|
|
ObjectNode node = objectMapper.createObjectNode();
|
|
|
|
|
node.put("display_name", name);
|
|
|
|
|
node.put("title", name);
|
|
|
|
|
node.put("name", getGroupNameOnCkan(name));
|
|
|
|
|
node.put("name", getGroupId(name));
|
|
|
|
|
String json = objectMapper.writeValueAsString(node);
|
|
|
|
|
logger.info(json);
|
|
|
|
|
ckanGroupToCreate.create(json);
|
|
|
|
|
// ckanGroupToCreate.create(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
@ -162,7 +176,7 @@ public class GRSFUtilities extends ContextTest {
|
|
|
|
|
for(String name : groupNames) {
|
|
|
|
|
CKANGroup ckanGroupToCreate = new CKANGroup();
|
|
|
|
|
ckanGroupToCreate.setApiKey(sysAdminAPI);
|
|
|
|
|
ckanGroupToCreate.setName(getGroupNameOnCkan(name));
|
|
|
|
|
ckanGroupToCreate.setName(getGroupId(name));
|
|
|
|
|
try {
|
|
|
|
|
ckanGroupToCreate.purge();
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
@ -173,15 +187,51 @@ public class GRSFUtilities extends ContextTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
public void associateUserToAllCKANGroups() throws ObjectNotFound, Exception {
|
|
|
|
|
public void associateUserToAllCKANGroupsAndOrganization() throws ObjectNotFound, Exception {
|
|
|
|
|
String username = "grsf_publisher";
|
|
|
|
|
|
|
|
|
|
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
|
|
|
|
List<String> groupNames = CKANGroupTest.listGroup();
|
|
|
|
|
for(String groupName : groupNames) {
|
|
|
|
|
CKANUser ckanUser = new CKANUser();
|
|
|
|
|
ckanUser.setApiKey(sysAdminAPI);
|
|
|
|
|
ckanUser.setName("grsf_publisher");
|
|
|
|
|
ckanUser.addToGroup(CKANGroup.getCKANGroupName(groupName));
|
|
|
|
|
ckanUser.setName(username);
|
|
|
|
|
ckanUser.addToGroup(groupName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> orgs = CKANOrganizationTest.listOrg();
|
|
|
|
|
for(String org : orgs) {
|
|
|
|
|
CKANUser ckanUser = new CKANUser();
|
|
|
|
|
ckanUser.setApiKey(sysAdminAPI);
|
|
|
|
|
ckanUser.addUserToOrganization(org, username, "admin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
public void manageOrganizations() throws JsonProcessingException {
|
|
|
|
|
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
|
|
|
|
String[] organizations = new String[] {
|
|
|
|
|
"GRSF_Pre", "FIRMS", "FishSource", "RAM"
|
|
|
|
|
};
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
for(String org : organizations) {
|
|
|
|
|
CKANOrganization ckanOrganization = new CKANOrganization();
|
|
|
|
|
ckanOrganization.setApiKey(sysAdminAPI);
|
|
|
|
|
ckanOrganization.setName(org.toLowerCase());
|
|
|
|
|
ObjectNode node = objectMapper.createObjectNode();
|
|
|
|
|
node.put("display_name", org);
|
|
|
|
|
node.put("title", org);
|
|
|
|
|
node.put("name", org.toLowerCase());
|
|
|
|
|
String json = objectMapper.writeValueAsString(node);
|
|
|
|
|
try {
|
|
|
|
|
// ckanOrganization.create(json);
|
|
|
|
|
// ckanOrganization.purge();
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void purgeGRSFRecords(int limit, int offset) throws Exception {
|
|
|
|
|