Search in sources :

Example 11 with Collection

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

the class NotEmptyValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    if (!supports(target)) {
        return;
    }
    if (((Collection<?>) target).isEmpty()) {
        Validation validation = new Validation();
        validation.setScope(scope);
        validation.setId(id);
        validation.setMessage(this.violationMessage);
        validation.setStatus(status);
        validations.add(validation);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Collection(java.util.Collection)

Example 12 with Collection

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

the class DocumentJavaFieldReader method extractFromCollection.

private Object extractFromCollection(AtlasInternalSession session, Object source, AtlasPath atlasPath) {
    if (source == null) {
        return null;
    }
    String lastSegment = atlasPath.getLastSegment();
    if (!AtlasPath.isCollectionSegment(lastSegment) || !atlasPath.isIndexedCollection()) {
        return source;
    }
    Integer index = atlasPath.getCollectionIndex(atlasPath.getLastSegment());
    if (AtlasPath.isArraySegment(lastSegment)) {
        return Array.get(source, index);
    } else if (AtlasPath.isListSegment(lastSegment)) {
        return Collection.class.cast(source).toArray()[index];
    } else if (AtlasPath.isMapSegment(lastSegment)) {
        // TODO support map key
        String key = index.toString();
        return Map.class.cast(source).get(key);
    } else {
        Field sourceField = session.head().getSourceField();
        AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Ignoring unknown collection type in path '%s'", sourceField.getPath()), sourceField.getPath(), AuditStatus.WARN, null);
        return source;
    }
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) Collection(java.util.Collection) Map(java.util.Map)

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