Search in sources :

Example 71 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class XmlModule method writeTargetValue.

@Override
public void writeTargetValue(AtlasInternalSession session) throws AtlasException {
    XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
    if (session.head().getTargetField() instanceof FieldGroup) {
        FieldGroup targetFieldGroup = (FieldGroup) session.head().getTargetField();
        if (targetFieldGroup.getField().size() > 0) {
            for (Field f : targetFieldGroup.getField()) {
                session.head().setTargetField(f);
                writer.write(session);
            }
            return;
        }
    }
    writer.write(session);
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlEnumField(io.atlasmap.xml.v2.XmlEnumField) FieldGroup(io.atlasmap.v2.FieldGroup) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter)

Example 72 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DefaultAtlasContext method processSourceFieldGroup.

private void processSourceFieldGroup(DefaultAtlasSession session, FieldGroup sourceFieldGroup) throws AtlasException {
    processSourceFields(session, sourceFieldGroup.getField());
    session.head().setSourceField(sourceFieldGroup);
    Field processed = applyFieldActions(session, session.head().getSourceField());
    session.head().setSourceField(processed);
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) PropertyField(io.atlasmap.v2.PropertyField) ConstantField(io.atlasmap.v2.ConstantField)

Example 73 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DefaultAtlasContext method processSeparateField.

/**
 * @deprecated .
 * @param session session
 * @param mapping mapping
 * @param sourceField source field
 * @return processed
 * @throws AtlasException .
 */
@Deprecated
protected List<Field> processSeparateField(DefaultAtlasSession session, Mapping mapping, Field sourceField) throws AtlasException {
    if (sourceField.getValue() == null) {
        AtlasUtil.addAudit(session, sourceField, String.format("null value can't be separated for sourceField.path=%s", sourceField.getPath()), AuditStatus.WARN, null);
        return null;
    }
    if (!sourceField.getValue().getClass().isAssignableFrom(String.class)) {
        Object converted = factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
        sourceField.setValue(converted);
    }
    List<Field> answer = new ArrayList<>();
    String sourceValue;
    try {
        sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
    } catch (AtlasConversionException e) {
        AtlasUtil.addAudit(session, sourceField, String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), AuditStatus.WARN, null);
        sourceValue = sourceField.getValue().toString();
    }
    List<String> separatedValues = null;
    StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
    if (delimiter != null) {
        separatedValues = factory.getSeparateStrategy().separateValue(sourceValue, delimiter);
    } else {
        separatedValues = factory.getSeparateStrategy().separateValue(sourceValue);
    }
    if (separatedValues == null || separatedValues.isEmpty()) {
        LOG.debug("Empty string for Separate mapping sourceField.path={}", sourceField.getPath());
    } else {
        for (String separatedValue : separatedValues) {
            SimpleField simpleField = AtlasModelFactory.cloneFieldToSimpleField(sourceField);
            simpleField.setValue(separatedValue);
            simpleField.setFieldType(FieldType.STRING);
            answer.add(simpleField);
        }
    }
    return answer;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) PropertyField(io.atlasmap.v2.PropertyField) ConstantField(io.atlasmap.v2.ConstantField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) ArrayList(java.util.ArrayList) SimpleField(io.atlasmap.v2.SimpleField) StringDelimiter(io.atlasmap.spi.StringDelimiter)

Example 74 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DefaultAtlasContext method processCombineField.

/**
 * @deprecated .
 * @param session session
 * @param mapping mapping
 * @param sourceFields source fields
 * @param targetField target field
 * @return processed
 */
@Deprecated
protected Field processCombineField(DefaultAtlasSession session, Mapping mapping, List<Field> sourceFields, Field targetField) {
    Map<Integer, String> combineValues = null;
    for (Field sourceField : sourceFields) {
        if (sourceField.getIndex() == null || sourceField.getIndex() < 0) {
            AtlasUtil.addAudit(session, targetField, String.format("Combine requires zero or positive Index value to be set on all sourceFields sourceField.path=%s", sourceField.getPath()), AuditStatus.WARN, null);
            continue;
        }
        if (combineValues == null) {
            // We need to support a sorted map w/ null values
            combineValues = new HashMap<>();
        }
        if (sourceField.getValue() != null) {
            String sourceValue;
            try {
                sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
            } catch (AtlasConversionException e) {
                AtlasUtil.addAudit(session, targetField, String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), AuditStatus.WARN, null);
                sourceValue = sourceField.getValue() != null ? sourceField.getValue().toString() : null;
            }
            combineValues.put(sourceField.getIndex(), sourceValue);
        }
    }
    String combinedValue = null;
    StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
    if (delimiter != null) {
        combinedValue = factory.getCombineStrategy().combineValues(combineValues, delimiter);
    } else if (mapping.getDelimiterString() != null && !mapping.getDelimiterString().isEmpty()) {
        combinedValue = factory.getCombineStrategy().combineValues(combineValues, mapping.getDelimiterString());
    } else {
        combinedValue = factory.getCombineStrategy().combineValues(combineValues);
    }
    Field answer = AtlasModelFactory.cloneFieldToSimpleField(sourceFields.get(0));
    if (combinedValue == null || combinedValue.trim().isEmpty()) {
        LOG.debug("Empty combined string for Combine mapping targetField.path={}", targetField.getPath());
    } else {
        answer.setValue(combinedValue);
    }
    return answer;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) PropertyField(io.atlasmap.v2.PropertyField) ConstantField(io.atlasmap.v2.ConstantField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) StringDelimiter(io.atlasmap.spi.StringDelimiter)

Example 75 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DefaultAtlasContext method processSourceFields.

private void processSourceFields(DefaultAtlasSession session, List<Field> sourceFields) throws AtlasException {
    for (int i = 0; i < sourceFields.size(); i++) {
        Field sourceField = sourceFields.get(i);
        session.head().setSourceField(sourceField);
        if (sourceField instanceof FieldGroup) {
            processSourceFields(session, ((FieldGroup) sourceField).getField());
            Field processed = applyFieldActions(session, sourceField);
            session.head().setSourceField(processed);
            continue;
        }
        AtlasModule module = resolveModule(FieldDirection.SOURCE, sourceField);
        if (module == null) {
            AtlasUtil.addAudit(session, sourceField, String.format("Module not found for docId '%s'", sourceField.getDocId()), AuditStatus.ERROR, null);
            return;
        }
        if (!module.isSupportedField(sourceField)) {
            AtlasUtil.addAudit(session, sourceField, String.format("Unsupported source field type '%s' for DataSource '%s'", sourceField.getClass().getName(), module.getUri()), AuditStatus.ERROR, null);
            return;
        }
        module.readSourceValue(session);
        Field processed = applyFieldActions(session, session.head().getSourceField());
        session.head().setSourceField(processed);
        sourceFields.set(i, processed);
    }
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) PropertyField(io.atlasmap.v2.PropertyField) ConstantField(io.atlasmap.v2.ConstantField) AtlasModule(io.atlasmap.spi.AtlasModule) FieldGroup(io.atlasmap.v2.FieldGroup)

Aggregations

Field (io.atlasmap.v2.Field)221 FieldGroup (io.atlasmap.v2.FieldGroup)86 Test (org.junit.jupiter.api.Test)67 SimpleField (io.atlasmap.v2.SimpleField)62 Field (org.apache.tapestry5.Field)46 JavaField (io.atlasmap.java.v2.JavaField)45 ArrayList (java.util.ArrayList)42 Mapping (io.atlasmap.v2.Mapping)39 Test (org.testng.annotations.Test)39 AtlasPath (io.atlasmap.core.AtlasPath)29 ConstantField (io.atlasmap.v2.ConstantField)29 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)26 AtlasException (io.atlasmap.api.AtlasException)25 JsonField (io.atlasmap.json.v2.JsonField)25 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)25 PropertyField (io.atlasmap.v2.PropertyField)22 AtlasMapping (io.atlasmap.v2.AtlasMapping)21 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)19 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)19 Head (io.atlasmap.spi.AtlasInternalSession.Head)18