some model changes

fao_state added (it's a new time series)
catches/landings separated
reference_year added
reporting_year is now a list
narrative_state_and_trend changed (is a time series)

species is a series with code, system and name (no longer species code and name separated)
assessment_distribution_area is now a list with objects having code, system, name 
assessment_methods  changed as list having name, reference_year and reporting_year_or_assessment

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@150670 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-06-30 13:32:38 +00:00
parent 679e6097d8
commit 00e2a6c6fc
8 changed files with 117 additions and 142 deletions

View File

@ -61,7 +61,11 @@ public class Common extends Base{
@JsonProperty("reporting_year") @JsonProperty("reporting_year")
@CustomField(key="Reporting year") @CustomField(key="Reporting year")
private Long reportingYear; private List<Long> reportingYear;
@JsonProperty("reference_year")
@CustomField(key="Reference year")
private List<Long> referenceYear;
// automatically compiled // automatically compiled
@JsonProperty("grsf_type") @JsonProperty("grsf_type")
@ -75,21 +79,27 @@ public class Common extends Base{
@CustomField(key=SOURCE_KEY) @CustomField(key=SOURCE_KEY)
private String sourceType; private String sourceType;
@JsonProperty("catches_or_landings") @JsonProperty("catches")
@CustomField(key="Catches or landings") @CustomField(key="Catches")
@TimeSeries @TimeSeries
@Valid @Valid
private List<TimeSeriesBean<String, String>> catchesOrLandings; private List<TimeSeriesBean<String, String>> catches;
@JsonProperty("species_name") @JsonProperty("landings")
@CustomField(key="Species Scientific Name") @CustomField(key="Landings")
@Tag @TimeSeries
private List<String> speciesName; @Valid
private List<TimeSeriesBean<String, String>> landings;
@JsonProperty("species_code") @JsonProperty("species")
@CustomField(key="Species code") @CustomField(key="species")
@Tag private List<String> species;
private List<String> speciesCode;
@JsonProperty("fao_state")
@CustomField(key="Fao State")
@TimeSeries
@Valid
private List<TimeSeriesBean<String, Void>> faoState;
public Common() { public Common() {
super(); super();
@ -104,19 +114,22 @@ public class Common extends Base{
* @param traceabilityFlag * @param traceabilityFlag
* @param status * @param status
* @param reportingYear * @param reportingYear
* @param referenceYear
* @param grsfType * @param grsfType
* @param sourceType * @param sourceType
* @param catchesOrLandings * @param catches
* @param speciesName * @param landings
* @param speciesCode * @param species
* @param faoState
*/ */
public Common(String dataOwner, List<Resource<Sources>> databaseSources, public Common(String dataOwner, List<Resource<Sources>> databaseSources,
List<Resource<String>> sourceOfInformation, List<Resource<String>> sourceOfInformation,
List<RefersToBean> refersTo, String shortTitle, List<RefersToBean> refersTo, String shortTitle,
Boolean traceabilityFlag, Status status, Long reportingYear, Boolean traceabilityFlag, Status status, List<Long> reportingYear,
String grsfType, String sourceType, List<Long> referenceYear, String grsfType, String sourceType,
List<TimeSeriesBean<String, String>> catchesOrLandings, List<TimeSeriesBean<String, String>> catches,
List<String> speciesName, List<String> speciesCode) { List<TimeSeriesBean<String, String>> landings,
List<String> species, List<TimeSeriesBean<String, Void>> faoState) {
super(); super();
this.dataOwner = dataOwner; this.dataOwner = dataOwner;
this.databaseSources = databaseSources; this.databaseSources = databaseSources;
@ -126,11 +139,13 @@ public class Common extends Base{
this.traceabilityFlag = traceabilityFlag; this.traceabilityFlag = traceabilityFlag;
this.status = status; this.status = status;
this.reportingYear = reportingYear; this.reportingYear = reportingYear;
this.referenceYear = referenceYear;
this.grsfType = grsfType; this.grsfType = grsfType;
this.sourceType = sourceType; this.sourceType = sourceType;
this.catchesOrLandings = catchesOrLandings; this.catches = catches;
this.speciesName = speciesName; this.landings = landings;
this.speciesCode = speciesCode; this.species = species;
this.faoState = faoState;
} }
public String getGrsfType() { public String getGrsfType() {
@ -165,11 +180,11 @@ public class Common extends Base{
this.refersTo = refersTo; this.refersTo = refersTo;
} }
public Long getReportingYear() { public List<Long> getReportingYear() {
return reportingYear; return reportingYear;
} }
public void setReportingYear(Long reportingYear) { public void setReportingYear(List<Long> reportingYear) {
this.reportingYear = reportingYear; this.reportingYear = reportingYear;
} }
@ -221,30 +236,44 @@ public class Common extends Base{
this.status = status; this.status = status;
} }
public List<String> getSpecies() {
public List<TimeSeriesBean<String, String>> getCatchesOrLandings() { return species;
return catchesOrLandings;
} }
public void setCatchesOrLandings( public void setSpecies(List<String> species) {
List<TimeSeriesBean<String, String>> catchesOrLandings) { this.species = species;
this.catchesOrLandings = catchesOrLandings;
} }
public List<String> getSpeciesName() { public List<TimeSeriesBean<String, String>> getCatches() {
return speciesName; return catches;
} }
public void setSpeciesName(List<String> speciesName) { public void setCatches(List<TimeSeriesBean<String, String>> catches) {
this.speciesName = speciesName; this.catches = catches;
} }
public List<String> getSpeciesCode() { public List<TimeSeriesBean<String, String>> getLandings() {
return speciesCode; return landings;
} }
public void setSpeciesCode(List<String> speciesCode) { public void setLandings(List<TimeSeriesBean<String, String>> landings) {
this.speciesCode = speciesCode; this.landings = landings;
}
public List<Long> getReferenceYear() {
return referenceYear;
}
public void setReferenceYear(List<Long> referenceYear) {
this.referenceYear = referenceYear;
}
public List<TimeSeriesBean<String, Void>> getFaoState() {
return faoState;
}
public void setFaoState(List<TimeSeriesBean<String, Void>> faoState) {
this.faoState = faoState;
} }
@Override @Override
@ -254,10 +283,10 @@ public class Common extends Base{
+ sourceOfInformation + ", refersTo=" + refersTo + sourceOfInformation + ", refersTo=" + refersTo
+ ", shortTitle=" + shortTitle + ", traceabilityFlag=" + ", shortTitle=" + shortTitle + ", traceabilityFlag="
+ traceabilityFlag + ", status=" + status + ", reportingYear=" + traceabilityFlag + ", status=" + status + ", reportingYear="
+ reportingYear + ", grsfType=" + grsfType + ", sourceType=" + reportingYear + ", referenceYear=" + referenceYear
+ sourceType + ", catchesOrLandings=" + catchesOrLandings + ", grsfType=" + grsfType + ", sourceType=" + sourceType
+ ", speciesName=" + speciesName + ", speciesCode=" + ", catches=" + catches + ", landings=" + landings
+ speciesCode + "]"; + ", species=" + species + ", faoState=" + faoState + "]";
} }
} }

View File

@ -34,14 +34,8 @@ public class StockRecord extends Common{
@CustomField(key="Stock id") @CustomField(key="Stock id")
private String stockId; private String stockId;
// @JsonProperty("species")
// @CustomField(key="Species")
// @Tag
// private List<String> species;
@JsonProperty("assessment_distribution_area") @JsonProperty("assessment_distribution_area")
@CustomField(key="Assessment distribution area") @CustomField(key="Assessment distribution area")
@Tag
private List<String> area; private List<String> area;
@JsonProperty("exploiting_fishery") @JsonProperty("exploiting_fishery")
@ -55,7 +49,7 @@ public class StockRecord extends Common{
@JsonProperty("assessment_methods") @JsonProperty("assessment_methods")
@CustomField(key="Assessment methods") @CustomField(key="Assessment methods")
private String assessmentMethods; private List<String> assessmentMethods;
@JsonProperty("state_of_marine_resource") @JsonProperty("state_of_marine_resource")
@CustomField(key="State of marine resources") @CustomField(key="State of marine resources")
@ -99,9 +93,9 @@ public class StockRecord extends Common{
@Valid @Valid
private List<TimeSeriesBean<String, String>> fishingPressure; private List<TimeSeriesBean<String, String>> fishingPressure;
@JsonProperty("narrative_state_and_trend") @JsonProperty("narrative_state")
@CustomField(key="Narrative state and trend") @CustomField(key="Narrative state")
private String narrativeStateAndTrend; private List<TimeSeriesBean<String, Void>> narrativeState;
@JsonProperty("scientific_advice") @JsonProperty("scientific_advice")
@CustomField(key="Scientific advice") @CustomField(key="Scientific advice")
@ -123,7 +117,6 @@ public class StockRecord extends Common{
@JsonProperty("type") @JsonProperty("type")
@CustomField(key="Type") @CustomField(key="Type")
//@Tag
@Group @Group
private Stock_Type type; private Stock_Type type;
@ -132,10 +125,8 @@ public class StockRecord extends Common{
} }
/** /**
* Create a Stock element.
* @param stockName * @param stockName
* @param stockID * @param stockId
* @param species
* @param area * @param area
* @param exploitingFishery * @param exploitingFishery
* @param managementEntity * @param managementEntity
@ -145,10 +136,11 @@ public class StockRecord extends Common{
* @param exploitationRate * @param exploitationRate
* @param abundanceLevelStandard * @param abundanceLevelStandard
* @param abundanceLevel * @param abundanceLevel
* @param narrativeStateAndTrend * @param fishingPressureStandard
* @param fishingPressure
* @param narrativeState
* @param scientificAdvice * @param scientificAdvice
* @param reportingEntity * @param assessor
* @param reportingYear
* @param stockUri * @param stockUri
* @param waterArea * @param waterArea
* @param type * @param type
@ -156,23 +148,23 @@ public class StockRecord extends Common{
public StockRecord( public StockRecord(
String stockName, String stockName,
String stockId, String stockId,
//List<String> species,
List<String> area, List<String> area,
List<String> exploitingFishery, List<String> exploitingFishery,
String managementEntity, String managementEntity,
String assessmentMethods, List<String> assessmentMethods,
String stateOfMarineResource, String stateOfMarineResource,
List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard, List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard,
List<TimeSeriesBean<String, String>> exploitationRate, List<TimeSeriesBean<String, String>> exploitationRate,
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard, List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard,
List<TimeSeriesBean<String, String>> abundanceLevel, List<TimeSeriesBean<String, String>> abundanceLevel,
String narrativeStateAndTrend, String scientificAdvice, List<TimeSeriesBean<String, Void>> fishingPressureStandard,
String assessor, Long reportingYear, String stockUri, List<TimeSeriesBean<String, String>> fishingPressure,
List<TimeSeriesBean<String, Void>> narrativeState,
String scientificAdvice, String assessor, String stockUri,
List<String> waterArea, Stock_Type type) { List<String> waterArea, Stock_Type type) {
super(); super();
this.stockName = stockName; this.stockName = stockName;
this.stockId = stockId; this.stockId = stockId;
//this.species = species;
this.area = area; this.area = area;
this.exploitingFishery = exploitingFishery; this.exploitingFishery = exploitingFishery;
this.managementEntity = managementEntity; this.managementEntity = managementEntity;
@ -182,7 +174,9 @@ public class StockRecord extends Common{
this.exploitationRate = exploitationRate; this.exploitationRate = exploitationRate;
this.abundanceLevelStandard = abundanceLevelStandard; this.abundanceLevelStandard = abundanceLevelStandard;
this.abundanceLevel = abundanceLevel; this.abundanceLevel = abundanceLevel;
this.narrativeStateAndTrend = narrativeStateAndTrend; this.fishingPressureStandard = fishingPressureStandard;
this.fishingPressure = fishingPressure;
this.narrativeState = narrativeState;
this.scientificAdvice = scientificAdvice; this.scientificAdvice = scientificAdvice;
this.assessor = assessor; this.assessor = assessor;
this.stockUri = stockUri; this.stockUri = stockUri;
@ -190,6 +184,10 @@ public class StockRecord extends Common{
this.type = type; this.type = type;
} }
public void setAssessmentMethods(List<String> assessmentMethods) {
this.assessmentMethods = assessmentMethods;
}
public Stock_Type getType() { public Stock_Type getType() {
return type; return type;
} }
@ -230,14 +228,6 @@ public class StockRecord extends Common{
this.stockId = stockId; this.stockId = stockId;
} }
// public List<String> getSpecies() {
// return species;
// }
//
// public void setSpecies(List<String> species) {
// this.species = species;
// }
public List<String> getArea() { public List<String> getArea() {
return area; return area;
} }
@ -280,14 +270,6 @@ public class StockRecord extends Common{
this.managementEntity = managementEntity; this.managementEntity = managementEntity;
} }
public String getAssessmentMethods() {
return assessmentMethods;
}
public void setAssessmentMethods(String assessmentMethods) {
this.assessmentMethods = assessmentMethods;
}
public String getStateOfMarineResource() { public String getStateOfMarineResource() {
return stateOfMarineResource; return stateOfMarineResource;
} }
@ -323,12 +305,12 @@ public class StockRecord extends Common{
this.abundanceLevel = abundanceLevel; this.abundanceLevel = abundanceLevel;
} }
public String getNarrativeStateAndTrend() { public List<TimeSeriesBean<String, Void>> getNarrativeState() {
return narrativeStateAndTrend; return narrativeState;
} }
public void setNarrativeStateAndTrend(String narrativeStateAndTrend) { public void setNarrativeState(List<TimeSeriesBean<String, Void>> narrativeState) {
this.narrativeStateAndTrend = narrativeStateAndTrend; this.narrativeState = narrativeState;
} }
public String getScientificAdvice() { public String getScientificAdvice() {
@ -368,11 +350,10 @@ public class StockRecord extends Common{
+ ", abundanceLevelStandard=" + abundanceLevelStandard + ", abundanceLevelStandard=" + abundanceLevelStandard
+ ", abundanceLevel=" + abundanceLevel + ", abundanceLevel=" + abundanceLevel
+ ", fishingPressureStandard=" + fishingPressureStandard + ", fishingPressureStandard=" + fishingPressureStandard
+ ", fishingPressure=" + fishingPressure + ", fishingPressure=" + fishingPressure + ", narrativeState="
+ ", narrativeStateAndTrend=" + narrativeStateAndTrend + narrativeState + ", scientificAdvice=" + scientificAdvice
+ ", scientificAdvice=" + scientificAdvice + ", assessor=" + ", assessor=" + assessor + ", stockUri=" + stockUri
+ assessor + ", stockUri=" + stockUri + ", waterArea=" + ", waterArea=" + waterArea + ", type=" + type + "]";
+ waterArea + ", type=" + type + "]";
} }
} }

View File

@ -87,10 +87,9 @@ public class CommonServiceUtils {
if(record.getClass().equals(StockRecord.class)){ if(record.getClass().equals(StockRecord.class)){
StockRecord stock = (StockRecord) record; StockRecord stock = (StockRecord) record;
List<String> speciesNames = stock.getSpeciesName(); List<String> species = stock.getSpecies();
List<String> speciesCodes = stock.getSpeciesCode(); if(species == null || species.isEmpty())
if(speciesNames == null || speciesNames.isEmpty() || speciesCodes == null || speciesCodes.isEmpty()) throw new Exception("species cannot be null/empty in a GRSF record");
throw new Exception("species name/code cannot be null/empty in a GRSF record");
} }
// check if it is a stock and perform related checks // check if it is a stock and perform related checks

View File

@ -291,14 +291,14 @@ public class GrsfPublisherFisheryService {
// write a post if the product has been published in grsf context // write a post if the product has been published in grsf context
if(context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){ if(context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){
new WritePostCatalogueManagerThread( /*new WritePostCatalogueManagerThread(
context, context,
token, token,
futureTitle, futureTitle,
itemUrl, itemUrl,
false, false,
new ArrayList<String>(), new ArrayList<String>(),
authorFullname).start(); authorFullname).start();*/
logger.info("Thread to write a post about the new product has been launched"); logger.info("Thread to write a post about the new product has been launched");
} }

View File

@ -288,7 +288,7 @@ public class GrsfPublisherStockService {
// write a post if the product has been published in grsf context // write a post if the product has been published in grsf context
if(context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){ if(context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){
new WritePostCatalogueManagerThread( /*new WritePostCatalogueManagerThread(
context, context,
token, token,
futureTitle, futureTitle,
@ -296,7 +296,7 @@ public class GrsfPublisherStockService {
false, false,
new ArrayList<String>(), new ArrayList<String>(),
authorFullname).start(); authorFullname).start();
logger.info("Thread to write a post about the new product has been launched"); logger.info("Thread to write a post about the new product has been launched");*/
} }
}else }else

View File

@ -17,7 +17,7 @@ public class CacheImpl <K, V> implements CacheInterface<K, V> {
/** /**
* The hashmap * The hashmap
*/ */
private Map<K, CacheValueBean<V>> userSpaceMap; private Map<K, CacheValueBean<V>> cache;
/** /**
* Cache entry expires after EXPIRED_AFTER ms * Cache entry expires after EXPIRED_AFTER ms
@ -26,16 +26,16 @@ public class CacheImpl <K, V> implements CacheInterface<K, V> {
public CacheImpl(long timeout){ public CacheImpl(long timeout){
ttl = timeout; ttl = timeout;
userSpaceMap = new ConcurrentHashMap<>(); cache = new ConcurrentHashMap<>();
} }
@Override @Override
public V get(K key) { public V get(K key) {
if(userSpaceMap.containsKey(key)){ if(cache.containsKey(key)){
CacheValueBean<V> bean = userSpaceMap.get(key); CacheValueBean<V> bean = cache.get(key);
if(CacheUtilities.expired(bean.getTTL(), ttl)){ if(CacheUtilities.expired(bean.getTTL(), ttl)){
userSpaceMap.remove(key); cache.remove(key);
logger.debug("Amount of space in the infrastructure used expired for key " + key + ", returning null"); logger.debug("Amount of space in the infrastructure used expired for key " + key + ", returning null");
} }
else else
@ -47,7 +47,7 @@ public class CacheImpl <K, V> implements CacheInterface<K, V> {
@Override @Override
public boolean insert(K key, V obj) { public boolean insert(K key, V obj) {
CacheValueBean<V> newBean = new CacheValueBean<V>(obj, System.currentTimeMillis()); CacheValueBean<V> newBean = new CacheValueBean<V>(obj, System.currentTimeMillis());
userSpaceMap.put(key, newBean); cache.put(key, newBean);
return true; return true;
} }
} }

View File

@ -27,16 +27,16 @@
<context-param> <context-param>
<description>Context of pending products under manage activities</description> <description>Context of pending products under manage activities</description>
<param-name>ManageVRE</param-name> <param-name>ManageVRE</param-name>
<param-value>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</param-value> <!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</param-value> -->
<!-- <param-value>/gcube/devNext/NextNext</param-value> --> <param-value>/gcube/devNext/NextNext</param-value>
<!-- <param-value>/gcube/preprod/Dorne</param-value> --> <!-- <param-value>/gcube/preprod/Dorne</param-value> -->
</context-param> </context-param>
<context-param> <context-param>
<description>Context of products no longer under manage activities</description> <description>Context of products no longer under manage activities</description>
<param-name>PublicVRE</param-name> <param-name>PublicVRE</param-name>
<param-value>/d4science.research-infrastructures.eu/FARM/GRSF</param-value> <!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF</param-value> -->
<!-- <param-value>/gcube/devNext/NextNext</param-value> --> <param-value>/gcube/devNext/NextNext</param-value>
<!-- <param-value>/gcube/preprod/preVRE</param-value> --> <!-- <param-value>/gcube/preprod/preVRE</param-value> -->
</context-param> </context-param>

View File

@ -8,7 +8,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -289,39 +288,6 @@ public class JTests {
instance.uploadResourceFile(csvFile, datasetName, instance.getApiKeyFromUsername("costantino.perciante"), "random_name.csv", null); instance.uploadResourceFile(csvFile, datasetName, instance.getApiKeyFromUsername("costantino.perciante"), "random_name.csv", null);
} }
//@Test
public void testlist() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException{
FisheryRecord record = new FisheryRecord();
ArrayList<TimeSeriesBean<String, String>> list = new ArrayList<TimeSeriesBean<String,String>>();
list.add(new TimeSeriesBean<String, String>("as", 65445L, "asd"));
record.setCatchesOrLandings(list);
Class<?> current = record.getClass();
do{
Field[] fields = current.getDeclaredFields();
for (Field field : fields) {
if (Collection.class.isAssignableFrom(field.getType())) {
// if the list is not null, get an element
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
if(f != null){
List asList = (List)f;
if(!asList.isEmpty())
if(asList.get(0).getClass().equals(TimeSeriesBean.class)){
logger.debug("Name is " + field.getName());
CustomField customAnnotation = field.getAnnotation(CustomField.class);
if(customAnnotation != null)
logger.debug("Name is " + customAnnotation.key());
}
}
}
}
}
while((current = current.getSuperclass())!=null); // iterate from the inherited class up to the Object.class
}
// @Test // @Test
public void sharedVREFolderWriteTest() throws Exception{ public void sharedVREFolderWriteTest() throws Exception{