distro fixed and other minor fixes
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@158310 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
05b48cd484
commit
cbb14577ef
|
@ -1,4 +1,10 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
|
<Changeset component="org.gcube.data-catalogue.grsf-publisher-ws.1-4-0"
|
||||||
|
date="2017-11-02">
|
||||||
|
<Change>Some fixes and improvements: added a common library between
|
||||||
|
service and management widget
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
<Changeset component="org.gcube.data-catalogue.grsf-publisher-ws.1-3-0"
|
<Changeset component="org.gcube.data-catalogue.grsf-publisher-ws.1-3-0"
|
||||||
date="2017-08-01">
|
date="2017-08-01">
|
||||||
<Change>Model upgrade</Change>
|
<Change>Model upgrade</Change>
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.data_catalogue.grsf_publish_ws.json.input.others;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.common.Constants;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@ -13,9 +15,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
||||||
public class DeleteRecord {
|
public class DeleteRecord {
|
||||||
|
|
||||||
@JsonProperty("id")
|
@JsonProperty(Constants.DELETE_RECORD_ID)
|
||||||
@NotNull(message="id cannot be null")
|
@NotNull(message= Constants.DELETE_RECORD_ID + " cannot be null")
|
||||||
@Size(min=1, message="id cannot be empty")
|
@Size(min=1, message= Constants.DELETE_RECORD_ID + " cannot be empty")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public DeleteRecord() {
|
public DeleteRecord() {
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.data_catalogue.grsf_publish_ws.json.input.others;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.common.Constants;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@ -14,11 +16,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class RefersToBean {
|
public class RefersToBean {
|
||||||
|
|
||||||
@JsonProperty("url")
|
@JsonProperty(Constants.REFERS_TO_URL)
|
||||||
@NotNull(message="url of field refers_to cannot be null")
|
@NotNull(message="url of field refers_to cannot be null")
|
||||||
String url;
|
String url;
|
||||||
|
|
||||||
@JsonProperty("id")
|
@JsonProperty(Constants.REFERS_TO_ID)
|
||||||
@NotNull(message="id of field refers_to cannot be null")
|
@NotNull(message="id of field refers_to cannot be null")
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.data_catalogue.grsf_publish_ws.json.input.others;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.common.Constants;
|
||||||
import org.gcube.datacatalogue.common.enums.Sources;
|
import org.gcube.datacatalogue.common.enums.Sources;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
@ -16,15 +17,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
||||||
public class Resource<T> {
|
public class Resource<T> {
|
||||||
|
|
||||||
@JsonProperty("url")
|
@JsonProperty(Constants.RESOURCE_URL)
|
||||||
@NotNull(message="'url' field of a resource cannot be null")
|
@NotNull(message="'url' field of a resource cannot be null")
|
||||||
@Size(min=1, message="'url' field of a resource cannot be empty")
|
@Size(min=1, message="'url' field of a resource cannot be empty")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@JsonProperty("description")
|
@JsonProperty(Constants.RESOURCE_DESCRIPTION)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@JsonProperty("name")
|
@JsonProperty(Constants.RESOURCE_NAME)
|
||||||
@NotNull(message="'name' field of a resource cannot be null")
|
@NotNull(message="'name' field of a resource cannot be null")
|
||||||
private T name;
|
private T name;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.data_catalogue.grsf_publish_ws.json.input.others;
|
package org.gcube.data_catalogue.grsf_publish_ws.json.input.others;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.common.Constants;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@ -13,29 +15,22 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
|
|
||||||
public static final String YEAR_FIELD = "reference_year";
|
@JsonProperty(Constants.TIME_SERIES_YEAR_FIELD)
|
||||||
public static final String VALUE_FIELD = "value";
|
|
||||||
public static final String UNIT_FIELD = "unit";
|
|
||||||
public static final String DB_SOURCE_FIELD = "db_source";
|
|
||||||
public static final String DATA_OWNER_FIELD = "data_owner";
|
|
||||||
public static final String ASSESSMENT_FIELD = "reporting_year_or_assessment_id";
|
|
||||||
|
|
||||||
@JsonProperty(YEAR_FIELD)
|
|
||||||
private Long year;
|
private Long year;
|
||||||
|
|
||||||
@JsonProperty(DB_SOURCE_FIELD)
|
@JsonProperty(Constants.TIME_SERIES_DB_SOURCE_FIELD)
|
||||||
private String databaseSource;
|
private String databaseSource;
|
||||||
|
|
||||||
@JsonProperty(ASSESSMENT_FIELD)
|
@JsonProperty(Constants.TIME_SERIES_ASSESSMENT_FIELD)
|
||||||
private String assessment;
|
private String assessment;
|
||||||
|
|
||||||
@JsonProperty(DATA_OWNER_FIELD)
|
@JsonProperty(Constants.TIME_SERIES_DATA_OWNER_FIELD)
|
||||||
private String dataOwner;
|
private String dataOwner;
|
||||||
|
|
||||||
@JsonProperty(VALUE_FIELD)
|
@JsonProperty(Constants.TIME_SERIES_VALUE_FIELD)
|
||||||
private T value;
|
private T value;
|
||||||
|
|
||||||
@JsonProperty(UNIT_FIELD)
|
@JsonProperty(Constants.TIME_SERIES_UNIT_FIELD)
|
||||||
private T1 unit;
|
private T1 unit;
|
||||||
|
|
||||||
public TimeSeriesBean() {
|
public TimeSeriesBean() {
|
||||||
|
@ -82,7 +77,8 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setYear(Long year) {
|
public void setYear(Long year) {
|
||||||
this.year = year == null? -1 : year;
|
// Check year
|
||||||
|
this.year = (year == null? -1 : year);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T1 getUnit() {
|
public T1 getUnit() {
|
||||||
|
|
|
@ -25,8 +25,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
public class StockRecord extends Common{
|
public class StockRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty(Constants.STOCK_NAME_JSON_KEY)
|
@JsonProperty(Constants.STOCK_NAME_JSON_KEY)
|
||||||
@NotNull(message="stock_name cannot be null")
|
@NotNull(message=Constants.STOCK_NAME_JSON_KEY + " cannot be null")
|
||||||
@Size(min=2, message="stock_name cannot be empty")
|
@Size(min=2, message=Constants.STOCK_NAME_JSON_KEY + " cannot be empty")
|
||||||
@CustomField(key=Constants.STOCK_NAME_CUSTOM_KEY)
|
@CustomField(key=Constants.STOCK_NAME_CUSTOM_KEY)
|
||||||
private String stockName;
|
private String stockName;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.data_catalogue.grsf_publish_ws.json.output;
|
package org.gcube.data_catalogue.grsf_publish_ws.json.output;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.common.Constants;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,16 +10,16 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
*/
|
*/
|
||||||
public class ResponseCreationBean {
|
public class ResponseCreationBean {
|
||||||
|
|
||||||
@JsonProperty("id")
|
@JsonProperty(Constants.RESPONSE_CREATE_PATCH_ID)
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@JsonProperty("knowledge_base_id")
|
@JsonProperty(Constants.RESPONSE_CREATE_KNOWLEDGE_BASE_ID)
|
||||||
private String kbUuid; // the original uuid given by the KB
|
private String kbUuid; // the original uuid given by the KB
|
||||||
|
|
||||||
@JsonProperty("product_url")
|
@JsonProperty(Constants.RESPONSE_CREATE_PRODUCT_URL)
|
||||||
private String itemUrl;
|
private String itemUrl;
|
||||||
|
|
||||||
@JsonProperty("error")
|
@JsonProperty(Constants.RESPONSE_CREATE_ERROR_MESSAGE)
|
||||||
private String error; // in case of error
|
private String error; // in case of error
|
||||||
|
|
||||||
public ResponseCreationBean() {
|
public ResponseCreationBean() {
|
||||||
|
|
|
@ -70,10 +70,19 @@ public class GrsfPublisherFisheryService {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getLicenses(){
|
public Response getLicenses(){
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
Map<String, String> licenses = CommonServiceUtils.getLicenses();
|
String context = ScopeProvider.instance.get();
|
||||||
|
DataCatalogue catalogue;
|
||||||
|
try {
|
||||||
|
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
|
Map<String, String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
||||||
if(licenses == null)
|
if(licenses == null)
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status).entity(licenses).build();
|
return Response.status(status).entity(licenses).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(new ResponseBean(false,
|
||||||
|
"Unable to retrieve license list " + e.getLocalizedMessage(), null)).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|
|
@ -69,13 +69,20 @@ public class GrsfPublisherStockService {
|
||||||
@Path("get-licenses")
|
@Path("get-licenses")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getLicenses(){
|
public Response getLicenses(){
|
||||||
|
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
Map<String, String> licenses = CommonServiceUtils.getLicenses();
|
String context = ScopeProvider.instance.get();
|
||||||
|
DataCatalogue catalogue;
|
||||||
|
try {
|
||||||
|
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
|
Map<String, String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
||||||
if(licenses == null)
|
if(licenses == null)
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status).entity(licenses).build();
|
return Response.status(status).entity(licenses).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(new ResponseBean(false,
|
||||||
|
"Unable to retrieve license list " + e.getLocalizedMessage(), null)).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
@ -217,6 +224,7 @@ public class GrsfPublisherStockService {
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to create stock record", e);
|
logger.error("Failed to create stock record", e);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
responseBean.setError(e.getMessage());
|
responseBean.setError(e.getMessage());
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CkanResource;
|
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;
|
||||||
|
@ -40,6 +39,7 @@ import org.json.simple.JSONObject;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||||
|
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services common utils.
|
* Services common utils.
|
||||||
|
@ -54,15 +54,15 @@ public class CommonServiceUtils {
|
||||||
* Retrieve the list of licenses for stocks and fisheries
|
* Retrieve the list of licenses for stocks and fisheries
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> getLicenses(){
|
public static Map<String, String> getLicenses(DataCatalogue catalogue){
|
||||||
Map<String, String> licenses = null;
|
|
||||||
try{
|
|
||||||
logger.info("Requested licenses...");
|
logger.info("Requested licenses...");
|
||||||
licenses = HelperMethods.getLicenses(HelperMethods.getDataCatalogueRunningInstance(ScopeProvider.instance.get()));
|
Map<String, String> toReturn = new HashMap<String, String>();
|
||||||
}catch(Exception e){
|
List<CkanLicense> licenses = catalogue.getLicenses();
|
||||||
logger.error("Failed to retrieve the list of licenses");
|
|
||||||
|
for (CkanLicense ckanLicense : licenses) {
|
||||||
|
toReturn.put(ckanLicense.getId(), ckanLicense.getTitle());
|
||||||
}
|
}
|
||||||
return licenses;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,6 @@ public class GcoreEndPointReaderSocial {
|
||||||
if(context == null || context.isEmpty())
|
if(context == null || context.isEmpty())
|
||||||
throw new IllegalArgumentException("A valid context is needed to discover the service");
|
throw new IllegalArgumentException("A valid context is needed to discover the service");
|
||||||
|
|
||||||
|
|
||||||
String oldContext = ScopeProvider.instance.get();
|
String oldContext = ScopeProvider.instance.get();
|
||||||
ScopeProvider.instance.set(context);
|
ScopeProvider.instance.set(context);
|
||||||
|
|
||||||
|
|
|
@ -230,22 +230,6 @@ public abstract class HelperMethods {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the list of ckan licenses and build up a map <license_id, license_title>
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static Map<String, String> getLicenses(DataCatalogue catalogue) throws Exception {
|
|
||||||
|
|
||||||
Map<String, String> toReturn = new HashMap<String, String>();
|
|
||||||
List<CkanLicense> licenses = catalogue.getLicenses();
|
|
||||||
|
|
||||||
for (CkanLicense ckanLicense : licenses) {
|
|
||||||
toReturn.put(ckanLicense.getId(), ckanLicense.getTitle());
|
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the given license id is in CKAN
|
* Check that the given license id is in CKAN
|
||||||
* @param license id to check
|
* @param license id to check
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.others.TimeSeriesBean;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.others.TimeSeriesBean;
|
||||||
|
import org.gcube.datacatalogue.common.Constants;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,31 +73,31 @@ public class CSVUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer headerLine = new StringBuffer();
|
StringBuffer headerLine = new StringBuffer();
|
||||||
headerLine.append(TimeSeriesBean.YEAR_FIELD);
|
headerLine.append(Constants.TIME_SERIES_YEAR_FIELD);
|
||||||
|
|
||||||
if(isValuePresent){
|
if(isValuePresent){
|
||||||
headerLine.append(CSV_SEPARATOR);
|
headerLine.append(CSV_SEPARATOR);
|
||||||
headerLine.append(TimeSeriesBean.VALUE_FIELD);
|
headerLine.append(Constants.TIME_SERIES_VALUE_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isUnitPresent){
|
if(isUnitPresent){
|
||||||
headerLine.append(CSV_SEPARATOR);
|
headerLine.append(CSV_SEPARATOR);
|
||||||
headerLine.append(TimeSeriesBean.UNIT_FIELD);
|
headerLine.append(Constants.TIME_SERIES_UNIT_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isSourcePresent){
|
if(isSourcePresent){
|
||||||
headerLine.append(CSV_SEPARATOR);
|
headerLine.append(CSV_SEPARATOR);
|
||||||
headerLine.append(TimeSeriesBean.DB_SOURCE_FIELD);
|
headerLine.append(Constants.TIME_SERIES_DB_SOURCE_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isDataOwnerPresent){
|
if(isDataOwnerPresent){
|
||||||
headerLine.append(CSV_SEPARATOR);
|
headerLine.append(CSV_SEPARATOR);
|
||||||
headerLine.append(TimeSeriesBean.DATA_OWNER_FIELD);
|
headerLine.append(Constants.TIME_SERIES_DATA_OWNER_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isAssessmentPresent){
|
if(isAssessmentPresent){
|
||||||
headerLine.append(CSV_SEPARATOR);
|
headerLine.append(CSV_SEPARATOR);
|
||||||
headerLine.append(TimeSeriesBean.ASSESSMENT_FIELD);
|
headerLine.append(Constants.TIME_SERIES_ASSESSMENT_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
bw.write(headerLine.toString());
|
bw.write(headerLine.toString());
|
||||||
|
|
Loading…
Reference in New Issue