4920: CKAN Metadata Profile advancements: provide vocabulary fields single selection or multi and tag field

Task-Url: https://support.d4science.org/issues/4920

Updated pom version at 2.0.0
Added datatype field 
Added isMultiSelection attribute

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@131295 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-09-12 13:24:41 +00:00
parent 510f9b9284
commit 0a7ba37651
9 changed files with 214 additions and 83 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry including="**/*.java" kind="src" output="target/gcubedatacatalogue-metadata-discovery-0.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry including="**/*.java" kind="src" output="target/gcubedatacatalogue-metadata-discovery-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -27,5 +27,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/gcubedatacatalogue-metadata-discovery-0.1.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/gcubedatacatalogue-metadata-discovery-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadataformat>
<metadatafield>
<fieldName>Name</fieldName>
<mandatory>true</mandatory>
<dataType>Date</dataType>
<defaulValue>default value</defaulValue>
<note>shown as suggestions in the insert/update metadata form of CKAN</note>
<vocabulary isMultiSelection="true">
<vocabularyField>field1</vocabularyField>
<vocabularyField>field2</vocabularyField>
<vocabularyField>field3</vocabularyField>
</vocabulary>
<validator>
<regularExpression>a regular expression for validating values</regularExpression>
</validator>
</metadatafield>
<metadatafield>
<fieldName>Accessibility</fieldName>
<mandatory>true</mandatory>
<dataType>String</dataType>
<defaulValue>virtual/public</defaulValue>
<note>shown as suggestions in the insert metadata form of CKAN</note>
<vocabulary isMultiSelection="false">
<vocabularyField>virtual/public</vocabularyField>
<vocabularyField>virtual/private</vocabularyField>
<vocabularyField>transactional</vocabularyField>
</vocabulary>
<validator>
<regularExpression>a regular expression for validating values</regularExpression>
</validator>
</metadatafield>
</metadataformat>

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.data-catalogue</groupId> <groupId>org.gcube.data-catalogue</groupId>
<artifactId>gcubedatacatalogue-metadata-discovery</artifactId> <artifactId>gcubedatacatalogue-metadata-discovery</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<name>The gCube data catalogue metadata discovery library</name> <name>The gCube data catalogue metadata discovery library</name>
<description>The gCube data catalogue metadata discovery library</description> <description>The gCube data catalogue metadata discovery library</description>
<scm> <scm>
@ -64,7 +64,7 @@
<artifactId>ic-client</artifactId> <artifactId>ic-client</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId> <artifactId>common-scope-maps</artifactId>
@ -87,6 +87,7 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- LOGGER --> <!-- LOGGER -->
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>

View File

@ -0,0 +1,35 @@
/**
*
*/
package org.gcube.datacatalogue.metadatadiscovery.adapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.DataType;
/**
* The Class DataTypeAdapter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 12, 2016
*/
public class DataTypeAdapter extends XmlAdapter<String, DataType> {
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
*/
public String marshal(DataType dt) {
return dt.name();
}
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
*/
public DataType unmarshal(String dt) {
return DataType.fromValue(dt);
}
}

View File

@ -0,0 +1,51 @@
/**
*
*/
package org.gcube.datacatalogue.metadatadiscovery.bean.jaxb;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* The Enum DataType.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 12, 2016
*/
@XmlType(name = "datatype")
@XmlEnum
public enum DataType {
String,
Date,
Text,
Boolean,
Number;
/**
* Value.
*
* @return the string
*/
public String value() {
return name();
}
/**
* From value.
*
* @param v the v
* @return the data type
*/
public static DataType fromValue(String v) {
DataType vv;
try{
vv = valueOf(v);
}catch(Exception e){
return DataType.String;
}
return vv;
}
}

View File

@ -9,6 +9,9 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.datacatalogue.metadatadiscovery.adapter.DataTypeAdapter;
@ -25,11 +28,15 @@ public class MetadataField implements Serializable{
/** /**
* *
*/ */
private static final long serialVersionUID = 1740491173451633254L; private static final long serialVersionUID = 5935573474465015727L;
@XmlElement(required = true)
private String fieldName; private String fieldName;
@XmlElement(required = true)
private Boolean mandatory = false; private Boolean mandatory = false;
private Boolean isBoolean = false; // private Boolean isBoolean = false;
@XmlJavaTypeAdapter(DataTypeAdapter.class)
private DataType dataType = DataType.String;
private String defaulValue; private String defaulValue;
private String note; private String note;
@ -46,37 +53,19 @@ public class MetadataField implements Serializable{
public MetadataField() { public MetadataField() {
} }
/** /**
* Instantiates a new metadata field. * @param fieldName
* * @param mandatory
* @param fieldName the field name
* @param mandatory the mandatory
* @param isBoolean the is boolean
* @param defaulValue the defaul value
* @param note the note
* @param vocabulary the vocabulary
* @param validator the validator
*/ */
public MetadataField( public MetadataField(String fieldName, Boolean mandatory) {
String fieldName, Boolean mandatory, Boolean isBoolean,
String defaulValue, String note, MetadataVocabulary vocabulary,
MetadataValidator validator) {
super();
this.fieldName = fieldName; this.fieldName = fieldName;
this.mandatory = mandatory; this.mandatory = mandatory;
this.isBoolean = isBoolean;
this.defaulValue = defaulValue;
this.note = note;
this.vocabulary = vocabulary;
this.validator = validator;
} }
/** /**
* Gets the field name.
*
* @return the fieldName * @return the fieldName
*/ */
public String getFieldName() { public String getFieldName() {
@ -85,10 +74,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Gets the mandatory.
*
* @return the mandatory * @return the mandatory
*/ */
public Boolean getMandatory() { public Boolean getMandatory() {
@ -97,22 +83,16 @@ public class MetadataField implements Serializable{
} }
/** /**
* Gets the checks if is boolean. * @return the dataType
*
* @return the isBoolean
*/ */
public Boolean getIsBoolean() { public DataType getDataType() {
return isBoolean; return dataType;
} }
/** /**
* Gets the defaul value.
*
* @return the defaulValue * @return the defaulValue
*/ */
public String getDefaulValue() { public String getDefaulValue() {
@ -121,10 +101,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Gets the note.
*
* @return the note * @return the note
*/ */
public String getNote() { public String getNote() {
@ -133,10 +110,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Gets the vocabulary.
*
* @return the vocabulary * @return the vocabulary
*/ */
public MetadataVocabulary getVocabulary() { public MetadataVocabulary getVocabulary() {
@ -145,10 +119,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Gets the validator.
*
* @return the validator * @return the validator
*/ */
public MetadataValidator getValidator() { public MetadataValidator getValidator() {
@ -157,10 +128,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Sets the field name.
*
* @param fieldName the fieldName to set * @param fieldName the fieldName to set
*/ */
public void setFieldName(String fieldName) { public void setFieldName(String fieldName) {
@ -169,10 +137,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Sets the mandatory.
*
* @param mandatory the mandatory to set * @param mandatory the mandatory to set
*/ */
public void setMandatory(Boolean mandatory) { public void setMandatory(Boolean mandatory) {
@ -181,22 +146,16 @@ public class MetadataField implements Serializable{
} }
/** /**
* Sets the checks if is boolean. * @param dataType the dataType to set
*
* @param isBoolean the isBoolean to set
*/ */
public void setIsBoolean(Boolean isBoolean) { public void setDataType(DataType dataType) {
this.isBoolean = isBoolean; this.dataType = dataType;
} }
/** /**
* Sets the defaul value.
*
* @param defaulValue the defaulValue to set * @param defaulValue the defaulValue to set
*/ */
public void setDefaulValue(String defaulValue) { public void setDefaulValue(String defaulValue) {
@ -205,10 +164,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Sets the note.
*
* @param note the note to set * @param note the note to set
*/ */
public void setNote(String note) { public void setNote(String note) {
@ -217,10 +173,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Sets the vocabulary.
*
* @param vocabulary the vocabulary to set * @param vocabulary the vocabulary to set
*/ */
public void setVocabulary(MetadataVocabulary vocabulary) { public void setVocabulary(MetadataVocabulary vocabulary) {
@ -229,10 +182,7 @@ public class MetadataField implements Serializable{
} }
/** /**
* Sets the validator.
*
* @param validator the validator to set * @param validator the validator to set
*/ */
public void setValidator(MetadataValidator validator) { public void setValidator(MetadataValidator validator) {
@ -240,7 +190,6 @@ public class MetadataField implements Serializable{
this.validator = validator; this.validator = validator;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@ -252,8 +201,8 @@ public class MetadataField implements Serializable{
builder.append(fieldName); builder.append(fieldName);
builder.append(", mandatory="); builder.append(", mandatory=");
builder.append(mandatory); builder.append(mandatory);
builder.append(", isBoolean="); builder.append(", dataType=");
builder.append(isBoolean); builder.append(dataType);
builder.append(", defaulValue="); builder.append(", defaulValue=");
builder.append(defaulValue); builder.append(defaulValue);
builder.append(", note="); builder.append(", note=");

View File

@ -8,15 +8,15 @@ import java.util.List;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
/** /**
* The Class MetadataVocabulary. * The Class MetadataVocabulary.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016 * Sep 12, 2016
*/ */
@XmlRootElement(name = "metadatavocabulary") @XmlRootElement(name = "metadatavocabulary")
@XmlAccessorType (XmlAccessType.FIELD) @XmlAccessorType (XmlAccessType.FIELD)
@ -25,10 +25,13 @@ public class MetadataVocabulary implements Serializable{
/** /**
* *
*/ */
private static final long serialVersionUID = 6697274733224694581L; private static final long serialVersionUID = 506451021936766592L;
private List<String> vocabularyField; private List<String> vocabularyField;
@XmlAttribute
private Boolean isMultiSelection = false;
/** /**
* Instantiates a new metadata vocabulary. * Instantiates a new metadata vocabulary.
*/ */
@ -47,6 +50,18 @@ public class MetadataVocabulary implements Serializable{
this.vocabularyField = vocabularyFields; this.vocabularyField = vocabularyFields;
} }
/**
* Instantiates a new metadata vocabulary.
*
* @param vocabularyField the vocabulary field
* @param isMultiSelection the is multi selection
*/
public MetadataVocabulary(List<String> vocabularyField, Boolean isMultiSelection) {
super();
this.vocabularyField = vocabularyField;
this.isMultiSelection = isMultiSelection;
}
/** /**
@ -72,6 +87,42 @@ public class MetadataVocabulary implements Serializable{
} }
/**
* Gets the vocabulary field.
*
* @return the vocabularyField
*/
public List<String> getVocabularyField() {
return vocabularyField;
}
/**
* Checks if is multi selection.
*
* @return the isMultiSelection
*/
public Boolean isMultiSelection() {
return isMultiSelection;
}
/**
* Sets the checks if is multi selection.
*
* @param isMultiSelection the isMultiSelection to set
*/
public void setIsMultiSelection(Boolean isMultiSelection) {
this.isMultiSelection = isMultiSelection;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@ -81,8 +132,12 @@ public class MetadataVocabulary implements Serializable{
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("MetadataVocabulary [vocabularyField="); builder.append("MetadataVocabulary [vocabularyField=");
builder.append(vocabularyField); builder.append(vocabularyField);
builder.append(", isMultiSelection=");
builder.append(isMultiSelection);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -80,7 +80,7 @@ public class MedataFormatDiscovery {
List<String> appProfile = client.submit(q); List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0) if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure, the scope is "+scopeString); throw new ApplicationProfileNotFoundException("ApplicationProfile with secondaryType: "+secondaryType+" is not registered in the scope: "+scopeString);
else { else {
for (String elem : appProfile) { for (String elem : appProfile) {
@ -99,8 +99,6 @@ public class MedataFormatDiscovery {
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, "+e); logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, "+e);
return list; return list;
} finally{
// ScopeProvider.instance.reset();
} }
return list; return list;

View File

@ -12,6 +12,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.DataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
@ -43,12 +44,14 @@ public class TestJaxbMetadataMarshUnmarsh {
ckanMetadata.setFieldName("Name"); ckanMetadata.setFieldName("Name");
ckanMetadata.setMandatory(true); ckanMetadata.setMandatory(true);
ckanMetadata.setDefaulValue("default value"); ckanMetadata.setDefaulValue("default value");
ckanMetadata.setDataType(DataType.Date);
List<String> vocabulary = new ArrayList<String>(); List<String> vocabulary = new ArrayList<String>();
vocabulary.add("field1"); vocabulary.add("field1");
vocabulary.add("field2"); vocabulary.add("field2");
vocabulary.add("field3"); vocabulary.add("field3");
MetadataVocabulary cvc = new MetadataVocabulary(vocabulary); MetadataVocabulary cvc = new MetadataVocabulary(vocabulary);
ckanMetadata.setVocabulary(cvc); ckanMetadata.setVocabulary(cvc);
cvc.setIsMultiSelection(true);
ckanMetadata.setNote("shown as suggestions in the insert/update metadata form of CKAN"); ckanMetadata.setNote("shown as suggestions in the insert/update metadata form of CKAN");
MetadataValidator validator = new MetadataValidator("a regular expression for validating values"); MetadataValidator validator = new MetadataValidator("a regular expression for validating values");
ckanMetadata.setValidator(validator); ckanMetadata.setValidator(validator);
@ -116,7 +119,13 @@ public class TestJaxbMetadataMarshUnmarsh {
for(MetadataField mtd : mtds.getMetadataFields()) for(MetadataField mtd : mtds.getMetadataFields())
{ {
System.out.println(mtd); System.out.println("Unmarshall: "+mtd);
} }
} }
public static void main(String[] args) {
System.out.println(DataType.valueOf("aa"));
}
} }