Working on #8267
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@147215 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
05972d72c3
commit
28d6a1c0e9
|
@ -28,8 +28,8 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
|
|||
|
||||
private MetadataFormatDiscovery medataFormatDiscovery;
|
||||
private ScopeBean scope;
|
||||
private Map<String, MetadataFormat> hashMetadataFormats = new HashMap<String, MetadataFormat>();
|
||||
private List<NamespaceCategory> namespaceCategories = new ArrayList<NamespaceCategory>();
|
||||
private Map<String, MetadataFormat> hashMetadataFormats = null;
|
||||
private List<NamespaceCategory> namespaceCategories = null;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DataCalogueMetadataFormatReader.class);
|
||||
|
||||
|
@ -47,8 +47,8 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
|
|||
throw new Exception("Please set a valid scope into ScopeProvider");
|
||||
|
||||
scope = new ScopeBean(scopeString);
|
||||
//readMetadaFormats();
|
||||
readNamespaces();
|
||||
readMetadaFormats();
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,6 +62,7 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
|
|||
medataFormatDiscovery = new MetadataFormatDiscovery(scope);
|
||||
logger.info("MedataFormatDiscovery has retrieved: "+medataFormatDiscovery.getMetadataProfiles().size() +" metadata type/s");
|
||||
logger.debug("filling cache for MedataFormat");
|
||||
hashMetadataFormats = new HashMap<String, MetadataFormat>(medataFormatDiscovery.getMetadataProfiles().size());
|
||||
for (MetadataProfile mT : medataFormatDiscovery.getMetadataProfiles()) {
|
||||
if(mT==null)
|
||||
continue;
|
||||
|
@ -80,6 +81,10 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
|
|||
|
||||
try{
|
||||
if(namespaceCategories == null || namespaceCategories.isEmpty()){
|
||||
|
||||
if(namespaceCategories == null)
|
||||
namespaceCategories = new ArrayList<NamespaceCategory>();
|
||||
|
||||
NamespaceCategoryReader rd = new NamespaceCategoryReader(scope, NamespaceCategoryReader.NamespacesCatalogueCategoriesResourceID());
|
||||
namespaceCategories.addAll(rd.getNamespaces().getNamespaceCategories());
|
||||
}
|
||||
|
@ -129,4 +134,25 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
|
|||
return namespaceCategories;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#resetMetadataProfile()
|
||||
*/
|
||||
@Override
|
||||
public void resetMetadataProfile() {
|
||||
|
||||
medataFormatDiscovery = null;
|
||||
hashMetadataFormats = null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#resetNamespaceCategories()
|
||||
*/
|
||||
@Override
|
||||
public void resetNamespaceCategories() {
|
||||
|
||||
namespaceCategories = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,4 +49,17 @@ public interface DataCatalogueMetadataDiscovery {
|
|||
*/
|
||||
MetadataFormat getMetadataFormatForMetadataProfile(MetadataProfile type) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Reset metadata profile.
|
||||
* Forces current list of Metadata Profile at null in order to read it from IS againg
|
||||
*/
|
||||
void resetMetadataProfile();
|
||||
|
||||
/**
|
||||
* Reset namespace categories.
|
||||
* Forces current list of Namespace Categories Profile at null in order to read it from IS againg
|
||||
*/
|
||||
void resetNamespaceCategories();
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ 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.XmlTransient;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.gcube.datacatalogue.metadatadiscovery.Namespace;
|
||||
|
@ -39,7 +38,7 @@ public class MetadataField implements Serializable{
|
|||
private static final long serialVersionUID = 5935573474465015727L;
|
||||
|
||||
@XmlAttribute(name=LOCAL_NAME_CATEGORYREF)
|
||||
private String categoryRef = null;
|
||||
private String categoryRef = null; //ITS VALUE IS A CATEGORY-ID
|
||||
@XmlElement(required = true)
|
||||
private String fieldName;
|
||||
@XmlElement(required = true)
|
||||
|
@ -60,13 +59,9 @@ public class MetadataField implements Serializable{
|
|||
@XmlElement(name = "tagging")
|
||||
private MetadataTagging tagging;
|
||||
|
||||
|
||||
@XmlElement(name = "grouping")
|
||||
private MetadataGrouping grouping;
|
||||
|
||||
@XmlTransient
|
||||
private String namespaceFieldToCategoryReference = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new metadata field.
|
||||
*/
|
||||
|
@ -87,9 +82,23 @@ public class MetadataField implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new metadata field.
|
||||
*
|
||||
* @param fieldName the field name
|
||||
* @param mandatory the mandatory
|
||||
* @param categoryID the category id
|
||||
*/
|
||||
public MetadataField(String fieldName, Boolean mandatory, String categoryID) {
|
||||
|
||||
super();
|
||||
this.fieldName = fieldName;
|
||||
this.mandatory = mandatory;
|
||||
setCategoryRefToCategoryId(categoryID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the category ref.
|
||||
* Gets the category ref. If exists its value is a Category-ID
|
||||
*
|
||||
* @return the categoryRef
|
||||
*/
|
||||
|
@ -100,61 +109,26 @@ public class MetadataField implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Sets the category ref.
|
||||
* Sets the category ref to category id.
|
||||
*
|
||||
* @param categoryRef the categoryRef to set
|
||||
* @param categoryID the new category ref to category id
|
||||
*/
|
||||
public void setCategoryRef(String categoryRef) {
|
||||
public void setCategoryRefToCategoryId(String categoryID) {
|
||||
|
||||
this.categoryRef = categoryRef;
|
||||
setNamespaceFieldToCategoryRef();
|
||||
this.categoryRef = categoryID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the namespace field to category ref.
|
||||
*/
|
||||
private void setNamespaceFieldToCategoryRef() {
|
||||
|
||||
this.namespaceFieldToCategoryReference = LOCAL_NAME_CATEGORYREF+Namespace.Separator+categoryRef;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the namespace field to category reference.
|
||||
*
|
||||
* @return the namespaceFieldToCategoryReference
|
||||
*/
|
||||
public String getNamespaceFieldToCategoryReference() {
|
||||
|
||||
initNamespaceFieldToCategoryReference();
|
||||
return namespaceFieldToCategoryReference;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inits the namespace field to category reference.
|
||||
*/
|
||||
private void initNamespaceFieldToCategoryReference(){
|
||||
if(namespaceFieldToCategoryReference==null && categoryRef!=null && !categoryRef.isEmpty())
|
||||
setNamespaceFieldToCategoryRef();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the category field qualified name.
|
||||
*
|
||||
* If the Metadata Field belongs to a category returns the qualified name: {@link MetadataField#LOCAL_NAME_CATEGORYREF} {@link Namespace#Separator}} fieldName;
|
||||
* If the Metadata Field belongs to a category, returns the qualified name: {@link CopyOfMetadataField#categoryRef} {@link Namespace#Separator}} fieldName;
|
||||
* Otherwise returns the fieldName
|
||||
*
|
||||
* @return the category q name
|
||||
*/
|
||||
public String getCategoryFieldQName(){
|
||||
|
||||
initNamespaceFieldToCategoryReference();
|
||||
return namespaceFieldToCategoryReference==null?fieldName:namespaceFieldToCategoryReference+Namespace.Separator+fieldName;
|
||||
return categoryRef==null?fieldName:categoryRef+Namespace.Separator+fieldName;
|
||||
|
||||
}
|
||||
|
||||
|
@ -359,11 +333,6 @@ public class MetadataField implements Serializable{
|
|||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
|
@ -388,8 +357,6 @@ public class MetadataField implements Serializable{
|
|||
builder.append(tagging);
|
||||
builder.append(", grouping=");
|
||||
builder.append(grouping);
|
||||
builder.append(", namespaceFieldToCategoryReference=");
|
||||
builder.append(namespaceFieldToCategoryReference);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ 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.XmlID;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.datacatalogue.metadatadiscovery.Namespace;
|
||||
|
@ -29,6 +30,7 @@ public class NamespaceCategory implements Namespace, Serializable{
|
|||
private static final long serialVersionUID = -1632300992065668875L;
|
||||
|
||||
@XmlAttribute(required = true)
|
||||
@XmlID
|
||||
private String id = null;
|
||||
|
||||
@XmlElement(required = true)
|
||||
|
|
|
@ -139,6 +139,8 @@ public class MetadataFormatDiscovery {
|
|||
else
|
||||
metadataProfile.setName(name.get(0));
|
||||
|
||||
logger.info("Building Profile for Resource Name: "+metadataProfile.getName());
|
||||
|
||||
List<String> description = helper.evaluate("/Resource/Profile/Description/text()");
|
||||
|
||||
if(description==null || description.isEmpty())
|
||||
|
@ -152,7 +154,7 @@ public class MetadataFormatDiscovery {
|
|||
String metadataType = (String) expr.evaluate(doc, XPathConstants.STRING);
|
||||
|
||||
if(metadataType==null || metadataType.isEmpty())
|
||||
throw new MetadataProfileNotFoundException("Required attribute '"+MetadataFormat.LOCAL_NAME_METADATA_TYPE+"' not found in the element '"+MetadataFormat.LOCAL_NAME_METADATA_FORMAT+"' for Metadata Profile (with Resource) Id: "+metadataProfile.getId());
|
||||
throw new MetadataProfileNotFoundException("Required attribute '"+MetadataFormat.LOCAL_NAME_METADATA_TYPE+"' not found in the element '"+MetadataFormat.LOCAL_NAME_METADATA_FORMAT+"' for Metadata Profile (within Resource) Id: "+metadataProfile.getId());
|
||||
else
|
||||
metadataProfile.setMetadataType(metadataType);
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ package org.gcube.datacatalogue.metadatadiscovery;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.NamespaceCategory;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -39,14 +41,14 @@ public class TestDataCatalogueMetadataFormatReader {
|
|||
}
|
||||
|
||||
i = 0;
|
||||
// for (MetadataProfile mt : reader.getListOfMetadataProfiles()) {
|
||||
//
|
||||
// if(mt==null)
|
||||
// continue;
|
||||
//
|
||||
// MetadataFormat metadataFormat = reader.getMetadataFormatForMetadataProfile(mt);
|
||||
// logger.trace("\n\n "+ ++i +".) Metadata source: "+metadataFormat.getMetadataSource().substring(0, 100));
|
||||
// }
|
||||
for (MetadataProfile mt : reader.getListOfMetadataProfiles()) {
|
||||
|
||||
if(mt==null)
|
||||
continue;
|
||||
|
||||
MetadataFormat metadataFormat = reader.getMetadataFormatForMetadataProfile(mt);
|
||||
logger.trace("\n\n "+ ++i +".) Metadata source: "+metadataFormat.getMetadataSource().substring(0, 100));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
|
|
@ -95,8 +95,8 @@ public class TestJaxbMetadataMarshUnmarsh {
|
|||
try {
|
||||
|
||||
//marshalingExample();
|
||||
//unMarshalingExample();
|
||||
unMarshalingCategories();
|
||||
unMarshalingMetadataFields();
|
||||
//unMarshalingCategories();
|
||||
}
|
||||
catch (JAXBException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
@ -129,8 +129,9 @@ public class TestJaxbMetadataMarshUnmarsh {
|
|||
*
|
||||
* @throws JAXBException the JAXB exception
|
||||
*/
|
||||
private static void unMarshalingExample() throws JAXBException
|
||||
private static void unMarshalingMetadataFields() throws JAXBException
|
||||
{
|
||||
unMarshalingCategories();
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
|
||||
|
@ -152,7 +153,6 @@ public class TestJaxbMetadataMarshUnmarsh {
|
|||
for (MetadataField field : mtds.getMetadataFields()) {
|
||||
System.out.println(field);
|
||||
System.out.println("Category Ref: "+field.getCategoryRef());
|
||||
System.out.println("Category Namespace: "+field.getNamespaceFieldToCategoryReference());
|
||||
System.out.println("Category CategoryField Q Name: "+field.getCategoryFieldQName());
|
||||
System.out.println("QName: "+field.getCategoryFieldQName());
|
||||
|
||||
|
|
Loading…
Reference in New Issue