Several changes to the model

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@135170 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-12-01 14:37:26 +00:00
parent 41c877cda7
commit 62d111688e
14 changed files with 326 additions and 244 deletions

View File

@ -135,6 +135,12 @@
<artifactId>jersey-bean-validation</artifactId> <artifactId>jersey-bean-validation</artifactId>
<version>${version.jersey}</version> <version>${version.jersey}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId> <groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId> <artifactId>jersey-test-framework-provider-jetty</artifactId>

View File

@ -13,6 +13,4 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
public @interface Group { public @interface Group {
Class parentGroup() default Class.class;
} }

View File

@ -1,5 +1,6 @@
package org.gcube.data_catalogue.grsf_publish_ws.json.input; package org.gcube.data_catalogue.grsf_publish_ws.json.input;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -12,9 +13,14 @@ import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CkanResource;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField; import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group; import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Tag; import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Tag;
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@ -22,11 +28,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* Information that both Stock and Fishery must contain * Information that both Stock and Fishery must contain
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
@JsonIgnoreProperties(value = {"author", "author_contact", "extras", "product_type"}, ignoreUnknown = true) // ignore in serialization/deserialization @JsonIgnoreProperties(value = {"author", "author_contact", "product_type"}) // ignore in serialization/deserialization
public class Common { public class Common {
private static Logger logger = LoggerFactory.getLogger(Common.class);
public static final String PRODUCT_TYPE_KEY = "Product type"; public static final String PRODUCT_TYPE_KEY = "Product type";
@JsonProperty("description") @JsonProperty("description")
private String description; private String description;
@ -58,15 +65,11 @@ public class Common {
@CkanResource @CkanResource
@NotNull(message="database_source cannot be null") @NotNull(message="database_source cannot be null")
@Size(min=1, message="database_source cannot be empty") @Size(min=1, message="database_source cannot be empty")
@Tag
@Group
@Valid @Valid
private List<Resource<Source>> databaseSources; private List<Resource<Source>> databaseSources;
@JsonProperty("source_of_information") @JsonProperty("source_of_information")
@CkanResource @CkanResource
@NotNull(message="source_of_information cannot be null")
@Size(min=1, message="source_of_information cannot be empty")
@Valid @Valid
private List<Resource<String>> sourceOfInformation; private List<Resource<String>> sourceOfInformation;
@ -100,9 +103,16 @@ public class Common {
@Tag @Tag
@Group @Group
private String productType; private String productType;
@JsonProperty("extras") @JsonProperty("reporting_year")
private Map<String, List<String>> extras = new HashMap<>(); @CustomField(key="Reporting year")
private Long reportingYear;
@JsonProperty("extras_fields")
private Map<String, List<String>> extrasFields = new HashMap<>();
@JsonProperty("extras_resources")
private List<ResourceBean> extrasResources = new ArrayList<ResourceBean>();
public Common() { public Common() {
super(); super();
@ -117,26 +127,27 @@ public class Common {
* @param authorContact * @param authorContact
* @param maintainer * @param maintainer
* @param maintainerContact * @param maintainerContact
* @param catchesOrLandings * @param dataOwner
* @param databaseSources * @param databaseSources
* @param sourceOfInformation * @param sourceOfInformation
* @param dataOwner
* @param type
* @param shortTitle * @param shortTitle
* @param uuid * @param uuid
* @param traceabilityFlag * @param traceabilityFlag
* @param extras
* @param status * @param status
* @param productType * @param productType
* @param reportingYear
* @param extrasFields
* @param extrasResources
*/ */
public Common(String description, String license, String author, public Common(String description, String license, String author,
Long version, String authorContact, String maintainer, Long version, String authorContact, String maintainer,
String maintainerContact, String maintainerContact, String dataOwner,
List<Resource<Source>> databaseSources, List<Resource<Source>> databaseSources,
List<Resource<String>> sourceOfInformation, String dataOwner, List<Resource<String>> sourceOfInformation, String shortTitle,
String shortTitle, String uuid, String uuid, boolean traceabilityFlag, Status status,
boolean traceabilityFlag, Map<String, List<String>> extras, String productType, Long reportingYear,
Status status, String productType) { Map<String, List<String>> extrasFields,
List<ResourceBean> extrasResources) {
super(); super();
this.description = description; this.description = description;
this.license = license; this.license = license;
@ -145,21 +156,47 @@ public class Common {
this.authorContact = authorContact; this.authorContact = authorContact;
this.maintainer = maintainer; this.maintainer = maintainer;
this.maintainerContact = maintainerContact; this.maintainerContact = maintainerContact;
this.dataOwner = dataOwner;
this.databaseSources = databaseSources; this.databaseSources = databaseSources;
this.sourceOfInformation = sourceOfInformation; this.sourceOfInformation = sourceOfInformation;
this.dataOwner = dataOwner;
this.shortTitle = shortTitle; this.shortTitle = shortTitle;
this.uuid = uuid; this.uuid = uuid;
this.traceabilityFlag = traceabilityFlag; this.traceabilityFlag = traceabilityFlag;
this.extras = extras;
this.status = status; this.status = status;
this.productType = productType; this.productType = productType;
this.reportingYear = reportingYear;
this.extrasFields = extrasFields;
this.extrasResources = extrasResources;
} }
public String getProductType() { public String getProductType() {
return productType; return productType;
} }
public Long getReportingYear() {
return reportingYear;
}
public void setReportingYear(Long reportingYear) {
this.reportingYear = reportingYear;
}
public Map<String, List<String>> getExtrasFields() {
return extrasFields;
}
public void setExtrasFields(Map<String, List<String>> extrasFields) {
this.extrasFields = extrasFields;
}
public List<ResourceBean> getExtrasResources() {
return extrasResources;
}
public void setExtrasResources(List<ResourceBean> extrasResources) {
this.extrasResources = extrasResources;
}
public void setProductType(String productType) { public void setProductType(String productType) {
this.productType = productType; this.productType = productType;
} }
@ -244,14 +281,6 @@ public class Common {
this.dataOwner = dataOwner; this.dataOwner = dataOwner;
} }
public void setExtras(Map<String, List<String>> extras) {
this.extras = extras;
}
public Map<String, List<String>> getExtras() {
return extras;
}
public String getShortTitle() { public String getShortTitle() {
return shortTitle; return shortTitle;
} }
@ -283,6 +312,28 @@ public class Common {
public void setStatus(Status status) { public void setStatus(Status status) {
this.status = status; this.status = status;
} }
@JsonAnySetter
/**
* Use for generics object passed into the map
* @param key
* @param value
*/
private void genericSetter(String key, Object value){
// found extra property
logger.info("Found extra property: [" + key + "," + value + "]");
// try to convert the value to a string and put into the hashmap
List<String> values = new ArrayList<String>();
if(extrasFields.containsKey(key))
values = extrasFields.get(key);
else
values = new ArrayList<String>();
values.add(HelperMethods.removeHTML(value.toString()));
extrasFields.put(key, values);
}
@Override @Override
public String toString() { public String toString() {
@ -292,9 +343,10 @@ public class Common {
+ maintainer + ", maintainerContact=" + maintainerContact + maintainer + ", maintainerContact=" + maintainerContact
+ ", dataOwner=" + dataOwner + ", databaseSources=" + ", dataOwner=" + dataOwner + ", databaseSources="
+ databaseSources + ", sourceOfInformation=" + databaseSources + ", sourceOfInformation="
+ sourceOfInformation + ", shortTitle=" + sourceOfInformation + ", shortTitle=" + shortTitle
+ shortTitle + ", uuid=" + uuid + ", traceabilityFlag=" + ", uuid=" + uuid + ", traceabilityFlag=" + traceabilityFlag
+ traceabilityFlag + ", extras=" + extras + ", status=" + ", status=" + status + ", productType=" + productType
+ status + ", productType=" + productType + "]"; + ", reportingYear=" + reportingYear + ", extrasFields="
+ extrasFields + ", extrasResources=" + extrasResources + "]";
} }
} }

View File

@ -1,6 +1,5 @@
package org.gcube.data_catalogue.grsf_publish_ws.json.input; package org.gcube.data_catalogue.grsf_publish_ws.json.input;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
@ -40,11 +39,11 @@ public class FisheryRecord extends Common{
@JsonProperty("fishing_area") @JsonProperty("fishing_area")
@CustomField(key="Fishing area") @CustomField(key="Fishing area")
private String fishingArea; private List<String> fishingArea;
@JsonProperty("exploited_stocks") @JsonProperty("exploited_stocks")
@CustomField(key="Exploited stocks") @CustomField(key="Exploited stocks")
private String exploitingStocks; private List<String> exploitingStocks;
@JsonProperty("management_entity") @JsonProperty("management_entity")
@Tag @Tag
@ -53,7 +52,7 @@ public class FisheryRecord extends Common{
@JsonProperty("jurisdiction_area") @JsonProperty("jurisdiction_area")
@CustomField(key="Jurisdiction Area") @CustomField(key="Jurisdiction Area")
private String jurisdictionArea; private List<String> jurisdictionArea;
@JsonProperty("production_system_type") @JsonProperty("production_system_type")
@Group @Group
@ -108,8 +107,9 @@ public class FisheryRecord extends Common{
* @param type * @param type
*/ */
public FisheryRecord(String fisheryName, String fisheryId, public FisheryRecord(String fisheryName, String fisheryId,
String scientificName, String fishingArea, String exploitingStocks, String scientificName, List<String> fishingArea,
String managementEntity, String jurisdictionArea, List<String> exploitingStocks, String managementEntity,
List<String> jurisdictionArea,
Production_System_Type productionSystemType, String flagState, Production_System_Type productionSystemType, String flagState,
String fishingGear, String environment, String fishingGear, String environment,
List<TimeSeriesBean<String, String>> catchesOrLandings, List<TimeSeriesBean<String, String>> catchesOrLandings,
@ -129,7 +129,7 @@ public class FisheryRecord extends Common{
this.catchesOrLandings = catchesOrLandings; this.catchesOrLandings = catchesOrLandings;
this.type = type; this.type = type;
} }
public String getFisheryName() { public String getFisheryName() {
return fisheryName; return fisheryName;
} }
@ -154,22 +154,14 @@ public class FisheryRecord extends Common{
this.scientificName = scientificName; this.scientificName = scientificName;
} }
public String getFishingArea() { public List<String> getFishingArea() {
return fishingArea; return fishingArea;
} }
public void setFishingArea(String fishingArea) { public void setFishingArea(List<String> fishingArea) {
this.fishingArea = fishingArea; this.fishingArea = fishingArea;
} }
public String getExploitingStocks() {
return exploitingStocks;
}
public void setExploitingStocks(String exploitingStocks) {
this.exploitingStocks = exploitingStocks;
}
public String getManagementEntity() { public String getManagementEntity() {
return managementEntity; return managementEntity;
} }
@ -178,11 +170,11 @@ public class FisheryRecord extends Common{
this.managementEntity = managementEntity; this.managementEntity = managementEntity;
} }
public String getJurisdictionArea() { public List<String> getJurisdictionArea() {
return jurisdictionArea; return jurisdictionArea;
} }
public void setJurisdictionArea(String jurisdictionArea) { public void setJurisdictionArea(List<String> jurisdictionArea) {
this.jurisdictionArea = jurisdictionArea; this.jurisdictionArea = jurisdictionArea;
} }
@ -224,10 +216,6 @@ public class FisheryRecord extends Common{
public void setCatchesOrLandings(List<TimeSeriesBean<String, String>> catchesOrLandings) { public void setCatchesOrLandings(List<TimeSeriesBean<String, String>> catchesOrLandings) {
this.catchesOrLandings = catchesOrLandings; this.catchesOrLandings = catchesOrLandings;
if(catchesOrLandings != null){
Collections.sort(catchesOrLandings);
}
} }
public Fishery_Type getType() { public Fishery_Type getType() {
@ -250,4 +238,5 @@ public class FisheryRecord extends Common{
+ ", environment=" + environment + ", catchesOrLandings=" + ", environment=" + environment + ", catchesOrLandings="
+ catchesOrLandings + ", type=" + type + "]"; + catchesOrLandings + ", type=" + type + "]";
} }
} }

View File

@ -66,7 +66,7 @@ public class Resource<T> {
@Override @Override
public String toString() { public String toString() {
// in case of @Tag, we check the class of the element Name // in case of @Tag/@Group, we check the class of the element Name
Class<? extends Object> nameClass = name.getClass(); Class<? extends Object> nameClass = name.getClass();
if(nameClass.equals(Source.class)) if(nameClass.equals(Source.class))

View File

@ -1,6 +1,5 @@
package org.gcube.data_catalogue.grsf_publish_ws.json.input; package org.gcube.data_catalogue.grsf_publish_ws.json.input;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
@ -23,7 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class StockRecord extends Common{ public class StockRecord extends Common{
@JsonProperty("stock_name") @JsonProperty("stock_name")
@NotNull(message="stock_name cannot be null") @NotNull(message="stock_name cannot be null")
@Size(min=2, message="stock_name cannot be empty") @Size(min=2, message="stock_name cannot be empty")
@ -34,22 +33,20 @@ public class StockRecord extends Common{
@CustomField(key="Stock Id") @CustomField(key="Stock Id")
private String stockID; private String stockID;
@JsonProperty("species_scientific_name") @JsonProperty("species")
@CustomField(key="Species scientific name") @CustomField(key="Species")
@Tag @Tag
@NotNull(message="species_scientific_name cannot be null") @Size(min=1, message="species cannot be empty")
@Size(min=1, message="species_scientific_name cannot be empty") private List<String> species;
private String speciesScientificName;
@JsonProperty("assessment_distribution_area") @JsonProperty("assessment_distribution_area")
@CustomField(key="Assessment distribution area") @CustomField(key="Assessment distribution area")
@NotNull(message="assessment distribution cannot be null")
@Size(min=1, message="assessment distribution area cannot be empty") @Size(min=1, message="assessment distribution area cannot be empty")
private String area; private List<String> area;
@JsonProperty("exploiting_fishery") @JsonProperty("exploiting_fishery")
@CustomField(key="Exploiting fishery") @CustomField(key="Exploiting fishery")
private String exploitingFishery; private List<String> exploitingFishery;
@JsonProperty("management_entity") @JsonProperty("management_entity")
@CustomField(key="Management entity") @CustomField(key="Management entity")
@ -63,25 +60,27 @@ public class StockRecord extends Common{
@CustomField(key="State of marine resources") @CustomField(key="State of marine resources")
private String stateOfMarineResource; private String stateOfMarineResource;
@JsonProperty("exploitation_rate") @JsonProperty("standard_exploitation_rate")
@CustomField(key="Exploitation Rate") @CustomField(key="Standard Exploitation Rate")
@Tag @Tag
@Valid @Valid
private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRate; private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard;
@JsonProperty("exploitation_rate")
@CustomField(key="Exploitation Rate")
@Valid
private List<TimeSeriesBean<String, String>> exploitationRate;
@JsonProperty("standard_abundance_level")
@CustomField(key="Standard Abundance Level")
@Tag
@Valid
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard;
@JsonProperty("abundance_level") @JsonProperty("abundance_level")
@CustomField(key="Abundance Level") @CustomField(key="Abundance Level")
@Tag
@Valid @Valid
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevel; private List<TimeSeriesBean<String, String>> abundanceLevel;
@JsonProperty("exploitation_rate_for_grouping")
@Group
private Exploitation_Rate exploitationRateForGrouping;
@JsonProperty("abundance_level_for_grouping")
@Group
private Abundance_Level abundanceLevelForGrouping;
@JsonProperty("narrative_state_and_trend") @JsonProperty("narrative_state_and_trend")
@CustomField(key="Narrative state and trend") @CustomField(key="Narrative state and trend")
@ -95,10 +94,6 @@ public class StockRecord extends Common{
@CustomField(key="Reporting entity") @CustomField(key="Reporting entity")
private String reportingEntity; private String reportingEntity;
@JsonProperty("reporting_year")
@CustomField(key="Reporting year")
private Long reportingYear;
@JsonProperty("stock_uri") @JsonProperty("stock_uri")
@CustomField(key="Stock Uri") @CustomField(key="Stock Uri")
private String stockUri; private String stockUri;
@ -106,7 +101,7 @@ public class StockRecord extends Common{
@JsonProperty("water_area") @JsonProperty("water_area")
@CustomField(key="Water Area") @CustomField(key="Water Area")
private List<String> waterArea; private List<String> waterArea;
@JsonProperty("type") @JsonProperty("type")
@CustomField(key="Type") @CustomField(key="Type")
@Tag @Tag
@ -121,16 +116,16 @@ public class StockRecord extends Common{
* Create a Stock element. * Create a Stock element.
* @param stockName * @param stockName
* @param stockID * @param stockID
* @param speciesScientificName * @param species
* @param area * @param area
* @param exploitingFishery * @param exploitingFishery
* @param managementEntity * @param managementEntity
* @param assessmentMethods * @param assessmentMethods
* @param stateOfMarineResource * @param stateOfMarineResource
* @param exploitationRateStandard
* @param exploitationRate * @param exploitationRate
* @param abundanceLevelStandard
* @param abundanceLevel * @param abundanceLevel
* @param exploitationRateForGrouping
* @param abundanceLevelForGrouping
* @param narrativeStateAndTrend * @param narrativeStateAndTrend
* @param scientificAdvice * @param scientificAdvice
* @param reportingEntity * @param reportingEntity
@ -139,39 +134,43 @@ public class StockRecord extends Common{
* @param waterArea * @param waterArea
* @param type * @param type
*/ */
public StockRecord(String stockName, String stockID, public StockRecord(
String speciesScientificName, String area, String stockName,
String exploitingFishery, String managementEntity, String stockID,
String assessmentMethods, String stateOfMarineResource, List<String> species,
List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRate, List<String> area,
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevel, List<String> exploitingFishery,
Exploitation_Rate exploitationRateForGrouping, String managementEntity,
Abundance_Level abundanceLevelForGrouping, String assessmentMethods,
String stateOfMarineResource,
List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard,
List<TimeSeriesBean<String, String>> exploitationRate,
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard,
List<TimeSeriesBean<String, String>> abundanceLevel,
String narrativeStateAndTrend, String scientificAdvice, String narrativeStateAndTrend, String scientificAdvice,
String reportingEntity, Long reportingYear, String stockUri, String reportingEntity, Long reportingYear, 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.speciesScientificName = speciesScientificName; this.species = species;
this.area = area; this.area = area;
this.exploitingFishery = exploitingFishery; this.exploitingFishery = exploitingFishery;
this.managementEntity = managementEntity; this.managementEntity = managementEntity;
this.assessmentMethods = assessmentMethods; this.assessmentMethods = assessmentMethods;
this.stateOfMarineResource = stateOfMarineResource; this.stateOfMarineResource = stateOfMarineResource;
this.exploitationRateStandard = exploitationRateStandard;
this.exploitationRate = exploitationRate; this.exploitationRate = exploitationRate;
this.abundanceLevelStandard = abundanceLevelStandard;
this.abundanceLevel = abundanceLevel; this.abundanceLevel = abundanceLevel;
this.exploitationRateForGrouping = exploitationRateForGrouping;
this.abundanceLevelForGrouping = abundanceLevelForGrouping;
this.narrativeStateAndTrend = narrativeStateAndTrend; this.narrativeStateAndTrend = narrativeStateAndTrend;
this.scientificAdvice = scientificAdvice; this.scientificAdvice = scientificAdvice;
this.reportingEntity = reportingEntity; this.reportingEntity = reportingEntity;
this.reportingYear = reportingYear;
this.stockUri = stockUri; this.stockUri = stockUri;
this.waterArea = waterArea; this.waterArea = waterArea;
this.type = type; this.type = type;
} }
public Stock_Type getType() { public Stock_Type getType() {
return type; return type;
} }
@ -179,24 +178,6 @@ public class StockRecord extends Common{
public void setType(Stock_Type type) { public void setType(Stock_Type type) {
this.type = type; this.type = type;
} }
public Exploitation_Rate getExploitationRateForGrouping() {
return exploitationRateForGrouping;
}
public void setExploitationRateForGrouping(
Exploitation_Rate exploitationRateForGrouping) {
this.exploitationRateForGrouping = exploitationRateForGrouping;
}
public Abundance_Level getAbundanceLevelForGrouping() {
return abundanceLevelForGrouping;
}
public void setAbundanceLevelForGrouping(
Abundance_Level abundanceLevelForGrouping) {
this.abundanceLevelForGrouping = abundanceLevelForGrouping;
}
public String getStockUri() { public String getStockUri() {
return stockUri; return stockUri;
@ -230,27 +211,27 @@ public class StockRecord extends Common{
this.stockID = stockID; this.stockID = stockID;
} }
public String getSpeciesScientificName() { public List<String> getSpecies() {
return speciesScientificName; return species;
} }
public void setSpeciesScientificName(String speciesScientificName) { public void setSpecies(List<String> species) {
this.speciesScientificName = speciesScientificName; this.species = species;
} }
public String getArea() { public List<String> getArea() {
return area; return area;
} }
public void setArea(String area) { public void setArea(List<String> area) {
this.area = area; this.area = area;
} }
public String getExploitingFishery() { public List<String> getExploitingFishery() {
return exploitingFishery; return exploitingFishery;
} }
public void setExploitingFishery(String exploitingFishery) { public void setExploitingFishery(List<String> exploitingFishery) {
this.exploitingFishery = exploitingFishery; this.exploitingFishery = exploitingFishery;
} }
@ -278,28 +259,31 @@ public class StockRecord extends Common{
this.stateOfMarineResource = stateOfMarineResource; this.stateOfMarineResource = stateOfMarineResource;
} }
public List<TimeSeriesBean<Exploitation_Rate, Void>> getExploitationRate() { public List<TimeSeriesBean<Exploitation_Rate, Void>> getExploitationRateStandard() {
return exploitationRate; return exploitationRateStandard;
} }
public void setExploitationRate(List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRate) { public void setExploitationRateStandard(
this.exploitationRate = exploitationRate; List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard) {
this.exploitationRateStandard = exploitationRateStandard;
if(exploitationRate != null){
Collections.sort(exploitationRate);
}
} }
public List<TimeSeriesBean<Abundance_Level, Void>> getAbundanceLevel() { public List<TimeSeriesBean<Abundance_Level, Void>> getAbundanceLevelStandard() {
return abundanceLevelStandard;
}
public void setAbundanceLevelStandard(
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard) {
this.abundanceLevelStandard = abundanceLevelStandard;
}
public List<TimeSeriesBean<String, String>> getAbundanceLevel() {
return abundanceLevel; return abundanceLevel;
} }
public void setAbundanceLevel(List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevel) { public void setAbundanceLevel(
List<TimeSeriesBean<String, String>> abundanceLevel) {
this.abundanceLevel = abundanceLevel; this.abundanceLevel = abundanceLevel;
if(abundanceLevel != null){
Collections.sort(abundanceLevel);
}
} }
public String getNarrativeStateAndTrend() { public String getNarrativeStateAndTrend() {
@ -325,32 +309,33 @@ public class StockRecord extends Common{
public void setReportingEntity(String reportingEntity) { public void setReportingEntity(String reportingEntity) {
this.reportingEntity = reportingEntity; this.reportingEntity = reportingEntity;
} }
public Long getReportingYear() { public List<TimeSeriesBean<String, String>> getExploitationRate() {
return reportingYear; return exploitationRate;
} }
public void setReportingYear(Long reportingYear) { public void setExploitationRate(
this.reportingYear = reportingYear; List<TimeSeriesBean<String, String>> exploitationRate) {
this.exploitationRate = exploitationRate;
} }
@Override @Override
public String toString() { public String toString() {
return "StockRecord [stockName=" + stockName + ", stockID=" + stockID return "StockRecord [stockName=" + stockName + ", stockID=" + stockID
+ ", speciesScientificName=" + speciesScientificName + ", species=" + species + ", area=" + area
+ ", area=" + area + ", exploitingFishery=" + exploitingFishery + ", exploitingFishery=" + exploitingFishery
+ ", managementEntity=" + managementEntity + ", managementEntity=" + managementEntity
+ ", assessmentMethods=" + assessmentMethods + ", assessmentMethods=" + assessmentMethods
+ ", stateOfMarineResource=" + stateOfMarineResource + ", stateOfMarineResource=" + stateOfMarineResource
+ ", exploitationRateStandard=" + exploitationRateStandard
+ ", exploitationRate=" + exploitationRate + ", exploitationRate=" + exploitationRate
+ ", abundanceLevelStandard=" + abundanceLevelStandard
+ ", abundanceLevel=" + abundanceLevel + ", abundanceLevel=" + abundanceLevel
+ ", exploitationRateForGrouping=" + ", narrativeStateAndTrend=" + narrativeStateAndTrend
+ exploitationRateForGrouping + ", abundanceLevelForGrouping=" + ", scientificAdvice=" + scientificAdvice
+ abundanceLevelForGrouping + ", narrativeStateAndTrend=" + ", reportingEntity=" + reportingEntity + ", stockUri="
+ narrativeStateAndTrend + ", scientificAdvice=" + stockUri + ", waterArea=" + waterArea + ", type=" + type
+ scientificAdvice + ", reportingEntity=" + reportingEntity + "]";
+ ", reportingYear=" + reportingYear + ", stockUri=" + stockUri
+ ", waterArea=" + waterArea + ", type=" + type + "]";
} }
} }

View File

@ -149,8 +149,8 @@ public class GrsfPublisherFisheryService {
// fishing area and jurisdiction area cannot be empty at the same time // fishing area and jurisdiction area cannot be empty at the same time
String futureName = record.getUuid(); String futureName = record.getUuid();
String futureTitle = record.getFisheryName(); String futureTitle = record.getFisheryName();
String fishingArea = record.getFishingArea(); List<String> fishingArea = record.getFishingArea();
String jurisdictionArea = record.getJurisdictionArea(); List<String> jurisdictionArea = record.getJurisdictionArea();
if(!HelperMethods.isNameValid(futureName)){ if(!HelperMethods.isNameValid(futureName)){
status = Status.BAD_REQUEST; status = Status.BAD_REQUEST;
@ -186,10 +186,7 @@ public class GrsfPublisherFisheryService {
HelperMethods.getGroups(groups, record); HelperMethods.getGroups(groups, record);
// evaluate the custom fields // evaluate the custom fields
Map<String, List<String>> customFields = new HashMap<String, List<String>>(); Map<String, List<String>> customFields = record.getExtrasFields();
if(record.getExtras() != null)
customFields = record.getExtras();
// automatically retrieve the other ones // automatically retrieve the other ones
HelperMethods.getExtras(customFields, record); HelperMethods.getExtras(customFields, record);
@ -207,7 +204,8 @@ public class GrsfPublisherFisheryService {
}else{ }else{
// evaluate the resources // evaluate the resources
List<ResourceBean> resources = HelperMethods.getResourcesFromBean(record, username, tags, groups); List<ResourceBean> resources = record.getExtrasResources();
HelperMethods.getResourcesFromBean(record, username, tags, groups, resources);
// check the license id // check the license id
String license = null; String license = null;
@ -225,7 +223,7 @@ public class GrsfPublisherFisheryService {
catalogue.getApiKeyFromUsername(username), catalogue.getApiKeyFromUsername(username),
futureTitle, futureTitle,
futureName, futureName,
organization, organization,//"grsf", //TO DELETE TODO
authorFullname, authorFullname,
authorMail, authorMail,
record.getMaintainer(), record.getMaintainer(),

View File

@ -175,10 +175,7 @@ public class GrsfPublisherStockService {
HelperMethods.getGroups(groups, record); HelperMethods.getGroups(groups, record);
// evaluate the custom fields // evaluate the custom fields
Map<String, List<String>> customFields = new HashMap<String, List<String>>(); Map<String, List<String>> customFields = record.getExtrasFields();
if(record.getExtras() != null)
customFields = record.getExtras();
// automatically retrieve the other ones // automatically retrieve the other ones
HelperMethods.getExtras(customFields, record); HelperMethods.getExtras(customFields, record);
@ -197,7 +194,8 @@ public class GrsfPublisherStockService {
}else{ }else{
// evaluate the resources // evaluate the resources
List<ResourceBean> resources = HelperMethods.getResourcesFromBean(record, username, tags, groups); List<ResourceBean> resources = record.getExtrasResources();
HelperMethods.getResourcesFromBean(record, username, tags, groups, resources);
// check the license id // check the license id
String license = null; String license = null;
@ -215,7 +213,7 @@ public class GrsfPublisherStockService {
catalogue.getApiKeyFromUsername(username), catalogue.getApiKeyFromUsername(username),
futureTitle, futureTitle,
futureName, futureName,
organization, organization,//"grsf", //TO DELETE TODO
authorFullname, authorFullname,
authorMail, authorMail,
record.getMaintainer(), record.getMaintainer(),

View File

@ -74,7 +74,7 @@ public abstract class HelperMethods {
modified = modified.substring(1); modified = modified.substring(1);
if(modified.endsWith("-")) if(modified.endsWith("-"))
modified = modified.substring(0, modified.length() -1); modified = modified.substring(0, modified.length() -1);
logger.info("Group name generated is " + modified); logger.info("Group name generated is " + modified);
return modified; return modified;
@ -169,34 +169,43 @@ public abstract class HelperMethods {
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record); Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
if(f != null){ if(f != null){
// also convert to the group name that should be on ckan if(f instanceof List<?>){
String groupName = getGroupNameOnCkan(f.toString().trim()); List asList = ((List) f);
if(!groups.contains(groupName)) if(!asList.isEmpty()){
groups.add(groupName);
logger.debug("The object annotated with @Tag/@Group is a list. Adding ... ");
// else add all the available elements
for (int i = 0; i < asList.size(); i++) {
String groupName = getGroupNameOnCkan(asList.get(i).toString().trim());
logger.debug(groupName);
if(!groups.contains(groupName))
groups.add(groupName);
}
}
}else{
// also convert to the group name that should be on ckan
String groupName = getGroupNameOnCkan(f.toString().trim());
if(!groups.contains(groupName))
groups.add(groupName);
}
} }
// check if the field is an enumerator, and the enum class is also annotated with @Group // check if the field is an enumerator, and the enum class is also annotated with @Group
if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){ if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){
logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group"); logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group");
// extract the name from the enum class and add it to the groups // extract the name from the enum class and add it to the groups
// also convert to the group name that should be on ckan // also convert to the group name that should be on ckan
String groupName = getGroupNameOnCkan(field.getType().getSimpleName()); String groupName = getGroupNameOnCkan(field.getType().getSimpleName());
if(!groups.contains(groupName)) if(!groups.contains(groupName))
groups.add(groupName); groups.add(groupName);
// check if this class has a father too (@Group annotation allows it)
Group groupAnnotationOnEnum = field.getType().getAnnotation(Group.class);
if(!groupAnnotationOnEnum.parentGroup().equals(Class.class)){
String groupNameFather = getGroupNameOnCkan(groupAnnotationOnEnum.parentGroup().getSimpleName());
if(!groups.contains(groupNameFather))
groups.add(groupNameFather);
}
} }
}catch(Exception e){ }catch(Exception e){
logger.error("Failed ot read value for field " + field.getName() + " skipping", e); logger.error("Failed ot read value for field " + field.getName() + " skipping", e);
} }
@ -427,11 +436,11 @@ public abstract class HelperMethods {
* @param username * @param username
* @param tags * @param tags
* @param groups * @param groups
* @param resources
* @return * @return
*/ */
public static List<ResourceBean> getResourcesFromBean(Common record, String username, List<String> tags, List<String> groups){ public static void getResourcesFromBean(Common record, String username, List<String> tags, List<String> groups, List<ResourceBean> resources){
List<ResourceBean> toReturn = new ArrayList<ResourceBean>();
Class<?> current = record.getClass(); Class<?> current = record.getClass();
do{ do{
Field[] fields = current.getDeclaredFields(); Field[] fields = current.getDeclaredFields();
@ -446,13 +455,13 @@ public abstract class HelperMethods {
List<Resource> listOfResources = (List<Resource>)f; List<Resource> listOfResources = (List<Resource>)f;
for (Resource resource : listOfResources) { for (Resource resource : listOfResources) {
toReturn.add(new ResourceBean(resource.getUrl(), resource.getName().toString(), resource.getDescription(), null, username, null, null)); resources.add(new ResourceBean(resource.getUrl(), resource.getName().toString(), resource.getDescription(), null, username, null, null));
} }
}else{ }else{
Resource res = (Resource)f; Resource res = (Resource)f;
toReturn.add(new ResourceBean(res.getUrl(), res.getName().toString(), res.getDescription(), null, username, null, null)); resources.add(new ResourceBean(res.getUrl(), res.getName().toString(), res.getDescription(), null, username, null, null));
} }
} }
@ -464,8 +473,7 @@ public abstract class HelperMethods {
} }
while((current = current.getSuperclass())!=null); // iterate from the inherited class up to the Object.class while((current = current.getSuperclass())!=null); // iterate from the inherited class up to the Object.class
logger.info("Returning resources " + toReturn); logger.info("Returning resources " + resources);
return toReturn;
} }
/** /**
@ -563,29 +571,12 @@ public abstract class HelperMethods {
if(html == null || html.isEmpty()) if(html == null || html.isEmpty())
return html; return html;
logger.info("Incoming text is " + html);
// remove html and clean // remove html and clean
String withoutHTML = Jsoup.parse(html).text(); String withoutHTML = Jsoup.parse(html).text();
withoutHTML = Jsoup.clean(withoutHTML, Whitelist.basic()); withoutHTML = Jsoup.clean(withoutHTML, Whitelist.basic());
// TODO ...
// could contain non ascii chars ... try to convert them to question marks and then remove them
// try{
// String strippedWithQuestionMarks = Normalizer.normalize(withoutHTML, Normalizer.Form.NFD);
// String regex = "[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+";
// strippedWithQuestionMarks = new String(strippedWithQuestionMarks.replaceAll(regex, "").getBytes("ascii"), "ascii");
// strippedWithQuestionMarks = strippedWithQuestionMarks.replaceAll("[?]+", " ");
// withoutHTML = strippedWithQuestionMarks;
// }catch(UnsupportedEncodingException e){
// logger.warn("Unable to convert to question marks non ascii chars..", e);
// // remove non ascii directly
// withoutHTML = withoutHTML.replaceAll("[^\\x00-\\x7F]", " ");
// }
// remove non ascii chars ... // remove non ascii chars ...
withoutHTML = withoutHTML.replaceAll("[^\\p{ASCII}]", " "); withoutHTML = withoutHTML.replaceAll("[^\\p{ASCII}]", " ");
logger.info("Without html is " + withoutHTML);
return withoutHTML; return withoutHTML;
} }
} }

View File

@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
* Abundance_Level for Stock records * Abundance_Level for Stock records
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
@Group(parentGroup=Indicator.class) @Group
public enum Abundance_Level { public enum Abundance_Level {
Intermediate_Abundance("Intermediate abundance"), Intermediate_Abundance("Intermediate abundance"),

View File

@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
* Exploitation_Rate for Stock records * Exploitation_Rate for Stock records
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
@Group(parentGroup=Indicator.class) @Group
public enum Exploitation_Rate { public enum Exploitation_Rate {
Moderate_Fishing_Mortality("Moderate fishing mortality"), Moderate_Fishing_Mortality("Moderate fishing mortality"),

View File

@ -1,12 +0,0 @@
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
/**
* Indicator group: father of Abundance level and Exploitation Rate
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
@Group
public enum Indicator {
}

View File

@ -1,12 +1,19 @@
package org.gcube.data_catalogue.grsf_publish_ws.utils.threads; package org.gcube.data_catalogue.grsf_publish_ws.utils.threads;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg; import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.model.CkanGroup;
/** /**
* Associate the dataset to a group. * Associate the dataset to a group.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
@ -40,31 +47,76 @@ public class AssociationToGroupThread extends Thread {
@Override @Override
public void run() { public void run() {
logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title(s) " + groupsTitles + " for user " + username); try{
String userApiKey = catalogue.getApiKeyFromUsername(username); logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title(s) " + groupsTitles + " for user " + username);
// retrieve the role to be assigned according the one the user has into the organization of the dataset // find parents' groups
RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organizationId, catalogue.getApiKeyFromUsername(username)).toUpperCase()); String userApiKey = catalogue.getApiKeyFromUsername(username);
findHierarchy(groupsTitles, catalogue, userApiKey);
if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
for (String groupTitle : groupsTitles) { Set<String> uniqueGroups = new HashSet<String>(groupsTitles);
logger.info("Full set of groups is " + groupsTitles);
logger.debug("Setting role " + role + " into group " + groupTitle + " to user " + username); // retrieve the role to be assigned according the one the user has into the organization of the dataset
boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, role); RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organizationId, userApiKey).toUpperCase());
if(!assigned){ if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
logger.warn("The user " + username + " has not enough privileges to associate the dataset into group OR the group doesn't exist" + groupTitle); role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
continue;
for (String groupTitle : uniqueGroups) {
logger.debug("Setting role " + role + " into group " + groupTitle + " to user " + username);
boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, role);
if(!assigned){
logger.warn("The user " + username + " has not enough privileges to associate the dataset into group OR the group doesn't exist" + groupTitle);
continue;
}
else{
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, userApiKey);
logger.info("Was product put into group " + groupTitle + "? " + putIntoGroup);
}
} }
else{ logger.info("The Association Group thread ended correctly");
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, userApiKey); }catch(Exception e){
logger.info("Was product put into group " + groupTitle + "? " + putIntoGroup); logger.error("Exception follows ", e);
}
}
/**
* Find the hierarchy of trees
* @param uniqueGroups
* @param catalogue
* @param user's api key
*/
public static void findHierarchy(
List<String> groupsTitles,
DataCatalogue catalogue,
String apiKey) {
ListIterator<String> iterator = groupsTitles.listIterator();
while (iterator.hasNext()) {
String group = (String) iterator.next();
List<CkanGroup> parents = catalogue.getParentGroups(group, apiKey);
if(parents == null || parents.isEmpty())
return;
for (CkanGroup ckanGroup : parents) {
List<String> parentsList = new ArrayList<String>(Arrays.asList(ckanGroup.getName()));
findHierarchy(parentsList, catalogue, apiKey);
for (String parent : parentsList) {
iterator.add(parent);
}
} }
} }
logger.info("The Association Group thread ended correctly");
} }
} }

View File

@ -13,8 +13,10 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
@ -41,9 +43,9 @@ import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Fishery_Type; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Fishery_Type;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -547,7 +549,7 @@ public class JTests {
logger.debug("Name is " +groupName ); logger.debug("Name is " +groupName );
} }
} }
} }
} }
@ -555,4 +557,27 @@ public class JTests {
} }
//@Test
public void testHierarchy(){
String name = "low-abundance";
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance("/gcube/devNext/NextNext");
List<String> uniqueGroups = new ArrayList<String>();
uniqueGroups.add(name);
uniqueGroups.add(name);
AssociationToGroupThread.findHierarchy(uniqueGroups, catalogue, catalogue.getApiKeyFromUsername("costantino_perciante"));
logger.debug("Hierarchy is " + uniqueGroups);
}
//@Test
public void testAssociationThread() throws InterruptedException{
String name = "low-abundance";
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance("/gcube/devNext/NextNext");
AssociationToGroupThread threadGroups = new AssociationToGroupThread(Arrays.asList(name), "another-test-test-please-ignore", "grsf", "costantino_perciante", catalogue);
threadGroups.start();
threadGroups.join();
logger.info("Thread stopped!");
}
} }