added some chances to upload the resource on the ckan as time series. Added a new @TimeSeries annotation
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@135199 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
291b542d61
commit
f076015318
|
@ -0,0 +1,16 @@
|
||||||
|
package org.gcube.data_catalogue.grsf_publish_ws.custom_annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TimeSeries annotation
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface TimeSeries {
|
||||||
|
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import javax.validation.constraints.Size;
|
||||||
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.custom_annotations.TimeSeries;
|
||||||
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.Production_System_Type;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Production_System_Type;
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ public class FisheryRecord extends Common{
|
||||||
@JsonProperty("catches_or_landings")
|
@JsonProperty("catches_or_landings")
|
||||||
@CustomField(key="Catches or landings")
|
@CustomField(key="Catches or landings")
|
||||||
@Tag
|
@Tag
|
||||||
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<String, String>> catchesOrLandings;
|
private List<TimeSeriesBean<String, String>> catchesOrLandings;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import javax.validation.constraints.Size;
|
||||||
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.custom_annotations.TimeSeries;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level;
|
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.Exploitation_Rate;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Stock_Type;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Stock_Type;
|
||||||
|
@ -63,22 +64,26 @@ public class StockRecord extends Common{
|
||||||
@JsonProperty("standard_exploitation_rate")
|
@JsonProperty("standard_exploitation_rate")
|
||||||
@CustomField(key="Standard Exploitation Rate")
|
@CustomField(key="Standard Exploitation Rate")
|
||||||
@Tag
|
@Tag
|
||||||
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard;
|
private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard;
|
||||||
|
|
||||||
@JsonProperty("exploitation_rate")
|
@JsonProperty("exploitation_rate")
|
||||||
@CustomField(key="Exploitation Rate")
|
@CustomField(key="Exploitation Rate")
|
||||||
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<String, String>> exploitationRate;
|
private List<TimeSeriesBean<String, String>> exploitationRate;
|
||||||
|
|
||||||
@JsonProperty("standard_abundance_level")
|
@JsonProperty("standard_abundance_level")
|
||||||
@CustomField(key="Standard Abundance Level")
|
@CustomField(key="Standard Abundance Level")
|
||||||
@Tag
|
@Tag
|
||||||
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard;
|
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard;
|
||||||
|
|
||||||
@JsonProperty("abundance_level")
|
@JsonProperty("abundance_level")
|
||||||
@CustomField(key="Abundance Level")
|
@CustomField(key="Abundance Level")
|
||||||
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<String, String>> abundanceLevel;
|
private List<TimeSeriesBean<String, String>> abundanceLevel;
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@ package org.gcube.data_catalogue.grsf_publish_ws.json.input;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
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 com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@ -67,16 +64,11 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
Class<? extends Object> valueClass = value.getClass();
|
if(this.unit != null && !this.unit.getClass().equals(Void.class)) // e.g., catches and landings
|
||||||
|
|
||||||
// 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(Void.class)) // e.g., catches and landings
|
|
||||||
return year + "-" + value + "-" + unit;
|
return year + "-" + value + "-" + unit;
|
||||||
else
|
else
|
||||||
return "TimeSeriesBean [value=" + value + ", unit=" + unit + ", year="
|
return year + "-" + value;
|
||||||
+ year + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.beans.PropertyDescriptor;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
@ -22,10 +21,10 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
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.TimeSeries;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.TimeSeriesBean;
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVHelpers;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVHelpers;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
||||||
|
@ -45,6 +44,7 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ManageTimeSeriesThread.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ManageTimeSeriesThread.class);
|
||||||
|
private static final int CANCHES = 3;
|
||||||
|
|
||||||
private Common record;
|
private Common record;
|
||||||
private String packageName;
|
private String packageName;
|
||||||
|
@ -167,7 +167,7 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
do{
|
do{
|
||||||
Field[] fields = current.getDeclaredFields();
|
Field[] fields = current.getDeclaredFields();
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
if (Collection.class.isAssignableFrom(field.getType())) {
|
if (field.isAnnotationPresent(TimeSeries.class)) {
|
||||||
|
|
||||||
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){
|
||||||
|
@ -175,7 +175,6 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
List asList = (List)f;
|
List asList = (List)f;
|
||||||
|
|
||||||
if(!asList.isEmpty()){
|
if(!asList.isEmpty()){
|
||||||
if(asList.get(0).getClass().equals(TimeSeriesBean.class)){
|
|
||||||
|
|
||||||
CustomField customAnnotation = field.getAnnotation(CustomField.class);
|
CustomField customAnnotation = field.getAnnotation(CustomField.class);
|
||||||
String resourceToAttachName = (productName + "_" + customAnnotation.key()).replaceAll("\\s", "_") + CSV_FILE_FORMAT;
|
String resourceToAttachName = (productName + "_" + customAnnotation.key()).replaceAll("\\s", "_") + CSV_FILE_FORMAT;
|
||||||
|
@ -184,10 +183,15 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
logger.debug("A time series has been just found (from field " + customAnnotation.key() + ")");
|
logger.debug("A time series has been just found (from field " + customAnnotation.key() + ")");
|
||||||
File csvFile = CSVHelpers.listToCSV(asList);
|
File csvFile = CSVHelpers.listToCSV(asList);
|
||||||
|
|
||||||
|
CkanResourceBase ckanResource = null;
|
||||||
|
|
||||||
if(csvFile != null){
|
if(csvFile != null){
|
||||||
|
|
||||||
|
for (int i = 0; i < CANCHES; i++) {
|
||||||
|
|
||||||
// upload this file on ckan
|
// upload this file on ckan
|
||||||
CkanResourceBase ckanResource = uploadFileOnCatalogue(csvFile, packageName, catalogue, username, resourceToAttachName, resourceToAttachDescription, apiKeyUser);
|
if(ckanResource == null)
|
||||||
|
ckanResource = uploadFileOnCatalogue(csvFile, packageName, catalogue, username, resourceToAttachName, resourceToAttachDescription, apiKeyUser);
|
||||||
|
|
||||||
//upload this file on the folder of the vre (under .catalogue) and change the url of the resource
|
//upload this file on the folder of the vre (under .catalogue) and change the url of the resource
|
||||||
if(ckanResource != null){
|
if(ckanResource != null){
|
||||||
|
@ -199,12 +203,16 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
logger.info("going to patch the created resource with id " + ckanResource.getId() + " with url " + publicUrlToSetOnCkan);
|
logger.info("going to patch the created resource with id " + ckanResource.getId() + " with url " + publicUrlToSetOnCkan);
|
||||||
boolean updated = catalogue.patchResource(ckanResource.getId(), publicUrlToSetOnCkan, resourceToAttachName, resourceToAttachDescription, "", apiKeyUser);
|
boolean updated = catalogue.patchResource(ckanResource.getId(), publicUrlToSetOnCkan, resourceToAttachName, resourceToAttachDescription, "", apiKeyUser);
|
||||||
|
|
||||||
if(updated)
|
if(updated){
|
||||||
logger.info("Resource has been updated with the new url");
|
logger.info("Resource has been updated with the new url");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// delete the file
|
// delete the file
|
||||||
csvFile.delete();
|
csvFile.delete();
|
||||||
}
|
}
|
||||||
|
@ -213,7 +221,6 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue