Improved code

This commit is contained in:
Luca Frosini 2022-09-12 16:53:39 +02:00
parent 1f52f9e5df
commit f13a36c1c6
1 changed files with 24 additions and 7 deletions

View File

@ -154,7 +154,7 @@ public class GRSFUtilities extends ContextTest {
} }
@Test // @Test
public void createNewGRSFGroups() throws ObjectNotFound, Exception { public void createNewGRSFGroups() throws ObjectNotFound, Exception {
String sysAdminAPI = CKANUtility.getSysAdminAPI(); String sysAdminAPI = CKANUtility.getSysAdminAPI();
String[] groupNames = new String[] { String[] groupNames = new String[] {
@ -238,18 +238,25 @@ public class GRSFUtilities extends ContextTest {
// @Test // @Test
public void manageOrganizations() throws JsonProcessingException { public void manageOrganizations() throws JsonProcessingException {
String context = SecretManagerProvider.instance.get().getContext();
ScopeBean scopeBean = new ScopeBean(context);
String sysAdminAPI = CKANUtility.getSysAdminAPI(); String sysAdminAPI = CKANUtility.getSysAdminAPI();
String[] organizations = new String[] { Map<String, String> organizations = new HashMap<>();
"GRSF_Pre", "FIRMS", "FishSource", "RAM" organizations.put(scopeBean.name(), scopeBean.name());
}; organizations.put("FIRMS", "FIRMS");
organizations.put("FishSource", "FishSource");
organizations.put("RAM", "RAM");
organizations.put("SDG", "FAO SDG 14.4.1 Questionnaire");
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
for(String org : organizations) { for(String org : organizations.keySet()) {
CKANOrganization ckanOrganization = new CKANOrganization(); CKANOrganization ckanOrganization = new CKANOrganization();
ckanOrganization.setApiKey(sysAdminAPI); ckanOrganization.setApiKey(sysAdminAPI);
ckanOrganization.setName(org.toLowerCase()); ckanOrganization.setName(org.toLowerCase());
ObjectNode node = objectMapper.createObjectNode(); ObjectNode node = objectMapper.createObjectNode();
node.put("display_name", org); String fancyName = organizations.get(org);
node.put("title", org); node.put("display_name", fancyName);
node.put("title", fancyName);
node.put("name", org.toLowerCase()); node.put("name", org.toLowerCase());
String json = objectMapper.writeValueAsString(node); String json = objectMapper.writeValueAsString(node);
try { try {
@ -404,4 +411,14 @@ public class GRSFUtilities extends ContextTest {
purgeGRSFRecords(100, 0); purgeGRSFRecords(100, 0);
} }
@Test
public void purgeSpecificGRSFRecord() throws Exception {
CKANPackage ckanPackage = new CKANPackage();
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<String,String>();
UriInfo uriInfo = CKANPackageTest.getUriInfo(mvm);
ckanPackage.setUriInfo(uriInfo);
ckanPackage.setName("70ae6895-7d3d-4f4a-86f9-bcb17d41bff6");
ckanPackage.purgeNoCheckNoDeleteFiles();
}
} }