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>
|
||||
<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"
|
||||
date="2017-08-01">
|
||||
<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.Size;
|
||||
|
||||
import org.gcube.datacatalogue.common.Constants;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
@ -13,9 +15,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
||||
public class DeleteRecord {
|
||||
|
||||
@JsonProperty("id")
|
||||
@NotNull(message="id cannot be null")
|
||||
@Size(min=1, message="id cannot be empty")
|
||||
@JsonProperty(Constants.DELETE_RECORD_ID)
|
||||
@NotNull(message= Constants.DELETE_RECORD_ID + " cannot be null")
|
||||
@Size(min=1, message= Constants.DELETE_RECORD_ID + " cannot be empty")
|
||||
private String id;
|
||||
|
||||
public DeleteRecord() {
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.data_catalogue.grsf_publish_ws.json.input.others;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.gcube.datacatalogue.common.Constants;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
@ -14,11 +16,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RefersToBean {
|
||||
|
||||
@JsonProperty("url")
|
||||
@JsonProperty(Constants.REFERS_TO_URL)
|
||||
@NotNull(message="url of field refers_to cannot be null")
|
||||
String url;
|
||||
|
||||
@JsonProperty("id")
|
||||
@JsonProperty(Constants.REFERS_TO_ID)
|
||||
@NotNull(message="id of field refers_to cannot be null")
|
||||
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.Size;
|
||||
|
||||
import org.gcube.datacatalogue.common.Constants;
|
||||
import org.gcube.datacatalogue.common.enums.Sources;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
@ -16,15 +17,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
||||
public class Resource<T> {
|
||||
|
||||
@JsonProperty("url")
|
||||
@JsonProperty(Constants.RESOURCE_URL)
|
||||
@NotNull(message="'url' field of a resource cannot be null")
|
||||
@Size(min=1, message="'url' field of a resource cannot be empty")
|
||||
private String url;
|
||||
|
||||
@JsonProperty("description")
|
||||
@JsonProperty(Constants.RESOURCE_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
@JsonProperty("name")
|
||||
@JsonProperty(Constants.RESOURCE_NAME)
|
||||
@NotNull(message="'name' field of a resource cannot be null")
|
||||
private T name;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.JsonProperty;
|
||||
|
||||
|
@ -13,29 +15,22 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||
|
||||
public static final String YEAR_FIELD = "reference_year";
|
||||
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)
|
||||
@JsonProperty(Constants.TIME_SERIES_YEAR_FIELD)
|
||||
private Long year;
|
||||
|
||||
@JsonProperty(DB_SOURCE_FIELD)
|
||||
@JsonProperty(Constants.TIME_SERIES_DB_SOURCE_FIELD)
|
||||
private String databaseSource;
|
||||
|
||||
@JsonProperty(ASSESSMENT_FIELD)
|
||||
@JsonProperty(Constants.TIME_SERIES_ASSESSMENT_FIELD)
|
||||
private String assessment;
|
||||
|
||||
@JsonProperty(DATA_OWNER_FIELD)
|
||||
@JsonProperty(Constants.TIME_SERIES_DATA_OWNER_FIELD)
|
||||
private String dataOwner;
|
||||
|
||||
@JsonProperty(VALUE_FIELD)
|
||||
@JsonProperty(Constants.TIME_SERIES_VALUE_FIELD)
|
||||
private T value;
|
||||
|
||||
@JsonProperty(UNIT_FIELD)
|
||||
@JsonProperty(Constants.TIME_SERIES_UNIT_FIELD)
|
||||
private T1 unit;
|
||||
|
||||
public TimeSeriesBean() {
|
||||
|
@ -82,7 +77,8 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
|||
}
|
||||
|
||||
public void setYear(Long year) {
|
||||
this.year = year == null? -1 : year;
|
||||
// Check year
|
||||
this.year = (year == null? -1 : year);
|
||||
}
|
||||
|
||||
public T1 getUnit() {
|
||||
|
|
|
@ -25,8 +25,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
public class StockRecord extends Common{
|
||||
|
||||
@JsonProperty(Constants.STOCK_NAME_JSON_KEY)
|
||||
@NotNull(message="stock_name cannot be null")
|
||||
@Size(min=2, message="stock_name cannot be empty")
|
||||
@NotNull(message=Constants.STOCK_NAME_JSON_KEY + " cannot be null")
|
||||
@Size(min=2, message=Constants.STOCK_NAME_JSON_KEY + " cannot be empty")
|
||||
@CustomField(key=Constants.STOCK_NAME_CUSTOM_KEY)
|
||||
private String stockName;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.json.output;
|
||||
|
||||
import org.gcube.datacatalogue.common.Constants;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
|
@ -8,16 +10,16 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
*/
|
||||
public class ResponseCreationBean {
|
||||
|
||||
@JsonProperty("id")
|
||||
@JsonProperty(Constants.RESPONSE_CREATE_PATCH_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
|
||||
|
||||
@JsonProperty("product_url")
|
||||
@JsonProperty(Constants.RESPONSE_CREATE_PRODUCT_URL)
|
||||
private String itemUrl;
|
||||
|
||||
@JsonProperty("error")
|
||||
@JsonProperty(Constants.RESPONSE_CREATE_ERROR_MESSAGE)
|
||||
private String error; // in case of error
|
||||
|
||||
public ResponseCreationBean() {
|
||||
|
|
|
@ -70,10 +70,19 @@ public class GrsfPublisherFisheryService {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getLicenses(){
|
||||
Status status = Status.OK;
|
||||
Map<String, String> licenses = CommonServiceUtils.getLicenses();
|
||||
if(licenses == null)
|
||||
String context = ScopeProvider.instance.get();
|
||||
DataCatalogue catalogue;
|
||||
try {
|
||||
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||
Map<String, String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
||||
if(licenses == null)
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(licenses).build();
|
||||
} catch (Exception e) {
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(licenses).build();
|
||||
return Response.status(status).entity(new ResponseBean(false,
|
||||
"Unable to retrieve license list " + e.getLocalizedMessage(), null)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
|
@ -69,13 +69,20 @@ public class GrsfPublisherStockService {
|
|||
@Path("get-licenses")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getLicenses(){
|
||||
|
||||
Status status = Status.OK;
|
||||
Map<String, String> licenses = CommonServiceUtils.getLicenses();
|
||||
if(licenses == null)
|
||||
String context = ScopeProvider.instance.get();
|
||||
DataCatalogue catalogue;
|
||||
try {
|
||||
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||
Map<String, String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
||||
if(licenses == null)
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(licenses).build();
|
||||
} catch (Exception e) {
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(licenses).build();
|
||||
|
||||
return Response.status(status).entity(new ResponseBean(false,
|
||||
"Unable to retrieve license list " + e.getLocalizedMessage(), null)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
|
@ -217,6 +224,7 @@ public class GrsfPublisherStockService {
|
|||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to create stock record", e);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
responseBean.setError(e.getMessage());
|
||||
}
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
|
@ -514,7 +522,7 @@ public class GrsfPublisherStockService {
|
|||
if(id != null){
|
||||
|
||||
logger.info("Item updated!");
|
||||
|
||||
|
||||
String description = Constants.SHORT_NAME_CUSTOM_KEY + ": " + record.getShortName() + "\n";
|
||||
|
||||
if(sourceInPath.equals(Sources.GRSF))
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Set;
|
|||
|
||||
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.CustomField;
|
||||
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 eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
||||
|
||||
/**
|
||||
* Services common utils.
|
||||
|
@ -54,15 +54,15 @@ public class CommonServiceUtils {
|
|||
* Retrieve the list of licenses for stocks and fisheries
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getLicenses(){
|
||||
Map<String, String> licenses = null;
|
||||
try{
|
||||
logger.info("Requested licenses...");
|
||||
licenses = HelperMethods.getLicenses(HelperMethods.getDataCatalogueRunningInstance(ScopeProvider.instance.get()));
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to retrieve the list of licenses");
|
||||
public static Map<String, String> getLicenses(DataCatalogue catalogue){
|
||||
logger.info("Requested licenses...");
|
||||
Map<String, String> toReturn = new HashMap<String, String>();
|
||||
List<CkanLicense> licenses = catalogue.getLicenses();
|
||||
|
||||
for (CkanLicense ckanLicense : licenses) {
|
||||
toReturn.put(ckanLicense.getId(), ckanLicense.getTitle());
|
||||
}
|
||||
return licenses;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,7 +518,7 @@ public class CommonServiceUtils {
|
|||
addField.put(modifiedUUIDKey, Arrays.asList(itemUrl));
|
||||
catalogue.patchProductCustomFields(datasetId, apiKey, addField);
|
||||
}
|
||||
|
||||
|
||||
// update description anyway
|
||||
description += ", Record URL: " + itemUrl;
|
||||
JSONObject obj = new JSONObject();
|
||||
|
|
|
@ -30,7 +30,6 @@ public class GcoreEndPointReaderSocial {
|
|||
if(context == null || context.isEmpty())
|
||||
throw new IllegalArgumentException("A valid context is needed to discover the service");
|
||||
|
||||
|
||||
String oldContext = ScopeProvider.instance.get();
|
||||
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
|
||||
* @param license id to check
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.others.TimeSeriesBean;
|
||||
import org.gcube.datacatalogue.common.Constants;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
@ -72,31 +73,31 @@ public class CSVUtils {
|
|||
}
|
||||
|
||||
StringBuffer headerLine = new StringBuffer();
|
||||
headerLine.append(TimeSeriesBean.YEAR_FIELD);
|
||||
headerLine.append(Constants.TIME_SERIES_YEAR_FIELD);
|
||||
|
||||
if(isValuePresent){
|
||||
headerLine.append(CSV_SEPARATOR);
|
||||
headerLine.append(TimeSeriesBean.VALUE_FIELD);
|
||||
headerLine.append(Constants.TIME_SERIES_VALUE_FIELD);
|
||||
}
|
||||
|
||||
if(isUnitPresent){
|
||||
headerLine.append(CSV_SEPARATOR);
|
||||
headerLine.append(TimeSeriesBean.UNIT_FIELD);
|
||||
headerLine.append(Constants.TIME_SERIES_UNIT_FIELD);
|
||||
}
|
||||
|
||||
if(isSourcePresent){
|
||||
headerLine.append(CSV_SEPARATOR);
|
||||
headerLine.append(TimeSeriesBean.DB_SOURCE_FIELD);
|
||||
headerLine.append(Constants.TIME_SERIES_DB_SOURCE_FIELD);
|
||||
}
|
||||
|
||||
if(isDataOwnerPresent){
|
||||
headerLine.append(CSV_SEPARATOR);
|
||||
headerLine.append(TimeSeriesBean.DATA_OWNER_FIELD);
|
||||
headerLine.append(Constants.TIME_SERIES_DATA_OWNER_FIELD);
|
||||
}
|
||||
|
||||
if(isAssessmentPresent){
|
||||
headerLine.append(CSV_SEPARATOR);
|
||||
headerLine.append(TimeSeriesBean.ASSESSMENT_FIELD);
|
||||
headerLine.append(Constants.TIME_SERIES_ASSESSMENT_FIELD);
|
||||
}
|
||||
|
||||
bw.write(headerLine.toString());
|
||||
|
|
Loading…
Reference in New Issue