Search in sources :

Example 6 with NestedDocument

use of org.sbolstandard.core.datatree.NestedDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseModule.

/**
 * @param module
 * @param nested
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10203, 10204, 10206, 10208, 10212, 10213, 11604, 11702; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link #parseMapsTo(NestedDocument, boolean)},</li>
 * 		<li>{@link Module#Module(URI, URI)},</li>
 * 		<li>{@link Module#setDisplayId(String)},</li>
 * 		<li>{@link Module#setVersion(String)},</li>
 * 		<li>{@link Module#setWasDerivedFrom(URI)},</li>
 * 		<li>{@link Identified#setAnnotations(List)}, or</li>
 * 		<li>{@link Module#setMapsTos(Set)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
@SuppressWarnings("unchecked")
private static Module parseModule(SBOLDocument SBOLDoc, NestedDocument<QName> module, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(module.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(module.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    URI definitionURI = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<MapsTo> mappings = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : module.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", module.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", module.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", module.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Module.hasMapsTo)) {
            if (namedProperty.getValue() instanceof NestedDocument) {
                NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
                if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-11706", module.getIdentity());
                }
                mappings.add(parseMapsTo(((NestedDocument<QName>) namedProperty.getValue()), false));
            } else {
                URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
                NestedDocument<QName> nestedDocument = nested.get(uri);
                if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-11706", module.getIdentity());
                }
                mappings.add(parseMapsTo(nested.get(uri), false));
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Module.hasMapping)) {
            System.err.println("Warning: tag should be sbol:mapTo, not sbol:mapping.");
            if (namedProperty.getValue() instanceof NestedDocument) {
                mappings.add(parseMapsTo(((NestedDocument<QName>) namedProperty.getValue()), true));
            } else {
                URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
                mappings.add(parseMapsTo(nested.get(uri), true));
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Module.hasDefinition)) {
            if (definitionURI != null) {
                throw new SBOLValidationException("sbol-11702", module.getIdentity());
            }
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-11702", module.getIdentity());
                }
                definitionURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ModuleDefinition.ModuleDefinition)) {
                    ModuleDefinition moduleDefinition = parseModuleDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
                    definitionURI = moduleDefinition.getIdentity();
                } else {
                    throw new SBOLValidationException("sbol-11702", module.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-11702", module.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", module.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", module.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", module.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", module.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Module submodule = new Module(module.getIdentity(), definitionURI);
    if (persistentIdentity != null)
        submodule.setPersistentIdentity(persistentIdentity);
    if (version != null)
        submodule.setVersion(version);
    if (displayId != null)
        submodule.setDisplayId(displayId);
    if (!mappings.isEmpty())
        submodule.setMapsTos(mappings);
    if (name != null)
        submodule.setName(name);
    if (description != null)
        submodule.setDescription(description);
    submodule.setWasDerivedFroms(wasDerivedFroms);
    submodule.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        submodule.setAnnotations(annotations);
    return submodule;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 7 with NestedDocument

use of org.sbolstandard.core.datatree.NestedDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseComponent.

/**
 * @param component
 * @param nested
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10203, 10204, 10206, 10208, 10212, 10213, 10519, 10602, 10607; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link #parseMapsTo(NestedDocument, boolean)},</li>
 * 		<li>{@link Component#Component(URI, AccessType, URI)},</li>
 * 		<li>{@link Component#setVersion(String)},</li>
 * 		<li>{@link Component#setDisplayId(String)},</li>
 * 		<li>{@link Component#setAccess(AccessType)},</li>
 * 		<li>{@link Component#setMapsTos(Set)},</li>
 * 		<li>{@link Component#setDefinition(URI)},</li>
 * 		<li>{@link Component#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
@SuppressWarnings("unchecked")
private static Component parseComponent(SBOLDocument SBOLDoc, NestedDocument<QName> component, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(component.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(component.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    URI subComponentURI = null;
    AccessType access = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> roles = new HashSet<>();
    URI roleIntegration = null;
    List<Annotation> annotations = new ArrayList<>();
    Set<MapsTo> mapsTo = new HashSet<>();
    for (NamedProperty<QName> namedProperty : component.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", component.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", component.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", component.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Component.roles)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10702", component.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Component.roleIntegration)) {
            if (!(namedProperty.getValue() instanceof Literal) || roleIntegration != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10708", component.getIdentity());
            }
            roleIntegration = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.access)) {
            if (!(namedProperty.getValue() instanceof Literal) || access != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10607", component.getIdentity());
            }
            String accessTypeStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            if (accessTypeStr.startsWith("http://www.sbolstandard.org/")) {
                System.err.println("Warning: namespace for access types should be http://sbols.org/v2#");
                accessTypeStr = accessTypeStr.replace("http://www.sbolstandard.org/", "http://sbols.org/v2#");
            }
            try {
                access = AccessType.convertToAccessType(URI.create(accessTypeStr));
            } catch (SBOLValidationException e) {
                throw new SBOLValidationException("sbol-10607", component.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Module.hasMapsTo)) {
            if (namedProperty.getValue() instanceof NestedDocument) {
                NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
                if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-10606", component.getIdentity());
                }
                mapsTo.add(parseMapsTo(((NestedDocument<QName>) namedProperty.getValue()), false));
            } else {
                URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
                NestedDocument<QName> nestedDocument = nested.get(uri);
                if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-10606", component.getIdentity());
                }
                mapsTo.add(parseMapsTo(nested.get(uri), false));
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.hasComponentDefinition)) {
            if (subComponentURI != null) {
                throw new SBOLValidationException("sbol-10602", component.getIdentity());
            }
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-10602", component.getIdentity());
                }
                subComponentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
                    ComponentDefinition componentDefinition = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
                    subComponentURI = componentDefinition.getIdentity();
                } else {
                    throw new SBOLValidationException("sbol-10602", component.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-10602", component.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", component.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", component.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", component.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", component.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Component c = new Component(component.getIdentity(), access, subComponentURI);
    if (persistentIdentity != null)
        c.setPersistentIdentity(persistentIdentity);
    if (version != null)
        c.setVersion(version);
    if (displayId != null)
        c.setDisplayId(displayId);
    if (access != null)
        c.setAccess(access);
    if (roleIntegration != null)
        try {
            c.setRoleIntegration(RoleIntegrationType.convertToRoleIntegrationType(roleIntegration));
        } catch (SBOLValidationException e) {
            throw new SBOLValidationException("sbol-10708", c);
        }
    if (!roles.isEmpty())
        c.setRoles(roles);
    if (!mapsTo.isEmpty())
        c.setMapsTos(mapsTo);
    if (subComponentURI != null)
        c.setDefinition(subComponentURI);
    if (name != null)
        c.setName(name);
    if (description != null)
        c.setDescription(description);
    c.setWasDerivedFroms(wasDerivedFroms);
    c.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        c.setAnnotations(annotations);
    return c;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 8 with NestedDocument

use of org.sbolstandard.core.datatree.NestedDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseInteraction.

/**
 * @param interaction
 * @param nested
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10203, 10204, 10206, 10208,  10212, 10213, 11605, 11902; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link #parseParticipation(NestedDocument)},</li>
 * 		<li>{@link Interaction#Interaction(URI, Set)},</li>
 * 		<li>{@link Interaction#setParticipations(Set)}, </li>
 * 		<li>{@link Interaction#setDisplayId(String)}, </li>
 * 		<li>{@link Interaction#setVersion(String)}, </li>
 * 		<li>{@link Interaction#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}. </li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static Interaction parseInteraction(NestedDocument<QName> interaction, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(interaction.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(interaction.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> type = new HashSet<>();
    Set<Participation> participations = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : interaction.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", interaction.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", interaction.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", interaction.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Interaction.type)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-11902", interaction.getIdentity());
            }
            type.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Interaction.hasParticipations)) {
            if (namedProperty.getValue() instanceof NestedDocument) {
                NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
                if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Participation.Participation)) {
                    throw new SBOLValidationException("sbol-11906", interaction.getIdentity());
                }
                participations.add(parseParticipation(((NestedDocument<QName>) namedProperty.getValue())));
            } else {
                URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
                NestedDocument<QName> nestedDocument = nested.get(uri);
                if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Participation.Participation)) {
                    throw new SBOLValidationException("sbol-11906", interaction.getIdentity());
                }
                participations.add(parseParticipation(nested.get(uri)));
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", interaction.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", interaction.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", interaction.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", interaction.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Interaction i = new Interaction(interaction.getIdentity(), type);
    if (!participations.isEmpty())
        i.setParticipations(participations);
    if (persistentIdentity != null)
        i.setPersistentIdentity(persistentIdentity);
    if (version != null)
        i.setVersion(version);
    if (displayId != null)
        i.setDisplayId(displayId);
    if (name != null)
        i.setName(name);
    if (description != null)
        i.setDescription(description);
    i.setWasDerivedFroms(wasDerivedFroms);
    i.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        i.setAnnotations(annotations);
    return i;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 9 with NestedDocument

use of org.sbolstandard.core.datatree.NestedDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseCollection.

/**
 * @param SBOLDoc
 * @param topLevel
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10202, 10203, 10204, 10206, 10208, 10212, 10213, 12102; or</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link Collection#Collection(URI)}, </li>
 * 		<li>{@link Collection#setDisplayId(String)}, </li>
 * 		<li>{@link Collection#setVersion(String)}, </li>
 * 		<li>{@link Collection#setMembers(Set)}, </li>
 * 		<li>{@link Collection#setWasDerivedFrom(URI)}, </li>
 * 		<li>{@link Identified#setAnnotations(List)}, or</li>
 * 		<li>{@link SBOLDocument#addCollection(Collection)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Collection parseCollection(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(topLevel.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(topLevel.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> attachments = new HashSet<>();
    Set<URI> members = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", topLevel.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", topLevel.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", topLevel.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Collection.hasMembers)) {
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-12102", topLevel.getIdentity());
                }
                members.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
            } else if (namedProperty.getValue() instanceof NestedDocument) {
                if (((IdentifiableDocument) namedProperty).getType().equals(Sbol2Terms.Collection.Collection))
                    parseCollection(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.ModuleDefinition.ModuleDefinition))
                    parseModuleDefinition(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Model.Model))
                    parseModel(SBOLDoc, (IdentifiableDocument) namedProperty);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Sequence.Sequence))
                    parseSequence(SBOLDoc, (IdentifiableDocument) namedProperty);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.ComponentDefinition.ComponentDefinition))
                    parseComponentDefinition(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.CombinatorialDerivation.CombinatorialDerivation))
                    parseCombinatorialDerivation(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Implementation.Implementation))
                    parseImplementation(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Attachment.Attachment))
                    parseAttachment(SBOLDoc, (IdentifiableDocument) namedProperty);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Activity.Activity))
                    parseActivity(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Agent.Agent))
                    parseAgent(SBOLDoc, (IdentifiableDocument) namedProperty);
                else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Plan.Plan))
                    parsePlan(SBOLDoc, (IdentifiableDocument) namedProperty);
                else
                    parseGenericTopLevel(SBOLDoc, (IdentifiableDocument) namedProperty);
            } else {
                throw new SBOLValidationException("sbol-12102", topLevel.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", topLevel.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", topLevel.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", topLevel.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", topLevel.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
                }
                attachments.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
                    Attachment attachment = parseAttachment(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue());
                    attachments.add(attachment.getIdentity());
                } else {
                    throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
            }
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Collection c = new Collection(topLevel.getIdentity());
    if (displayId != null)
        c.setDisplayId(displayId);
    if (version != null)
        c.setVersion(version);
    if (persistentIdentity != null)
        c.setPersistentIdentity(persistentIdentity);
    if (!members.isEmpty())
        c.setMembers(members);
    if (name != null)
        c.setName(name);
    if (description != null)
        c.setDescription(description);
    c.setWasDerivedFroms(wasDerivedFroms);
    c.setWasGeneratedBys(wasGeneratedBys);
    c.setAttachments(attachments);
    if (!annotations.isEmpty())
        c.setAnnotations(annotations);
    Collection oldC = SBOLDoc.getCollection(topLevel.getIdentity());
    if (oldC == null) {
        SBOLDoc.addCollection(c);
    } else {
        if (!c.equals(oldC)) {
            throw new SBOLValidationException("sbol-10202", c);
        }
    }
    return c;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 10 with NestedDocument

use of org.sbolstandard.core.datatree.NestedDocument in project libSBOLj by SynBioDex.

the class SBOLWriter method formatComponents.

private static void formatComponents(Set<Component> components, List<NamedProperty<QName>> properties) {
    for (Component s : components) {
        List<NamedProperty<QName>> list = new ArrayList<>();
        formatCommonIdentifiedData(list, s);
        for (URI roles : s.getRoles()) {
            list.add(NamedProperty(Sbol2Terms.Component.roles, roles));
        }
        if (s.isSetRoleIntegration()) {
            list.add(NamedProperty(Sbol2Terms.Component.roleIntegration, RoleIntegrationType.convertToURI(s.getRoleIntegration())));
        }
        list.add(NamedProperty(Sbol2Terms.ComponentInstance.access, AccessType.convertToURI(s.getAccess())));
        list.add(NamedProperty(Sbol2Terms.ComponentInstance.hasComponentDefinition, s.getDefinitionURI()));
        List<NestedDocument<QName>> referenceList = getMapsTo(s.getMapsTos());
        for (NestedDocument<QName> n : referenceList) {
            list.add(NamedProperty(Sbol2Terms.ComponentInstance.hasMapsTo, n));
        }
        properties.add(NamedProperty(Sbol2Terms.ComponentDefinition.hasComponent, NestedDocument(Sbol2Terms.Component.Component, s.getIdentity(), NamedProperties(list))));
    }
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) NamedProperty(org.sbolstandard.core.datatree.NamedProperty) NamedProperty(org.sbolstandard.core.datatree.Datatree.NamedProperty) ArrayList(java.util.ArrayList) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) NestedDocument(org.sbolstandard.core.datatree.Datatree.NestedDocument)

Aggregations

URI (java.net.URI)16 ArrayList (java.util.ArrayList)16 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)16 QName (javax.xml.namespace.QName)15 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)15 HashSet (java.util.HashSet)13 Literal (org.sbolstandard.core.datatree.Literal)13 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)13 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)9 NamedProperty (org.sbolstandard.core.datatree.Datatree.NamedProperty)3 NestedDocument (org.sbolstandard.core.datatree.Datatree.NestedDocument)3 NamedProperty (org.sbolstandard.core.datatree.NamedProperty)3 HashMap (java.util.HashMap)1 Set (java.util.Set)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1