Search in sources :

Example 1 with Collection

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;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Collection(io.atlasmap.v2.Collection)

Example 2 with Collection

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);
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ConstantField(io.atlasmap.v2.ConstantField) ArrayList(java.util.ArrayList) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Field(io.atlasmap.v2.Field) ConstantField(io.atlasmap.v2.ConstantField) Validations(io.atlasmap.v2.Validations) Audits(io.atlasmap.v2.Audits) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTable(io.atlasmap.v2.LookupTable) Collection(io.atlasmap.v2.Collection) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 3 with Collection

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());
}
Also used : MockField(io.atlasmap.v2.MockField) Field(io.atlasmap.v2.Field) MockField(io.atlasmap.v2.MockField) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 4 with Collection

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));
}
Also used : SBOLDocument(org.sbolstandard.core2.SBOLDocument) Collection(org.sbolstandard.core2.Collection)

Example 5 with Collection

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;
}
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)

Aggregations

URI (java.net.URI)8 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)8 AtlasMapping (io.atlasmap.v2.AtlasMapping)5 Collection (io.atlasmap.v2.Collection)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 BaseMapping (io.atlasmap.v2.BaseMapping)3 Field (io.atlasmap.v2.Field)3 Mapping (io.atlasmap.v2.Mapping)3 Mappings (io.atlasmap.v2.Mappings)3 QName (javax.xml.namespace.QName)3 Literal (org.sbolstandard.core.datatree.Literal)3 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)3 ConstantField (io.atlasmap.v2.ConstantField)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HttpResponse (org.apache.http.HttpResponse)2 Test (org.junit.Test)2 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)2