separated types for stock and fishery. The main thread will wait for the groups association thread to finish before starting the one of the files

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@134895 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-25 17:25:23 +00:00
parent 00b2442632
commit 2c394704a5
13 changed files with 146 additions and 67 deletions

View File

@ -14,7 +14,6 @@ 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.utils.groups.Source;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -67,12 +66,6 @@ public class Common {
@Valid
private List<Resource<String>> sourceOfInformation;
@JsonProperty("type")
@CustomField(key="Type")
@Tag
@Group
private Type type;
@JsonProperty("short_title")
@CustomField(key="Short Title")
@NotNull(message="short_title cannot be null")
@ -137,7 +130,7 @@ public class Common {
String maintainerContact,
List<Resource<Source>> databaseSources,
List<Resource<String>> sourceOfInformation, String dataOwner,
Type type, String shortTitle, String uuid,
String shortTitle, String uuid,
boolean traceabilityFlag, Map<String, List<String>> extras,
Status status, String productType) {
super();
@ -151,7 +144,6 @@ public class Common {
this.databaseSources = databaseSources;
this.sourceOfInformation = sourceOfInformation;
this.dataOwner = dataOwner;
this.type = type;
this.shortTitle = shortTitle;
this.uuid = uuid;
this.traceabilityFlag = traceabilityFlag;
@ -248,14 +240,6 @@ public class Common {
this.dataOwner = dataOwner;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public void setExtras(Map<String, List<String>> extras) {
this.extras = extras;
}
@ -304,7 +288,7 @@ public class Common {
+ maintainer + ", maintainerContact=" + maintainerContact
+ ", dataOwner=" + dataOwner + ", databaseSources="
+ databaseSources + ", sourceOfInformation="
+ sourceOfInformation + ", type=" + type + ", shortTitle="
+ sourceOfInformation + ", shortTitle="
+ shortTitle + ", uuid=" + uuid + ", traceabilityFlag="
+ traceabilityFlag + ", extras=" + extras + ", status="
+ status + ", productType=" + productType + "]";

View File

@ -11,6 +11,7 @@ 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.Tag;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Production_System_Type;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Fishery;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -79,6 +80,12 @@ public class FisheryRecord extends Common{
@Tag
@Valid
private List<TimeSeriesBean<String, String>> catchesOrLandings;
@JsonProperty("type")
@CustomField(key="Type")
@Tag
@Group
private Type_Fishery type;
public FisheryRecord() {
super();
@ -98,13 +105,15 @@ public class FisheryRecord extends Common{
* @param fishingGear
* @param environment
* @param catchesOrLandings
* @param type
*/
public FisheryRecord(String fisheryName, String fisheryId,
String scientificName, String fishingArea, String exploitingStocks,
String managementEntity, String jurisdictionArea,
Production_System_Type productionSystemType, String flagState,
String fishingGear, String environment,
List<TimeSeriesBean<String, String>> catchesOrLandings) {
List<TimeSeriesBean<String, String>> catchesOrLandings,
Type_Fishery type) {
super();
this.fisheryName = fisheryName;
this.fisheryId = fisheryId;
@ -118,6 +127,7 @@ public class FisheryRecord extends Common{
this.fishingGear = fishingGear;
this.environment = environment;
this.catchesOrLandings = catchesOrLandings;
this.type = type;
}
public String getFisheryName() {
@ -220,6 +230,14 @@ public class FisheryRecord extends Common{
}
}
public Type_Fishery getType() {
return type;
}
public void setType(Type_Fishery type) {
this.type = type;
}
@Override
public String toString() {
return "FisheryRecord [fisheryName=" + fisheryName + ", fisheryId="
@ -230,6 +248,6 @@ public class FisheryRecord extends Common{
+ ", productionSystemType=" + productionSystemType
+ ", flagState=" + flagState + ", fishingGear=" + fishingGear
+ ", environment=" + environment + ", catchesOrLandings="
+ catchesOrLandings + "]";
+ catchesOrLandings + ", type=" + type + "]";
}
}

View File

@ -9,8 +9,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* A resource object bean. The generic argument applies to the resource's name.
* A resource object bean. The generic argument T applies to the resource's name.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* @param <T> the resource's name type
*/
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
public class Resource<T> {

View File

@ -12,6 +12,7 @@ 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.utils.groups.Abundance_Level;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Exploitation_Rate;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Stock;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -105,6 +106,12 @@ public class StockRecord extends Common{
@JsonProperty("water_area")
@CustomField(key="Water Area")
private List<String> waterArea;
@JsonProperty("type")
@CustomField(key="Type")
@Tag
@Group
private Type_Stock type;
public StockRecord() {
super();
@ -130,6 +137,7 @@ public class StockRecord extends Common{
* @param reportingYear
* @param stockUri
* @param waterArea
* @param type
*/
public StockRecord(String stockName, String stockID,
String speciesScientificName, String area,
@ -141,7 +149,7 @@ public class StockRecord extends Common{
Abundance_Level abundanceLevelForGrouping,
String narrativeStateAndTrend, String scientificAdvice,
String reportingEntity, Long reportingYear, String stockUri,
List<String> waterArea) {
List<String> waterArea, Type_Stock type) {
super();
this.stockName = stockName;
this.stockID = stockID;
@ -161,8 +169,17 @@ public class StockRecord extends Common{
this.reportingYear = reportingYear;
this.stockUri = stockUri;
this.waterArea = waterArea;
this.type = type;
}
public Type_Stock getType() {
return type;
}
public void setType(Type_Stock type) {
this.type = type;
}
public Exploitation_Rate getExploitationRateForGrouping() {
return exploitationRateForGrouping;
}
@ -319,7 +336,7 @@ public class StockRecord extends Common{
@Override
public String toString() {
return "StockRecord [" + super.toString() + "stockName=" + stockName + ", stockID=" + stockID
return "StockRecord [stockName=" + stockName + ", stockID=" + stockID
+ ", speciesScientificName=" + speciesScientificName
+ ", area=" + area + ", exploitingFishery=" + exploitingFishery
+ ", managementEntity=" + managementEntity
@ -333,6 +350,7 @@ public class StockRecord extends Common{
+ narrativeStateAndTrend + ", scientificAdvice="
+ scientificAdvice + ", reportingEntity=" + reportingEntity
+ ", reportingYear=" + reportingYear + ", stockUri=" + stockUri
+ ", waterArea=" + waterArea + "]";
}
+ ", waterArea=" + waterArea + ", type=" + type + "]";
}
}

View File

@ -9,11 +9,11 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* A time series bean that contains couple <year, value>
* A time series bean that contains elements &lt year, T, T1 &gt
* Catches_and_landings contains also Unit
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* @param T the first type value of the series
* @param T1 the second type value of the series
* @param <T> the first type value of the series
* @param <T1> the second type value of the series (optional)
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
@ -72,7 +72,7 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
// when the value belongs to these classes annotated with @Tag..
if(valueClass.equals(Abundance_Level.class) || valueClass.equals(Exploitation_Rate.class))
return year + "-" + value;
else if(this.unit != null && this.unit.getClass().equals(String.class)) // catches and landings
else if(this.unit != null && !this.unit.getClass().equals(Void.class)) // e.g., catches and landings
return year + "-" + value + "-" + unit;
else
return "TimeSeriesBean [value=" + value + ", unit=" + unit + ", year="

View File

@ -1,10 +1,9 @@
package org.gcube.data_catalogue.grsf_publish_ws.json.output;
/**
* Response bean.
* Response bean to be used by the service.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class ResponseBean{

View File

@ -237,21 +237,19 @@ public class GrsfPublisherFisheryService {
responseBean.setProductUrl(catalogue.getPortletUrl() + "?" + URLEncoder.encode("path=/dataset/" + futureName, "UTF-8"));
responseBean.setKbUuid(record.getUuid());
// manage time series
logger.info("Launching thread for time series handling");
ManageTimeSeriesThread threadFiles = new ManageTimeSeriesThread(record, futureName, username, catalogue, ScopeProvider.instance.get());
// wait this one to finish
threadFiles.start();
logger.info("Waiting time series thread to die..");
threadFiles.join();
logger.debug("Ok, it died");
if(!groups.isEmpty()){
logger.info("Launching thread for association to the list of groups " + groups);
new AssociationToGroupThread(groups, id, organization, username, catalogue).start();
AssociationToGroupThread threadGroups = new AssociationToGroupThread(groups, id, organization, username, catalogue);
threadGroups.start();
logger.info("Waiting association thread to die..");
threadGroups.join();
logger.debug("Ok, it died");
}
// manage time series
logger.info("Launching thread for time series handling");
new ManageTimeSeriesThread(record, futureName, username, catalogue, ScopeProvider.instance.get()).start();
}
}
}

View File

@ -225,22 +225,19 @@ public class GrsfPublisherStockService {
status = Status.CREATED;
responseBean.setProductUrl(catalogue.getPortletUrl() + "?" + URLEncoder.encode("path=/dataset/" + futureName, "UTF-8"));
responseBean.setKbUuid(record.getUuid());
// manage time series
logger.info("Launching thread for time series handling");
ManageTimeSeriesThread threadFiles = new ManageTimeSeriesThread(record, futureName, username, catalogue, ScopeProvider.instance.get());
// wait this one to finish
threadFiles.start();
logger.info("Waiting time series thread to die..");
threadFiles.join();
logger.debug("Ok, it died");
if(!groups.isEmpty()){
logger.info("Launching thread for association to the list of groups " + groups);
new AssociationToGroupThread(groups, id, organization, username, catalogue).start();
AssociationToGroupThread threadGroups = new AssociationToGroupThread(groups, id, organization, username, catalogue);
threadGroups.start();
logger.info("Waiting association thread to die..");
threadGroups.join();
logger.debug("Ok, it died");
}
// manage time series
logger.info("Launching thread for time series handling");
new ManageTimeSeriesThread(record, futureName, username, catalogue, ScopeProvider.instance.get()).start();
}
}
}

View File

@ -25,6 +25,8 @@ public class CSVHelpers {
* Write a time series to a csv file, and returns the file reference.<br>
* Please give the timeSeries already sorted per year
* @param timeSeries
* @param <T>
* @param <T1>
*/
public static <T, T1> File listToCSV(List<TimeSeriesBean<T, T1>> timeSeries){

View File

@ -5,19 +5,17 @@ import com.fasterxml.jackson.annotation.JsonValue;
/**
* Type for Stock/Fishery records
* Type for Fishery records
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public enum Type {
public enum Type_Fishery {
Assessment_Unit("Assessment Unit"),// for stock
Resource("Resource"), // for stock
Fishery_Activity("Fishery Activity"), // for fishery
Fishing_Description("Fishing Description"); // for fishery
private String subGroupNameOrig;
private Type(String origName) {
private Type_Fishery(String origName) {
this.subGroupNameOrig = origName;
}
@ -44,9 +42,9 @@ public enum Type {
* @return
*/
@JsonCreator
public static Type onDeserialize(String typeString) {
public static Type_Fishery onDeserialize(String typeString) {
if(typeString != null) {
for(Type type : Type.values()) {
for(Type_Fishery type : Type_Fishery.values()) {
if(type.getOrigName().equalsIgnoreCase(typeString.trim()))
return type;
}

View File

@ -0,0 +1,63 @@
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* Stock types
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*/
public enum Type_Stock {
Assessment_Unit("Assessment Unit"),// for stock
Resource("Resource"); // for stock
private String subGroupNameOrig;
private Type_Stock(String origName) {
this.subGroupNameOrig = origName;
}
/**
* Return the original name
* @return
*/
public String getOrigName(){
return subGroupNameOrig;
}
/**
* Get the json value
* @return
*/
@JsonValue
public String onSerialize(){
return subGroupNameOrig.toLowerCase();
}
/**
* Get back an enum from json string
* @param typeString
* @return
*/
@JsonCreator
public static Type_Stock onDeserialize(String typeString) {
if(typeString != null) {
for(Type_Stock type : Type_Stock.values()) {
if(type.getOrigName().equalsIgnoreCase(typeString.trim()))
return type;
}
}
return null;
}
/**
* Used by reflection
*/
@Override
public String toString() {
return getOrigName();
}
}

View File

@ -14,7 +14,8 @@ import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherFisherySer
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherStockService;
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.Type;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Fishery;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Stock;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
@ -34,7 +35,7 @@ public class JJerseyTest extends JerseyTest{
recordFishery.setAuthorContact("costantino.perciante@isti.cnr.it");
recordFishery.setLicense("a caso una lincense");
recordFishery.setDataOwner("data owner");
recordFishery.setType(Type.Fishing_Description);
recordFishery.setType(Type_Fishery.Fishing_Description);
recordFishery.setDatabaseSources(new ArrayList<Resource<Source>>(1));
recordFishery.setSourceOfInformation(new ArrayList<Resource<String>>(1));
recordFishery.setStatus(Status.Pending);
@ -47,7 +48,7 @@ public class JJerseyTest extends JerseyTest{
StockRecord stock = new StockRecord();
stock.setAuthor("Costantino Perciante");
stock.setAuthorContact("costantino.perciante@isti.cnr.it");
stock.setType(Type.Fishing_Description);
stock.setType(Type_Stock.Assessment_Unit);
stock.setDatabaseSources(null);
stock.setStatus(Status.Pending);

View File

@ -28,7 +28,7 @@ import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level;
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.Type;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Fishery;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
import org.junit.Test;
@ -51,7 +51,7 @@ public class JTests {
public void test() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IntrospectionException {
FisheryRecord recordFishery = new FisheryRecord();
recordFishery.setType(Type.Fishing_Description);
recordFishery.setType(Type_Fishery.Fishing_Description);
recordFishery.setDatabaseSources(new ArrayList<Resource<Source>>());
recordFishery.setStatus(Status.Pending);