Search in sources :

Example 41 with SBOLValidationException

use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.

the class SBOLDocument method addTopLevel.

/**
 * @param newTopLevel
 * @param instancesMap
 * @param typeName
 * @param maps
 * @throws SBOLValidationException
 *             if either of the following SBOL validation rules was violated:
 *             10202, 10220.
 */
@SafeVarargs
private final <TL extends TopLevel> void addTopLevel(TL newTopLevel, Map<URI, TL> instancesMap, String typeName, Map<URI, ? extends Identified>... maps) throws SBOLValidationException {
    boolean childrenCompliant = true;
    try {
        URIcompliance.isURIcompliant(newTopLevel);
    // newTopLevel.checkDescendantsURIcompliance();
    } catch (SBOLValidationException e) {
        childrenCompliant = false;
    }
    if (compliant && childrenCompliant) {
        URI persistentId = URI.create(extractPersistentId(newTopLevel.getIdentity()));
        if (keyExistsInAnyMap(persistentId, maps))
            throw new SBOLValidationException("sbol-10220", newTopLevel);
        if (instancesMap.containsKey(newTopLevel.getIdentity()))
            throw new SBOLValidationException("sbol-10202", newTopLevel);
        String prefix = extractURIprefix(persistentId);
        while (prefix != null) {
            if (keyExistsInAnyMap(URI.create(prefix), maps))
                throw new SBOLValidationException("sbol-10202", newTopLevel);
            if (instancesMap.containsKey(URI.create(prefix)))
                throw new SBOLValidationException("sbol-10202", newTopLevel);
            prefix = extractURIprefix(URI.create(prefix));
        }
        if (prefixes.contains(persistentId.toString())) {
            throw new IllegalArgumentException("Persistent identity `" + persistentId.toString() + "' matches URI prefix in document.");
        }
        prefix = extractURIprefix(persistentId);
        while (prefix != null) {
            prefixes.add(prefix);
            prefix = extractURIprefix(URI.create(prefix));
        }
        instancesMap.put(newTopLevel.getIdentity(), newTopLevel);
        Identified latest = instancesMap.get(persistentId);
        if (latest == null) {
            instancesMap.put(persistentId, newTopLevel);
        } else {
            if (isFirstVersionNewer(extractVersion(newTopLevel.getIdentity()), extractVersion(latest.getIdentity()))) {
                instancesMap.put(persistentId, newTopLevel);
            }
        }
    } else {
        // Only check if URI exists in all maps.
        if (keyExistsInAnyMap(newTopLevel.getIdentity()))
            throw new SBOLValidationException("sbol-10202", newTopLevel);
        if (instancesMap.containsKey(newTopLevel.getIdentity()))
            throw new SBOLValidationException("sbol-10202", newTopLevel);
        instancesMap.put(newTopLevel.getIdentity(), newTopLevel);
        if (newTopLevel.isSetPersistentIdentity()) {
            Identified latest = instancesMap.get(newTopLevel.getPersistentIdentity());
            if (latest == null) {
                instancesMap.put(newTopLevel.getPersistentIdentity(), newTopLevel);
            } else {
                if (isFirstVersionNewer(extractVersion(newTopLevel.getIdentity()), extractVersion(latest.getIdentity()))) {
                    instancesMap.put(newTopLevel.getPersistentIdentity(), newTopLevel);
                }
            }
        }
    }
    newTopLevel.setSBOLDocument(this);
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Example 42 with SBOLValidationException

use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.

the class Module method createMapsTo.

/**
 * Creates a child mapsTo for this module with the given arguments, and then adds it to its list of mapsTos.
 * <p>
 * This method creates a compliant URI for the mapsTo to be created. It starts with this module's persistent
 * identity, followed by the mapsTo's display ID, and ends with this module's version.
 *
 * @param displayId the display ID of the mapsTo to be created
 * @param refinement the relationship between the local and remote components
 * @param local the identity URI of the local functional component
 * @param remote the identity URI of the remote functional component
 * @return the created mapsTo
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10802, 10803, 10804, 10805, 10807, 10808, 10809, 10811, 11609.
 */
public MapsTo createMapsTo(String displayId, RefinementType refinement, URI local, URI remote) throws SBOLValidationException {
    String parentPersistentIdStr = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI newMapsToURI = createCompliantURI(parentPersistentIdStr, displayId, version);
    MapsTo m = createMapsTo(newMapsToURI, refinement, local, remote);
    m.setPersistentIdentity(createCompliantURI(parentPersistentIdStr, displayId, ""));
    m.setDisplayId(displayId);
    m.setVersion(version);
    return m;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 43 with SBOLValidationException

use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.

the class ModuleDefinition method createFunctionalComponent.

/**
 * Creates a child functional component for this module definition with the given arguments, and then adds to this
 * module definition's list of functional components.
 * <p>
 * This method creates a compliant URI for the functional component to be created. It starts with
 * this component defintion's persistent identity, followed by the given functional component's display ID,
 * and ends with this module definition's version.
 *
 * @param displayId the display ID of the functional component to be created
 * @param access the access property of the functional component to be created
 * @param definitionURI the identity URI of the component definition referenced by the functional component to be created
 * @param direction the direction property of the functional component to be created
 * @return the created functional component
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10602, 10604, 10607, 11802, 10804.
 */
public FunctionalComponent createFunctionalComponent(String displayId, AccessType access, URI definitionURI, DirectionType direction) throws SBOLValidationException {
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isComplete()) {
        if (this.getSBOLDocument().getComponentDefinition(definitionURI) == null) {
            throw new SBOLValidationException("sbol-10604", this);
        }
    }
    String URIprefix = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI functionalComponentURI = createCompliantURI(URIprefix, displayId, version);
    FunctionalComponent fc = createFunctionalComponent(functionalComponentURI, access, definitionURI, direction);
    fc.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    fc.setDisplayId(displayId);
    fc.setVersion(version);
    return fc;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 44 with SBOLValidationException

use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.

the class ModuleDefinition method flattenRecurse.

/**
 * @return flattened ModuleDefinition
 * @throws SBOLValidationException if either of the following condition is satisfied:
 * <ul>
 * <li>The following SBOL validation rule was violated: 10811; or</li>
 *
 * <li>if an SBOL validation rule violation occurred in any of the following methods:</li>
 *	 <ul>
 *     	<li>{@link #deepCopy()},</li>
 * 		<li>{@link #flattenRecurse()},</li>
 * 		<li>{@link FunctionalComponent#setDefinition(URI)},</li>
 * 		<li>{@link FunctionalComponent#deepCopy()},</li>
 * 		<li>{@link FunctionalComponent#updateCompliantURI(String, String, String)},</li>
 * 		<li>{@link #addFunctionalComponent(FunctionalComponent)},</li>
 * 		<li>{@link Participation#setParticipant(URI)},</li>
 * 		<li>{@link #addInteraction(Interaction)}, or</li>
 * 		<li>{@link Interaction#deepCopy()}.</li>
 * 	</ul>
 * </ul>
 */
private ModuleDefinition flattenRecurse() throws SBOLValidationException {
    ModuleDefinition flatModuleDefinition = this.deepCopy();
    for (Module module : this.getModules()) {
        ModuleDefinition flatModule = module.getDefinition().flattenRecurse();
        for (FunctionalComponent fc : flatModule.getFunctionalComponents()) {
            boolean foundIt = false;
            URI oldURI = fc.getIdentity();
            URI newURI = null;
            for (MapsTo mapsTo : module.getMapsTos()) {
                if (mapsTo.getRemoteURI().equals(fc.getIdentity())) {
                    newURI = mapsTo.getLocalURI();
                    FunctionalComponent topFc = flatModuleDefinition.getFunctionalComponent(newURI);
                    if (mapsTo.getRefinement() == RefinementType.USEREMOTE) {
                        topFc.setDefinition(fc.getDefinitionURI());
                    } else if (mapsTo.getRefinement() == RefinementType.VERIFYIDENTICAL) {
                        if (!topFc.getDefinitionURI().equals(fc.getDefinitionURI())) {
                            // + "' are not identical.");
                            throw new SBOLValidationException("sbol-10811", mapsTo);
                        }
                    } else if (mapsTo.getRefinement() == RefinementType.MERGE) {
                    // TODO: merge?
                    }
                    foundIt = true;
                    break;
                }
            }
            if (!foundIt) {
                FunctionalComponent newFC = fc.deepCopy();
                newFC.updateCompliantURI(this.getPersistentIdentity().toString(), module.getDisplayId() + "__" + fc.getDisplayId(), this.getVersion());
                newURI = newFC.getIdentity();
                flatModuleDefinition.addFunctionalComponent(newFC);
            }
            for (Interaction i : flatModule.getInteractions()) {
                for (Participation p : i.getParticipations()) {
                    if (p.getParticipantURI().equals(oldURI)) {
                        p.setParticipant(newURI);
                    }
                }
            }
        }
        for (Interaction i : flatModule.getInteractions()) {
            flatModuleDefinition.addInteraction(i.deepCopy());
        }
    }
    flatModuleDefinition.clearModules();
    return flatModuleDefinition;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 45 with SBOLValidationException

use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.

the class ModuleDefinition method createModule.

/**
 * Creates a child module for this module definition with the
 * given arguments, and then adds to this module definition's list of modules.
 * <p>
 * This method creates a compliant Module URI with the default URI prefix
 * for this SBOLDocument instance, the given display ID of the module to be created, and this
 * module definition's version.
 *
 * @param displayId the display ID for the module to be created
 * @param moduleDefinitionURI the identity URI of the module definition referenced by the module to be created
 * @return the created module
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10804, 11702, 11703, 11704, 11705.
 */
public Module createModule(String displayId, URI moduleDefinitionURI) throws SBOLValidationException {
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isComplete()) {
        if (this.getSBOLDocument().getModuleDefinition(moduleDefinitionURI) == null) {
            throw new SBOLValidationException("sbol-11703", this);
        }
    }
    String URIprefix = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI newModuleURI = createCompliantURI(URIprefix, displayId, version);
    Module m = createModule(newModuleURI, moduleDefinitionURI);
    m.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    m.setDisplayId(displayId);
    m.setVersion(version);
    return m;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Aggregations

URI (java.net.URI)81 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)75 QName (javax.xml.namespace.QName)36 HashSet (java.util.HashSet)35 ArrayList (java.util.ArrayList)31 Literal (org.sbolstandard.core.datatree.Literal)30 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)30 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)17 Test (org.junit.Test)16 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)13 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)9 SBOLDocument (org.sbolstandard.core2.SBOLDocument)9 ModuleDefinition (org.sbolstandard.core2.ModuleDefinition)6 Sequence (org.sbolstandard.core2.Sequence)5 Interaction (org.sbolstandard.core2.Interaction)4 GenericTopLevel (org.sbolstandard.core2.GenericTopLevel)3 MapsTo (org.sbolstandard.core2.MapsTo)3 Set (java.util.Set)2 Annotation (org.sbolstandard.core2.Annotation)2 GenericLocation (org.sbolstandard.core2.GenericLocation)2