From 00e2a6c6fccd0cfb20c73f4aa6d7dfcd29ec64ac Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Fri, 30 Jun 2017 13:32:38 +0000 Subject: [PATCH] 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 --- .../grsf_publish_ws/json/input/Common.java | 113 +++++++++++------- .../json/input/StockRecord.java | 77 +++++------- .../services/CommonServiceUtils.java | 7 +- .../services/GrsfPublisherFisheryService.java | 4 +- .../services/GrsfPublisherStockService.java | 4 +- .../utils/cache/CacheImpl.java | 12 +- src/main/webapp/WEB-INF/web.xml | 8 +- .../grsf_publish_ws/JTests.java | 34 ------ 8 files changed, 117 insertions(+), 142 deletions(-) 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 89bade6..4a73d00 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 @@ -61,7 +61,11 @@ public class Common extends Base{ @JsonProperty("reporting_year") @CustomField(key="Reporting year") - private Long reportingYear; + private List reportingYear; + + @JsonProperty("reference_year") + @CustomField(key="Reference year") + private List referenceYear; // automatically compiled @JsonProperty("grsf_type") @@ -75,21 +79,27 @@ public class Common extends Base{ @CustomField(key=SOURCE_KEY) private String sourceType; - @JsonProperty("catches_or_landings") - @CustomField(key="Catches or landings") + @JsonProperty("catches") + @CustomField(key="Catches") @TimeSeries @Valid - private List> catchesOrLandings; + private List> catches; - @JsonProperty("species_name") - @CustomField(key="Species Scientific Name") - @Tag - private List speciesName; + @JsonProperty("landings") + @CustomField(key="Landings") + @TimeSeries + @Valid + private List> landings; - @JsonProperty("species_code") - @CustomField(key="Species code") - @Tag - private List speciesCode; + @JsonProperty("species") + @CustomField(key="species") + private List species; + + @JsonProperty("fao_state") + @CustomField(key="Fao State") + @TimeSeries + @Valid + private List> faoState; public Common() { super(); @@ -104,19 +114,22 @@ public class Common extends Base{ * @param traceabilityFlag * @param status * @param reportingYear + * @param referenceYear * @param grsfType * @param sourceType - * @param catchesOrLandings - * @param speciesName - * @param speciesCode + * @param catches + * @param landings + * @param species + * @param faoState */ public Common(String dataOwner, List> databaseSources, List> sourceOfInformation, List refersTo, String shortTitle, - Boolean traceabilityFlag, Status status, Long reportingYear, - String grsfType, String sourceType, - List> catchesOrLandings, - List speciesName, List speciesCode) { + Boolean traceabilityFlag, Status status, List reportingYear, + List referenceYear, String grsfType, String sourceType, + List> catches, + List> landings, + List species, List> faoState) { super(); this.dataOwner = dataOwner; this.databaseSources = databaseSources; @@ -126,11 +139,13 @@ public class Common extends Base{ this.traceabilityFlag = traceabilityFlag; this.status = status; this.reportingYear = reportingYear; + this.referenceYear = referenceYear; this.grsfType = grsfType; this.sourceType = sourceType; - this.catchesOrLandings = catchesOrLandings; - this.speciesName = speciesName; - this.speciesCode = speciesCode; + this.catches = catches; + this.landings = landings; + this.species = species; + this.faoState = faoState; } public String getGrsfType() { @@ -165,11 +180,11 @@ public class Common extends Base{ this.refersTo = refersTo; } - public Long getReportingYear() { + public List getReportingYear() { return reportingYear; } - public void setReportingYear(Long reportingYear) { + public void setReportingYear(List reportingYear) { this.reportingYear = reportingYear; } @@ -221,30 +236,44 @@ public class Common extends Base{ this.status = status; } - - public List> getCatchesOrLandings() { - return catchesOrLandings; + public List getSpecies() { + return species; } - public void setCatchesOrLandings( - List> catchesOrLandings) { - this.catchesOrLandings = catchesOrLandings; + public void setSpecies(List species) { + this.species = species; } - public List getSpeciesName() { - return speciesName; + public List> getCatches() { + return catches; } - public void setSpeciesName(List speciesName) { - this.speciesName = speciesName; + public void setCatches(List> catches) { + this.catches = catches; } - public List getSpeciesCode() { - return speciesCode; + public List> getLandings() { + return landings; } - public void setSpeciesCode(List speciesCode) { - this.speciesCode = speciesCode; + public void setLandings(List> landings) { + this.landings = landings; + } + + public List getReferenceYear() { + return referenceYear; + } + + public void setReferenceYear(List referenceYear) { + this.referenceYear = referenceYear; + } + + public List> getFaoState() { + return faoState; + } + + public void setFaoState(List> faoState) { + this.faoState = faoState; } @Override @@ -254,10 +283,10 @@ public class Common extends Base{ + sourceOfInformation + ", refersTo=" + refersTo + ", shortTitle=" + shortTitle + ", traceabilityFlag=" + traceabilityFlag + ", status=" + status + ", reportingYear=" - + reportingYear + ", grsfType=" + grsfType + ", sourceType=" - + sourceType + ", catchesOrLandings=" + catchesOrLandings - + ", speciesName=" + speciesName + ", speciesCode=" - + speciesCode + "]"; + + reportingYear + ", referenceYear=" + referenceYear + + ", grsfType=" + grsfType + ", sourceType=" + sourceType + + ", catches=" + catches + ", landings=" + landings + + ", species=" + species + ", faoState=" + faoState + "]"; } } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java index afcfb72..dc5374a 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java @@ -34,14 +34,8 @@ public class StockRecord extends Common{ @CustomField(key="Stock id") private String stockId; - // @JsonProperty("species") - // @CustomField(key="Species") - // @Tag - // private List species; - @JsonProperty("assessment_distribution_area") @CustomField(key="Assessment distribution area") - @Tag private List area; @JsonProperty("exploiting_fishery") @@ -55,7 +49,7 @@ public class StockRecord extends Common{ @JsonProperty("assessment_methods") @CustomField(key="Assessment methods") - private String assessmentMethods; + private List assessmentMethods; @JsonProperty("state_of_marine_resource") @CustomField(key="State of marine resources") @@ -99,9 +93,9 @@ public class StockRecord extends Common{ @Valid private List> fishingPressure; - @JsonProperty("narrative_state_and_trend") - @CustomField(key="Narrative state and trend") - private String narrativeStateAndTrend; + @JsonProperty("narrative_state") + @CustomField(key="Narrative state") + private List> narrativeState; @JsonProperty("scientific_advice") @CustomField(key="Scientific advice") @@ -123,7 +117,6 @@ public class StockRecord extends Common{ @JsonProperty("type") @CustomField(key="Type") - //@Tag @Group private Stock_Type type; @@ -132,10 +125,8 @@ public class StockRecord extends Common{ } /** - * Create a Stock element. * @param stockName - * @param stockID - * @param species + * @param stockId * @param area * @param exploitingFishery * @param managementEntity @@ -145,10 +136,11 @@ public class StockRecord extends Common{ * @param exploitationRate * @param abundanceLevelStandard * @param abundanceLevel - * @param narrativeStateAndTrend + * @param fishingPressureStandard + * @param fishingPressure + * @param narrativeState * @param scientificAdvice - * @param reportingEntity - * @param reportingYear + * @param assessor * @param stockUri * @param waterArea * @param type @@ -156,23 +148,23 @@ public class StockRecord extends Common{ public StockRecord( String stockName, String stockId, - //List species, List area, List exploitingFishery, String managementEntity, - String assessmentMethods, + List assessmentMethods, String stateOfMarineResource, List> exploitationRateStandard, List> exploitationRate, List> abundanceLevelStandard, List> abundanceLevel, - String narrativeStateAndTrend, String scientificAdvice, - String assessor, Long reportingYear, String stockUri, + List> fishingPressureStandard, + List> fishingPressure, + List> narrativeState, + String scientificAdvice, String assessor, String stockUri, List waterArea, Stock_Type type) { super(); this.stockName = stockName; this.stockId = stockId; - //this.species = species; this.area = area; this.exploitingFishery = exploitingFishery; this.managementEntity = managementEntity; @@ -182,7 +174,9 @@ public class StockRecord extends Common{ this.exploitationRate = exploitationRate; this.abundanceLevelStandard = abundanceLevelStandard; this.abundanceLevel = abundanceLevel; - this.narrativeStateAndTrend = narrativeStateAndTrend; + this.fishingPressureStandard = fishingPressureStandard; + this.fishingPressure = fishingPressure; + this.narrativeState = narrativeState; this.scientificAdvice = scientificAdvice; this.assessor = assessor; this.stockUri = stockUri; @@ -190,6 +184,10 @@ public class StockRecord extends Common{ this.type = type; } + public void setAssessmentMethods(List assessmentMethods) { + this.assessmentMethods = assessmentMethods; + } + public Stock_Type getType() { return type; } @@ -230,14 +228,6 @@ public class StockRecord extends Common{ this.stockId = stockId; } - // public List getSpecies() { - // return species; - // } - // - // public void setSpecies(List species) { - // this.species = species; - // } - public List getArea() { return area; } @@ -280,14 +270,6 @@ public class StockRecord extends Common{ this.managementEntity = managementEntity; } - public String getAssessmentMethods() { - return assessmentMethods; - } - - public void setAssessmentMethods(String assessmentMethods) { - this.assessmentMethods = assessmentMethods; - } - public String getStateOfMarineResource() { return stateOfMarineResource; } @@ -323,12 +305,12 @@ public class StockRecord extends Common{ this.abundanceLevel = abundanceLevel; } - public String getNarrativeStateAndTrend() { - return narrativeStateAndTrend; + public List> getNarrativeState() { + return narrativeState; } - public void setNarrativeStateAndTrend(String narrativeStateAndTrend) { - this.narrativeStateAndTrend = narrativeStateAndTrend; + public void setNarrativeState(List> narrativeState) { + this.narrativeState = narrativeState; } public String getScientificAdvice() { @@ -368,11 +350,10 @@ public class StockRecord extends Common{ + ", abundanceLevelStandard=" + abundanceLevelStandard + ", abundanceLevel=" + abundanceLevel + ", fishingPressureStandard=" + fishingPressureStandard - + ", fishingPressure=" + fishingPressure - + ", narrativeStateAndTrend=" + narrativeStateAndTrend - + ", scientificAdvice=" + scientificAdvice + ", assessor=" - + assessor + ", stockUri=" + stockUri + ", waterArea=" - + waterArea + ", type=" + type + "]"; + + ", fishingPressure=" + fishingPressure + ", narrativeState=" + + narrativeState + ", scientificAdvice=" + scientificAdvice + + ", assessor=" + assessor + ", stockUri=" + stockUri + + ", waterArea=" + waterArea + ", type=" + type + "]"; } } 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 92fb894..799fa4f 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 @@ -87,10 +87,9 @@ public class CommonServiceUtils { if(record.getClass().equals(StockRecord.class)){ StockRecord stock = (StockRecord) record; - List speciesNames = stock.getSpeciesName(); - List speciesCodes = stock.getSpeciesCode(); - if(speciesNames == null || speciesNames.isEmpty() || speciesCodes == null || speciesCodes.isEmpty()) - throw new Exception("species name/code cannot be null/empty in a GRSF record"); + List species = stock.getSpecies(); + if(species == null || species.isEmpty()) + throw new Exception("species cannot be null/empty in a GRSF record"); } // check if it is a stock and perform related checks diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java index 6ecdf4e..3e1422b 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java @@ -291,14 +291,14 @@ public class GrsfPublisherFisheryService { // write a post if the product has been published in grsf context if(context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){ - new WritePostCatalogueManagerThread( + /*new WritePostCatalogueManagerThread( context, token, futureTitle, itemUrl, false, new ArrayList(), - authorFullname).start(); + authorFullname).start();*/ logger.info("Thread to write a post about the new product has been launched"); } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java index dac4337..4a3232d 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java @@ -288,7 +288,7 @@ public class GrsfPublisherStockService { // write a post if the product has been published in grsf context if(context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){ - new WritePostCatalogueManagerThread( + /*new WritePostCatalogueManagerThread( context, token, futureTitle, @@ -296,7 +296,7 @@ public class GrsfPublisherStockService { false, new ArrayList(), 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 diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java index f5054a1..6ad08d4 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java @@ -17,7 +17,7 @@ public class CacheImpl implements CacheInterface { /** * The hashmap */ - private Map> userSpaceMap; + private Map> cache; /** * Cache entry expires after EXPIRED_AFTER ms @@ -26,16 +26,16 @@ public class CacheImpl implements CacheInterface { public CacheImpl(long timeout){ ttl = timeout; - userSpaceMap = new ConcurrentHashMap<>(); + cache = new ConcurrentHashMap<>(); } @Override public V get(K key) { - if(userSpaceMap.containsKey(key)){ - CacheValueBean bean = userSpaceMap.get(key); + if(cache.containsKey(key)){ + CacheValueBean bean = cache.get(key); 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"); } else @@ -47,7 +47,7 @@ public class CacheImpl implements CacheInterface { @Override public boolean insert(K key, V obj) { CacheValueBean newBean = new CacheValueBean(obj, System.currentTimeMillis()); - userSpaceMap.put(key, newBean); + cache.put(key, newBean); return true; } } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 80003b8..a030303 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -27,16 +27,16 @@ Context of pending products under manage activities ManageVRE - /d4science.research-infrastructures.eu/FARM/GRSF_Admin - + + /gcube/devNext/NextNext Context of products no longer under manage activities PublicVRE - /d4science.research-infrastructures.eu/FARM/GRSF - + + /gcube/devNext/NextNext diff --git a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java index 2e2c070..b45c857 100644 --- a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java +++ b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java @@ -8,7 +8,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -289,39 +288,6 @@ public class JTests { 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> list = new ArrayList>(); - list.add(new TimeSeriesBean("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 public void sharedVREFolderWriteTest() throws Exception{