diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java index ae637bb..6ac8360 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class Common extends Base{ public static final String GRSF_DOMAIN_KEY = "GRSF Domain"; // stock, fishery - public static final String SOURCE_KEY = "Source"; // in case it is a RAM/FIRMS/FishSource record it is not added // it is added in case of GRSF record @JsonProperty("data_owner") @@ -64,11 +63,6 @@ public class Common extends Base{ @CustomField(key=GRSF_DOMAIN_KEY) private String grsfType; - // automatically compiled - @JsonProperty("source") - @CustomField(key=SOURCE_KEY) - private String sourceType; - @JsonProperty("catches") @CustomField(key="Catches") @TimeSeries @@ -102,7 +96,6 @@ public class Common extends Base{ * @param traceabilityFlag * @param status * @param grsfType - * @param sourceType * @param catches * @param landings * @param species @@ -113,7 +106,7 @@ public class Common extends Base{ List> sourceOfInformation, List refersTo, String shortTitle, Boolean traceabilityFlag, Status status, String grsfType, - String sourceType, List> catches, + List> catches, List> landings, List species, List similarRecords) { super(); @@ -125,7 +118,6 @@ public class Common extends Base{ this.traceabilityFlag = traceabilityFlag; this.status = status; this.grsfType = grsfType; - this.sourceType = sourceType; this.catches = catches; this.landings = landings; this.species = species; @@ -140,14 +132,6 @@ public class Common extends Base{ this.grsfType = grsfType; } - public String getSourceType() { - return sourceType; - } - - public void setSourceType(String sourceType) { - this.sourceType = sourceType; - } - public Boolean getTraceabilityFlag() { return traceabilityFlag; } @@ -246,9 +230,9 @@ public class Common extends Base{ + sourceOfInformation + ", refersTo=" + refersTo + ", shortTitle=" + shortTitle + ", traceabilityFlag=" + traceabilityFlag + ", status=" + status + ", grsfType=" - + grsfType + ", sourceType=" + sourceType + ", catches=" - + catches + ", landings=" + landings + ", species=" + species - + ", similarRecords=" + similarRecords + "]"; + + grsfType + ", catches=" + catches + ", landings=" + landings + + ", species=" + species + ", similarRecords=" + similarRecords + + "]"; } } \ No newline at end of file diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/TimeSeriesBean.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/TimeSeriesBean.java index 2fa6926..f51f56f 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/TimeSeriesBean.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/TimeSeriesBean.java @@ -15,14 +15,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class TimeSeriesBean implements Comparable>{ - public static final String YEAR_FIELD = "year"; + public static final String YEAR_FIELD = "reference_year"; public static final String VALUE_FIELD = "value"; public static final String UNIT_FIELD = "unit"; public static final String SOURCE_FIELD = "source"; - public static final String ASSESSMENT_FIELD = "assessment"; + public static final String ASSESSMENT_FIELD = "reporting_year_or_assessment"; @JsonProperty(YEAR_FIELD) - @NotNull(message="year of a time series cannot be null") + @NotNull(message="reference_year of a time series cannot be null") private Long year; @JsonProperty(SOURCE_FIELD) @@ -122,12 +122,13 @@ public class TimeSeriesBean implements Comparable>{ @Override public String toString() { - String firstPart = "" + year; - String secondPart = (value != null ? " - " + value : "") - + (unit != null ? " - " + unit : "") - + (source != null ? " (" + source + ")" : "") - + (assessment != null ? " (Ref. year " + assessment + ")" : ""); - return firstPart + (secondPart != null && !secondPart.isEmpty() ? secondPart : ""); + String value = "" + this.value; + String unit = (this.unit != null ? " " + this.unit : ""); + String source = (this.source != null ? " (" + this.source + ")" : ""); + String referenceYear = " Ref. Year " + year; + String reportingYearOrAssessment = (assessment != null ? " and Rep. Year or Assessment " + assessment + "" : ""); + + return value + unit + source + referenceYear + reportingYearOrAssessment; } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java index 3e1abe2..ef2a7e7 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java @@ -4,6 +4,7 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -113,8 +114,6 @@ public class CommonServiceUtils { if((fishingArea == null || fishingArea.isEmpty()) && (jurisdictionArea == null || jurisdictionArea.isEmpty())) throw new Exception("fishing_area and jurisdiction_area cannot be null/empty at the same time!"); } - - } /** @@ -261,9 +260,7 @@ public class CommonServiceUtils { logger.error("Failed to read value for field " + field.getName() + " skipping", e); } } - - // add the record among the source group (check for grsf-group) - //groups.add(source.equals(Sources.GRSF) ? CommonServiceUtils.GRSF_GROUP_NAME : source.getOrigName().toLowerCase()); + } /** @@ -363,14 +360,6 @@ public class CommonServiceUtils { public static void hasAdminRole(String username, DataCatalogue catalogue, String apiKey, String organization) throws Exception{ String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey); - // Iterator> roles = catalogue.getUserRoleByOrganization(username, apiKey).get(organization).entrySet().iterator(); - // - // while (roles.hasNext()) { - // Map.Entry entry = (Map.Entry) roles - // .next(); - // role = RolesCkanGroupOrOrg.convertToCkanCapacity(entry.getValue()); - // } - logger.info("Role of the user " + username + " is " + role + " in " + organization); if(role == null || role.isEmpty() || !role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString())) @@ -403,7 +392,6 @@ public class CommonServiceUtils { /** * Validate and check sources - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @param apiKey * @param context * @param contextServlet @@ -425,19 +413,28 @@ public class CommonServiceUtils { // Status field is needed only in the Manage context for GRSF records if(context.equals((String)contextServlet.getInitParameter(HelperMethods.MANAGE_CONTEX_KEY))){ if(sourceInPath.equals(Sources.GRSF)){ - //Evaluate the sources - List> recordSources = record.getDatabaseSources(); - String sources = ""; - for (Resource resource : recordSources) { - sources += resource.getName() + ", "; + + List refersTo = record.getRefersTo(); + if(refersTo == null || refersTo.isEmpty()) + throw new Exception("refers_to is empty for a GRSF record"); + + List sourcesList = new ArrayList(); + + // we have the id within the catalog of this record. This means that we can retrieve the record and its system:type + for (RefersToBean refersToBean : refersTo) { + String sourceSysType = getSystemTypeValue(refersToBean.getId(), apiKey, context); + resources.add(new ResourceBean(refersToBean.getUrl(), sourceSysType , "The source record has id " + refersToBean.getId() + " in the catalog", null, username, null, null)); + sourcesList.add(sourceSysType.toLowerCase()); } - sources = sources.endsWith(", ") ? sources.substring(0, sources.length() -2) : sources; - record.setSourceType(sources); + + // append to groups: we need to add this record to the correspondent group of the sources + addRecordToGroupSources(groups, sourcesList, productType, sourceInPath); + + // validate CommonServiceUtils.validateAggregatedRecord(record); } } - // set the grsf type: fishery or stock record.setGrsfType(productType.getOrigName()); @@ -446,22 +443,29 @@ public class CommonServiceUtils { boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false, customFields, record, username, sourceInPath); - // manage the refers to - if(sourceInPath.equals(Sources.GRSF)){ - List refersTo = record.getRefersTo(); - if(refersTo == null || refersTo.isEmpty()) - throw new Exception("refers_to is empty for a GRSF record"); - - // we have the id within the catalog of this record. This means that we can retrieve the record and its system:type - for (RefersToBean refersToBean : refersTo) { - resources.add(new ResourceBean(refersToBean.getUrl(), getSystemTypeValue(refersToBean.getId(), apiKey, context) , "The source record has id " + refersToBean.getId() + " in the catalog", null, username, null, null)); - } - } - // add the SYSTEM_TYPE customFields.put(CommonServiceUtils.SYSTEM_TYPE, Arrays.asList(sourceInPath.getOrigName())); } + /** + * Add the record to the group of sources + * @param groups + * @param sourcesList + * @param productType + * @param sourceInPath + */ + private static void addRecordToGroupSources(Set groups, + List 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; + } + + groups.add(groupName); + } + /** * Fetch the system:type property from a record * @param itemIdOrName diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Abundance_Level.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Abundance_Level.java index 3457f8a..facd2a8 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Abundance_Level.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Abundance_Level.java @@ -14,7 +14,8 @@ public enum Abundance_Level { Uncertain_Not_Assessed("Uncertain/Not assessed"), Not_applicable("Not applicable"), Pre_exploitation_Or_High_Abundance("Pre-exploitation biomass or high abundance"), - Depleted("Depleted"); + Depleted("Depleted"), + Virgin_Or_High_Abundance("Virgin or High abundance"); private String subGroupNameOrig; @@ -39,7 +40,7 @@ public enum Abundance_Level { public static Abundance_Level onDeserialize(String abundanceString) { if(abundanceString != null) { for (Abundance_Level abundanceValue : Abundance_Level.values()) { - if(abundanceValue.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(abundanceString.replaceAll("[^A-Za-z]", " "))) + if(abundanceValue.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(abundanceString.trim().replaceAll("[^A-Za-z]", " "))) return abundanceValue; } } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Exploitation_Rate.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Exploitation_Rate.java index a6666a1..82747a1 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Exploitation_Rate.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Exploitation_Rate.java @@ -32,7 +32,7 @@ public enum Exploitation_Rate { public static Exploitation_Rate onDeserialize(String exploitationString) { if(exploitationString != null) { for (Exploitation_Rate exploitationValue : Exploitation_Rate.values()) { - if(exploitationValue.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(exploitationString.replaceAll("[^A-Za-z]", " "))) + if(exploitationValue.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(exploitationString.trim().replaceAll("[^A-Za-z]", " "))) return exploitationValue; } } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Fishing_Pressure.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Fishing_Pressure.java index cd9d3b6..87e876e 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Fishing_Pressure.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Fishing_Pressure.java @@ -33,7 +33,7 @@ public enum Fishing_Pressure { public static Fishing_Pressure onDeserialize(String fishing_Pressure) { if(fishing_Pressure != null) { for (Fishing_Pressure fishingPressure : Fishing_Pressure.values()) { - if(fishingPressure.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(fishing_Pressure.replaceAll("[^A-Za-z]", " "))) + if(fishingPressure.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(fishing_Pressure.trim().replaceAll("[^A-Za-z]", " "))) return fishingPressure; } } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Production_System_Type.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Production_System_Type.java index 5404825..c9bd118 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Production_System_Type.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Production_System_Type.java @@ -41,7 +41,7 @@ public enum Production_System_Type { public static Production_System_Type onDeserialize(String productionString) { if(productionString != null) { for (Production_System_Type productionValue : Production_System_Type.values()) { - if(productionValue.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(productionString.replaceAll("[^A-Za-z]", " "))) + if(productionValue.getOrigName().replaceAll("[^A-Za-z]", " ").equalsIgnoreCase(productionString.trim().replaceAll("[^A-Za-z]", " "))) return productionValue; } }