fixed tagging and grouping

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@146255 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-03-21 17:37:40 +00:00
parent eda283325a
commit ec53a4028e
7 changed files with 148 additions and 15 deletions

View File

@ -23,7 +23,7 @@ public class TaggingGroupingAdapter extends XmlAdapter<String, TaggingGroupingVa
*/
public String marshal(TaggingGroupingValue dt) {
return dt.name();
return dt.value();
}
/* (non-Javadoc)

View File

@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 12, 2016
*/
@XmlType(name = "datatype")
@XmlType(name = "dataType")
@XmlEnum
public enum DataType {

View File

@ -13,6 +13,7 @@ import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class MetadataCategory.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
@ -36,13 +37,46 @@ public class MetadataCategory implements Serializable{
/**
*
* Instantiates a new metadata category.
*/
public MetadataCategory() {
}
/**
* Instantiates a new metadata category.
*
* @param id the id
* @param title the title
*/
public MetadataCategory(String id, String title) {
super();
this.id = id;
this.title = title;
}
/**
* Instantiates a new metadata category.
*
* @param id the id
* @param title the title
* @param description the description
*/
public MetadataCategory(String id, String title, String description) {
super();
this.id = id;
this.title = title;
this.description = description;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
@ -52,6 +86,8 @@ public class MetadataCategory implements Serializable{
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() {
@ -61,6 +97,8 @@ public class MetadataCategory implements Serializable{
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
@ -70,6 +108,8 @@ public class MetadataCategory implements Serializable{
/**
* Sets the id.
*
* @param id the id to set
*/
public void setId(String id) {
@ -79,6 +119,8 @@ public class MetadataCategory implements Serializable{
/**
* Sets the title.
*
* @param title the title to set
*/
public void setTitle(String title) {
@ -88,6 +130,8 @@ public class MetadataCategory implements Serializable{
/**
* Sets the description.
*
* @param description the description to set
*/
public void setDescription(String description) {

View File

@ -8,14 +8,15 @@ import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.datacatalogue.metadatadiscovery.adapter.TaggingGroupingAdapter;
/**
* The Class MetadataGrouping.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
@ -33,17 +34,31 @@ public class MetadataGrouping implements Serializable{
private Boolean create = false;
@XmlJavaTypeAdapter(TaggingGroupingAdapter.class)
@XmlElement(required=true)
@XmlValue
private TaggingGroupingValue groupingValue = null;
/**
*
* Instantiates a new metadata grouping.
*/
public MetadataGrouping() {
}
/**
* Instantiates a new metadata grouping.
*
* @param create the create
* @param groupingValue the grouping value
*/
public MetadataGrouping(Boolean create, TaggingGroupingValue groupingValue) {
this.create = create;
this.groupingValue = groupingValue;
}
/**
* Gets the creates the.
*
* @return the create
*/
public Boolean getCreate() {
@ -53,6 +68,8 @@ public class MetadataGrouping implements Serializable{
/**
* Gets the grouping value.
*
* @return the groupingValue
*/
public TaggingGroupingValue getGroupingValue() {
@ -62,6 +79,8 @@ public class MetadataGrouping implements Serializable{
/**
* Sets the creates the.
*
* @param create the create to set
*/
public void setCreate(Boolean create) {
@ -71,6 +90,8 @@ public class MetadataGrouping implements Serializable{
/**
* Sets the grouping value.
*
* @param groupingValue the groupingValue to set
*/
public void setGroupingValue(TaggingGroupingValue groupingValue) {

View File

@ -8,14 +8,15 @@ import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.datacatalogue.metadatadiscovery.adapter.TaggingGroupingAdapter;
/**
* The Class MetadataTagging.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
@ -24,6 +25,11 @@ import org.gcube.datacatalogue.metadatadiscovery.adapter.TaggingGroupingAdapter;
@XmlAccessorType (XmlAccessType.FIELD)
public class MetadataTagging implements Serializable{
/**
*
*/
private static final long serialVersionUID = 641412896487091012L;
@XmlAttribute
private Boolean create = false;
@ -31,22 +37,35 @@ public class MetadataTagging implements Serializable{
private String separator = ":";
@XmlJavaTypeAdapter(TaggingGroupingAdapter.class)
@XmlElement(required=true)
@XmlValue
private TaggingGroupingValue taggingValue = null;
/**
*
*/
private static final long serialVersionUID = 3853551415977545419L;
/**
*
* Instantiates a new metadata tagging.
*/
public MetadataTagging() {
}
/**
* @param create
* @param separator
* @param taggingValue
*/
public MetadataTagging(
Boolean create, String separator, TaggingGroupingValue taggingValue) {
super();
this.create = create;
this.separator = separator;
this.taggingValue = taggingValue;
}
/**
* Gets the creates the.
*
* @return the create
*/
public Boolean getCreate() {
@ -56,6 +75,8 @@ public class MetadataTagging implements Serializable{
/**
* Gets the separator.
*
* @return the separator
*/
public String getSeparator() {
@ -65,6 +86,8 @@ public class MetadataTagging implements Serializable{
/**
* Gets the tagging value.
*
* @return the taggingValue
*/
public TaggingGroupingValue getTaggingValue() {
@ -74,6 +97,8 @@ public class MetadataTagging implements Serializable{
/**
* Sets the creates the.
*
* @param create the create to set
*/
public void setCreate(Boolean create) {
@ -83,6 +108,8 @@ public class MetadataTagging implements Serializable{
/**
* Sets the separator.
*
* @param separator the separator to set
*/
public void setSeparator(String separator) {
@ -92,6 +119,8 @@ public class MetadataTagging implements Serializable{
/**
* Sets the tagging value.
*
* @param taggingValue the taggingValue to set
*/
public void setTaggingValue(TaggingGroupingValue taggingValue) {

View File

@ -3,6 +3,8 @@
*/
package org.gcube.datacatalogue.metadatadiscovery.bean.jaxb;
import javax.xml.bind.annotation.XmlEnum;
/**
* The Enum TaggingGroupingValue.
@ -10,6 +12,7 @@ package org.gcube.datacatalogue.metadatadiscovery.bean.jaxb;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
*/
@XmlEnum
public enum TaggingGroupingValue {
onFieldName("onFieldName"),

View File

@ -6,6 +6,7 @@ package org.gcube.datacatalogue.metadatadiscovery;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -13,10 +14,14 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.DataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataCategory;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataGrouping;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataTagging;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.TaggingGroupingValue;
import org.junit.Test;
@ -31,6 +36,8 @@ public class TestJaxbMetadataMarshUnmarsh {
static MetadataField ckanMetadata;
static MetadataFormat metadatas;
static String tmpFileXML = "." + File.separator + "CkanMetadatas.xml";
private ArrayList<MetadataCategory> ckanCategories;
public static int MAX_CATEGORIES = 3;
/**
* Test.
@ -40,11 +47,22 @@ public class TestJaxbMetadataMarshUnmarsh {
metadatas = new MetadataFormat();
ckanCategories = new ArrayList<MetadataCategory>();
for (int i=0; i<MAX_CATEGORIES; i++) {
ckanCategories.add(new MetadataCategory("cat "+i, "title cat "+i, "description "+i));
}
metadatas.setMetadataCategories(ckanCategories);
ckanMetadata = new MetadataField();
ckanMetadata.setFieldName("Name");
ckanMetadata.setMandatory(true);
ckanMetadata.setDefaultValue("default value");
ckanMetadata.setDataType(DataType.Time);
ckanMetadata.setCategoryRef(ckanCategories.get(new Random().nextInt(MAX_CATEGORIES)).getId());
List<String> vocabulary = new ArrayList<String>();
vocabulary.add("field1");
vocabulary.add("field2");
@ -61,6 +79,13 @@ public class TestJaxbMetadataMarshUnmarsh {
ckanMetadata.setFieldName("Accessibility");
ckanMetadata.setMandatory(true);
ckanMetadata.setDefaultValue("virtual/public");
ckanMetadata.setTagging(new MetadataTagging(true, ":", TaggingGroupingValue.onValue_onFieldName));
MetadataGrouping grouping = new MetadataGrouping();
grouping.setCreate(true);
grouping.setGroupingValue(TaggingGroupingValue.onValue);
ckanMetadata.setGrouping(grouping);
List<String> vocabulary2 = new ArrayList<String>();
vocabulary2.add("virtual/public");
vocabulary2.add("virtual/private");
@ -75,7 +100,7 @@ public class TestJaxbMetadataMarshUnmarsh {
try {
// marshalingExample();
marshalingExample();
unMarshalingExample();
}
catch (JAXBException e) {
@ -117,8 +142,19 @@ public class TestJaxbMetadataMarshUnmarsh {
//We had written this file in marshalling example
MetadataFormat mtds = (MetadataFormat) jaxbUnmarshaller.unmarshal(new File(tmpFileXML));
System.out.println(mtds);
System.out.println("Metadata Categories");
if(mtds.getMetadataCategories()!=null){
for (MetadataCategory cat : mtds.getMetadataCategories()) {
System.out.println(cat);
}
}
System.out.println("\n\nMetadata Fields");
for (MetadataField field : mtds.getMetadataFields()) {
System.out.println(field);
System.out.println(field.getGrouping());
System.out.println(field.getTagging());
}
}