Search in sources :

Example 1 with Collection

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

the class StringComplexFieldActions method concatenate.

@AtlasFieldActionInfo(name = "Concatenate", sourceType = FieldType.ANY, targetType = FieldType.STRING, sourceCollectionType = CollectionType.ALL, targetCollectionType = CollectionType.NONE)
public static String concatenate(Action action, Object input) {
    if (action == null || !(action instanceof Concatenate)) {
        throw new IllegalArgumentException("Action must be a Concatenate action");
    }
    if (input == null) {
        return null;
    }
    Concatenate concat = (Concatenate) action;
    String delim = concat.getDelimiter() == null ? "" : concat.getDelimiter();
    Collection<?> inputs = collection(input);
    StringBuilder builder = new StringBuilder();
    for (Object entry : inputs) {
        if (builder.length() > 0) {
            builder.append(delim);
        }
        if (entry != null) {
            builder.append(entry.toString());
        }
    }
    return builder.toString();
}
Also used : Concatenate(io.atlasmap.v2.Concatenate) SubString(io.atlasmap.v2.SubString) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 2 with Collection

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

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

the class DefaultAtlasFieldActionService method packExpressionActionOutcomeIntoField.

private Field packExpressionActionOutcomeIntoField(Object values, Field field) {
    if (values instanceof List) {
        // n -> n and 1 -> n - create new FieldGroup
        FieldGroup fieldGroup = new FieldGroup();
        // Make sure fieldGroup is of a collection type
        AtlasPath groupPath = new AtlasPath(AtlasModelFactory.GENERATED_PATH);
        fieldGroup.setCollectionType(CollectionType.LIST);
        groupPath = new AtlasPath(groupPath.toString() + AtlasPath.PATH_LIST_SUFFIX);
        fieldGroup.setPath(groupPath.toString());
        List<?> tmpSourceList = (List<?>) values;
        while (tmpSourceList.size() == 1 && (tmpSourceList.get(0) instanceof List)) {
            tmpSourceList = (List<Object>) tmpSourceList.get(0);
        }
        FieldType type = null;
        for (int i = 0; i < tmpSourceList.size(); i++) {
            Object subValue = tmpSourceList.get(i);
            if (type == null && subValue != null) {
                type = getConversionService().fieldTypeFromClass(subValue.getClass());
            }
            Field subField = new SimpleField();
            AtlasPath subPath = groupPath.clone();
            subPath.setVacantCollectionIndex(i);
            AtlasModelFactory.copyField(fieldGroup, subField, false);
            subField.setPath(subPath.toString());
            subField.setIndex(null);
            subField.setValue(subValue);
            subField.setFieldType(type);
            subField.setCollectionType(CollectionType.NONE);
            fieldGroup.getField().add(subField);
        }
        return fieldGroup;
    }
    if (values != null) {
        field = new SimpleField();
        field.setPath(AtlasModelFactory.GENERATED_PATH);
        field.setValue(values);
        field.setFieldType(getConversionService().fieldTypeFromClass(values.getClass()));
    }
    return field;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) FieldGroup(io.atlasmap.v2.FieldGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SimpleField(io.atlasmap.v2.SimpleField) FieldType(io.atlasmap.v2.FieldType)

Example 5 with Collection

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

the class AtlasPath method setCollectionIndexRecursively.

/**
 * Sets the collection indexes recursively, which includes modifying path of the subsequent children.
 * @param group parent field
 * @param segmentIndex target segment index
 * @param index index to set
 */
public static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index) {
    AtlasPath path = new AtlasPath(group.getPath());
    path.setCollectionIndex(segmentIndex, index);
    group.setPath(path.toString());
    for (Field f : group.getField()) {
        if (f instanceof FieldGroup) {
            setCollectionIndexRecursively((FieldGroup) f, segmentIndex, index);
        } else {
            AtlasPath fpath = new AtlasPath(f.getPath());
            fpath.setCollectionIndex(segmentIndex, index);
            f.setPath(fpath.toString());
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) FieldGroup(io.atlasmap.v2.FieldGroup)

Aggregations

Field (io.atlasmap.v2.Field)25 FieldGroup (io.atlasmap.v2.FieldGroup)15 AtlasPath (io.atlasmap.core.AtlasPath)14 AtlasMapping (io.atlasmap.v2.AtlasMapping)14 AtlasException (io.atlasmap.api.AtlasException)11 ArrayList (java.util.ArrayList)10 Mapping (io.atlasmap.v2.Mapping)9 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)8 Collection (io.atlasmap.v2.Collection)7 SimpleField (io.atlasmap.v2.SimpleField)7 List (java.util.List)7 Test (org.junit.jupiter.api.Test)7 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)6 JavaField (io.atlasmap.java.v2.JavaField)6 LinkedList (java.util.LinkedList)6 AtlasContext (io.atlasmap.api.AtlasContext)5 AtlasSession (io.atlasmap.api.AtlasSession)5 ADMArchiveHandler (io.atlasmap.core.ADMArchiveHandler)5 ConstantField (io.atlasmap.v2.ConstantField)5 InputStream (java.io.InputStream)5