minor fix
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133167 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
da21b374aa
commit
e32ccbac4d
|
@ -218,7 +218,7 @@ public class GrsfPublisherStockService {
|
|||
license,
|
||||
tags,
|
||||
customFields,
|
||||
null,
|
||||
resources,
|
||||
setPublic); // TODO
|
||||
|
||||
if(id != null){
|
||||
|
|
|
@ -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<DatabaseSource> list = new ArrayList<DatabaseSource>();
|
||||
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<DatabaseSource> list = new ArrayList<DatabaseSource>();
|
||||
// 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<String> groups = new ArrayList<String>();
|
||||
//
|
||||
// // check group generation
|
||||
// HelperMethods.getGroups(groups, record);
|
||||
//
|
||||
// for (String group : groups) {
|
||||
// System.out.println("Group is " + group);
|
||||
// }
|
||||
//
|
||||
// List<String> tags = new ArrayList<String>();
|
||||
//
|
||||
// // check group generation
|
||||
// HelperMethods.getTags(tags, record);
|
||||
//
|
||||
// for (String tag : tags) {
|
||||
// System.out.println("Tag is " + tag);
|
||||
// }
|
||||
//
|
||||
// Map<String, String> extras = new HashMap<String, String>();
|
||||
// HelperMethods.getExtras(extras, record);
|
||||
//
|
||||
// Iterator<Entry<String, String>> it = extras.entrySet().iterator();
|
||||
//
|
||||
// while (it.hasNext()) {
|
||||
// Map.Entry<java.lang.String, java.lang.String> entry = (Map.Entry<java.lang.String, java.lang.String>) it
|
||||
// .next();
|
||||
// System.out.println("Extra is " + entry);
|
||||
// }
|
||||
|
||||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
||||
Validator validator = factory.getValidator();
|
||||
|
||||
Set<ConstraintViolation<Common>> violations = validator.validate((Common)recordStock);
|
||||
for (ConstraintViolation<Common> 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<DatabaseSource> databaseSources = recordStock.getDatabaseSources();
|
||||
for (DatabaseSource databaseSource : databaseSources) {
|
||||
Set<ConstraintViolation<DatabaseSource>> violationsDatabaseSourcesBean = validator.validate(databaseSource);
|
||||
for (ConstraintViolation<DatabaseSource> constraintViolation : violationsDatabaseSourcesBean) {
|
||||
System.out.println("Violation is about " + constraintViolation.getPropertyPath() + ", message error is " + constraintViolation.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// List<Resource> 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());
|
||||
|
|
Loading…
Reference in New Issue