refactoring
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@157684 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bd1cd054cc
commit
3c10c7467c
|
@ -9,20 +9,20 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when @Valid fail
|
* Exception thrown on fail
|
||||||
* @author Costantino Perciante at ISTI-CNR
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
*/
|
*/
|
||||||
//@Provider
|
@Provider
|
||||||
public class ApplicationException implements ExceptionMapper<Exception> {
|
public class ApplicationException implements ExceptionMapper<Exception> {
|
||||||
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ApplicationException.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ApplicationException.class);
|
||||||
|
|
||||||
public Response toResponse(Exception e) {
|
public Response toResponse(Exception e) {
|
||||||
logger.warn("ApplicationException invoked for error " + e);
|
logger.warn("ApplicationException invoked for error " + e);
|
||||||
return Response
|
return Response
|
||||||
.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
|
.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
|
||||||
.type(MediaType.APPLICATION_JSON)
|
.type(MediaType.APPLICATION_JSON)
|
||||||
.entity(new ResponseBean(false, e.toString(), null))
|
.entity(new ResponseBean(false, e.toString(), null))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown on fail
|
* Exception thrown when @Valid fails
|
||||||
* @author Costantino Perciante at ISTI-CNR
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Provider
|
@Provider
|
||||||
|
|
|
@ -13,16 +13,18 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class contains basic information needed to publish something in the data catalogue.
|
* The base class contains basic information needed to publish something in the data catalogue.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class Base {
|
public class Base {
|
||||||
|
|
||||||
private static final List<String> FIELDS_TO_IGNORE = Arrays.asList(
|
private static final List<String> FIELDS_TO_IGNORE = Arrays.asList(
|
||||||
Constants.AUTHOR, Constants.AUTHOR_CONTACT, Constants.SYSTEM_TYPE_CUSTOM_KEY);
|
Constants.AUTHOR, Constants.AUTHOR_CONTACT, Constants.SYSTEM_TYPE_CUSTOM_KEY, Constants.GRSF_TYPE_JSON_KEY);
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(Base.class);
|
private static Logger logger = LoggerFactory.getLogger(Base.class);
|
||||||
|
|
||||||
|
@ -183,7 +185,7 @@ public class Base {
|
||||||
logger.info("Found extra property: [" + key + "," + value + "]");
|
logger.info("Found extra property: [" + key + "," + value + "]");
|
||||||
|
|
||||||
if(FIELDS_TO_IGNORE.contains(key)){
|
if(FIELDS_TO_IGNORE.contains(key)){
|
||||||
logger.debug("Ignoring it");
|
logger.debug("Ignoring field with key " + key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,12 @@ import org.gcube.datacatalogue.common.Constants;
|
||||||
import org.gcube.datacatalogue.common.enums.Sources;
|
import org.gcube.datacatalogue.common.enums.Sources;
|
||||||
import org.gcube.datacatalogue.common.enums.Status;
|
import org.gcube.datacatalogue.common.enums.Status;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information that both Stock and Fishery records must contain.
|
* Information that both Stock and Fishery records must contain.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(value = {Constants.GRSF_TYPE_JSON_KEY})
|
|
||||||
public class Common extends Base{
|
public class Common extends Base{
|
||||||
|
|
||||||
// it is added in case of GRSF record
|
// it is added in case of GRSF record
|
||||||
|
|
|
@ -12,14 +12,12 @@ import org.gcube.datacatalogue.common.Constants;
|
||||||
import org.gcube.datacatalogue.common.enums.Fishery_Type;
|
import org.gcube.datacatalogue.common.enums.Fishery_Type;
|
||||||
import org.gcube.datacatalogue.common.enums.Production_System_Type;
|
import org.gcube.datacatalogue.common.enums.Production_System_Type;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fishery record bean.
|
* A fishery record bean.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class FisheryRecord extends Common{
|
public class FisheryRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty(Constants.FISHERY_NAME_JSON_KEY)
|
@JsonProperty(Constants.FISHERY_NAME_JSON_KEY)
|
||||||
|
|
|
@ -16,14 +16,12 @@ import org.gcube.datacatalogue.common.enums.Abundance_Level;
|
||||||
import org.gcube.datacatalogue.common.enums.Fishing_Pressure;
|
import org.gcube.datacatalogue.common.enums.Fishing_Pressure;
|
||||||
import org.gcube.datacatalogue.common.enums.Stock_Type;
|
import org.gcube.datacatalogue.common.enums.Stock_Type;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stock record bean.
|
* A stock record bean.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class StockRecord extends Common{
|
public class StockRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty(Constants.STOCK_NAME_JSON_KEY)
|
@JsonProperty(Constants.STOCK_NAME_JSON_KEY)
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class GrsfPublisherFisheryService {
|
||||||
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
||||||
|
|
||||||
// convert extras' keys to keys with namespace
|
// convert extras' keys to keys with namespace
|
||||||
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.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!");
|
||||||
|
@ -471,7 +471,7 @@ public class GrsfPublisherFisheryService {
|
||||||
customFields.put(Constants.SYSTEM_TYPE_CUSTOM_KEY, Arrays.asList(sourceInPath.getOrigName()));
|
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(HelperMethods.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!");
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class GrsfPublisherStockService {
|
||||||
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
||||||
|
|
||||||
// convert extras' keys to keys with namespace
|
// convert extras' keys to keys with namespace
|
||||||
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK);
|
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK);
|
||||||
|
|
||||||
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!");
|
||||||
|
@ -478,7 +478,7 @@ public class GrsfPublisherStockService {
|
||||||
customFields.put(Constants.SYSTEM_TYPE_CUSTOM_KEY, Arrays.asList(sourceInPath.getOrigName()));
|
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(HelperMethods.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK);
|
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK);
|
||||||
|
|
||||||
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!");
|
||||||
|
|
|
@ -26,8 +26,8 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
|
||||||
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.csv.ManageTimeSeriesThread;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.ManageTimeSeriesThread;
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.WritePostCatalogueManagerThread;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.WritePostCatalogueManagerThread;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
||||||
|
|
|
@ -67,9 +67,6 @@ public abstract class HelperMethods {
|
||||||
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "/2/posts/write-post-app/";
|
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "/2/posts/write-post-app/";
|
||||||
private static final String MEDIATYPE_JSON = "application/json";
|
private static final String MEDIATYPE_JSON = "application/json";
|
||||||
|
|
||||||
public static final String GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK = "GRSF Stock";
|
|
||||||
public static final String GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY = "GRSF Fishery";
|
|
||||||
|
|
||||||
// to be retrieved from the web.xml
|
// to be retrieved from the web.xml
|
||||||
public static final String MANAGE_CONTEX_KEY = "ManageVRE";
|
public static final String MANAGE_CONTEX_KEY = "ManageVRE";
|
||||||
public static final String PUBLIC_CONTEX_KEY = "PublicVRE";
|
public static final String PUBLIC_CONTEX_KEY = "PublicVRE";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.data_catalogue.grsf_publish_ws.utils;
|
package org.gcube.data_catalogue.grsf_publish_ws.utils.csv;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.data_catalogue.grsf_publish_ws.utils.threads;
|
package org.gcube.data_catalogue.grsf_publish_ws.utils.csv;
|
||||||
|
|
||||||
import java.beans.IntrospectionException;
|
import java.beans.IntrospectionException;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
|
@ -25,7 +25,6 @@ import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.TimeSeries;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVUtils;
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.common.caches.CacheImpl;
|
import org.gcube.datacatalogue.common.caches.CacheImpl;
|
|
@ -32,8 +32,8 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.input.others.TimeSeriesBean
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVUtils;
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
||||||
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.csv.CSVUtils;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
||||||
|
|
Loading…
Reference in New Issue