minor changes to timeseries bean
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@151416 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
05de8af64f
commit
202523d031
|
@ -23,7 +23,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
public class Common extends Base{
|
public class Common extends Base{
|
||||||
|
|
||||||
public static final String GRSF_DOMAIN_KEY = "GRSF Domain"; // stock, fishery
|
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
|
// it is added in case of GRSF record
|
||||||
@JsonProperty("data_owner")
|
@JsonProperty("data_owner")
|
||||||
|
@ -64,11 +63,6 @@ public class Common extends Base{
|
||||||
@CustomField(key=GRSF_DOMAIN_KEY)
|
@CustomField(key=GRSF_DOMAIN_KEY)
|
||||||
private String grsfType;
|
private String grsfType;
|
||||||
|
|
||||||
// automatically compiled
|
|
||||||
@JsonProperty("source")
|
|
||||||
@CustomField(key=SOURCE_KEY)
|
|
||||||
private String sourceType;
|
|
||||||
|
|
||||||
@JsonProperty("catches")
|
@JsonProperty("catches")
|
||||||
@CustomField(key="Catches")
|
@CustomField(key="Catches")
|
||||||
@TimeSeries
|
@TimeSeries
|
||||||
|
@ -102,7 +96,6 @@ public class Common extends Base{
|
||||||
* @param traceabilityFlag
|
* @param traceabilityFlag
|
||||||
* @param status
|
* @param status
|
||||||
* @param grsfType
|
* @param grsfType
|
||||||
* @param sourceType
|
|
||||||
* @param catches
|
* @param catches
|
||||||
* @param landings
|
* @param landings
|
||||||
* @param species
|
* @param species
|
||||||
|
@ -113,7 +106,7 @@ public class Common extends Base{
|
||||||
List<Resource<String>> sourceOfInformation,
|
List<Resource<String>> sourceOfInformation,
|
||||||
List<RefersToBean> refersTo, String shortTitle,
|
List<RefersToBean> refersTo, String shortTitle,
|
||||||
Boolean traceabilityFlag, Status status, String grsfType,
|
Boolean traceabilityFlag, Status status, String grsfType,
|
||||||
String sourceType, List<TimeSeriesBean<String, String>> catches,
|
List<TimeSeriesBean<String, String>> catches,
|
||||||
List<TimeSeriesBean<String, String>> landings,
|
List<TimeSeriesBean<String, String>> landings,
|
||||||
List<String> species, List<SimilarRecordBean> similarRecords) {
|
List<String> species, List<SimilarRecordBean> similarRecords) {
|
||||||
super();
|
super();
|
||||||
|
@ -125,7 +118,6 @@ public class Common extends Base{
|
||||||
this.traceabilityFlag = traceabilityFlag;
|
this.traceabilityFlag = traceabilityFlag;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.grsfType = grsfType;
|
this.grsfType = grsfType;
|
||||||
this.sourceType = sourceType;
|
|
||||||
this.catches = catches;
|
this.catches = catches;
|
||||||
this.landings = landings;
|
this.landings = landings;
|
||||||
this.species = species;
|
this.species = species;
|
||||||
|
@ -140,14 +132,6 @@ public class Common extends Base{
|
||||||
this.grsfType = grsfType;
|
this.grsfType = grsfType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSourceType() {
|
|
||||||
return sourceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSourceType(String sourceType) {
|
|
||||||
this.sourceType = sourceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getTraceabilityFlag() {
|
public Boolean getTraceabilityFlag() {
|
||||||
return traceabilityFlag;
|
return traceabilityFlag;
|
||||||
}
|
}
|
||||||
|
@ -246,9 +230,9 @@ public class Common extends Base{
|
||||||
+ sourceOfInformation + ", refersTo=" + refersTo
|
+ sourceOfInformation + ", refersTo=" + refersTo
|
||||||
+ ", shortTitle=" + shortTitle + ", traceabilityFlag="
|
+ ", shortTitle=" + shortTitle + ", traceabilityFlag="
|
||||||
+ traceabilityFlag + ", status=" + status + ", grsfType="
|
+ traceabilityFlag + ", status=" + status + ", grsfType="
|
||||||
+ grsfType + ", sourceType=" + sourceType + ", catches="
|
+ grsfType + ", catches=" + catches + ", landings=" + landings
|
||||||
+ catches + ", landings=" + landings + ", species=" + species
|
+ ", species=" + species + ", similarRecords=" + similarRecords
|
||||||
+ ", similarRecords=" + similarRecords + "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,14 +15,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
|
|
||||||
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 VALUE_FIELD = "value";
|
||||||
public static final String UNIT_FIELD = "unit";
|
public static final String UNIT_FIELD = "unit";
|
||||||
public static final String SOURCE_FIELD = "source";
|
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)
|
@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;
|
private Long year;
|
||||||
|
|
||||||
@JsonProperty(SOURCE_FIELD)
|
@JsonProperty(SOURCE_FIELD)
|
||||||
|
@ -122,12 +122,13 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
String firstPart = "" + year;
|
String value = "" + this.value;
|
||||||
String secondPart = (value != null ? " - " + value : "")
|
String unit = (this.unit != null ? " " + this.unit : "");
|
||||||
+ (unit != null ? " - " + unit : "")
|
String source = (this.source != null ? " (" + this.source + ")" : "");
|
||||||
+ (source != null ? " (" + source + ")" : "")
|
String referenceYear = " Ref. Year " + year;
|
||||||
+ (assessment != null ? " (Ref. year " + assessment + ")" : "");
|
String reportingYearOrAssessment = (assessment != null ? " and Rep. Year or Assessment " + assessment + "" : "");
|
||||||
return firstPart + (secondPart != null && !secondPart.isEmpty() ? secondPart : "");
|
|
||||||
|
return value + unit + source + referenceYear + reportingYearOrAssessment;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -113,8 +114,6 @@ public class CommonServiceUtils {
|
||||||
if((fishingArea == null || fishingArea.isEmpty()) && (jurisdictionArea == null || jurisdictionArea.isEmpty()))
|
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!");
|
throw new Exception("fishing_area and jurisdiction_area cannot be null/empty at the same time!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,8 +261,6 @@ public class CommonServiceUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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{
|
public static void hasAdminRole(String username, DataCatalogue catalogue, String apiKey, String organization) throws Exception{
|
||||||
|
|
||||||
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
|
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
|
||||||
// Iterator<Entry<CkanOrganization, RolesCkanGroupOrOrg>> roles = catalogue.getUserRoleByOrganization(username, apiKey).get(organization).entrySet().iterator();
|
|
||||||
//
|
|
||||||
// while (roles.hasNext()) {
|
|
||||||
// Map.Entry<CkanOrganization, RolesCkanGroupOrOrg> entry = (Map.Entry<CkanOrganization, RolesCkanGroupOrOrg>) roles
|
|
||||||
// .next();
|
|
||||||
// role = RolesCkanGroupOrOrg.convertToCkanCapacity(entry.getValue());
|
|
||||||
// }
|
|
||||||
|
|
||||||
logger.info("Role of the user " + username + " is " + role + " in " + organization);
|
logger.info("Role of the user " + username + " is " + role + " in " + organization);
|
||||||
|
|
||||||
if(role == null || role.isEmpty() || !role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString()))
|
if(role == null || role.isEmpty() || !role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString()))
|
||||||
|
@ -403,7 +392,6 @@ public class CommonServiceUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and check sources
|
* Validate and check sources
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
||||||
* @param apiKey
|
* @param apiKey
|
||||||
* @param context
|
* @param context
|
||||||
* @param contextServlet
|
* @param contextServlet
|
||||||
|
@ -425,19 +413,28 @@ public class CommonServiceUtils {
|
||||||
// Status field is needed only in the Manage context for GRSF records
|
// Status field is needed only in the Manage context for GRSF records
|
||||||
if(context.equals((String)contextServlet.getInitParameter(HelperMethods.MANAGE_CONTEX_KEY))){
|
if(context.equals((String)contextServlet.getInitParameter(HelperMethods.MANAGE_CONTEX_KEY))){
|
||||||
if(sourceInPath.equals(Sources.GRSF)){
|
if(sourceInPath.equals(Sources.GRSF)){
|
||||||
//Evaluate the sources
|
|
||||||
List<Resource<Sources>> recordSources = record.getDatabaseSources();
|
List<RefersToBean> refersTo = record.getRefersTo();
|
||||||
String sources = "";
|
if(refersTo == null || refersTo.isEmpty())
|
||||||
for (Resource<Sources> resource : recordSources) {
|
throw new Exception("refers_to is empty for a GRSF record");
|
||||||
sources += resource.getName() + ", ";
|
|
||||||
|
List<String> sourcesList = new ArrayList<String>();
|
||||||
|
|
||||||
|
// 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);
|
CommonServiceUtils.validateAggregatedRecord(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// set the grsf type: fishery or stock
|
// set the grsf type: fishery or stock
|
||||||
record.setGrsfType(productType.getOrigName());
|
record.setGrsfType(productType.getOrigName());
|
||||||
|
|
||||||
|
@ -446,22 +443,29 @@ public class CommonServiceUtils {
|
||||||
boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
|
boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
|
||||||
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false, customFields, record, username, sourceInPath);
|
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false, customFields, record, username, sourceInPath);
|
||||||
|
|
||||||
// manage the refers to
|
|
||||||
if(sourceInPath.equals(Sources.GRSF)){
|
|
||||||
List<RefersToBean> 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
|
// add the SYSTEM_TYPE
|
||||||
customFields.put(CommonServiceUtils.SYSTEM_TYPE, Arrays.asList(sourceInPath.getOrigName()));
|
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<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;
|
||||||
|
}
|
||||||
|
|
||||||
|
groups.add(groupName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the system:type property from a record
|
* Fetch the system:type property from a record
|
||||||
* @param itemIdOrName
|
* @param itemIdOrName
|
||||||
|
|
|
@ -14,7 +14,8 @@ public enum Abundance_Level {
|
||||||
Uncertain_Not_Assessed("Uncertain/Not assessed"),
|
Uncertain_Not_Assessed("Uncertain/Not assessed"),
|
||||||
Not_applicable("Not applicable"),
|
Not_applicable("Not applicable"),
|
||||||
Pre_exploitation_Or_High_Abundance("Pre-exploitation biomass or high abundance"),
|
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;
|
private String subGroupNameOrig;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ public enum Abundance_Level {
|
||||||
public static Abundance_Level onDeserialize(String abundanceString) {
|
public static Abundance_Level onDeserialize(String abundanceString) {
|
||||||
if(abundanceString != null) {
|
if(abundanceString != null) {
|
||||||
for (Abundance_Level abundanceValue : Abundance_Level.values()) {
|
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;
|
return abundanceValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public enum Exploitation_Rate {
|
||||||
public static Exploitation_Rate onDeserialize(String exploitationString) {
|
public static Exploitation_Rate onDeserialize(String exploitationString) {
|
||||||
if(exploitationString != null) {
|
if(exploitationString != null) {
|
||||||
for (Exploitation_Rate exploitationValue : Exploitation_Rate.values()) {
|
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;
|
return exploitationValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public enum Fishing_Pressure {
|
||||||
public static Fishing_Pressure onDeserialize(String fishing_Pressure) {
|
public static Fishing_Pressure onDeserialize(String fishing_Pressure) {
|
||||||
if(fishing_Pressure != null) {
|
if(fishing_Pressure != null) {
|
||||||
for (Fishing_Pressure fishingPressure : Fishing_Pressure.values()) {
|
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;
|
return fishingPressure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public enum Production_System_Type {
|
||||||
public static Production_System_Type onDeserialize(String productionString) {
|
public static Production_System_Type onDeserialize(String productionString) {
|
||||||
if(productionString != null) {
|
if(productionString != null) {
|
||||||
for (Production_System_Type productionValue : Production_System_Type.values()) {
|
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;
|
return productionValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue