minor fixes to csv
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@157715 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3c10c7467c
commit
4d9c4888b2
|
@ -82,7 +82,7 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setYear(Long year) {
|
public void setYear(Long year) {
|
||||||
this.year = year;
|
this.year = year == null? -1 : year;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T1 getUnit() {
|
public T1 getUnit() {
|
||||||
|
@ -132,7 +132,7 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
|
|
||||||
@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 Long.compare(this.year, o.year);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,7 +142,7 @@ public class TimeSeriesBean<T, T1> implements Comparable<TimeSeriesBean<T, T1>>{
|
||||||
String unit = (this.unit != null ? " " + this.unit : "");
|
String unit = (this.unit != null ? " " + this.unit : "");
|
||||||
String databaseSource = (this.databaseSource != null ? " (" + this.databaseSource + ")" : "");
|
String databaseSource = (this.databaseSource != null ? " (" + this.databaseSource + ")" : "");
|
||||||
String dataOwner = (this.dataOwner != null ? " " + this.dataOwner : "");
|
String dataOwner = (this.dataOwner != null ? " " + this.dataOwner : "");
|
||||||
String referenceYear = " Ref. Year " + year;
|
String referenceYear = year >= 0 ? " Ref. Year " + year : "";
|
||||||
String reportingYearOrAssessment = (assessment != null ? " and Rep. Year or Assessment Id " + assessment + "" : "");
|
String reportingYearOrAssessment = (assessment != null ? " and Rep. Year or Assessment Id " + assessment + "" : "");
|
||||||
|
|
||||||
return value + unit + databaseSource + dataOwner + referenceYear + reportingYearOrAssessment;
|
return value + unit + databaseSource + dataOwner + referenceYear + reportingYearOrAssessment;
|
||||||
|
|
|
@ -49,7 +49,7 @@ import eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||||
* Fishery web service methods.
|
* Fishery web service methods.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
@Path("{source:firms|FIRMS|ram|RAM|grsf|GRSF|FishSource|fishsource}/fishery/")
|
@Path("{source:firms|FIRMS|grsf|GRSF|FishSource|fishsource}/fishery/")
|
||||||
public class GrsfPublisherFisheryService {
|
public class GrsfPublisherFisheryService {
|
||||||
|
|
||||||
// the context
|
// the context
|
||||||
|
@ -108,7 +108,7 @@ public class GrsfPublisherFisheryService {
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||||
String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";
|
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
||||||
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
||||||
|
|
||||||
// extend this role to the other organizations in this context
|
// extend this role to the other organizations in this context
|
||||||
|
@ -136,7 +136,19 @@ public class GrsfPublisherFisheryService {
|
||||||
List<ResourceBean> resources = record.getExtrasResources();
|
List<ResourceBean> resources = record.getExtrasResources();
|
||||||
|
|
||||||
// validate end set sources
|
// validate end set sources
|
||||||
CommonServiceUtils.validateRecordAndMapFields(apiKey, context, contextServlet, sourceInPath, record, Product_Type.FISHERY, tags, customFields, groups, resources, username, futureTitle);
|
CommonServiceUtils.validateRecordAndMapFields(
|
||||||
|
apiKey,
|
||||||
|
context,
|
||||||
|
contextServlet,
|
||||||
|
sourceInPath,
|
||||||
|
record,
|
||||||
|
Product_Type.FISHERY,
|
||||||
|
tags,
|
||||||
|
customFields,
|
||||||
|
groups,
|
||||||
|
resources,
|
||||||
|
username,
|
||||||
|
futureTitle);
|
||||||
|
|
||||||
// check the license id
|
// check the license id
|
||||||
String license = null;
|
String license = null;
|
||||||
|
@ -145,7 +157,8 @@ public class GrsfPublisherFisheryService {
|
||||||
else
|
else
|
||||||
if(HelperMethods.existsLicenseId(record.getLicense(), catalogue))
|
if(HelperMethods.existsLicenseId(record.getLicense(), catalogue))
|
||||||
license = record.getLicense();
|
license = record.getLicense();
|
||||||
else throw new Exception("Please check the license id!");
|
else
|
||||||
|
throw new Exception("Please check the license id!");
|
||||||
|
|
||||||
long version = record.getVersion() == null ? 1 : record.getVersion();
|
long version = record.getVersion() == null ? 1 : record.getVersion();
|
||||||
|
|
||||||
|
@ -186,10 +199,10 @@ public class GrsfPublisherFisheryService {
|
||||||
if(id != null){
|
if(id != null){
|
||||||
|
|
||||||
logger.info("Created record with identifier " + id);
|
logger.info("Created record with identifier " + id);
|
||||||
String description = "Short Name: " + record.getShortName() + "\n";
|
String description = Constants.SHORT_NAME_CUSTOM_KEY + ": " + record.getShortName() + "\n";
|
||||||
|
|
||||||
if(sourceInPath.equals(Sources.GRSF))
|
if(sourceInPath.equals(Sources.GRSF))
|
||||||
description += ", GRSF Semantic Identifier: " + record.getFisheryId() + "\n";
|
description += ", " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + ": " + record.getFisheryId() + "\n";
|
||||||
|
|
||||||
CommonServiceUtils.actionsPostCreateOrUpdate(
|
CommonServiceUtils.actionsPostCreateOrUpdate(
|
||||||
id, futureName, record, apiKey, username, organization,
|
id, futureName, record, apiKey, username, organization,
|
||||||
|
@ -261,10 +274,6 @@ public class GrsfPublisherFisheryService {
|
||||||
status = Status.OK;
|
status = Status.OK;
|
||||||
responseBean.setId(fisheryInCkan.getId());
|
responseBean.setId(fisheryInCkan.getId());
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
|
||||||
throw new Exception("Request failed, sorry. Unable to delete/purge the fishery");
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
throw new Exception("The id you are using doesn't belong to a Fishery item having source " + source + "!");
|
throw new Exception("The id you are using doesn't belong to a Fishery item having source " + source + "!");
|
||||||
|
@ -394,7 +403,7 @@ public class GrsfPublisherFisheryService {
|
||||||
|
|
||||||
if(catalogId == null || catalogId.isEmpty()){
|
if(catalogId == null || catalogId.isEmpty()){
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
throw new Exception("Please specify the 'catalog_id' property");
|
throw new Exception("Please specify the '" + Constants.CATALOG_ID + "' property");
|
||||||
}
|
}
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
|
@ -419,13 +428,12 @@ public class GrsfPublisherFisheryService {
|
||||||
throw new Exception("Sorry but there was not possible to retrieve your fullname/email!");
|
throw new Exception("Sorry but there was not possible to retrieve your fullname/email!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
||||||
String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";
|
|
||||||
|
|
||||||
// check he/she has admin role
|
// check he/she has admin role
|
||||||
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
||||||
|
|
||||||
// name, title, product url and are going to remain unchanged (so we keep them from the publisher record);
|
// name, title, product url and are going to remain unchanged (so we keep them from the already published record);
|
||||||
String name = recordPublished.getName();
|
String name = recordPublished.getName();
|
||||||
String title = recordPublished.getTitle();
|
String title = recordPublished.getTitle();
|
||||||
|
|
||||||
|
@ -467,16 +475,13 @@ public class GrsfPublisherFisheryService {
|
||||||
// set the visibility of the datatest according the context
|
// set the visibility of the datatest according the context
|
||||||
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
||||||
|
|
||||||
// add the SYSTEM_TYPE
|
|
||||||
customFields.put(Constants.SYSTEM_TYPE_CUSTOM_KEY, Arrays.asList(sourceInPath.getOrigName()));
|
|
||||||
|
|
||||||
// convert extras' keys to keys with namespace
|
// convert extras' keys to keys with namespace
|
||||||
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
||||||
|
|
||||||
if(namespaces == null)
|
if(namespaces == null)
|
||||||
throw new Exception("Failed to retrieve the namespaces for the key fields!");
|
throw new Exception("Failed to retrieve the namespaces for the key fields!");
|
||||||
|
|
||||||
// retrieve the url
|
// retrieve the already generated url
|
||||||
String modifiedUUIDKey = namespaces.containsKey(Constants.ITEM_URL_FIELD) ?
|
String modifiedUUIDKey = namespaces.containsKey(Constants.ITEM_URL_FIELD) ?
|
||||||
namespaces.get(Constants.ITEM_URL_FIELD) :
|
namespaces.get(Constants.ITEM_URL_FIELD) :
|
||||||
Constants.ITEM_URL_FIELD;
|
Constants.ITEM_URL_FIELD;
|
||||||
|
@ -522,7 +527,6 @@ public class GrsfPublisherFisheryService {
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to update fishery record" + e);
|
logger.error("Failed to update fishery 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();
|
||||||
|
|
|
@ -200,15 +200,16 @@ public class GrsfPublisherStockService {
|
||||||
if(id != null){
|
if(id != null){
|
||||||
|
|
||||||
logger.info("Product created! Id is " + id);
|
logger.info("Product created! Id is " + id);
|
||||||
String description = "Short Name: " + record.getShortName() + "\n";
|
String description = Constants.SHORT_NAME_CUSTOM_KEY + ": " + record.getShortName() + "\n";
|
||||||
|
|
||||||
if(sourceInPath.equals(Sources.GRSF))
|
if(sourceInPath.equals(Sources.GRSF))
|
||||||
description += ", GRSF Semantic Identifier: " + record.getStockId() + "\n";
|
description += ", " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + ": " + record.getStockId() + "\n";
|
||||||
|
|
||||||
CommonServiceUtils.actionsPostCreateOrUpdate(
|
CommonServiceUtils.actionsPostCreateOrUpdate(
|
||||||
id, futureName, record, apiKey, username, organization, null,
|
id, futureName, record, apiKey, username, organization, null,
|
||||||
responseBean, catalogue, namespaces, groups, context, token,
|
responseBean, catalogue, namespaces, groups, context, token,
|
||||||
futureTitle, authorFullname, contextServlet, false, description);
|
futureTitle, authorFullname, contextServlet, false, description);
|
||||||
|
|
||||||
status = Status.CREATED;
|
status = Status.CREATED;
|
||||||
|
|
||||||
}else
|
}else
|
||||||
|
@ -323,7 +324,6 @@ public class GrsfPublisherStockService {
|
||||||
for (String id : fullGroupListIds) {
|
for (String id : fullGroupListIds) {
|
||||||
CkanDataset dataset = catalogue.getDataset(id, catalogue.getApiKeyFromUsername(username));
|
CkanDataset dataset = catalogue.getDataset(id, catalogue.getApiKeyFromUsername(username));
|
||||||
if(dataset != null){
|
if(dataset != null){
|
||||||
|
|
||||||
String type = dataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY);
|
String type = dataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY);
|
||||||
if(Product_Type.STOCK.getOrigName().equals(type))
|
if(Product_Type.STOCK.getOrigName().equals(type))
|
||||||
datasetsIds.add(id);
|
datasetsIds.add(id);
|
||||||
|
@ -474,9 +474,6 @@ public class GrsfPublisherStockService {
|
||||||
// set the visibility of the datatest according the context
|
// set the visibility of the datatest according the context
|
||||||
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
||||||
|
|
||||||
// add the SYSTEM_TYPE
|
|
||||||
customFields.put(Constants.SYSTEM_TYPE_CUSTOM_KEY, Arrays.asList(sourceInPath.getOrigName()));
|
|
||||||
|
|
||||||
// convert extras' keys to keys with namespace
|
// convert extras' keys to keys with namespace
|
||||||
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK);
|
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK);
|
||||||
|
|
||||||
|
@ -529,7 +526,6 @@ public class GrsfPublisherStockService {
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to update stock record", e);
|
logger.error("Failed to update 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();
|
||||||
|
|
|
@ -61,7 +61,6 @@ public class CommonServiceUtils {
|
||||||
licenses = HelperMethods.getLicenses(HelperMethods.getDataCatalogueRunningInstance(ScopeProvider.instance.get()));
|
licenses = HelperMethods.getLicenses(HelperMethods.getDataCatalogueRunningInstance(ScopeProvider.instance.get()));
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to retrieve the list of licenses");
|
logger.error("Failed to retrieve the list of licenses");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return licenses;
|
return licenses;
|
||||||
}
|
}
|
||||||
|
@ -583,7 +582,7 @@ public class CommonServiceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate in which organization a record has to be published. The only expcetion is when grsf_admin is involved.
|
* Evaluate in which organization a record has to be published. The only exception is when grsf_admin is involved.
|
||||||
* @param organization
|
* @param organization
|
||||||
* @param sourceInPath
|
* @param sourceInPath
|
||||||
* @return
|
* @return
|
||||||
|
|
|
@ -44,14 +44,14 @@ public class GcoreEndPointReaderSocial {
|
||||||
|
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> endpoints = client.submit(query);
|
List<String> endpoints = client.submit(query);
|
||||||
if (endpoints == null || endpoints.isEmpty()) throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context);
|
if (endpoints == null || endpoints.isEmpty())
|
||||||
|
throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context);
|
||||||
|
|
||||||
|
|
||||||
this.basePath = endpoints.get(0);
|
this.basePath = endpoints.get(0);
|
||||||
if(basePath==null)
|
if(basePath==null)
|
||||||
throw new Exception("Endpoint:"+resource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context);
|
throw new Exception("Endpoint:"+resource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context);
|
||||||
|
|
||||||
logger.info("found entyname "+basePath+" for ckanResource: "+resource);
|
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Unable to retrieve such service endpoint information!", e);
|
logger.error("Unable to retrieve such service endpoint information!", e);
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class CSVUtils {
|
||||||
for (TimeSeriesBean<T, T1> bean : timeSeries)
|
for (TimeSeriesBean<T, T1> bean : timeSeries)
|
||||||
{
|
{
|
||||||
StringBuffer oneLine = new StringBuffer();
|
StringBuffer oneLine = new StringBuffer();
|
||||||
oneLine.append(bean.getYear());
|
oneLine.append(bean.getYear() > 0 ? bean.getYear() : "");
|
||||||
|
|
||||||
if(isValuePresent){
|
if(isValuePresent){
|
||||||
oneLine.append(CSV_SEPARATOR);
|
oneLine.append(CSV_SEPARATOR);
|
||||||
|
@ -144,9 +144,6 @@ public class CSVUtils {
|
||||||
|
|
||||||
bw.close();
|
bw.close();
|
||||||
|
|
||||||
// file created
|
|
||||||
logger.debug("CSV file created correctly on this machine!");
|
|
||||||
|
|
||||||
// Add names of the sources to the file's name
|
// Add names of the sources to the file's name
|
||||||
for (String source : sources) {
|
for (String source : sources) {
|
||||||
relevantSources[0] += source + "_";
|
relevantSources[0] += source + "_";
|
||||||
|
@ -155,6 +152,10 @@ public class CSVUtils {
|
||||||
|
|
||||||
// on exit delete it...
|
// on exit delete it...
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
|
|
||||||
|
// file created
|
||||||
|
logger.debug("CSV file created correctly on this machine!");
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){
|
||||||
|
|
Loading…
Reference in New Issue