From e32ccbac4d681204548bbd16549e2c8f9f83957d Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Thu, 13 Oct 2016 12:25:11 +0000 Subject: [PATCH] minor fix git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133167 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../services/GrsfPublisherStockService.java | 2 +- .../grsf_publish_ws/JTests.java | 104 +++++++++++------- 2 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java index 8b62e5f..21543da 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java @@ -218,7 +218,7 @@ public class GrsfPublisherStockService { license, tags, customFields, - null, + resources, setPublic); // TODO if(id != null){ diff --git a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java index c9c1817..1eda4ca 100644 --- a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java +++ b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java @@ -11,25 +11,19 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; - -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; 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.json.input.Common; 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.utils.HelperMethods; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level; -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 org.junit.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse; import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpGet; @@ -119,37 +113,63 @@ public class JTests { System.out.println(res.name()); } - //@Test + @Test public void testJSONMapping() throws IOException{ - StockRecord recordStock = new StockRecord(); - recordStock.setType(Type.Fishing_Description); - ArrayList list = new ArrayList(); - list.add(new DatabaseSource("http", null, Source.onDeserialize("s"))); - recordStock.setDatabaseSources(list); - recordStock.setAuthor("Costantino Perciante"); - recordStock.setMaintainer("Costantino Perciante"); - recordStock.setAuthorContact("costantino.perciante@isti.cnr.it"); - recordStock.setStatus(Status.Pending); - recordStock.setVersion(new Long(1)); + FisheryRecord record = new FisheryRecord(); + // record.setType(Type.Assessment_Unit); + // record.setFisheryId("sajhdskajda"); + // record.setScientificName("assadsadada"); + // // record.setExploitationRate(Exploitation_Rate.High_Fishing_Mortality); + // // record.setAbundanceLevel(Abundance_Level.Uncertain_Not_Assessed); + // ArrayList list = new ArrayList(); + // list.add(new DatabaseSource("http", null, Source.FIRMS)); + // list.add(new DatabaseSource("http", null, Source.FIRMS)); + // list.add(new DatabaseSource("http", null, Source.FIRMS)); + // list.add(new DatabaseSource("http", null, Source.FIRMS)); + // list.add(new DatabaseSource("http", null, Source.FISHSOURCE)); + // list.add(new DatabaseSource("http", null, Source.RAM)); + // record.setManagementEntity("management ashdskad"); + // record.setProductionSystemType(Production_System_Type.Artisanal); + // record.setDatabaseSources(list); + // record.setAuthor("Costantino Perciante"); + // record.setMaintainer("Costantino Perciante"); + // record.setAuthorContact("costantino.perciante@isti.cnr.it"); + // record.setStatus(Status.Pending); + // record.setVersion(new Long(1)); + // // record.setSpeciesScientificName("Katsuwonus pelamis (or SKJ)"); + // record.setCatchesOrLandings("Catch - 18962 - ton - 2014"); + // record.setDataOwner("Giancarlo Panichi"); + // + // List groups = new ArrayList(); + // + // // check group generation + // HelperMethods.getGroups(groups, record); + // + // for (String group : groups) { + // System.out.println("Group is " + group); + // } + // + // List tags = new ArrayList(); + // + // // check group generation + // HelperMethods.getTags(tags, record); + // + // for (String tag : tags) { + // System.out.println("Tag is " + tag); + // } + // + // Map extras = new HashMap(); + // HelperMethods.getExtras(extras, record); + // + // Iterator> it = extras.entrySet().iterator(); + // + // while (it.hasNext()) { + // Map.Entry entry = (Map.Entry) it + // .next(); + // System.out.println("Extra is " + entry); + // } - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - - Set> violations = validator.validate((Common)recordStock); - for (ConstraintViolation constraintViolation : violations) { - System.out.println("Violation is about " + constraintViolation.getPropertyPath() + ", message error is " + constraintViolation.getMessage()); - } - - // check database_sources and source_of_information (they are not null nor empty at this point) - List databaseSources = recordStock.getDatabaseSources(); - for (DatabaseSource databaseSource : databaseSources) { - Set> violationsDatabaseSourcesBean = validator.validate(databaseSource); - for (ConstraintViolation constraintViolation : violationsDatabaseSourcesBean) { - System.out.println("Violation is about " + constraintViolation.getPropertyPath() + ", message error is " + constraintViolation.getMessage()); - - } - } // List sourcesOfInformation = recordStock.getSourceOfInformation(); // for (Resource sourceOfinformation : sourcesOfInformation) { @@ -161,11 +181,11 @@ public class JTests { // // - // ObjectMapper mapper = new ObjectMapper(); - // - // //Object to JSON in String - // String jsonInString = mapper.writeValueAsString(recordStock); - // System.out.println(jsonInString); + ObjectMapper mapper = new ObjectMapper(); + + //Object to JSON in String + String jsonInString = mapper.writeValueAsString(record); + System.out.println(jsonInString); // // // JSON back to object // StockRecord converted = mapper.readValue(jsonInString, recordStock.getClass());