Search in sources :

Example 96 with Field

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

the class ClassInspectionService method detectParameterizedTypes.

private List<String> detectParameterizedTypes(Field field, boolean onlyClasses) {
    List<String> pTypes = null;
    if (field == null || field.getGenericType() == null || !(field.getGenericType() instanceof ParameterizedType)) {
        return null;
    }
    Type[] types = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
    if (types.length == 0) {
        return null;
    }
    for (Type t : types) {
        if (pTypes == null) {
            pTypes = new ArrayList<>();
        }
        if (!onlyClasses && t instanceof TypeVariable) {
            TypeVariable<?> tv = (TypeVariable<?>) t;
            // TODO: no current need, but we may want to have treatment for 'T'
            // tv.getTypeName()
            pTypes.add(((Class<?>) tv.getAnnotatedBounds()[0].getType()).getCanonicalName());
        }
        if (!onlyClasses && t instanceof WildcardType) {
            WildcardType wc = (WildcardType) t;
            Type[] upperBounds = wc.getUpperBounds();
            Type[] lowerBounds = wc.getLowerBounds();
            // wc.getTypeName()
            if (upperBounds != null && upperBounds.length > 0) {
                pTypes.add(wc.getUpperBounds()[0].getClass().getCanonicalName());
            } else if (lowerBounds != null && lowerBounds.length > 0) {
                pTypes.add(wc.getLowerBounds()[0].getClass().getCanonicalName());
            }
        }
        if (t instanceof Class) {
            pTypes.add(((Class<?>) t).getCanonicalName());
        }
    }
    return pTypes;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) WildcardType(java.lang.reflect.WildcardType) FieldType(io.atlasmap.v2.FieldType) CollectionType(io.atlasmap.v2.CollectionType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) TypeVariable(java.lang.reflect.TypeVariable) JavaClass(io.atlasmap.java.v2.JavaClass)

Example 97 with Field

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

the class BaseDocumentWriterTest method reset.

@Before
public void reset() {
    classLoader = Thread.currentThread().getContextClassLoader();
    writer = new DocumentJavaFieldWriter(conversionService);
    writer.setTargetValueConverter(new TargetValueConverter(classLoader, conversionService) {

        public Object convert(AtlasInternalSession session, LookupTable lookupTable, Field sourceField, Object parentObject, Field targetField) throws AtlasException {
            return targetField.getValue();
        }
    });
    field = null;
    segmentContexts = new LinkedList<>();
    targetTestClassInstance = new TargetTestClass();
    targetTestClassInstance.setContact(new TargetContact());
    targetTestClassInstance.setAddress(new TargetAddress());
    targetOrderListInstance = new TestListOrders();
    targetOrderListInstance.setOrders(new LinkedList<>());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetTestClassInstance.setListOrders(targetOrderListInstance);
    targetOrderArrayInstance = new TargetOrderArray();
    targetOrderArrayInstance.setOrders(new BaseOrder[2]);
    targetOrderArrayInstance.getOrders()[0] = new TargetOrder();
    targetOrderArrayInstance.getOrders()[1] = new TargetOrder();
    targetTestClassInstance.setOrderArray(targetOrderArrayInstance);
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) TargetContact(io.atlasmap.java.test.TargetContact) TargetAddress(io.atlasmap.java.test.TargetAddress) AtlasException(io.atlasmap.api.AtlasException) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) TestListOrders(io.atlasmap.java.test.TestListOrders) LookupTable(io.atlasmap.v2.LookupTable) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) Before(org.junit.Before)

Example 98 with Field

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

the class BaseDocumentWriterTest method write.

protected void write(String path, String targetValue) throws AtlasException {
    Field field = createField(path, targetValue);
    setTargetValue(targetValue);
    write(field);
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField)

Example 99 with Field

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

the class BaseDocumentWriterTest method write.

protected void write(String path, int targetValue) throws AtlasException {
    Field field = createIntField(path, targetValue);
    setTargetValue(targetValue);
    write(field);
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField)

Example 100 with Field

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

the class DocumentJavaFieldReader method getValueFromMemberField.

private Object getValueFromMemberField(AtlasInternalSession session, Object source, String fieldName) throws IllegalArgumentException, IllegalAccessException {
    java.lang.reflect.Field reflectField = lookupJavaField(source, fieldName);
    if (reflectField != null) {
        reflectField.setAccessible(true);
        return reflectField.get(source);
    }
    Field sourceField = session.head().getSourceField();
    AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Field '%s' not found on object '%s'", fieldName, source), sourceField.getPath(), AuditStatus.ERROR, null);
    return null;
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField)

Aggregations

Field (io.atlasmap.v2.Field)66 Test (org.junit.Test)27 JavaField (io.atlasmap.java.v2.JavaField)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)26 Mapping (io.atlasmap.v2.Mapping)25 BaseMapping (io.atlasmap.v2.BaseMapping)17 SimpleField (io.atlasmap.v2.SimpleField)17 Validation (io.atlasmap.v2.Validation)14 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)13 AtlasException (io.atlasmap.api.AtlasException)12 FieldType (io.atlasmap.v2.FieldType)12 JsonField (io.atlasmap.json.v2.JsonField)10 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 XmlField (io.atlasmap.xml.v2.XmlField)9 LookupTable (io.atlasmap.v2.LookupTable)8 ArrayList (java.util.ArrayList)8 AtlasConversionException (io.atlasmap.api.AtlasConversionException)7 ConstantField (io.atlasmap.v2.ConstantField)7 JavaClass (io.atlasmap.java.v2.JavaClass)6 Head (io.atlasmap.spi.AtlasInternalSession.Head)6