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