minor fixes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133817 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-02 15:02:28 +00:00
parent c5d9730ef5
commit f2b47b9e0a
3 changed files with 10 additions and 6 deletions

View File

@ -79,6 +79,7 @@ public class Common {
@JsonProperty("short_title") @JsonProperty("short_title")
@CustomField(key="Short Title") @CustomField(key="Short Title")
@NotNull @NotNull
@Size(min=1, message="short_title cannot be empty")
private String shortTitle; private String shortTitle;
@JsonProperty("uuid_knowledge_base") @JsonProperty("uuid_knowledge_base")

View File

@ -178,6 +178,7 @@ public abstract class HelperMethods {
if(field.isAnnotationPresent(CustomField.class)){ if(field.isAnnotationPresent(CustomField.class)){
try{ try{
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record); Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
String keyField = field.getAnnotation(CustomField.class).key();
if(f != null){ if(f != null){
if(f.getClass().isArray()){ if(f.getClass().isArray()){
@ -185,16 +186,16 @@ public abstract class HelperMethods {
logger.debug("The object " + field.getName() + " is a collection"); logger.debug("The object " + field.getName() + " is a collection");
List<String> res = (List<String>)f; List<String> res = (List<String>)f;
extras.put(field.getAnnotation(CustomField.class).key(), res); extras.put(keyField, res);
}else }else
logger.error("The object " + field.getName() + " cannot be convert to a list/array"); logger.error("The object " + field.getName() + " cannot be convert to a list/array");
}else{ }else{
List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
if(extras.containsKey(field.getAnnotation(CustomField.class).key())) if(extras.containsKey(keyField))
values = extras.get(field.getAnnotation(CustomField.class).key()); values = extras.get(keyField);
values.add(f.toString().trim()); values.add(f.toString().trim());
extras.put(field.getAnnotation(CustomField.class).key(), values); extras.put(keyField, values);
} }
} }

View File

@ -23,6 +23,7 @@ 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.Abundance_Level;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type; import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -35,6 +36,7 @@ import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpCl
public class JTests { public class JTests {
private static final String TEST_TOKEN = ""; private static final String TEST_TOKEN = "";
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(JTests.class);
//@Test //@Test
public void test() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IntrospectionException { public void test() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IntrospectionException {
@ -245,13 +247,13 @@ public class JTests {
record.setWaterArea(Arrays.asList("aa", "bb", "cc", "dd")); record.setWaterArea(Arrays.asList("aa", "bb", "cc", "dd"));
Map<String, List<String>> extras = new HashMap<String, List<String>>(); Map<String, List<String>> extras = new HashMap<String, List<String>>();
HelperMethods.getExtras(extras , record); HelperMethods.getExtras(extras , record);
System.out.println("Extras = " + extras); logger.debug("Extras = " + extras);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
//Object to JSON in String //Object to JSON in String
String jsonInString = mapper.writeValueAsString(record); String jsonInString = mapper.writeValueAsString(record);
System.out.println(jsonInString); logger.debug(jsonInString);
} }