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:
Costantino Perciante 2017-07-21 13:33:22 +00:00
parent 8ac6dd0989
commit 76207370e9
4 changed files with 39 additions and 21 deletions

View File

@ -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 UNIT_FIELD = "unit";
public static final String SOURCE_FIELD = "source";
public static final String ASSESSMENT_FIELD = "assessment";
@JsonProperty(YEAR_FIELD)
@NotNull(message="year of a time series cannot be null")
@ -26,6 +27,9 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
@JsonProperty(SOURCE_FIELD)
private String source;
@JsonProperty(ASSESSMENT_FIELD)
private String assessment;
@JsonProperty(VALUE_FIELD)
private T value;
@ -39,16 +43,19 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
/**
* @param year
* @param source
* @param assessment
* @param value
* @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();
this.year = year;
this.source = source;
this.assessment = assessment;
this.value = value;
this.unit = unit;
this.source = source;
}
public T getValue() {
@ -89,23 +96,24 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
String firstPart = "" + year;
String secondPart = (value != null ? " - " + value : "")
+ (unit != null ? " - " + unit : "")
+ (source != null ? " (" + source + ")" : "");
+ (source != null ? " (" + source + ")" : "")
+ (assessment != null ? " (" + assessment + ")" : "");
return firstPart + (secondPart != null && !secondPart.isEmpty() ? secondPart : "");
}
public boolean isSourcePresent(){
return source != null;
public String getAssessment() {
return assessment;
}
public void setAssessment(String assessment) {
this.assessment = assessment;
}
public boolean isUnitPresent(){
return unit != null && !unit.getClass().equals(Void.class);
}
public boolean isValuePresent(){
return value != null ;
}
@Override
public int compareTo(TimeSeriesBean<T, T1> o) {
return (int) (this.year - o.year); // ascending.. low to highest

View File

@ -46,8 +46,9 @@ public class CSVHelpers {
// discover how the header will look like
boolean isUnitPresent = timeSeries.get(0).isUnitPresent();
boolean isValuePresent = timeSeries.get(0).isValuePresent();
boolean isSourcePresent = timeSeries.get(0).isSourcePresent();
boolean isValuePresent = true;
boolean isSourcePresent = true;
boolean isAssessmentPresent = true;
StringBuffer headerLine = new StringBuffer();
headerLine.append(TimeSeriesBean.YEAR_FIELD);
@ -66,7 +67,11 @@ public class CSVHelpers {
headerLine.append(CSV_SEPARATOR);
headerLine.append(TimeSeriesBean.SOURCE_FIELD);
}
if(isAssessmentPresent){
headerLine.append(CSV_SEPARATOR);
headerLine.append(TimeSeriesBean.ASSESSMENT_FIELD);
}
bw.write(headerLine.toString());
bw.newLine();
@ -92,6 +97,11 @@ public class CSVHelpers {
oneLine.append(CSV_SEPARATOR);
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.newLine();

View File

@ -46,8 +46,8 @@ public class ManageTimeSeriesThread extends Thread{
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ManageTimeSeriesThread.class);
// try to attach the source at most CANCHES times ..
private static final int CANCHES = 3;
// try to attach the source at most CHANCES times ..
private static final int CHANCES = 3;
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;
if(csvFile != null){
for (int i = 0; i < CANCHES; i++) {
for (int i = 0; i < CHANCES; i++) {
// upload this file on ckan
if(ckanResource == null)

View File

@ -225,11 +225,11 @@ public class JTests {
// time series
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>(2231L, "Value B", null, null));
timeSeries.add(new TimeSeriesBean<String, Void>(1943L, "Value C", null, null));
timeSeries.add(new TimeSeriesBean<String, Void>(1054L, "Value D", null, null));
timeSeries.add(new TimeSeriesBean<String, Void>(3422L, "Value E", 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, null));
timeSeries.add(new TimeSeriesBean<String, Void>(1943L, "Value C", null, 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, null));
Collections.sort(timeSeries);