use of io.atlasmap.v2.ProcessMappingRequest in project atlasmap by atlasmap.
the class AtlasServiceTest method testJarUploadNoProcessorLoader.
@Test
public void testJarUploadNoProcessorLoader() throws Exception {
assumeFalse(isWindowsJDK8());
createJarFile(false, true);
FileInputStream jarIn = new FileInputStream(TEST_JAR_PATH);
Response resUL = service.uploadLibrary(jarIn);
assertEquals(200, resUL.getStatus());
Response resFA = service.listFieldActions(null);
assertEquals(200, resFA.getStatus());
String responseJson = new String((byte[]) resFA.getEntity());
assertFalse(responseJson.contains("myCustomFieldAction"));
BufferedInputStream in = new BufferedInputStream(new FileInputStream("src/test/resources/mappings/atlasmapping-custom-action.json"));
AtlasMapping am = mapper.readValue(in, AtlasMapping.class);
Mapping m = (Mapping) am.getMappings().getMapping().get(0);
Field f = m.getInputField().get(0);
f.setValue("foo");
Action action = f.getActions().get(0);
Method method = action.getClass().getDeclaredMethod("setParam", new Class[] { String.class });
method.invoke(action, "param");
ProcessMappingRequest request = new ProcessMappingRequest();
request.setMapping(m);
Response resMR = service.processMappingRequest(new ByteArrayInputStream(mapper.writeValueAsBytes(request)), null);
assertEquals(200, resMR.getStatus());
ProcessMappingResponse pmr = Json.mapper().readValue((byte[]) resMR.getEntity(), ProcessMappingResponse.class);
assertEquals(1, pmr.getAudits().getAudit().size(), printAudit(pmr.getAudits()));
Audit audit = pmr.getAudits().getAudit().get(0);
assertEquals(AuditStatus.WARN, audit.getStatus());
assertTrue(audit.getMessage().contains("Couldn't find metadata for a FieldAction 'MyFieldActionsModel'"));
assertEquals("foo", pmr.getMapping().getOutputField().get(0).getValue());
}
use of io.atlasmap.v2.ProcessMappingRequest in project atlasmap by atlasmap.
the class AtlasServiceTest method testProcessMappingCustomAction.
@Test
public void testProcessMappingCustomAction() throws Exception {
createJarFile(false, false);
FileInputStream jarIn = new FileInputStream(TEST_JAR_PATH);
Response resUL = service.uploadLibrary(jarIn);
assertEquals(200, resUL.getStatus());
Response resFA = service.listFieldActions(null);
assertEquals(200, resFA.getStatus());
BufferedInputStream in = new BufferedInputStream(new FileInputStream("src/test/resources/mappings/atlasmapping-custom-action.json"));
AtlasMapping am = mapper.readValue(in, AtlasMapping.class);
Mapping m = (Mapping) am.getMappings().getMapping().get(0);
Field f = m.getInputField().get(0);
f.setValue("foo");
Action action = f.getActions().get(0);
Method method = action.getClass().getDeclaredMethod("setParam", new Class[] { String.class });
method.invoke(action, "param");
ProcessMappingRequest request = new ProcessMappingRequest();
request.setMapping(m);
Response resMR = service.processMappingRequest(new ByteArrayInputStream(mapper.writeValueAsBytes(request)), null);
assertEquals(200, resMR.getStatus());
ProcessMappingResponse pmr = Json.mapper().readValue((byte[]) resMR.getEntity(), ProcessMappingResponse.class);
assertEquals(0, pmr.getAudits().getAudit().size(), printAudit(pmr.getAudits()));
assertEquals("param foo", pmr.getMapping().getOutputField().get(0).getValue());
}
use of io.atlasmap.v2.ProcessMappingRequest in project atlasmap by atlasmap.
the class AtlasService method processMappingRequest.
/**
* Processes mapping by feeding input data.
* @param request request
* @param uriInfo URI info
* @return {@link ProcessMappingResponse} which holds the result of the mappings
*/
@PUT
@Path("/mapping/process")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Process Mapping", description = "Process Mapping by feeding input data")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ProcessMappingResponse.class)), description = "Return a mapping result"), @ApiResponse(responseCode = "204", description = "Skipped empty mapping execution") })
public Response processMappingRequest(InputStream request, @Context UriInfo uriInfo) {
ProcessMappingRequest pmr = fromJson(request, ProcessMappingRequest.class);
if (pmr.getAtlasMapping() != null) {
throw new WebApplicationException("Whole mapping execution is not yet supported");
}
Mapping mapping = pmr.getMapping();
if (mapping == null) {
return Response.noContent().build();
}
Audits audits = null;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Preview request: {}", new String(toJson(mapping)));
}
audits = previewContext.processPreview(mapping);
} catch (AtlasException e) {
throw new WebApplicationException("Unable to process mapping preview", e);
}
ProcessMappingResponse response = new ProcessMappingResponse();
response.setMapping(mapping);
if (audits != null) {
response.setAudits(audits);
}
byte[] serialized = toJson(response);
if (LOG.isDebugEnabled()) {
LOG.debug("Preview outcome: {}", new String(serialized));
}
return Response.ok().entity(serialized).build();
}
Aggregations