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 // check system type
boolean isGRSF = !record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY) 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) if(!isGRSF)
throw new Exception("You are trying to modify a Legacy record!"); throw new Exception("You are trying to modify a Legacy record!");

View File

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

View File

@ -231,8 +231,8 @@ public class CommonServiceUtils {
StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer = new StringBuffer();
if(prependSource) { if(prependSource) {
stringBuffer.append(source.toString().toLowerCase()); stringBuffer.append(source.toString());
stringBuffer.append("-"); stringBuffer.append(" ");
} }
if(groupNameOverValue.isEmpty()) { 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 addRecordToGroups(groups, sourcesList, productType, sourceInPath);
addRecordToGroupSources(groups, new ArrayList(sourcesList), productType, sourceInPath);
// validate // validate
CommonServiceUtils.validateAggregatedRecord(record, sourceInPath); CommonServiceUtils.validateAggregatedRecord(record, sourceInPath);
@ -508,15 +508,16 @@ public class CommonServiceUtils {
sourceInPath.equals(Sources.GRSF) sourceInPath.equals(Sources.GRSF)
? productType.equals(Product_Type.FISHERY) ? ((FisheryRecord) record).getType().getOrigName() ? productType.equals(Product_Type.FISHERY) ? ((FisheryRecord) record).getType().getOrigName()
: ((StockRecord) 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()); 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); customFields, record, username, sourceInPath);
} }
@ -528,38 +529,42 @@ public class CommonServiceUtils {
* @param productType * @param productType
* @param sourceInPath * @param sourceInPath
*/ */
private static void addRecordToGroupSources(Set<String> groups, List<String> sourcesList, Product_Type productType, private static void addRecordToGroups(Set<String> groups, Set<String> sourcesList, Product_Type productType, Sources sourceInPath) {
Sources sourceInPath) { if(sourceInPath == Sources.GRSF) {
groups.add(HelperMethods.getGroupNameOnCkan(Sources.GRSF.getOrigName())); // i.e. grsf
Collections.sort(sourcesList); // be sure the name are sorted because the groups have been generated this way }else {
String groupName = sourceInPath.getOrigName().toLowerCase() + "-" + productType.getOrigName().toLowerCase(); groups.add(HelperMethods.getGroupNameOnCkan(Constants.SYSTEM_TYPE_LEGACY_RECORD)); // i.e. legacy
for(String source : sourcesList) {
groupName += "-" + source;
} }
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 // * Fetch the system:type property from a record
* @param itemIdOrName // * @param itemIdOrName
* @param apiKey // * @param apiKey
* @return null on error // * @return null on error
* @throws Exception // * @throws Exception
*/ // */
public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception { // public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
// DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context); // CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey); // if(dataset == null) {
if(dataset == null) // throw new Exception("Unable to find record with id or name " + itemIdOrName);
throw new Exception("Unable to find record with id or name " + itemIdOrName); // }
String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY); // String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
if(systemTypeValue == null || systemTypeValue.isEmpty()) // if(systemTypeValue == null || systemTypeValue.isEmpty()) {
throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName); // throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
else // }else {
return systemTypeValue; // return systemTypeValue;
// }
} //
// }
public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception { public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception {
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context); DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);