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:
parent
510f9b9284
commit
0a7ba37651
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -27,5 +27,5 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</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>
|
||||
|
|
|
@ -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>
|
3
pom.xml
3
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>gcubedatacatalogue-metadata-discovery</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<name>The gCube data catalogue metadata discovery library</name>
|
||||
<description>The gCube data catalogue metadata discovery library</description>
|
||||
<scm>
|
||||
|
@ -87,6 +87,7 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- LOGGER -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,9 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
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;
|
||||
@XmlElement(required = true)
|
||||
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 note;
|
||||
|
||||
|
@ -46,37 +53,19 @@ public class MetadataField implements Serializable{
|
|||
public MetadataField() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new metadata field.
|
||||
*
|
||||
* @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
|
||||
* @param fieldName
|
||||
* @param mandatory
|
||||
*/
|
||||
public MetadataField(
|
||||
String fieldName, Boolean mandatory, Boolean isBoolean,
|
||||
String defaulValue, String note, MetadataVocabulary vocabulary,
|
||||
MetadataValidator validator) {
|
||||
public MetadataField(String fieldName, Boolean mandatory) {
|
||||
|
||||
super();
|
||||
this.fieldName = fieldName;
|
||||
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
|
||||
*/
|
||||
public String getFieldName() {
|
||||
|
@ -85,10 +74,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the mandatory.
|
||||
*
|
||||
* @return the mandatory
|
||||
*/
|
||||
public Boolean getMandatory() {
|
||||
|
@ -97,22 +83,16 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the checks if is boolean.
|
||||
*
|
||||
* @return the isBoolean
|
||||
* @return the dataType
|
||||
*/
|
||||
public Boolean getIsBoolean() {
|
||||
public DataType getDataType() {
|
||||
|
||||
return isBoolean;
|
||||
return dataType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the defaul value.
|
||||
*
|
||||
* @return the defaulValue
|
||||
*/
|
||||
public String getDefaulValue() {
|
||||
|
@ -121,10 +101,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the note.
|
||||
*
|
||||
* @return the note
|
||||
*/
|
||||
public String getNote() {
|
||||
|
@ -133,10 +110,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the vocabulary.
|
||||
*
|
||||
* @return the vocabulary
|
||||
*/
|
||||
public MetadataVocabulary getVocabulary() {
|
||||
|
@ -145,10 +119,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the validator.
|
||||
*
|
||||
* @return the validator
|
||||
*/
|
||||
public MetadataValidator getValidator() {
|
||||
|
@ -157,10 +128,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the field name.
|
||||
*
|
||||
* @param fieldName the fieldName to set
|
||||
*/
|
||||
public void setFieldName(String fieldName) {
|
||||
|
@ -169,10 +137,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the mandatory.
|
||||
*
|
||||
* @param mandatory the mandatory to set
|
||||
*/
|
||||
public void setMandatory(Boolean mandatory) {
|
||||
|
@ -181,22 +146,16 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the checks if is boolean.
|
||||
*
|
||||
* @param isBoolean the isBoolean to set
|
||||
* @param dataType the dataType 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
|
||||
*/
|
||||
public void setDefaulValue(String defaulValue) {
|
||||
|
@ -205,10 +164,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the note.
|
||||
*
|
||||
* @param note the note to set
|
||||
*/
|
||||
public void setNote(String note) {
|
||||
|
@ -217,10 +173,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the vocabulary.
|
||||
*
|
||||
* @param vocabulary the vocabulary to set
|
||||
*/
|
||||
public void setVocabulary(MetadataVocabulary vocabulary) {
|
||||
|
@ -229,10 +182,7 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the validator.
|
||||
*
|
||||
* @param validator the validator to set
|
||||
*/
|
||||
public void setValidator(MetadataValidator validator) {
|
||||
|
@ -240,7 +190,6 @@ public class MetadataField implements Serializable{
|
|||
this.validator = validator;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
@ -252,8 +201,8 @@ public class MetadataField implements Serializable{
|
|||
builder.append(fieldName);
|
||||
builder.append(", mandatory=");
|
||||
builder.append(mandatory);
|
||||
builder.append(", isBoolean=");
|
||||
builder.append(isBoolean);
|
||||
builder.append(", dataType=");
|
||||
builder.append(dataType);
|
||||
builder.append(", defaulValue=");
|
||||
builder.append(defaulValue);
|
||||
builder.append(", note=");
|
||||
|
|
|
@ -8,15 +8,15 @@ import java.util.List;
|
|||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class MetadataVocabulary.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jun 8, 2016
|
||||
* Sep 12, 2016
|
||||
*/
|
||||
@XmlRootElement(name = "metadatavocabulary")
|
||||
@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;
|
||||
|
||||
@XmlAttribute
|
||||
private Boolean isMultiSelection = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new metadata vocabulary.
|
||||
*/
|
||||
|
@ -47,6 +50,18 @@ public class MetadataVocabulary implements Serializable{
|
|||
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)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
@ -81,8 +132,12 @@ public class MetadataVocabulary implements Serializable{
|
|||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("MetadataVocabulary [vocabularyField=");
|
||||
builder.append(vocabularyField);
|
||||
builder.append(", isMultiSelection=");
|
||||
builder.append(isMultiSelection);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public class MedataFormatDiscovery {
|
|||
List<String> appProfile = client.submit(q);
|
||||
|
||||
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 {
|
||||
|
||||
for (String elem : appProfile) {
|
||||
|
@ -99,8 +99,6 @@ public class MedataFormatDiscovery {
|
|||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, "+e);
|
||||
return list;
|
||||
} finally{
|
||||
// ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.xml.bind.JAXBException;
|
|||
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.MetadataField;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
|
||||
|
@ -43,12 +44,14 @@ public class TestJaxbMetadataMarshUnmarsh {
|
|||
ckanMetadata.setFieldName("Name");
|
||||
ckanMetadata.setMandatory(true);
|
||||
ckanMetadata.setDefaulValue("default value");
|
||||
ckanMetadata.setDataType(DataType.Date);
|
||||
List<String> vocabulary = new ArrayList<String>();
|
||||
vocabulary.add("field1");
|
||||
vocabulary.add("field2");
|
||||
vocabulary.add("field3");
|
||||
MetadataVocabulary cvc = new MetadataVocabulary(vocabulary);
|
||||
ckanMetadata.setVocabulary(cvc);
|
||||
cvc.setIsMultiSelection(true);
|
||||
ckanMetadata.setNote("shown as suggestions in the insert/update metadata form of CKAN");
|
||||
MetadataValidator validator = new MetadataValidator("a regular expression for validating values");
|
||||
ckanMetadata.setValidator(validator);
|
||||
|
@ -116,7 +119,13 @@ public class TestJaxbMetadataMarshUnmarsh {
|
|||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue