use of org.vcell.util.document.Identifiable in project vcell by virtualcell.
the class VCMetaData method cleanupMetadata.
public void cleanupMetadata() {
Set<Registry.Entry> entries = registry.getAllEntries();
for (Registry.Entry entry : entries) {
Identifiable entryIdentifiable = entry.getIdentifiable();
VCID vcid = identifiableProvider.getVCID(entryIdentifiable);
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
if (identifiable == null) {
// use miriamManager to remove RDF statements from resource for identifiable
try {
Map<MiriamRefGroup, MIRIAMQualifier> miriamRefGps = getMiriamManager().getAllMiriamRefGroups(entryIdentifiable);
if (miriamRefGps != null) {
for (Map.Entry<MiriamRefGroup, MIRIAMQualifier> groupEntry : miriamRefGps.entrySet()) {
MiriamRefGroup refGroup = groupEntry.getKey();
MIRIAMQualifier qualifier = groupEntry.getValue();
getMiriamManager().remove(entryIdentifiable, qualifier, refGroup);
}
}
} catch (URNParseFailureException e) {
e.printStackTrace(System.out);
}
// set nonRDF annotations to null
NonRDFAnnotation nonRDFAnnotation = getExistingNonRDFAnnotation(entryIdentifiable);
if (nonRDFAnnotation != null) {
nonRDFAnnotation.setFreeTextAnnotation(null);
nonRDFAnnotation.setXhtmlNotes(null);
nonRDFAnnotation.setXmlAnnotations(null);
}
System.err.println("Deleting resource for identifiable '" + entryIdentifiable.toString() + "' since it is not found in " + identifiableProvider.getClass().getName());
}
}
}
use of org.vcell.util.document.Identifiable in project vcell by virtualcell.
the class VCMetaDataMiriamManager method getMiriamTreeMap.
public synchronized TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>> getMiriamTreeMap() {
if (miriamTreeMap == null) {
final IdentifiableProvider identifiableProvider = vcMetaData.getIdentifiableProvider();
miriamTreeMap = new TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>>(new IdentifiableComparator(identifiableProvider));
Set<Entry> allEntries = vcMetaData.getRegistry().getAllEntries();
for (Entry entry : allEntries) {
if (entry.getResource() != null) {
Map<MiriamRefGroup, MIRIAMQualifier> refGroupMap = queryAllMiriamRefGroups(entry.getIdentifiable());
if (refGroupMap.size() > 0) {
miriamTreeMap.put(entry.getIdentifiable(), refGroupMap);
}
}
}
}
return miriamTreeMap;
}
use of org.vcell.util.document.Identifiable in project vcell by virtualcell.
the class XMLMetaDataReader method readFromElement.
@SuppressWarnings("unchecked")
public static void readFromElement(VCMetaData metaData, IdentifiableProvider identifiableProvider, Element metadataElement) throws XmlParseException {
Element bindingElement = metadataElement.getChild(XMLMetaData.URI_BINDING_LIST_TAG, VCMetaData.nsVCML);
if (bindingElement != null) {
// read binding
List<Element> entryElements = bindingElement.getChildren(XMLMetaData.URI_BINDING_TAG, VCMetaData.nsVCML);
for (Iterator<Element> iterator = entryElements.iterator(); iterator.hasNext(); ) {
Element entryElement = iterator.next();
try {
String uri = entryElement.getAttributeValue(XMLMetaData.URI_ATTR_TAG);
String vcidString = entryElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
// make new entry based on URI
// create VCID
VCID vcid = VCID.fromString(vcidString);
// lookup Identifiable object using VCID ... add to entry.
metaData.getRegistry().newEntry(metaData.getRdfData(), identifiableProvider.getIdentifiableObject(vcid), uri);
} catch (VCID.InvalidVCIDException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
}
Element rdfElement = metadataElement.getChild(XMLRDF.tagRDF, XMLRDF.nsRDF);
if (rdfElement != null) {
// read RDF
try {
metaData.addToModelFromElement(rdfElement);
} catch (RDFParseException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
} catch (RDFHandlerException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
}
}
Element nonRDFAnnotationListElement = metadataElement.getChild(XMLMetaData.NONRDF_ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
if (nonRDFAnnotationListElement != null) {
List<Element> nonRDFAnnotationElements = nonRDFAnnotationListElement.getChildren(XMLMetaData.NONRDF_ANNOTATION_TAG, VCMetaData.nsVCML);
for (Element nonRDFAnnotationElement : nonRDFAnnotationElements) {
String vcidString = nonRDFAnnotationElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
VCID vcid = null;
try {
vcid = VCID.fromString(vcidString);
} catch (InvalidVCIDException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
}
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
if (identifiable != null) {
// populate the annotation
Element freeTextAnnotationElement = nonRDFAnnotationElement.getChild(XMLMetaData.FREETEXT_TAG, VCMetaData.nsVCML);
if (freeTextAnnotationElement != null) {
String freeText = freeTextAnnotationElement.getText();
metaData.setFreeTextAnnotation(identifiable, freeText);
}
Element xhtmlNotesElement = nonRDFAnnotationElement.getChild(XMLMetaData.NOTES_TAG, VCMetaData.nsVCML);
if (xhtmlNotesElement != null) {
metaData.setXhtmlNotes(identifiable, xhtmlNotesElement);
}
Element annotationListElement = nonRDFAnnotationElement.getChild(XMLMetaData.ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
if (annotationListElement != null) {
List<?> annotationContents = annotationListElement.getContent();
List<Element> annotationElements = new ArrayList<Element>();
for (int i = 0; i < annotationContents.size(); i++) {
if (annotationContents.get(i) instanceof Element) {
annotationElements.add((Element) annotationContents.get(i));
}
}
metaData.setXmlAnnotations(identifiable, annotationElements.toArray(new Element[annotationElements.size()]));
}
} else {
System.err.println("Cannot find identifiable for vcid : " + vcidString);
}
}
}
}
use of org.vcell.util.document.Identifiable in project vcell by virtualcell.
the class XMLMetaDataWriter method createNonRDFAnnotationElement.
/**
* creating XMLMetaData element for nonRDFAnnotation element here since nonRDFAnnotation was made package level
* this is similar to XMLRDFWriter.createElement(metaData)
*
* @return the created NonRDFAnnotationListElement
*/
private static Element createNonRDFAnnotationElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
Set<Map.Entry<Entry, NonRDFAnnotation>> allNonRdfAnnotations = metaData.getAllNonRDFAnnotations();
Element nonRDFAnnotationListElement = new Element(XMLMetaData.NONRDF_ANNOTATION_LIST_TAG);
Iterator<Map.Entry<Entry, NonRDFAnnotation>> iter = allNonRdfAnnotations.iterator();
while (iter.hasNext()) {
Map.Entry<Entry, NonRDFAnnotation> mapEntry = iter.next();
Entry openEntry = mapEntry.getKey();
NonRDFAnnotation nonRDFAnnotation = mapEntry.getValue();
VCID vcid = identifiableProvider.getVCID(openEntry.getIdentifiable());
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
// only write out nonRDF annotation if identifiable in identifiableProvider is not null
if (identifiable != null) {
if (!nonRDFAnnotation.isEmpty()) {
Element nonRDFAnnotationElement = new Element(XMLMetaData.NONRDF_ANNOTATION_TAG);
nonRDFAnnotationElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
nonRDFAnnotationListElement.addContent(nonRDFAnnotationElement);
String freeTextAnnotation = nonRDFAnnotation.getFreeTextAnnotation();
if (freeTextAnnotation != null && freeTextAnnotation.length() > 0) {
Element freeTextAnnotationElement = new Element(XMLMetaData.FREETEXT_TAG);
freeTextAnnotationElement.addContent(new Text(freeTextAnnotation));
nonRDFAnnotationElement.addContent(freeTextAnnotationElement);
}
Element xhtmlNotes = nonRDFAnnotation.getXhtmlNotes();
if (xhtmlNotes != null) {
// Element notesElement = new Element(XMLMetaData.NOTES_TAG);
// notesElement.addContent(xhtmlNotes));
nonRDFAnnotationElement.addContent(xhtmlNotes.detach());
}
Element[] otherAnnotations = nonRDFAnnotation.getXmlAnnotations();
if (otherAnnotations != null && otherAnnotations.length > 0) {
Element annotationListElement = new Element(XMLMetaData.ANNOTATION_LIST_TAG);
nonRDFAnnotationElement.addContent(annotationListElement);
for (int i = 0; i < otherAnnotations.length; i++) {
annotationListElement.addContent(otherAnnotations[i].detach());
}
}
}
}
}
return nonRDFAnnotationListElement;
}
use of org.vcell.util.document.Identifiable in project vcell by virtualcell.
the class XMLMetaDataWriter method getElement.
public static Element getElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
Element element = new Element(XMLMetaData.VCMETADATA_TAG);
Element elementRDF = metaData.createElement();
// add RDF data
if (elementRDF != null) {
element.addContent(elementRDF);
}
Element elementNonRDFList = createNonRDFAnnotationElement(metaData, identifiableProvider);
element.addContent(elementNonRDFList);
// add resource binding table
Element bindingListElement = new Element(XMLMetaData.URI_BINDING_LIST_TAG);
Set<Registry.Entry> resources = metaData.getRegistry().getAllEntries();
for (Registry.Entry entry : resources) {
VCID vcid = identifiableProvider.getVCID(entry.getIdentifiable());
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
if (identifiable != null && entry.getResource() != null) {
Element entryElement = new Element(XMLMetaData.URI_BINDING_TAG);
Resource resource = entry.getResource();
if (resource != null) {
entryElement.setAttribute(XMLMetaData.URI_ATTR_TAG, resource.stringValue());
}
entryElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
bindingListElement.addContent(entryElement);
}
}
element.addContent(bindingListElement);
return element;
}
Aggregations