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 = new Collection();
cMapping.getMappings().getMapping().addAll(innerMapping1.getMappings().getMapping());
cMapping.getMappings().getMapping().addAll(innerMapping2.getMappings().getMapping());
cMapping.setCollectionType(CollectionType.LIST);
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 DefaultAtlasContextTest method testProcess.
@Test
public void testProcess() throws AtlasException {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
when(session.getAtlasContext()).thenReturn(context);
Head head = mock(Head.class);
when(session.head()).thenReturn(head);
when(head.setMapping(any(Mapping.class))).thenReturn(head);
when(head.setLookupTable(any(LookupTable.class))).thenReturn(head);
Field headField = mock(ConstantField.class);
when(head.getSourceField()).thenReturn(headField);
Audits audits = mock(Audits.class);
when(session.getAudits()).thenReturn(audits);
Validations validations = mock(Validations.class);
when(session.getValidations()).thenReturn(validations);
AtlasMapping mapping = mock(AtlasMapping.class);
when(session.getMapping()).thenReturn(mapping);
when(session.hasErrors()).thenReturn(true);
context.process(session);
when(session.hasErrors()).thenReturn(false);
Mappings mappings = mock(Mappings.class);
when(mapping.getMappings()).thenReturn(mappings);
List<BaseMapping> baseMappings = new ArrayList<>();
Collection baseMapping = mock(Collection.class);
when(baseMapping.getMappingType()).thenReturn(MappingType.COLLECTION);
baseMappings.add(baseMapping);
when(mappings.getMapping()).thenReturn(baseMappings);
Mappings subMappings = mock(Mappings.class);
when(baseMapping.getMappings()).thenReturn(subMappings);
List<BaseMapping> baseMappingList = new ArrayList<>();
Mapping mappingElement1 = mock(Mapping.class);
List<Field> sourceFieldList = new ArrayList<>();
ConstantField sourceField = mock(ConstantField.class);
sourceFieldList.add(sourceField);
when(sourceField.getPath()).thenReturn("contact.firstName");
when(mappingElement1.getInputField()).thenReturn(sourceFieldList);
List<Field> outputFieldList = new ArrayList<>();
Field outputField = mock(Field.class);
outputFieldList.add(outputField);
when(outputField.getPath()).thenReturn("contact.firstName");
when(mappingElement1.getOutputField()).thenReturn(outputFieldList);
when(mappingElement1.getMappingType()).thenReturn(MappingType.ALL);
baseMappingList.add(mappingElement1);
when(subMappings.getMapping()).thenReturn(baseMappingList);
Mapping mappingElement2 = mock(Mapping.class);
when(mappingElement2.getMappingType()).thenReturn(MappingType.ALL);
baseMappingList.add(mappingElement2);
List<Field> sourceFieldList2 = new ArrayList<>();
ConstantField sourceField2 = mock(ConstantField.class);
sourceFieldList2.add(sourceField2);
when(sourceField2.getPath()).thenReturn("contact[1]");
when(mappingElement2.getInputField()).thenReturn(sourceFieldList2);
ConstantModule mockConstantModule = mock(ConstantModule.class);
when(mockConstantModule.getCollectionSize(any(AtlasInternalSession.class), any(Field.class))).thenReturn(1);
ConstantField clonedField = mock(ConstantField.class);
when(clonedField.getPath()).thenReturn("cloned[1]");
when(mockConstantModule.cloneField(any(Field.class))).thenReturn(clonedField);
List<Field> mockSourceFieldList = new ArrayList<>();
ConstantField mockSourceField = mock(ConstantField.class);
mockSourceFieldList.add(mockSourceField);
when(mockSourceField.getPath()).thenReturn("source[1]");
when(mappingElement2.getInputField()).thenReturn(mockSourceFieldList);
List<Field> mockOutputFieldList = new ArrayList<>();
ConstantField mockOutputField = mock(ConstantField.class);
mockOutputFieldList.add(mockOutputField);
when(mockOutputField.getPath()).thenReturn("output[1]");
when(mappingElement2.getOutputField()).thenReturn(mockOutputFieldList);
context.getSourceModules().put(DefaultAtlasContext.CONSTANTS_DOCUMENT_ID, mockConstantModule);
context.process(session);
}
use of org.sbolstandard.core2.Collection in project atlasmap by atlasmap.
the class AtlasModuleSupportTest method testListTargetPathsListOfBaseMapping.
@Test
public void testListTargetPathsListOfBaseMapping() {
List<BaseMapping> mappings = null;
assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
mappings = new ArrayList<>();
assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
Mapping mapping = new Mapping();
Field field = new MockField();
field.setPath("MockPath");
mapping.getOutputField().add(field);
mappings.add(mapping);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
Collection collection = null;
mappings.add(collection);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
collection = new Collection();
mappings.add(collection);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
Mappings mapings = new Mappings();
collection.setMappings(mapings);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
}
use of org.sbolstandard.core2.Collection in project libSBOLj by SynBioDex.
the class CollectionOutput method main.
/**
* @param args
* @throws SBOLValidationException see SBOL validation rule violation at {@link Collection#addMember(URI)}
* @throws SBOLConversionException
*/
public static void main(String[] args) throws SBOLValidationException, SBOLConversionException {
SBOLDocument document = new SBOLDocument();
document.setDefaultURIprefix("http://parts.igem.org/Promoters/Catalog");
document.setTypesInURIs(false);
Collection col = document.createCollection("Anderson", "");
col.setName("Anderson promoters");
col.setDescription("The Anderson promoter collection");
col.addMember(URI.create("http://partsregistry.org/Part:BBa_J23119"));
col.addMember(URI.create("http://partsregistry.org/Part:BBa_J23118"));
SBOLWriter.write(document, (System.out));
}
use of org.sbolstandard.core2.Collection 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;
}
Aggregations