Search in sources :

Example 66 with SBOLValidationException

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

the class SBOLReader method parseParticipation.

/**
 * @param participation
 * @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, 11906, 12002, 12004; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link Participation#Participation(URI, URI, Set)},</li>
 * 		<li>{@link Participation#setDisplayId(String)},</li>
 * 		<li>{@link Participation#setVersion(String)},</li>
 * 		<li>{@link Participation#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static Participation parseParticipation(NestedDocument<QName> participation) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(participation.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(participation.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    Set<URI> roles = new HashSet<>();
    URI participant = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : participation.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", participation.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", participation.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", participation.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } 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", participation.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", participation.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Participation.role)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12004", participation.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Participation.hasParticipant)) {
            if (!(namedProperty.getValue() instanceof Literal) || participant != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12002", participation.getIdentity());
            }
            participant = URI.create(((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", participation.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", participation.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Participation p = new Participation(participation.getIdentity(), participant, roles);
    if (displayId != null)
        p.setDisplayId(displayId);
    if (name != null)
        p.setName(name);
    if (description != null)
        p.setDescription(description);
    if (persistentIdentity != null)
        p.setPersistentIdentity(persistentIdentity);
    if (version != null)
        p.setVersion(version);
    p.setWasDerivedFroms(wasDerivedFroms);
    p.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        p.setAnnotations(annotations);
    return p;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) Literal(org.sbolstandard.core.datatree.Literal) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 67 with SBOLValidationException

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

the class SBOLReader method parseMapsTo.

/**
 * @param mapsTo
 * @param inModule
 * @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, 10606, 10802, 10805, 10810, 11706; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link MapsTo#MapsTo(URI, RefinementType, URI, URI)},</li>
 * 		<li>{@link MapsTo#setDisplayId(String)},</li>
 * 		<li>{@link MapsTo#setVersion(String)},</li>
 * 		<li>{@link MapsTo#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static MapsTo parseMapsTo(NestedDocument<QName> mapsTo, boolean inModule) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(mapsTo.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(mapsTo.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    URI remote = null;
    RefinementType refinement = null;
    URI local = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : mapsTo.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", mapsTo.getIdentity());
            }
            persistentIdentity = URI.create(((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", mapsTo.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } 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", mapsTo.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", mapsTo.getIdentity());
            }
            description = ((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", mapsTo.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.refinement)) {
            if (!(namedProperty.getValue() instanceof Literal) || refinement != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10810", mapsTo.getIdentity());
            }
            String refinementStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            if (!refinementStr.startsWith("http://sbols.org/v2#")) {
                System.err.println("Warning: namespace for refinement types should be http://sbols.org/v2#");
                refinementStr = "http://sbols.org/v2#" + refinementStr;
            }
            try {
                refinement = RefinementType.convertToRefinementType(URI.create(refinementStr));
            } catch (SBOLValidationException e) {
                throw new SBOLValidationException("sbol-10810", mapsTo.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.hasRemote)) {
            if (!(namedProperty.getValue() instanceof Literal) || remote != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10805", mapsTo.getIdentity());
            }
            remote = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.hasLocal)) {
            if (!(namedProperty.getValue() instanceof Literal) || local != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10802", mapsTo.getIdentity());
            }
            local = URI.create(((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", mapsTo.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", mapsTo.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    MapsTo map = new MapsTo(mapsTo.getIdentity(), refinement, local, remote);
    if (displayId != null)
        map.setDisplayId(displayId);
    if (name != null)
        map.setName(name);
    if (description != null)
        map.setDescription(description);
    if (persistentIdentity != null)
        map.setPersistentIdentity(persistentIdentity);
    if (version != null)
        map.setVersion(version);
    map.setWasDerivedFroms(wasDerivedFroms);
    map.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        map.setAnnotations(annotations);
    return map;
}
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) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 68 with SBOLValidationException

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

the class SBOLDocument method updateReferences.

// TODO: need to update persistentIdentities too
private void updateReferences(URI originalIdentity, URI newIdentity) throws SBOLValidationException {
    for (TopLevel topLevel : getTopLevels()) {
        for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
            if (wasDerivedFrom.equals(originalIdentity)) {
                topLevel.removeWasDerivedFrom(originalIdentity);
                topLevel.addWasDerivedFrom(newIdentity);
            }
        }
        for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
            if (wasGeneratedBy.equals(originalIdentity)) {
                topLevel.removeWasGeneratedBy(originalIdentity);
                topLevel.addWasGeneratedBy(newIdentity);
            }
        }
        for (URI attachmentURI : topLevel.getAttachmentURIs()) {
            if (attachmentURI.equals(originalIdentity)) {
                topLevel.removeAttachment(originalIdentity);
                topLevel.addAttachment(newIdentity);
            }
        }
    }
    for (Collection collection : getCollections()) {
        for (URI memberURI : collection.getMemberURIs()) {
            if (memberURI.equals(originalIdentity)) {
                collection.removeMember(originalIdentity);
                collection.addMember(newIdentity);
            }
        }
        updateReferences(collection, originalIdentity, newIdentity);
    }
    for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, originalIdentity, newIdentity);
        for (Component component : componentDefinition.getComponents()) {
            if (component.getDefinitionURI().equals(originalIdentity)) {
                component.setDefinition(newIdentity);
                for (MapsTo mapsTo : component.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(newIdentity);
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(component, originalIdentity, newIdentity);
            for (MapsTo mapsTo : component.getMapsTos()) {
                updateReferences(mapsTo, originalIdentity, newIdentity);
            }
        }
        for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                updateReferences(loc, originalIdentity, newIdentity);
            }
            updateReferences(sa, originalIdentity, newIdentity);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, originalIdentity, newIdentity);
        }
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (sequenceURI.equals(originalIdentity)) {
                componentDefinition.removeSequence(originalIdentity);
                componentDefinition.addSequence(newIdentity);
            }
        }
    }
    for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
        updateReferences(moduleDefinition, originalIdentity, newIdentity);
        for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
            if (functionalComponent.getDefinitionURI().equals(originalIdentity)) {
                functionalComponent.setDefinition(newIdentity);
                for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(newIdentity);
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(functionalComponent, originalIdentity, newIdentity);
            for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                updateReferences(mapsTo, originalIdentity, newIdentity);
            }
        }
        for (Module module : moduleDefinition.getModules()) {
            if (module.getDefinitionURI().equals(originalIdentity)) {
                module.setDefinition(newIdentity);
                for (MapsTo mapsTo : module.getMapsTos()) {
                    ModuleDefinition md = getModuleDefinition(newIdentity);
                    if (md != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(module, originalIdentity, newIdentity);
            for (MapsTo mapsTo : module.getMapsTos()) {
                updateReferences(mapsTo, originalIdentity, newIdentity);
            }
        }
        for (Interaction interaction : moduleDefinition.getInteractions()) {
            updateReferences(interaction, originalIdentity, newIdentity);
            for (Participation participation : interaction.getParticipations()) {
                updateReferences(participation, originalIdentity, newIdentity);
            }
        }
        for (URI modelURI : moduleDefinition.getModelURIs()) {
            if (modelURI.equals(originalIdentity)) {
                moduleDefinition.removeModel(originalIdentity);
                moduleDefinition.addModel(newIdentity);
            }
        }
    }
    for (Model model : getModels()) {
        updateReferences(model, originalIdentity, newIdentity);
    }
    for (Attachment attachment : getAttachments()) {
        updateReferences(attachment, originalIdentity, newIdentity);
    }
    for (Implementation implementation : getImplementations()) {
        if (implementation.isSetBuilt() && implementation.getBuiltURI().equals(originalIdentity)) {
            implementation.setBuilt(newIdentity);
        }
        updateReferences(implementation, originalIdentity, newIdentity);
    }
    for (Sequence sequence : getSequences()) {
        updateReferences(sequence, originalIdentity, newIdentity);
    }
    for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
        updateReferences(genericTopLevel, originalIdentity, newIdentity);
    }
    for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
        updateReferences(combinatorialDerivation, originalIdentity, newIdentity);
        if (combinatorialDerivation.getTemplateURI().equals(originalIdentity)) {
            combinatorialDerivation.setTemplate(newIdentity);
            ComponentDefinition cd = getComponentDefinition(newIdentity);
            if (cd != null) {
                for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
                    String displayId = URIcompliance.extractDisplayId(variableComponent.getVariableURI());
                    URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                    variableComponent.setVariable(newURI);
                }
            }
        }
        for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
            updateReferences(variableComponent, originalIdentity, newIdentity);
        }
    }
    for (Activity activity : getActivities()) {
        updateReferences(activity, originalIdentity, newIdentity);
        for (Association association : activity.getAssociations()) {
            if (association.getAgentURI().equals(originalIdentity)) {
                association.setAgent(newIdentity);
            }
            if (association.isSetPlan() && association.getPlanURI().equals(originalIdentity)) {
                association.setPlan(newIdentity);
            }
            updateReferences(association, originalIdentity, newIdentity);
        }
        for (Usage usage : activity.getUsages()) {
            if (usage.getEntityURI().equals(originalIdentity)) {
                usage.setEntity(newIdentity);
            }
            updateReferences(usage, originalIdentity, newIdentity);
        }
    }
    for (Agent agent : getAgents()) {
        updateReferences(agent, originalIdentity, newIdentity);
    }
    for (Plan plan : getPlans()) {
        updateReferences(plan, originalIdentity, newIdentity);
    }
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Example 69 with SBOLValidationException

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

the class SBOLDocument method removeTopLevel.

/**
 * Removes the given top-level from this SBOL document's list of top-levels.
 *
 * @param topLevel
 *            the top-level to be removed
 * @param instancesMap
 *            map of toplevel instances
 * @return {@code true} if the given top-level was successfully removed,
 *         {@code false} otherwise
 * @throws SBOLValidationException
 *             if the following SBOL validation rule was violated: 12103.
 */
