minor fixes: added super.toString() to print common fields for fishery and stock. Added more junit tests
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@132959 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d665ab0d5a
commit
0d27ef2e17
|
@ -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 the extras on ckan
|
||||
public String key() default ""; // this will be the key of this custom field field on ckan
|
||||
|
||||
}
|
||||
|
|
|
@ -15,43 +15,43 @@ public class FisheryRecord extends Common{
|
|||
|
||||
@JsonProperty("fishery_name")
|
||||
private String fisheryName;
|
||||
|
||||
|
||||
@JsonProperty("fishery_id")
|
||||
@CustomField(key="Fishery id")
|
||||
private String fisheryId;
|
||||
|
||||
|
||||
@JsonProperty("scientific_name")
|
||||
@Tag
|
||||
@CustomField(key="Scientific name")
|
||||
private String scientificName;
|
||||
|
||||
|
||||
@JsonProperty("fishing_area")
|
||||
@CustomField(key="Fishing area")
|
||||
private String fishingArea;
|
||||
|
||||
|
||||
@JsonProperty("exploiting_stocks")
|
||||
@CustomField(key="Exploiting stocks")
|
||||
private String exploitingStocks;
|
||||
|
||||
|
||||
@JsonProperty("management_entity")
|
||||
@Tag
|
||||
@CustomField(key="Management entity")
|
||||
private String managementEntity;
|
||||
|
||||
|
||||
@JsonProperty("jurisdiction_area")
|
||||
@CustomField(key="Jurisdiction Area")
|
||||
private String jurisdictionArea;
|
||||
|
||||
|
||||
@JsonProperty("production_system_type")
|
||||
@Group
|
||||
@CustomField(key="Production system type")
|
||||
private Production_System_Type productionSystemType;
|
||||
|
||||
|
||||
@JsonProperty("flag_state")
|
||||
@Tag
|
||||
@CustomField(key="Flag state")
|
||||
private String flagState;
|
||||
|
||||
|
||||
@JsonProperty("fishing_gear")
|
||||
@Tag
|
||||
@CustomField(key="Fishing gear")
|
||||
|
@ -173,7 +173,7 @@ public class FisheryRecord extends Common{
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FisheryRecord [fisheryName=" + fisheryName + ", fisheryId="
|
||||
return "FisheryRecord [" + super.toString() + ", fisheryName=" + fisheryName + ", fisheryId="
|
||||
+ fisheryId + ", scientificName=" + scientificName
|
||||
+ ", fishingArea=" + fishingArea + ", exploitingStocks="
|
||||
+ exploitingStocks + ", managementEntity=" + managementEntity
|
||||
|
@ -182,5 +182,6 @@ public class FisheryRecord extends Common{
|
|||
+ ", flagState=" + flagState + ", fishingGear=" + fishingGear
|
||||
+ "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ public class StockRecord extends Common{
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StockRecord [stockName=" + stockName + ", stockID=" + stockID
|
||||
return "StockRecord [" + super.toString() + ", stockName=" + stockName + ", stockID=" + stockID
|
||||
+ ", speciesScientificName=" + speciesScientificName
|
||||
+ ", area=" + area + ", exploitingFishery=" + exploitingFishery
|
||||
+ ", managementEntity=" + managementEntity
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.data_catalogue.grsf_publish_ws;
|
|||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -18,6 +19,8 @@ import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
|||
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.databind.ObjectMapper;
|
||||
|
||||
public class JTests {
|
||||
|
||||
//@Test
|
||||
|
@ -67,7 +70,7 @@ public class JTests {
|
|||
}
|
||||
}
|
||||
while((current = current.getSuperclass())!=null);
|
||||
|
||||
|
||||
// print
|
||||
System.out.println("TAGS " + tags);
|
||||
System.out.println("GROUPS " + groupsTitles);
|
||||
|
@ -86,17 +89,42 @@ public class JTests {
|
|||
Abundance_Level type = Abundance_Level.onDeserialize("Uncertain Not assessed");
|
||||
System.out.println("Res is " + type.onSerialize());
|
||||
}
|
||||
|
||||
|
||||
//@Test
|
||||
public void testNameToStringEnum(){
|
||||
|
||||
|
||||
Abundance_Level elem = Abundance_Level.Uncertain_Not_Assessed;
|
||||
System.out.println("Enum name is = " + elem.name() + ", enum to string is = " + elem.toString() + ", enum on serialize = " + elem.onSerialize());
|
||||
|
||||
|
||||
// try deserializer
|
||||
String deserialize = "uncertain not assessed";
|
||||
Abundance_Level res = Abundance_Level.onDeserialize(deserialize);
|
||||
System.out.println(res.name());
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testJSONMapping() throws IOException{
|
||||
|
||||
FisheryRecord recordFishery = new FisheryRecord();
|
||||
recordFishery.setType(Type.Fishing_Description);
|
||||
recordFishery.setDatabaseSources(Source.FIRMS);
|
||||
recordFishery.setStatus(Status.Pending);
|
||||
recordFishery.setVersion(new Long(10));
|
||||
HashMap<String, String> extras = new HashMap<String, String>();
|
||||
extras.put("test1", "testValue");
|
||||
extras.put("test2", "test2Value");
|
||||
recordFishery.setProperties(extras);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
//Object to JSON in String
|
||||
String jsonInString = mapper.writeValueAsString(recordFishery);
|
||||
|
||||
System.out.println(jsonInString);
|
||||
|
||||
FisheryRecord converted = mapper.readValue(jsonInString, recordFishery.getClass());
|
||||
|
||||
System.out.println(converted);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue