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:
Costantino Perciante 2017-07-28 12:48:46 +00:00
parent 05de8af64f
commit 202523d031
7 changed files with 58 additions and 68 deletions

View File

@ -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<Resource<String>> sourceOfInformation,
List<RefersToBean> refersTo, String shortTitle,
Boolean traceabilityFlag, Status status, String grsfType,
String sourceType, List<TimeSeriesBean<String, String>> catches,
List<TimeSeriesBean<String, String>> catches,
List<TimeSeriesBean<String, String>> landings,
List<String> species, List<SimilarRecordBean> 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
+ "]";
}
}

View File

@ -15,14 +15,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
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 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<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
@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;
}

View File

@ -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<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);
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<Resource<Sources>> recordSources = record.getDatabaseSources();
String sources = "";
for (Resource<Sources> resource : recordSources) {
sources += resource.getName() + ", ";
List<RefersToBean> refersTo = record.getRefersTo();
if(refersTo == null || refersTo.isEmpty())
throw new Exception("refers_to is empty for a GRSF record");
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);
}
}
// 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<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
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
* @param itemIdOrName

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}