use of org.sbolstandard.core2.Collection in project libSBOLj by SynBioDex.
the class VariableComponent method addVariantCollection.
/**
* Adds the given variant collection to the list of variant collections.
*
* @param uriPrefix
* URI prefix for variant collection
* @param displayId
* display id for variant collection
* @param version
* version for variant collection
* @throws SBOLValidationException if the following SBOL validation rule was violated:
*/
public void addVariantCollection(String uriPrefix, String displayId, String version) throws SBOLValidationException {
URI uri = URIcompliance.createCompliantURI(uriPrefix, displayId, version);
Collection collection = this.getSBOLDocument().getCollection(uri);
addVariantCollection(collection.getIdentity());
}
use of org.sbolstandard.core2.Collection in project libSBOLj by SynBioDex.
the class SBOLDocument method updateReferences.
// TODO: need to update persistentIdentities too
private void updateReferences(HashMap<URI, URI> uriMap) throws SBOLValidationException {
for (TopLevel topLevel : getTopLevels()) {
for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
if (uriMap.get(wasDerivedFrom) != null) {
topLevel.removeWasDerivedFrom(wasDerivedFrom);
topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
}
}
for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
if (uriMap.get(wasGeneratedBy) != null) {
topLevel.removeWasGeneratedBy(wasGeneratedBy);
topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
}
}
for (URI attachmentURI : topLevel.getAttachmentURIs()) {
if (uriMap.get(attachmentURI) != null) {
topLevel.removeAttachment(attachmentURI);
topLevel.addAttachment(uriMap.get(attachmentURI));
}
}
}
for (Collection collection : getCollections()) {
for (URI memberURI : collection.getMemberURIs()) {
if (uriMap.get(memberURI) != null) {
collection.removeMember(memberURI);
collection.addMember(uriMap.get(memberURI));
}
}
updateReferences(collection, uriMap);
}
for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
updateReferences(componentDefinition, uriMap);
for (Component component : componentDefinition.getComponents()) {
if (uriMap.get(component.getDefinitionURI()) != null) {
component.setDefinition(uriMap.get(component.getDefinitionURI()));
for (MapsTo mapsTo : component.getMapsTos()) {
ComponentDefinition cd = getComponentDefinition(component.getDefinitionURI());
if (cd != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(component, uriMap);
for (MapsTo mapsTo : component.getMapsTos()) {
updateReferences(mapsTo, uriMap);
}
}
for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
for (Location loc : sa.getLocations()) {
updateReferences(loc, uriMap);
}
updateReferences(sa, uriMap);
}
for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
updateReferences(sc, uriMap);
}
for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
if (uriMap.get(sequenceURI) != null) {
componentDefinition.removeSequence(sequenceURI);
componentDefinition.addSequence(uriMap.get(sequenceURI));
}
}
}
for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
updateReferences(moduleDefinition, uriMap);
for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
ComponentDefinition cd = getComponentDefinition(functionalComponent.getDefinitionURI());
if (cd != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(functionalComponent, uriMap);
for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
updateReferences(mapsTo, uriMap);
}
}
for (Module module : moduleDefinition.getModules()) {
if (uriMap.get(module.getDefinitionURI()) != null) {
module.setDefinition(uriMap.get(module.getDefinitionURI()));
for (MapsTo mapsTo : module.getMapsTos()) {
ModuleDefinition md = getModuleDefinition(module.getDefinitionURI());
if (md != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(module, uriMap);
for (MapsTo mapsTo : module.getMapsTos()) {
updateReferences(mapsTo, uriMap);
}
}
for (Interaction interaction : moduleDefinition.getInteractions()) {
updateReferences(interaction, uriMap);
for (Participation participation : interaction.getParticipations()) {
updateReferences(participation, uriMap);
}
}
for (URI modelURI : moduleDefinition.getModelURIs()) {
if (uriMap.get(modelURI) != null) {
moduleDefinition.removeModel(modelURI);
moduleDefinition.addModel(uriMap.get(modelURI));
}
}
}
for (Model model : getModels()) {
updateReferences(model, uriMap);
}
for (Sequence sequence : getSequences()) {
updateReferences(sequence, uriMap);
}
for (Attachment attachment : getAttachments()) {
updateReferences(attachment, uriMap);
}
for (Implementation implementation : getImplementations()) {
if (implementation.isSetBuilt()) {
URI built = implementation.getBuiltURI();
if (uriMap.get(built) != null) {
implementation.setBuilt(uriMap.get(built));
}
}
updateReferences(implementation, uriMap);
}
for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
updateReferences(genericTopLevel, uriMap);
}
for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
updateReferences(combinatorialDerivation, uriMap);
if (uriMap.get(combinatorialDerivation.getTemplateURI()) != null) {
combinatorialDerivation.setTemplate(uriMap.get(combinatorialDerivation.getTemplateURI()));
ComponentDefinition cd = getComponentDefinition(combinatorialDerivation.getTemplateURI());
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, uriMap);
}
}
for (Activity activity : getActivities()) {
updateReferences(activity, uriMap);
for (Association association : activity.getAssociations()) {
if (uriMap.get(association.getAgentURI()) != null) {
association.setAgent(uriMap.get(association.getAgentURI()));
}
if (uriMap.get(association.getPlanURI()) != null) {
association.setPlan(uriMap.get(association.getPlanURI()));
}
updateReferences(association, uriMap);
}
for (Usage usage : activity.getUsages()) {
if (uriMap.get(usage.getEntityURI()) != null) {
usage.setEntity(uriMap.get(usage.getEntityURI()));
}
updateReferences(usage, uriMap);
}
}
for (Agent agent : getAgents()) {
updateReferences(agent, uriMap);
}
for (Plan plan : getPlans()) {
updateReferences(plan, uriMap);
}
}
use of org.sbolstandard.core2.Collection in project atlasmap by atlasmap.
the class BaseMarshallerTest method generateCollectionMapping.
protected AtlasMapping generateCollectionMapping() {
AtlasMapping innerMapping1 = generateAtlasMapping();
AtlasMapping innerMapping2 = generateAtlasMapping();
Collection cMapping = (Collection) AtlasModelFactory.createMapping(MappingType.COLLECTION);
cMapping.setMappings(new Mappings());
cMapping.getMappings().getMapping().addAll(innerMapping1.getMappings().getMapping());
cMapping.getMappings().getMapping().addAll(innerMapping2.getMappings().getMapping());
cMapping.setCollectionType(CollectionType.LIST);
cMapping.setCollectionSize(new BigInteger("2"));
cMapping.setAlias("alias");
cMapping.setDescription("description");
AtlasMapping mapping = generateAtlasMapping();
mapping.getMappings().getMapping().clear();
mapping.getMappings().getMapping().add(cMapping);
return mapping;
}
use of org.sbolstandard.core2.Collection in project atlasmap by atlasmap.
the class DefaultAtlasContext method extractCollectionMappings.
private List<Mapping> extractCollectionMappings(DefaultAtlasSession session, BaseMapping baseMapping) throws AtlasException {
if (LOG.isDebugEnabled()) {
LOG.debug("Generating Source Mappings from mapping: {}", baseMapping);
}
if (!baseMapping.getMappingType().equals(MappingType.COLLECTION)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Mapping is not a collection mapping, not cloning: {}", baseMapping);
}
return Arrays.asList((Mapping) baseMapping);
}
List<Mapping> mappings = new LinkedList<>();
for (BaseMapping m : ((Collection) baseMapping).getMappings().getMapping()) {
Mapping mapping = (Mapping) m;
Field sourceField = mapping.getInputField().get(0);
boolean sourceIsCollection = AtlasPath.isCollection(sourceField.getPath());
if (!sourceIsCollection) {
// just copy it over
if (LOG.isDebugEnabled()) {
LOG.debug("Internal mapping's source field is not a collection, not cloning: {}", mapping);
}
// output object to be created for our copied firstName value
for (Field f : mapping.getOutputField()) {
f.setPath(AtlasPath.overwriteCollectionIndex(f.getPath(), 0));
}
mappings.add(mapping);
continue;
}
AtlasModule module = resolveModule(FieldDirection.SOURCE, sourceField);
int sourceCollectionSize = module.getCollectionSize(session, sourceField);
if (LOG.isDebugEnabled()) {
LOG.debug("Internal mapping's source field is a collection. Cloning it for each item ({} clones): {}", sourceCollectionSize, mapping);
}
for (int i = 0; i < sourceCollectionSize; i++) {
Mapping cloneMapping = (Mapping) AtlasModelFactory.cloneMapping(mapping, false);
for (Field f : mapping.getInputField()) {
Field clonedField = module.cloneField(f);
clonedField.setPath(AtlasPath.overwriteCollectionIndex(clonedField.getPath(), i));
cloneMapping.getInputField().add(clonedField);
}
for (Field f : mapping.getOutputField()) {
Field clonedField = module.cloneField(f);
if (AtlasPath.isCollection(clonedField.getPath())) {
clonedField.setPath(AtlasPath.overwriteCollectionIndex(clonedField.getPath(), i));
}
cloneMapping.getOutputField().add(clonedField);
}
mappings.add(cloneMapping);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Generated {} mappings from mapping: {}", mappings.size(), baseMapping);
}
((Collection) baseMapping).getMappings().getMapping().clear();
((Collection) baseMapping).getMappings().getMapping().addAll(mappings);
return mappings;
}
use of org.sbolstandard.core2.Collection in project libSBOLj by SynBioDex.
the class SBOLReader method parseVariableComponent.
// TODO: FIX COMMENTED SECTION
@SuppressWarnings("unchecked")
private static VariableComponent parseVariableComponent(SBOLDocument SBOLDoc, NestedDocument<QName> variableComponent, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
String displayId = null;
String name = null;
String description = null;
URI persistentIdentity = null;
String version = null;
List<Annotation> annotations = new ArrayList<>();
URI variable = null;
OperatorType operator = null;
HashSet<URI> variants = new HashSet<>();
HashSet<URI> variantCollections = new HashSet<>();
HashSet<URI> variantDerivations = new HashSet<>();
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
for (NamedProperty<QName> namedProperty : variableComponent.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", variableComponent.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", variableComponent.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", variableComponent.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", variableComponent.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", variableComponent.getIdentity());
}
description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.VariableComponent.hasVariable)) {
if (!(namedProperty.getValue() instanceof Literal) || variable != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-13004", variableComponent.getIdentity());
}
variable = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getName().equals(Sbol2Terms.VariableComponent.hasVariants)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-13007", variableComponent.getIdentity());
}
variants.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
ComponentDefinition cd = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
variants.add(cd.getIdentity());
} else {
throw new SBOLValidationException("sbol-13007", variableComponent.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-13007", variableComponent.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.VariableComponent.hasVariantCollections)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-13009", variableComponent.getIdentity());
}
variantCollections.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Collection.Collection)) {
Collection cd = parseCollection(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
variantCollections.add(cd.getIdentity());
} else {
throw new SBOLValidationException("sbol-13009", variableComponent.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-13009", variableComponent.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.VariableComponent.hasVariantDerivations)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-13013", variableComponent.getIdentity());
}
variantDerivations.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Collection.Collection)) {
CombinatorialDerivation cd = parseCombinatorialDerivation(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
variantDerivations.add(cd.getIdentity());
} else {
throw new SBOLValidationException("sbol-13013", variableComponent.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-13013", variableComponent.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.VariableComponent.hasOperator)) {
if (!(namedProperty.getValue() instanceof Literal) || operator != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-13002", variableComponent.getIdentity());
}
String operatorTypeStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
try {
operator = OperatorType.convertToOperatorType(URI.create(operatorTypeStr));
} catch (SBOLValidationException e) {
throw new SBOLValidationException("sbol-13003", variableComponent.getIdentity());
}
} 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", variableComponent.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", variableComponent.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else {
annotations.add(new Annotation(namedProperty));
}
}
VariableComponent c = new VariableComponent(variableComponent.getIdentity(), operator, variable);
if (persistentIdentity != null)
c.setPersistentIdentity(persistentIdentity);
if (version != null)
c.setVersion(version);
if (displayId != null)
c.setDisplayId(displayId);
if (!variants.isEmpty())
c.setVariants(variants);
if (!variantCollections.isEmpty())
c.setVariantCollections(variantCollections);
if (!variantDerivations.isEmpty())
c.setVariantDerivations(variantDerivations);
if (name != null)
c.setName(name);
if (description != null)
c.setDescription(description);
if (!annotations.isEmpty())
c.setAnnotations(annotations);
return c;
}
Aggregations