Fixed traceability unit
This commit is contained in:
parent
1bbf0a2b3d
commit
5854fe741d
|
@ -21,6 +21,8 @@
|
|||
<@metadata key="GRSF Semantic Identifier" namespace=identity_namespace var=grsf_semantic_identifier />
|
||||
<@metadata key="GRSF Type" namespace=identity_namespace var="Traceability Unit" />
|
||||
<@metadata key="Short Name" namespace=identity_namespace var=short_name />
|
||||
<@metadata key="Connected Stock Record" namespace=identity_namespace var=referring_stock_record.url />
|
||||
<@metadata key="Connected Fishery Record" namespace=identity_namespace var=referring_fishery_record.url />
|
||||
<@metadatalist key="Species" namespace=identity_namespace list=species tagValues=true />
|
||||
<@metadatalist key="Assessment Area" namespace=identity_namespace list=assessment_area />
|
||||
<@metadatalist key="Management/Reporting Area" namespace=identity_namespace list=management_reporting_area tagValues=true />
|
||||
|
|
|
@ -40,6 +40,20 @@ public class GRSFUtilities extends ContextTest {
|
|||
|
||||
public static final String PREPROD_GRSF_PRE = "/pred4s/preprod/GRSF_Pre";
|
||||
|
||||
public static final Map<String,String> SOURCE_TO_ID;
|
||||
public static final Map<String,String> ID_TO_SOURCE;
|
||||
|
||||
static {
|
||||
ID_TO_SOURCE = new HashMap<>();
|
||||
ID_TO_SOURCE.put("ram", "RAMLDB");
|
||||
ID_TO_SOURCE.put("sdg", "FAO SDG 14.4.1 Questionnaire");
|
||||
|
||||
SOURCE_TO_ID = new HashMap<>();
|
||||
for(String id : ID_TO_SOURCE.keySet()) {
|
||||
SOURCE_TO_ID.put(ID_TO_SOURCE.get(id), id);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
// ContextTest.setContextByName(PREPROD_GRSF_PRE);
|
||||
|
@ -80,7 +94,12 @@ public class GRSFUtilities extends ContextTest {
|
|||
groupArray = objectMapper.readValue(groups, String[].class);
|
||||
}else {
|
||||
groupArray = new String[] {
|
||||
"GRSF", "Legacy", "Fishery", "Stock", "FIRMS", "FishSource", "RAM",
|
||||
"Legacy", "Fishery", "Stock",
|
||||
"GRSF",
|
||||
"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",
|
||||
|
@ -88,8 +107,8 @@ public class GRSFUtilities extends ContextTest {
|
|||
"GRSF SDG Flag", "GRSF Traceability Flag", "Traceability Unit"
|
||||
};
|
||||
groupArray = new String[] {
|
||||
"Traceability Unit"
|
||||
};
|
||||
"RAMLDB"
|
||||
};
|
||||
}
|
||||
return Arrays.asList(groupArray);
|
||||
}
|
||||
|
@ -124,11 +143,14 @@ public class GRSFUtilities extends ContextTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getGroupNameOnCkan(String origName){
|
||||
if(origName == null) {
|
||||
throw new IllegalArgumentException("origName cannot be null");
|
||||
public static String getGroupNameOnCkan(String originalName){
|
||||
if(originalName == null) {
|
||||
throw new IllegalArgumentException("original Name cannot be null");
|
||||
}
|
||||
String modified = origName.replaceAll("\\(", "");
|
||||
if(SOURCE_TO_ID.containsKey(originalName)) {
|
||||
return SOURCE_TO_ID.get(originalName);
|
||||
}
|
||||
String modified = originalName.replaceAll("\\(", "");
|
||||
modified = modified.replaceAll("\\)", "");
|
||||
modified = modified.trim().toLowerCase().replaceAll("[^A-Za-z0-9-]", "-");
|
||||
if(modified.startsWith("-")) {
|
||||
|
@ -163,7 +185,7 @@ public class GRSFUtilities extends ContextTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Ignore
|
||||
@Test
|
||||
public void createNewGRSFGroups() throws ObjectNotFound, Exception {
|
||||
String[] usernames = getUsers();
|
||||
|
@ -174,12 +196,12 @@ public class GRSFUtilities extends ContextTest {
|
|||
for(String name : groupNames) {
|
||||
CKANGroup ckanGroupToCreate = new CKANGroup();
|
||||
ckanGroupToCreate.setApiKey(sysAdminAPI);
|
||||
name = getGroupId(name);
|
||||
ckanGroupToCreate.setName(name);
|
||||
String id = getGroupId(name);
|
||||
ckanGroupToCreate.setName(id);
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("display_name", name);
|
||||
node.put("title", name);
|
||||
node.put("name", name);
|
||||
node.put("name", id);
|
||||
String json = objectMapper.writeValueAsString(node);
|
||||
logger.info(json);
|
||||
ckanGroupToCreate.create(json);
|
||||
|
@ -189,6 +211,27 @@ public class GRSFUtilities extends ContextTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateGroups() throws ObjectNotFound, Exception {
|
||||
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
||||
List<String> groupNames = listGroup(false);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
for(String name : groupNames) {
|
||||
CKANGroup ckanGroup = new CKANGroup();
|
||||
ckanGroup.setApiKey(sysAdminAPI);
|
||||
ckanGroup.setName(getGroupId(name));
|
||||
String read = ckanGroup.read();
|
||||
|
||||
ObjectNode node = (ObjectNode) objectMapper.readTree(read);
|
||||
node.put("display_name", name);
|
||||
node.put("title", name);
|
||||
|
||||
String json = objectMapper.writeValueAsString(node);
|
||||
logger.info(json);
|
||||
ckanGroup.update(json);
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void deleteGRSFGroups() throws ObjectNotFound, Exception {
|
||||
|
@ -239,13 +282,14 @@ public class GRSFUtilities extends ContextTest {
|
|||
}
|
||||
|
||||
protected String[] getUsers() {
|
||||
String[] usernames = new String[] { "luca_frosini" };
|
||||
String[] usernames = new String[] { "grsf_publisher", "luca_frosini" };
|
||||
return usernames;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Ignore
|
||||
@Test
|
||||
public void associateUserToAllCKANGroupsAndOrganization() throws ObjectNotFound, Exception {
|
||||
ContextTest.setContextByName(VRE_GRSF_PRE);
|
||||
String[] usernames = getUsers();
|
||||
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
||||
boolean fromCKAN = true;
|
||||
|
@ -271,11 +315,7 @@ public class GRSFUtilities extends ContextTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
|
Loading…
Reference in New Issue