Search in sources :

Example 6 with ClassInspectionService

use of io.atlasmap.java.inspect.ClassInspectionService in project atlasmap by atlasmap.

the class JavaModule method processPreSourceExecution.

@Override
public void processPreSourceExecution(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null || atlasSession.getMapping().getMappings() == null || atlasSession.getMapping().getMappings().getMapping() == null) {
        throw new AtlasException("AtlasSession not properly intialized with a mapping that contains field mappings");
    }
    if (javaInspectionService == null) {
        javaInspectionService = new ClassInspectionService();
        javaInspectionService.setConversionService(getConversionService());
    }
    Object sourceDocument = atlasSession.getSourceDocument(getDocId());
    if (sourceDocument == null) {
        AtlasUtil.addAudit(atlasSession, getDocId(), String.format("Null source document: docId='%s'", getDocId()), null, AuditStatus.WARN, null);
    } else {
        DocumentJavaFieldReader reader = new DocumentJavaFieldReader();
        reader.setConversionService(getConversionService());
        reader.setDocument(sourceDocument);
        atlasSession.setFieldReader(getDocId(), reader);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreSourceExcution completed", getDocId());
    }
}
Also used : DocumentJavaFieldReader(io.atlasmap.java.core.DocumentJavaFieldReader) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) AtlasException(io.atlasmap.api.AtlasException)

Example 7 with ClassInspectionService

use of io.atlasmap.java.inspect.ClassInspectionService in project atlasmap by atlasmap.

the class JavaModule method processPreTargetExecution.

@Override
public void processPreTargetExecution(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null || atlasSession.getMapping().getMappings() == null || atlasSession.getMapping().getMappings().getMapping() == null) {
        throw new AtlasException("AtlasSession not properly intialized with a mapping that contains field mappings");
    }
    if (javaInspectionService == null) {
        javaInspectionService = new ClassInspectionService();
        javaInspectionService.setConversionService(getConversionService());
    }
    List<BaseMapping> mapping = atlasSession.getMapping().getMappings().getMapping();
    Object rootObject;
    String targetClassName = AtlasUtil.getUriParameterValue(getUri(), "className");
    JavaClass inspectClass = getJavaInspectionService().inspectClass(targetClassName);
    merge(inspectClass, mapping);
    List<String> targetPaths = AtlasModuleSupport.listTargetPaths(mapping);
    try {
        rootObject = getJavaConstructService().constructClass(inspectClass, targetPaths);
    } catch (Exception e) {
        throw new AtlasException(e);
    }
    DocumentJavaFieldWriter writer = new DocumentJavaFieldWriter(getConversionService());
    writer.setRootObject(rootObject);
    writer.setTargetValueConverter(targetValueConverter);
    atlasSession.setFieldWriter(getDocId(), writer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreTargetExcution completed", getDocId());
    }
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException)

Aggregations

ClassInspectionService (io.atlasmap.java.inspect.ClassInspectionService)7 JavaClass (io.atlasmap.java.v2.JavaClass)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AtlasException (io.atlasmap.api.AtlasException)2 IOException (java.io.IOException)2 ApplicationPath (javax.ws.rs.ApplicationPath)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 DocumentJavaFieldReader (io.atlasmap.java.core.DocumentJavaFieldReader)1 DocumentJavaFieldWriter (io.atlasmap.java.core.DocumentJavaFieldWriter)1 TargetValueConverter (io.atlasmap.java.core.TargetValueConverter)1 JavaConstructService (io.atlasmap.java.inspect.JavaConstructService)1 ClassInspectionRequest (io.atlasmap.java.v2.ClassInspectionRequest)1 ClassInspectionResponse (io.atlasmap.java.v2.ClassInspectionResponse)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 File (java.io.File)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1