Added the following fields : short_title, uuid, traceability_flag, water_area (as list), stock_uri

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133639 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-10-27 09:40:19 +00:00
parent 33514c202a
commit 08cbe4dee0
9 changed files with 76 additions and 64 deletions

View File

@ -13,6 +13,6 @@ import java.lang.annotation.Target;
@Target(ElementType.FIELD)
public @interface CustomField {
public String key() default ""; // this will be the key of this custom field field on ckan
public String key() default ""; // this will be the key of this custom field on ckan
}

View File

@ -11,6 +11,7 @@ import javax.validation.constraints.Size;
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.Tag;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -20,7 +21,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* Information that both Stock and Fishery must contain
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
@JsonIgnoreProperties(value = {"author", "author_contact"}, ignoreUnknown = true) // ignore in serialization/deserialization
@JsonIgnoreProperties(value = {"author", "author_contact", "extras"}, ignoreUnknown = true) // ignore in serialization/deserialization
public class Common {
@JsonProperty("description")
@ -80,6 +81,7 @@ public class Common {
@JsonProperty("uuid_knowledge_base")
@CustomField(key="UUID Knowledge Base")
@NotNull
@Size(min=1, message="uuid_knowledge_base cannot be empty")
private String uuid;
@JsonProperty("traceability_flag")
@ -88,7 +90,14 @@ public class Common {
private boolean traceabilityFlag;
@JsonProperty("extras")
private Map<String, String> extras = new HashMap<>();
private Map<String, List<String>> extras = new HashMap<>();
@JsonProperty("status")
@CustomField(key="Status")
@Group
@Tag
@NotNull(message="status cannot be null")
private Status status;
public Common() {
super();
@ -118,7 +127,7 @@ public class Common {
List<DatabaseSource> databaseSources,
List<Resource> sourceOfInformation, String dataOwner, Type type,
String shortTitle, String uuid, boolean traceabilityFlag,
Map<String, String> extras) {
Map<String, List<String>> extras) {
super();
this.description = description;
this.license = license;
@ -234,11 +243,11 @@ public class Common {
this.type = type;
}
public void setExtras(Map<String, String> extras) {
public void setExtras(Map<String, List<String>> extras) {
this.extras = extras;
}
public Map<String, String> getExtras() {
public Map<String, List<String>> getExtras() {
return extras;
}
@ -265,6 +274,14 @@ public class Common {
public void setTraceabilityFlag(boolean traceabilityFlag) {
this.traceabilityFlag = traceabilityFlag;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
@Override
public String toString() {

View File

@ -7,7 +7,6 @@ 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.Tag;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Production_System_Type;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -67,13 +66,6 @@ public class FisheryRecord extends Common{
@CustomField(key="Fishing gear")
private String fishingGear;
@JsonProperty("status")
@CustomField(key="Status")
@Group
@Tag
@NotNull(message="status cannot be null")
private Status status;
@JsonProperty("environment")
@CustomField(key="Environment")
private String environment;
@ -100,7 +92,7 @@ public class FisheryRecord extends Common{
String scientificName, String fishingArea, String exploitingStocks,
String managementEntity, String jurisdictionArea,
Production_System_Type productionSystemType, String flagState,
String fishingGear, Status status, String environment) {
String fishingGear, String environment) {
super();
this.fisheryName = fisheryName;
this.fisheryId = fisheryId;
@ -112,7 +104,6 @@ public class FisheryRecord extends Common{
this.productionSystemType = productionSystemType;
this.flagState = flagState;
this.fishingGear = fishingGear;
this.status = status;
this.environment = environment;
}
@ -196,14 +187,6 @@ public class FisheryRecord extends Common{
this.fishingGear = fishingGear;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getEnvironment() {
return environment;
}
@ -214,14 +197,14 @@ public class FisheryRecord extends Common{
@Override
public String toString() {
return "FisheryRecord [" + super.toString() + ", fisheryName=" + fisheryName + ", fisheryId="
return "FisheryRecord [" + super.toString() + ",fisheryName=" + fisheryName + ", fisheryId="
+ fisheryId + ", scientificName=" + scientificName
+ ", fishingArea=" + fishingArea + ", exploitingStocks="
+ exploitingStocks + ", managementEntity=" + managementEntity
+ ", jurisdictionArea=" + jurisdictionArea
+ ", productionSystemType=" + productionSystemType
+ ", flagState=" + flagState + ", fishingGear=" + fishingGear
+ ", status=" + status + ", environment=" + environment + "]";
+ ", environment=" + environment + "]";
}
}

View File

@ -10,7 +10,6 @@ import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Tag;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Exploitation_Rate;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -89,20 +88,11 @@ public class StockRecord extends Common{
@CustomField(key="Reporting year")
private Long reportingYear;
@JsonProperty("status")
@Tag
@Group
@NotNull(message="status cannot be null")
@CustomField(key="Status")
private Status status;
@JsonProperty("stock_uri")
@NotNull(message="stock_uri cannot be null")
@CustomField(key="Stock Uri")
private String stockUri;
@JsonProperty("water_area")
@NotNull(message="water_area cannot be null")
@CustomField(key="Water Area")
private List<String> waterArea;// TODO check that multiple values are mapped to ckan
@ -138,7 +128,7 @@ public class StockRecord extends Common{
String assessmentMethods, String stateOfMarineResource,
Exploitation_Rate exploitationRate, Abundance_Level abundanceLevel,
String narrativeStateAndTrend, String scientificAdvice,
String reportingEntity, Long reportingYear, Status status,
String reportingEntity, Long reportingYear,
String stockUri, List<String> waterArea) {
super();
this.stockName = stockName;
@ -155,7 +145,6 @@ public class StockRecord extends Common{
this.scientificAdvice = scientificAdvice;
this.reportingEntity = reportingEntity;
this.reportingYear = reportingYear;
this.status = status;
this.stockUri = stockUri;
this.waterArea = waterArea;
}
@ -288,17 +277,9 @@ public class StockRecord extends Common{
this.reportingYear = reportingYear;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
@Override
public String toString() {
return "StockRecord [" + super.toString() + ",stockName=" + stockName + ", stockID=" + stockID
return "StockRecord [" + super.toString() + "stockName=" + stockName + ", stockID=" + stockID
+ ", speciesScientificName=" + speciesScientificName
+ ", area=" + area + ", exploitingFishery=" + exploitingFishery
+ ", managementEntity=" + managementEntity
@ -309,7 +290,7 @@ public class StockRecord extends Common{
+ ", narrativeStateAndTrend=" + narrativeStateAndTrend
+ ", scientificAdvice=" + scientificAdvice
+ ", reportingEntity=" + reportingEntity + ", reportingYear="
+ reportingYear + ", status=" + status + ", stockUri="
+ stockUri + ", waterArea=" + waterArea + "]";
+ reportingYear + ", stockUri=" + stockUri + ", waterArea="
+ waterArea + "]";
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.data_catalogue.grsf_publish_ws.services;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -174,7 +175,7 @@ public class GrsfPublisherFisheryService {
HelperMethods.getGroups(groups, record);
// evaluate the custom fields
Map<String, String> customFields = new HashMap<String, String>();
Map<String, List<String>> customFields = new HashMap<String, List<String>>();
if(record.getExtras() != null)
customFields = record.getExtras();
@ -183,7 +184,7 @@ public class GrsfPublisherFisheryService {
HelperMethods.getExtras(customFields, record);
// add the type
customFields.put(HelperMethods.PRODUCT_TYPE, THIS_TYPE);
customFields.put(HelperMethods.PRODUCT_TYPE, Arrays.asList(THIS_TYPE));
// retrieve the user's email and fullname
String authorMail = HelperMethods.getUserEmail(context, SecurityTokenProvider.instance.get());
@ -216,7 +217,7 @@ public class GrsfPublisherFisheryService {
long version = record.getVersion() == null ? 1 : record.getVersion();
// create the product
id = catalogue.createCKanDataset(
id = catalogue.createCKanDatasetMultipleCustomFields(
catalogue.getApiKeyFromUsername(username),
futureTitle,
organization,

View File

@ -1,6 +1,7 @@
package org.gcube.data_catalogue.grsf_publish_ws.services;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -166,7 +167,7 @@ public class GrsfPublisherStockService {
HelperMethods.getGroups(groups, record);
// evaluate the custom fields
Map<String, String> customFields = new HashMap<String, String>();
Map<String, List<String>> customFields = new HashMap<String, List<String>>();
if(record.getExtras() != null)
customFields = record.getExtras();
@ -175,7 +176,7 @@ public class GrsfPublisherStockService {
HelperMethods.getExtras(customFields, record);
// add the type
customFields.put(HelperMethods.PRODUCT_TYPE, THIS_TYPE);
customFields.put(HelperMethods.PRODUCT_TYPE, Arrays.asList(THIS_TYPE));
// retrieve the user's email and fullname
String authorMail = HelperMethods.getUserEmail(context, SecurityTokenProvider.instance.get());
@ -207,7 +208,7 @@ public class GrsfPublisherStockService {
long version = record.getVersion() == null ? 1 : record.getVersion();
// create the product
id = catalogue.createCKanDataset(
id = catalogue.createCKanDatasetMultipleCustomFields(
catalogue.getApiKeyFromUsername(username),
futureTitle,
organization,

View File

@ -5,6 +5,7 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -165,7 +166,7 @@ public abstract class HelperMethods {
/**
* Retrieve the list of extras for this object
*/
public static void getExtras(Map<String, String> extras, Common record){
public static void getExtras(Map<String, List<String>> extras, Common record){
Class<?> current = record.getClass();
do{
@ -176,8 +177,22 @@ public abstract class HelperMethods {
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
if(f != null){
// get the key to put into the map first
extras.put(field.getAnnotation(CustomField.class).key(), f.toString().trim());
if(f.getClass().isArray()){
if(Collection.class.isAssignableFrom(f.getClass())){
logger.debug("The object " + field.getName() + " is a collection");
List<String> res = (List<String>)f;
extras.put(field.getAnnotation(CustomField.class).key(), res);
}else
logger.error("The object " + field.getName() + " cannot be convert to a list/array");
}else{
List<String> values = new ArrayList<String>();
if(extras.containsKey(field.getAnnotation(CustomField.class).key()))
values = extras.get(field.getAnnotation(CustomField.class).key());
values.add(f.toString().trim());
extras.put(field.getAnnotation(CustomField.class).key(), values);
}
}
}catch(Exception e){

View File

@ -1,8 +1,5 @@
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
import org.gcube.data_catalogue.grsf_publish_ws.filters.RequestsAuthAccountingFilter;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
@ -45,7 +42,6 @@ public enum Status {
*/
@JsonCreator
public static Status onDeserialize(String statusString) {
System.out.println("STATUS IS " + statusString);
if(statusString != null) {
for(Status status : Status.values()) {
if (status.toString().equalsIgnoreCase(statusString.trim()))

View File

@ -8,6 +8,7 @@ import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -18,13 +19,12 @@ import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Tag;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.DatabaseSource;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse;
@ -237,4 +237,22 @@ public class JTests {
// System.out.println(HelperMethods.retrieveOrgNameFromScope("/gcube/devNext/NextNext"));
}
//@Test
public void testCustomFieldAnnotation() throws JsonProcessingException{
StockRecord record = new StockRecord();
record.setWaterArea(Arrays.asList("aa", "bb", "cc", "dd"));
Map<String, List<String>> extras = new HashMap<String, List<String>>();
HelperMethods.getExtras(extras , record);
System.out.println("Extras = " + extras);
ObjectMapper mapper = new ObjectMapper();
//Object to JSON in String
String jsonInString = mapper.writeValueAsString(record);
System.out.println(jsonInString);
}
}