private final <TL extends TopLevel> boolean removeTopLevel(TopLevel topLevel, Map<URI, TL> instancesMap) throws SBOLValidationException {
    if (complete) {
        for (Collection c : collections.values()) {
            if (c.containsMember(topLevel.getIdentity())) {
                throw new SBOLValidationException("sbol-12103", c);
            }
        }
    }
    Set<TopLevel> setToRemove = new HashSet<>();
    setToRemove.add(topLevel);
    boolean changed = instancesMap.values().removeAll(setToRemove);
    URI latestVersion = null;
    for (TL tl : instancesMap.values()) {
        if (topLevel.getPersistentIdentity().toString().equals(tl.getPersistentIdentity().toString())) {
            if (latestVersion == null) {
                latestVersion = tl.getIdentity();
            } else if (isFirstVersionNewer(extractVersion(tl.getIdentity()), extractVersion(latestVersion))) {
                latestVersion = tl.getIdentity();
            }
        }
    }
    if (latestVersion != null) {
        instancesMap.put(topLevel.getPersistentIdentity(), instancesMap.get(latestVersion));
    }
    return changed;
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 70 with SBOLValidationException

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

the class ComponentDefinition method createSequenceConstraint.

/**
 * Creates a child sequence constraint for this component definition with the given arguments,
 * and then adds to this component definition's list of sequence constraints.
 * <p>
 * Creation of a sequence constraint requires URIs of a subject component and an object component.
 * This method creates compliant URIs for them respectively. The subject component compliant URI is created with this
 * component defintion's persistent identity URI, followed by the given subject component's display ID,
 * followed by this component's version. The object component compliant URI is created similarly.
 * This method then calls {@link #createSequenceConstraint(String, RestrictionType, URI, URI)} to create
 * the sequence constraint.
 * <p>
 * This method automatically creates a subject component if all of the following conditions are satisfied:
 * <ul>
 * <li>the associated SBOLDocument, i.e., the SBOLDocument instance hosting this component definition, is not {@code null};</li>
 * <li>if default components should be automatically created when not present for the associated SBOLDocument instance,
 * i.e., {@link SBOLDocument#isCreateDefaults} returns {@code true}; and</li>
 * <li>if this component definition does not already have a component with the created compliant subject component URI.</li>
 * </ul>
 * An object component is automatically created if the similar set of conditions hold.
 *
 * @param displayId the display ID of the sequence constraint to be created
 * @param restriction the structural restriction of the subject and object components
 * @param subjectId the display ID of the subject component
 * @param objectId the display ID of the object component
 * @return the created sequence constraint
 * @throws SBOLValidationException if any of the following condition is satisfied:
 * <ul>
 * <li>if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10602, 10604, 10605, 10607, 10803; or</li>
 * <li>an SBOL validation rule violation occurred in {@link #createSequenceConstraint(String, RestrictionType, URI, URI)}.</li>
 * </ul>
 */
public SequenceConstraint createSequenceConstraint(String displayId, RestrictionType restriction, String subjectId, String objectId) throws SBOLValidationException {
    URI subjectURI = URIcompliance.createCompliantURI(this.getPersistentIdentity().toString(), subjectId, this.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && this.getComponent(subjectURI) == null) {
        this.createComponent(subjectId, AccessType.PUBLIC, subjectId, "");
    }
    URI objectURI = URIcompliance.createCompliantURI(this.getPersistentIdentity().toString(), objectId, this.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && this.getComponent(objectURI) == null) {
        this.createComponent(objectId, AccessType.PUBLIC, objectId, "");
    }
    return createSequenceConstraint(displayId, restriction, subjectURI, objectURI);
}
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