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