Added _group as suffix of group id
This commit is contained in:
parent
d316a10887
commit
13097d3ab9
|
@ -218,6 +218,43 @@ public class CommonServiceUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static final String GROUP_SUFFIX = "_group";
|
||||
|
||||
/**
|
||||
* Convert a group name to its id on ckan
|
||||
* @param origName
|
||||
* @return
|
||||
*/
|
||||
private static String getGroupIDOnCkan(String origName){
|
||||
if(origName == null) {
|
||||
throw new IllegalArgumentException("origName cannot be null");
|
||||
}
|
||||
String modified = origName.replaceAll("\\(", "");
|
||||
modified = modified.replaceAll("\\)", "");
|
||||
modified = modified.trim().toLowerCase().replaceAll("[^A-Za-z0-9-]", "-");
|
||||
if(modified.startsWith("-")) {
|
||||
modified = modified.substring(1);
|
||||
}
|
||||
if(modified.endsWith("-")) {
|
||||
modified = modified.substring(0, modified.length() -1);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static String getGroupId(String groupName) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(groupName);
|
||||
/*
|
||||
* The "_group" suffix is added to all groups to
|
||||
* avoid issues on groups and organizations having the same name
|
||||
* e.g. RAM organization (id=ram) and RAM group (id=ram_group)
|
||||
*/
|
||||
if(!groupName.endsWith(GROUP_SUFFIX)) {
|
||||
stringBuffer.append(GROUP_SUFFIX);
|
||||
}
|
||||
return getGroupIDOnCkan(stringBuffer.toString());
|
||||
}
|
||||
|
||||
private static void addGroup(Group group, Sources source, String value, Set<String> groups) {
|
||||
String conditionToCheck = group.condition();
|
||||
String groupNameOverValue = group.groupNameOverValue();
|
||||
|
@ -227,27 +264,44 @@ public class CommonServiceUtils {
|
|||
: value.matches(conditionToCheck);
|
||||
|
||||
if(match) {
|
||||
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
|
||||
if(prependSource) {
|
||||
stringBuffer.append(source.toString());
|
||||
stringBuffer.append(" ");
|
||||
}
|
||||
|
||||
if(groupNameOverValue.isEmpty()) {
|
||||
stringBuffer.append(value);
|
||||
}else {
|
||||
stringBuffer.append(groupNameOverValue);
|
||||
}
|
||||
|
||||
String groupName = HelperMethods.getGroupNameOnCkan(stringBuffer.toString());
|
||||
|
||||
groups.add(groupName);
|
||||
String groupId = getGroupId(stringBuffer.toString());
|
||||
groups.add(groupId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the record to the group of sources
|
||||
* @param groups
|
||||
* @param sourcesList
|
||||
* @param productType
|
||||
* @param sourceInPath
|
||||
*/
|
||||
private static void addRecordToGroups(Set<String> groups, Set<String> sourcesList, Product_Type productType, Sources sourceInPath) {
|
||||
if(sourceInPath == Sources.GRSF) {
|
||||
groups.add(getGroupId(Sources.GRSF.getOrigName())); // i.e. grsf_group
|
||||
}else {
|
||||
groups.add(getGroupId(Constants.SYSTEM_TYPE_LEGACY_RECORD)); // i.e. legacy_group
|
||||
}
|
||||
|
||||
// evaluate the custom fields/tags, resources and groups
|
||||
groups.add(getGroupId(productType.getOrigName())); //i.e. stock_group or fishery_group
|
||||
|
||||
for(String source : sourcesList) {
|
||||
groups.add(getGroupId(source)); // i.e. firms_group, fishsource_group, ram_group
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of groups' names for this object
|
||||
*/
|
||||
|
@ -522,28 +576,6 @@ public class CommonServiceUtils {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the record to the group of sources
|
||||
* @param groups
|
||||
* @param sourcesList
|
||||
* @param productType
|
||||
* @param sourceInPath
|
||||
*/
|
||||
private static void addRecordToGroups(Set<String> groups, Set<String> sourcesList, Product_Type productType, Sources sourceInPath) {
|
||||
if(sourceInPath == Sources.GRSF) {
|
||||
groups.add(HelperMethods.getGroupNameOnCkan(Sources.GRSF.getOrigName())); // i.e. grsf
|
||||
}else {
|
||||
groups.add(HelperMethods.getGroupNameOnCkan(Constants.SYSTEM_TYPE_LEGACY_RECORD)); // i.e. legacy
|
||||
}
|
||||
|
||||
// evaluate the custom fields/tags, resources and groups
|
||||
groups.add(HelperMethods.getGroupNameOnCkan(productType.getOrigName())); //i.e. stock or fishery
|
||||
|
||||
for(String source : sourcesList) {
|
||||
groups.add(HelperMethods.getGroupNameOnCkan(source)); // i.e. FIRMS, FishSource, RAM
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Fetch the system:type property from a record
|
||||
// * @param itemIdOrName
|
||||
|
|
|
@ -80,27 +80,6 @@ public abstract class HelperMethods {
|
|||
private static CacheInterface<String, Map<String, String>> namespacesCache = new CacheImpl<String, Map<String, String>>(1000 * 60 * 60 * 24);
|
||||
private static CacheInterface<String, DataCatalogue> catalogueCache = new CacheImpl<String, DataCatalogue>(1000 * 60 * 60 * 24);
|
||||
|
||||
/**
|
||||
* Convert a group name to its id on ckan
|
||||
* @param origName
|
||||
* @return
|
||||
*/
|
||||
public static String getGroupNameOnCkan(String origName){
|
||||
if(origName == null) {
|
||||
throw new IllegalArgumentException("origName cannot be null");
|
||||
}
|
||||
String modified = origName.replaceAll("\\(", "");
|
||||
modified = modified.replaceAll("\\)", "");
|
||||
modified = modified.trim().toLowerCase().replaceAll("[^A-Za-z0-9-]", "-");
|
||||
if(modified.startsWith("-")) {
|
||||
modified = modified.substring(1);
|
||||
}
|
||||
if(modified.endsWith("-")) {
|
||||
modified = modified.substring(0, modified.length() -1);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the running instance of the data catalogue for this scope
|
||||
* @return
|
||||
|
|
Loading…
Reference in New Issue