Added the possibility to specify the title of the group while creating

it
This commit is contained in:
Luca Frosini 2024-08-01 14:16:27 +02:00
parent 7a662fbc64
commit b81414252d
1 changed files with 70 additions and 28 deletions

View File

@ -68,10 +68,12 @@ public class GRSFUtilities extends ContextTest {
if(createdGroup.contains(name)) {
return;
}
String sysAdminAPI = ""; // CKANUtility.getSysAdminAPI();
String sysAdminAPI = CKANUtility.getSysAdminAPI();
CKANGroup ckanGroupToCreate = new CKANGroup();
ckanGroupToCreate.setApiKey(sysAdminAPI);
ckanGroupToCreate.setName(name);
String id = getGroupId(name);
ckanGroupToCreate.setName(id);
ckanGroupToCreate.setTitle(name);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(groups.get(name));
ArrayNode array = (ArrayNode) jsonNode.get("groups");
@ -94,31 +96,41 @@ public class GRSFUtilities extends ContextTest {
groupArray = objectMapper.readValue(groups, String[].class);
}else {
groupArray = new String[] {
"Legacy", "Fishery", "Stock",
"GRSF",
"Abundance Level",
"Abundance Level (FIRMS Standard)",
"Assessment Method",
"Biomass",
"Catch",
"FAO SDG 14.4.1 Questionnaire",
"FAO Stock Status Category",
"FIRMS",
"FishSource",
"RAMLDB",
"FAO SDG 14.4.1 Questionnaire",
"Catch", "Landing", "Assessment Method",
"Abundance Level", "Abundance Level (FIRMS Standard)", "Biomass",
"Fishing Pressure", "Fishing Pressure (FIRMS Standard)", "State and Trend",
"FAO Stock Status Category", "Scientific Advice",
"GRSF SDG Flag", "GRSF Traceability Flag", "Traceability Unit"
};
groupArray = new String[] {
"RAMLDB"
"Fishery",
"Fishing Effort",
"Fishing Pressure",
"Fishing Pressure (FIRMS Standard)",
"GRSF",
"GRSF SDG Flag",
"GRSF Traceability Flag",
"Landing",
"Legacy",
"RAM",
"Scientific Advice",
"State and Trend",
"Stock",
"Traceability Unit"
};
//groupArray = new String[] {};
}
return Arrays.asList(groupArray);
}
@Ignore
// @Ignore
@Test
public void createGRSFGroups() throws ObjectNotFound, Exception {
// Reading groups from a CKAN related to a VRE
ContextTest.setContextByName("");
ContextTest.setContextByName(PREPROD_GRSF_PRE);
String key = CKANUtility.getSysAdminAPI();
@ -136,11 +148,36 @@ public class GRSFUtilities extends ContextTest {
Set<String> createdGroup = new HashSet<>();
// Creating groups in another related to another VRE
ContextTest.setContextByName("");
ContextTest.setContextByName(PRODUCTION_GRSF_PRE);
String sysAdminAPI = CKANUtility.getSysAdminAPI();
for(String name : groupNames) {
create(createdGroup, groups, name);
}
String[] usernames = getUsers();
boolean fromCKAN = true;
Set<String> orgs = getOrganizations().keySet();
for(String username : usernames) {
CKANUser ckanUser = new CKANUser();
ckanUser.setApiKey(sysAdminAPI);
ckanUser.setName(username);
for(String groupName : groupNames) {
if(!fromCKAN) {
groupName = getGroupId(groupName);
}
ckanUser = addUserToGroup(ckanUser, groupName);
}
for(String org : orgs) {
ckanUser = addUserToOrganization(ckanUser, org);
}
}
}
public static String getGroupNameOnCkan(String originalName){
@ -185,9 +222,11 @@ public class GRSFUtilities extends ContextTest {
}
}
@Ignore
//@Ignore
@Test
public void createNewGRSFGroups() throws ObjectNotFound, Exception {
ContextTest.setContextByName(PROD_VRE_GRSF_PRE);
String[] usernames = getUsers();
String sysAdminAPI = CKANUtility.getSysAdminAPI();
@ -232,9 +271,11 @@ public class GRSFUtilities extends ContextTest {
}
}
@Ignore
// @Ignore
@Test
public void deleteGRSFGroups() throws ObjectNotFound, Exception {
ContextTest.setContextByName(PROD_VRE_GRSF_PRE);
String sysAdminAPI = CKANUtility.getSysAdminAPI();
boolean fromCKAN = true;
List<String> groupNames = listGroup(fromCKAN);
@ -250,7 +291,7 @@ public class GRSFUtilities extends ContextTest {
ckanGroupToCreate.setName(name);
try {
// ckanGroupToCreate.purge();
ckanGroupToCreate.purge();
}catch (Exception e) {
logger.error("Error while purging group with name {}", name, e);
}
@ -277,7 +318,7 @@ public class GRSFUtilities extends ContextTest {
}
protected CKANUser addUserToOrganization(CKANUser ckanUser, String orgName) {
ckanUser.addUserToOrganization(orgName, ckanUser.getName(), "admin");
ckanUser.addUserToOrganization(orgName, ckanUser.getName(), "member");
return ckanUser;
}
@ -289,7 +330,7 @@ public class GRSFUtilities extends ContextTest {
// @Ignore
@Test
public void associateUserToAllCKANGroupsAndOrganization() throws ObjectNotFound, Exception {
ContextTest.setContextByName(VRE_GRSF_PRE);
ContextTest.setContextByName(PROD_VRE_GRSF_PRE);
String[] usernames = getUsers();
String sysAdminAPI = CKANUtility.getSysAdminAPI();
boolean fromCKAN = true;
@ -318,9 +359,10 @@ public class GRSFUtilities extends ContextTest {
}
@Ignore
// @Ignore
@Test
public void manageOrganizations() throws JsonProcessingException {
public void manageOrganizations() throws Exception {
ContextTest.setContextByName(PROD_VRE_GRSF_PRE);
String sysAdminAPI = CKANUtility.getSysAdminAPI();
ObjectMapper objectMapper = new ObjectMapper();
@ -344,7 +386,7 @@ public class GRSFUtilities extends ContextTest {
logger.info("Organization {} created successfully", ckanOrganization.getName());
}else {
logger.info("Going to purge organization {}", ckanOrganization.getName());
// ckanOrganization.purge();
ckanOrganization.purge();
logger.info("Organization {} purged successfully", ckanOrganization.getName());
}
}catch (Exception e) {