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;
}
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;
}
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);
}
}
}
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();
}
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();
}
Aggregations