Search in sources :

Example 1 with CustomMapping

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

the class DefaultAtlasContext method process.

@Override
public void process(AtlasSession userSession) throws AtlasException {
    if (!(userSession instanceof DefaultAtlasSession)) {
        throw new AtlasException(String.format("Unsupported session class '%s'", userSession.getClass().getName()));
    }
    if (!this.equals(userSession.getAtlasContext())) {
        throw new AtlasException("Cannot execute AtlasSession created by the other AtlasContext");
    }
    DefaultAtlasSession session = (DefaultAtlasSession) userSession;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Begin process {}", (session == null ? null : session.toString()));
    }
    session.head().unset();
    session.getAudits().getAudit().clear();
    session.getValidations().getValidation().clear();
    // TODO https://github.com/atlasmap/atlasmap/issues/863 - Add an option to enable/disable runtime validation
    processValidation(session);
    for (Validation v : session.getValidations().getValidation()) {
        AtlasUtil.addAudit(session, v);
    }
    // Additional runtime only audit
    Mappings mappings = session.getMapping().getMappings();
    if (mappings != null && mappings.getMapping().isEmpty()) {
        AtlasUtil.addAudit(session, (String) null, String.format("Field mappings should not be empty"), AuditStatus.WARN, null);
    }
    session.getValidations().getValidation().clear();
    if (session.hasErrors()) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Aborting due to {} errors in pre-validation", session.errorCount());
        }
        return;
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPreSourceExecution(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPreTargetExecution(session);
    }
    if (session.hasErrors()) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Aborting due to {} errors in pre-execution", session.errorCount());
        }
        return;
    }
    for (BaseMapping baseMapping : session.getMapping().getMappings().getMapping()) {
        for (BaseMapping innerMapping : unwrapCollectionMappings(session, baseMapping)) {
            if (innerMapping instanceof CustomMapping) {
                DefaultAtlasCustomMappingProcessor.getInstance().process(session, (CustomMapping) innerMapping);
                continue;
            }
            Mapping mapping = (Mapping) innerMapping;
            session.head().setMapping(mapping).setLookupTable(lookupTables.get(mapping.getLookupTableName()));
            if (mapping.getOutputField() == null || mapping.getOutputField().isEmpty()) {
                AtlasUtil.addAudit(session, (String) null, String.format("Mapping does not contain at least one target field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), AuditStatus.WARN, null);
                continue;
            }
            processSourceFieldMapping(session);
            if (!session.head().hasError()) {
                processTargetFieldMapping(session, mapping);
            }
            session.getAudits().getAudit().addAll(session.head().getAudits());
            session.head().unset();
        }
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPostValidation(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPostValidation(session);
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPostSourceExecution(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPostTargetExecution(session);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("End process {}", session == null ? null : session.toString());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasModule(io.atlasmap.spi.AtlasModule) CustomMapping(io.atlasmap.v2.CustomMapping) Mappings(io.atlasmap.v2.Mappings) CustomMapping(io.atlasmap.v2.CustomMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 2 with CustomMapping

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

the class BaseModuleValidationService method validateCustomMapping.

/**
 * Validates the custom mapping.
 * @param mapping custom mapping
 * @param validations a container to put the result validations
 */
protected void validateCustomMapping(CustomMapping mapping, List<Validation> validations) {
    if (mapping.getClassName() == null || mapping.getClassName().isEmpty()) {
        Validation v = new Validation();
        v.setScope(ValidationScope.MAPPING);
        v.setMessage("Class name must be specified for custom mapping");
        v.setStatus(ValidationStatus.ERROR);
        validations.add(v);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Aggregations

Validation (io.atlasmap.v2.Validation)2 AtlasException (io.atlasmap.api.AtlasException)1 AtlasModule (io.atlasmap.spi.AtlasModule)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 CustomMapping (io.atlasmap.v2.CustomMapping)1 Mapping (io.atlasmap.v2.Mapping)1 Mappings (io.atlasmap.v2.Mappings)1