Search in sources :

Example 1 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method processDataShapeIntoFields.

private List<Field> processDataShapeIntoFields(String stepSpecification, DataShapeKinds dsKind) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
    List<Field> fields = null;
    log.debug(stepSpecification);
    if (dsKind.equals(DataShapeKinds.JAVA)) {
        try {
            JavaClass jClass = mapper.readValue(stepSpecification, JavaClass.class);
            jClass = mapper.readValue(stepSpecification, JavaClass.class);
            List<JavaField> jfields = getJavaFields(jClass);
            fields = jfields.stream().map(f -> (Field) f).collect(Collectors.toList());
        } catch (IOException e) {
            log.error("error: {}" + e);
        }
    } else if (dsKind.equals(DataShapeKinds.JSON_SCHEMA) || dsKind.equals(DataShapeKinds.JSON_INSTANCE)) {
        JsonInspectionResponse inspectionResponse = atlasmapEndpoint.inspectJson(generateJsonInspectionRequest(stepSpecification));
        try {
            String mapperString = mapper.writeValueAsString(inspectionResponse);
            log.debug(mapperString);
            fields = inspectionResponse.getJsonDocument().getFields().getField();
        } catch (JsonProcessingException e) {
            log.error("error: {}" + e);
        }
    } else if (dsKind.equals(DataShapeKinds.XML_SCHEMA) || dsKind.equals(DataShapeKinds.XML_INSTANCE)) {
        // TODO(tplevko)
        throw new UnsupportedOperationException("XML support is not implemented yet");
    }
    return fields;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method getJavaFields.

private List<JavaField> getJavaFields(JavaClass jClass) {
    List<JavaField> fields = jClass.getJavaFields().getJavaField();
    List<JavaField> javaField = new ArrayList<>();
    for (JavaField jf : fields) {
        if (jf instanceof JavaClass) {
            javaField.addAll(getJavaFields((JavaClass) jf));
        } else if (jf instanceof JavaField) {
            javaField.add(jf);
        }
    }
    return javaField;
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) ArrayList(java.util.ArrayList)

Example 3 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class GenerateInspectionsMojo method generateInspection.

private void generateInspection(List<String> artifacts, Collection<String> classNames) throws MojoFailureException, MojoExecutionException {
    List<URL> urls = artifacts == null ? Collections.emptyList() : resolveClasspath(artifacts);
    ClassLoader origTccl = Thread.currentThread().getContextClassLoader();
    for (String className : classNames) {
        Class<?> clazz = null;
        JavaClass c = null;
        // Not even this plugin will be available on this new URLClassLoader
        try (URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), origTccl)) {
            clazz = loader.loadClass(className);
            ClassInspectionService classInspectionService = new ClassInspectionService();
            classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
            c = classInspectionService.inspectClass(loader, clazz);
        } catch (ClassNotFoundException | IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        try {
            ObjectMapper objectMapper = Json.mapper();
            File target = outputFile;
            if (target == null) {
                target = new File(outputDir, "atlasmap-inpection-" + className + ".json");
            }
            objectMapper.writeValue(target, c);
            getLog().info("Created: " + target);
        } catch (JsonProcessingException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) URL(java.net.URL) JavaClass(io.atlasmap.java.v2.JavaClass) URLClassLoader(java.net.URLClassLoader) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) URLClassLoader(java.net.URLClassLoader) File(java.io.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaService method inspectClass.

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("/class")
public Response inspectClass(InputStream requestIn) {
    ClassInspectionRequest request = fromJson(requestIn, ClassInspectionRequest.class);
    ClassInspectionResponse response = new ClassInspectionResponse();
    ClassInspectionService classInspectionService = new ClassInspectionService();
    classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
    configureInspectionService(classInspectionService, request);
    long startTime = System.currentTimeMillis();
    try {
        JavaClass c = null;
        if (request.getClasspath() == null || request.getClasspath().isEmpty()) {
            c = classInspectionService.inspectClass(request.getClassName());
        } else {
            c = classInspectionService.inspectClass(request.getClassName(), request.getClasspath());
        }
        response.setJavaClass(c);
    } catch (Exception e) {
        LOG.error("Error inspecting class with classpath: " + e.getMessage(), e);
        response.setErrorMessage(e.getMessage());
    } finally {
        response.setExecutionTime(System.currentTimeMillis() - startTime);
    }
    return Response.ok().entity(toJson(response)).build();
}
Also used : ClassInspectionResponse(io.atlasmap.java.v2.ClassInspectionResponse) JavaClass(io.atlasmap.java.v2.JavaClass) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) ClassInspectionRequest(io.atlasmap.java.v2.ClassInspectionRequest) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaService method getClass.

// example from:
// https://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
@GET
@Path("/class")
@Produces(MediaType.APPLICATION_JSON)
public Response getClass(@QueryParam("className") String className) {
    ClassInspectionService classInspectionService = new ClassInspectionService();
    classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
    JavaClass c = classInspectionService.inspectClass(className);
    classInspectionService = null;
    return Response.ok().entity(toJson(c)).build();
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JavaClass (io.atlasmap.java.v2.JavaClass)47 JavaField (io.atlasmap.java.v2.JavaField)21 Test (org.junit.Test)18 ClassInspectionService (io.atlasmap.java.inspect.ClassInspectionService)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TargetAddress (io.atlasmap.java.test.TargetAddress)2 TargetOrder (io.atlasmap.java.test.TargetOrder)2 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)2 ModifierList (io.atlasmap.java.v2.ModifierList)2 BaseMapping (io.atlasmap.v2.BaseMapping)2 Field (io.atlasmap.v2.Field)2 Method (java.lang.reflect.Method)2 ApplicationPath (javax.ws.rs.ApplicationPath)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AtlasException (io.atlasmap.api.AtlasException)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 DocumentJavaFieldWriter (io.atlasmap.java.core.DocumentJavaFieldWriter)1