Fixing groups assign

This commit is contained in:
Luca Frosini 2022-04-27 15:56:19 +02:00
parent 0458379cb4
commit 745aaf417d
3 changed files with 44 additions and 39 deletions

View File

@ -551,7 +551,7 @@ public class GrsfPublisherFisheryService {
// check system type
boolean isGRSF = !record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY)
.equals(Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
.equals(Constants.SYSTEM_TYPE_LEGACY_RECORD);
if(!isGRSF)
throw new Exception("You are trying to modify a Legacy record!");

View File

@ -554,7 +554,7 @@ public class GrsfPublisherStockService {
// check system type
boolean isGRSF = !record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY)
.equals(Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
.equals(Constants.SYSTEM_TYPE_LEGACY_RECORD);
if(!isGRSF)
throw new Exception("You are trying to modify a Legacy record!");

View File

@ -231,8 +231,8 @@ public class CommonServiceUtils {
StringBuffer stringBuffer = new StringBuffer();
if(prependSource) {
stringBuffer.append(source.toString().toLowerCase());
stringBuffer.append("-");
stringBuffer.append(source.toString());
stringBuffer.append(" ");
}
if(groupNameOverValue.isEmpty()) {
@ -494,8 +494,8 @@ public class CommonServiceUtils {
}
}
// append to groups: we need to add this record to the correspondent group of the sources
addRecordToGroupSources(groups, new ArrayList(sourcesList), productType, sourceInPath);
addRecordToGroups(groups, sourcesList, productType, sourceInPath);
// validate
CommonServiceUtils.validateAggregatedRecord(record, sourceInPath);
@ -508,15 +508,16 @@ public class CommonServiceUtils {
sourceInPath.equals(Sources.GRSF)
? productType.equals(Product_Type.FISHERY) ? ((FisheryRecord) record).getType().getOrigName()
: ((StockRecord) record).getType().getOrigName()
: Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
: Constants.SYSTEM_TYPE_LEGACY_RECORD);
logger.debug("Domain is " + productType.getOrigName() + " and system type " + record.getSystemType());
// evaluate the custom fields/tags, resources and groups
groups.add(productType.getOrigName().toLowerCase()); //i.e. stock or fishery
boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false,
/*
* It has been decided to add tags also for legacy records see #23216
* boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
*/
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, false, groups, false, resources, false,
customFields, record, username, sourceInPath);
}
@ -528,38 +529,42 @@ public class CommonServiceUtils {
* @param productType
* @param sourceInPath
*/
private static void addRecordToGroupSources(Set<String> groups, List<String> sourcesList, Product_Type productType,
Sources sourceInPath) {
Collections.sort(sourcesList); // be sure the name are sorted because the groups have been generated this way
String groupName = sourceInPath.getOrigName().toLowerCase() + "-" + productType.getOrigName().toLowerCase();
for(String source : sourcesList) {
groupName += "-" + source;
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
}
groups.add(groupName);
// 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
* @param apiKey
* @return null on error
* @throws Exception
*/
public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
if(dataset == null)
throw new Exception("Unable to find record with id or name " + itemIdOrName);
String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
if(systemTypeValue == null || systemTypeValue.isEmpty())
throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
else
return systemTypeValue;
}
// /**
// * Fetch the system:type property from a record
// * @param itemIdOrName
// * @param apiKey
// * @return null on error
// * @throws Exception
// */
// public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
// DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
// CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
// if(dataset == null) {
// throw new Exception("Unable to find record with id or name " + itemIdOrName);
// }
// String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
// if(systemTypeValue == null || systemTypeValue.isEmpty()) {
// throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
// }else {
// return systemTypeValue;
// }
//
// }
public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception {
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);