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