Search in sources :

Example 6 with Collection

use of io.atlasmap.v2.Collection in project atlasmap by atlasmap.

the class BaseMarshallerTest method validateCollectionMapping.

private void validateCollectionMapping(Collection collection) {
    assertEquals(new BigInteger("2"), collection.getCollectionSize());
    assertEquals(CollectionType.LIST, collection.getCollectionType());
    Mapping mapping = (Mapping) collection.getMappings().getMapping().get(0);
    assertEquals(1, mapping.getInputField().size());
    validateJavaField((JavaField) mapping.getInputField().get(0));
    assertEquals(1, mapping.getOutputField().size());
    validateJavaField((JavaField) mapping.getOutputField().get(0));
    validateMapping(mapping, MappingType.MAP, generateMappingParams());
    mapping = (Mapping) collection.getMappings().getMapping().get(1);
    assertEquals(1, mapping.getInputField().size());
    validateJavaField((JavaField) mapping.getInputField().get(0));
    assertEquals(1, mapping.getOutputField().size());
    validateJavaField((JavaField) mapping.getOutputField().get(0));
    validateMapping(mapping, MappingType.MAP, generateMappingParams());
}
Also used : BigInteger(java.math.BigInteger) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 7 with Collection

use of io.atlasmap.v2.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 8 with Collection

use of io.atlasmap.v2.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;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) BigInteger(java.math.BigInteger)

Example 9 with Collection

use of io.atlasmap.v2.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;
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) AtlasModule(io.atlasmap.spi.AtlasModule) Collection(io.atlasmap.v2.Collection) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) LinkedList(java.util.LinkedList) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 10 with Collection

use of io.atlasmap.v2.Collection in project atlasmap by atlasmap.

the class SchemaInspector method printAttributes.

private void printAttributes(XSComplexType xsComplexType, String rootName, XmlComplexType xmlComplexType) {
    Collection<? extends XSAttributeUse> c = xsComplexType.getDeclaredAttributeUses();
    for (XSAttributeUse aC : c) {
        XmlField xmlField = AtlasXmlModelFactory.createXmlField();
        XSAttributeDecl attributeDecl = aC.getDecl();
        xmlField.setName(getNameNS(attributeDecl));
        if (attributeDecl.getDefaultValue() != null) {
            xmlField.setValue(attributeDecl.getDefaultValue().value);
        } else if (attributeDecl.getFixedValue() != null) {
            xmlField.setValue(attributeDecl.getFixedValue().value);
        }
        xmlField.setPath(rootName + "/" + "@" + getNameNS(attributeDecl));
        FieldType attrType = getFieldType(attributeDecl.getType().getName());
        xmlField.setFieldType(attrType);
        if (xmlField.getFieldType() == null) {
            // check the simple types in the schema....
            XSSimpleType simpleType = xsComplexType.getRoot().getSimpleType(xsComplexType.getTargetNamespace(), attributeDecl.getType().getName());
            if (simpleType != null) {
                FieldType fieldType = getFieldType(simpleType.getBaseType().getName());
                xmlField.setFieldType(fieldType);
                xmlField.setTypeName(attributeDecl.getType().getName());
                if (simpleType.asRestriction() != null) {
                    mapRestrictions(xmlField, simpleType.asRestriction());
                }
            } else {
                // cannot figure it out....
                xmlField.setFieldType(FieldType.UNSUPPORTED);
            }
        }
        xmlComplexType.getXmlFields().getXmlField().add(xmlField);
    }
}
Also used : XSSimpleType(com.sun.xml.xsom.XSSimpleType) XmlField(io.atlasmap.xml.v2.XmlField) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) XSAttributeUse(com.sun.xml.xsom.XSAttributeUse) FieldType(io.atlasmap.v2.FieldType)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Collection (io.atlasmap.v2.Collection)5 Field (io.atlasmap.v2.Field)4 Mapping (io.atlasmap.v2.Mapping)4 BaseMapping (io.atlasmap.v2.BaseMapping)3 Mappings (io.atlasmap.v2.Mappings)3 Test (org.junit.Test)3 ConstantField (io.atlasmap.v2.ConstantField)2 BigInteger (java.math.BigInteger)2 Collection (java.util.Collection)2 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)1 XSAttributeUse (com.sun.xml.xsom.XSAttributeUse)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1 JavaField (io.atlasmap.java.v2.JavaField)1 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)1 Head (io.atlasmap.spi.AtlasInternalSession.Head)1 AtlasModule (io.atlasmap.spi.AtlasModule)1 Audits (io.atlasmap.v2.Audits)1