added assessment field in time series
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@151195 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8ac6dd0989
commit
76207370e9
|
@ -19,6 +19,7 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
public static final String VALUE_FIELD = "value";
|
public static final String VALUE_FIELD = "value";
|
||||||
public static final String UNIT_FIELD = "unit";
|
public static final String UNIT_FIELD = "unit";
|
||||||
public static final String SOURCE_FIELD = "source";
|
public static final String SOURCE_FIELD = "source";
|
||||||
|
public static final String ASSESSMENT_FIELD = "assessment";
|
||||||
|
|
||||||
@JsonProperty(YEAR_FIELD)
|
@JsonProperty(YEAR_FIELD)
|
||||||
@NotNull(message="year of a time series cannot be null")
|
@NotNull(message="year of a time series cannot be null")
|
||||||
|
@ -27,6 +28,9 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
@JsonProperty(SOURCE_FIELD)
|
@JsonProperty(SOURCE_FIELD)
|
||||||
private String source;
|
private String source;
|
||||||
|
|
||||||
|
@JsonProperty(ASSESSMENT_FIELD)
|
||||||
|
private String assessment;
|
||||||
|
|
||||||
@JsonProperty(VALUE_FIELD)
|
@JsonProperty(VALUE_FIELD)
|
||||||
private T value;
|
private T value;
|
||||||
|
|
||||||
|
@ -39,16 +43,19 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param year
|
* @param year
|
||||||
|
* @param source
|
||||||
|
* @param assessment
|
||||||
* @param value
|
* @param value
|
||||||
* @param unit
|
* @param unit
|
||||||
* @param source
|
|
||||||
*/
|
*/
|
||||||
public TimeSeriesBean(Long year, T value, T1 unit, String source) {
|
public TimeSeriesBean(Long year, String source, String assessment, T value,
|
||||||
|
T1 unit) {
|
||||||
super();
|
super();
|
||||||
this.year = year;
|
this.year = year;
|
||||||
|
this.source = source;
|
||||||
|
this.assessment = assessment;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.unit = unit;
|
this.unit = unit;
|
||||||
this.source = source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getValue() {
|
public T getValue() {
|
||||||
|
@ -89,23 +96,24 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
String firstPart = "" + year;
|
String firstPart = "" + year;
|
||||||
String secondPart = (value != null ? " - " + value : "")
|
String secondPart = (value != null ? " - " + value : "")
|
||||||
+ (unit != null ? " - " + unit : "")
|
+ (unit != null ? " - " + unit : "")
|
||||||
+ (source != null ? " (" + source + ")" : "");
|
+ (source != null ? " (" + source + ")" : "")
|
||||||
|
+ (assessment != null ? " (" + assessment + ")" : "");
|
||||||
return firstPart + (secondPart != null && !secondPart.isEmpty() ? secondPart : "");
|
return firstPart + (secondPart != null && !secondPart.isEmpty() ? secondPart : "");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSourcePresent(){
|
public String getAssessment() {
|
||||||
return source != null;
|
return assessment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssessment(String assessment) {
|
||||||
|
this.assessment = assessment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUnitPresent(){
|
public boolean isUnitPresent(){
|
||||||
return unit != null && !unit.getClass().equals(Void.class);
|
return unit != null && !unit.getClass().equals(Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValuePresent(){
|
|
||||||
return value != null ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(TimeSeriesBean<T, T1> o) {
|
public int compareTo(TimeSeriesBean<T, T1> o) {
|
||||||
return (int) (this.year - o.year); // ascending.. low to highest
|
return (int) (this.year - o.year); // ascending.. low to highest
|
||||||
|
|
|
@ -46,8 +46,9 @@ public class CSVHelpers {
|
||||||
|
|
||||||
// discover how the header will look like
|
// discover how the header will look like
|
||||||
boolean isUnitPresent = timeSeries.get(0).isUnitPresent();
|
boolean isUnitPresent = timeSeries.get(0).isUnitPresent();
|
||||||
boolean isValuePresent = timeSeries.get(0).isValuePresent();
|
boolean isValuePresent = true;
|
||||||
boolean isSourcePresent = timeSeries.get(0).isSourcePresent();
|
boolean isSourcePresent = true;
|
||||||
|
boolean isAssessmentPresent = true;
|
||||||
|
|
||||||
StringBuffer headerLine = new StringBuffer();
|
StringBuffer headerLine = new StringBuffer();
|
||||||
headerLine.append(TimeSeriesBean.YEAR_FIELD);
|
headerLine.append(TimeSeriesBean.YEAR_FIELD);
|
||||||
|
@ -67,6 +68,10 @@ public class CSVHelpers {
|
||||||
headerLine.append(TimeSeriesBean.SOURCE_FIELD);
|
headerLine.append(TimeSeriesBean.SOURCE_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isAssessmentPresent){
|
||||||
|
headerLine.append(CSV_SEPARATOR);
|
||||||
|
headerLine.append(TimeSeriesBean.ASSESSMENT_FIELD);
|
||||||
|
}
|
||||||
|
|
||||||
bw.write(headerLine.toString());
|
bw.write(headerLine.toString());
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
|
@ -93,6 +98,11 @@ public class CSVHelpers {
|
||||||
oneLine.append(bean.getSource() != null? bean.getSource() : "");
|
oneLine.append(bean.getSource() != null? bean.getSource() : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isAssessmentPresent){
|
||||||
|
oneLine.append(CSV_SEPARATOR);
|
||||||
|
oneLine.append(bean.getAssessment() != null? bean.getAssessment() : "");
|
||||||
|
}
|
||||||
|
|
||||||
bw.write(oneLine.toString());
|
bw.write(oneLine.toString());
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
bw.flush();
|
bw.flush();
|
||||||
|
|
|
@ -46,8 +46,8 @@ 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);
|
||||||
|
|
||||||
// try to attach the source at most CANCHES times ..
|
// try to attach the source at most CHANCES times ..
|
||||||
private static final int CANCHES = 3;
|
private static final int CHANCES = 3;
|
||||||
|
|
||||||
private static CacheInterface<String, WorkspaceCatalogue> vreFolderCache = new CacheImpl<String, WorkspaceCatalogue>(1000 * 60 * 60 * 24);
|
private static CacheInterface<String, WorkspaceCatalogue> vreFolderCache = new CacheImpl<String, WorkspaceCatalogue>(1000 * 60 * 60 * 24);
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ public class ManageTimeSeriesThread extends Thread{
|
||||||
ExternalFile createdFileOnWorkspace = null;
|
ExternalFile createdFileOnWorkspace = null;
|
||||||
if(csvFile != null){
|
if(csvFile != null){
|
||||||
|
|
||||||
for (int i = 0; i < CANCHES; i++) {
|
for (int i = 0; i < CHANCES; i++) {
|
||||||
|
|
||||||
// upload this file on ckan
|
// upload this file on ckan
|
||||||
if(ckanResource == null)
|
if(ckanResource == null)
|
||||||
|
|
|
@ -225,11 +225,11 @@ public class JTests {
|
||||||
|
|
||||||
// time series
|
// time series
|
||||||
List<TimeSeriesBean<String, Void>> timeSeries = new ArrayList<TimeSeriesBean<String,Void>>();
|
List<TimeSeriesBean<String, Void>> timeSeries = new ArrayList<TimeSeriesBean<String,Void>>();
|
||||||
timeSeries.add(new TimeSeriesBean<String, Void>(2001L, "Value A", null, null));
|
timeSeries.add(new TimeSeriesBean<String, Void>(2001L, "Value A", null, null, null));
|
||||||
timeSeries.add(new TimeSeriesBean<String, Void>(2231L, "Value B", null, null));
|
timeSeries.add(new TimeSeriesBean<String, Void>(2231L, "Value B", null, null, null));
|
||||||
timeSeries.add(new TimeSeriesBean<String, Void>(1943L, "Value C", null, null));
|
timeSeries.add(new TimeSeriesBean<String, Void>(1943L, "Value C", null, null, null));
|
||||||
timeSeries.add(new TimeSeriesBean<String, Void>(1054L, "Value D", null, null));
|
timeSeries.add(new TimeSeriesBean<String, Void>(1054L, "Value D", null, null, null));
|
||||||
timeSeries.add(new TimeSeriesBean<String, Void>(3422L, "Value E", null, null));
|
timeSeries.add(new TimeSeriesBean<String, Void>(3422L, "Value E", null, null, null));
|
||||||
|
|
||||||
Collections.sort(timeSeries);
|
Collections.sort(timeSeries);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue