Search in sources :

Example 81 with Mappings

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

the class AtlasServiceTest method testJarUpload.

@Test
public void testJarUpload() 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());
    String responseJson = new String((byte[]) resFA.getEntity());
    assertTrue(responseJson.contains("myCustomFieldAction"));
    Response resMB = service.listMappingBuilderClasses(null);
    assertEquals(200, resMB.getStatus());
    ArrayNode builders = (ArrayNode) new ObjectMapper().readTree((byte[]) resMB.getEntity()).get("ArrayList");
    assertEquals(1, builders.size());
    assertEquals("io.atlasmap.service.my.MyCustomMappingBuilder", builders.get(0).asText());
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("src/test/resources/mappings/atlasmapping-custom-action.json"));
    Response resVD = service.validateMappingRequest(in, 0, null);
    assertEquals(200, resVD.getStatus());
}
Also used : ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Response(javax.ws.rs.core.Response) BufferedInputStream(java.io.BufferedInputStream) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FileInputStream(java.io.FileInputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 82 with Mappings

use of io.atlasmap.v2.Mappings 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();
}
Also used : Audits(io.atlasmap.v2.Audits) WebApplicationException(javax.ws.rs.WebApplicationException) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) ProcessMappingRequest(io.atlasmap.v2.ProcessMappingRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Example 83 with Mappings

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

the class AtlasTestData method generateAtlasSession.

public static AtlasSession generateAtlasSession() throws Exception {
    AtlasMapping mappings = generateAtlasMapping();
    Map<String, Object> runtimeProperties = generateRuntimeProperties();
    return new DefaultAtlasSession(new DefaultAtlasContext(null)) {

        @Override
        public Map<String, Object> getSourceProperties() {
            return runtimeProperties;
        }

        @Override
        public AtlasMapping getMapping() {
            return mappings;
        }
    };
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 84 with Mappings

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

the class BaseMarshallerTest method generateCollectionMapping.

protected AtlasMapping generateCollectionMapping() {
    AtlasMapping innerMapping1 = generateAtlasMapping();
    AtlasMapping innerMapping2 = generateAtlasMapping();
    Collection cMapping = (Collection) AtlasModelFactory.createMapping(MappingType.COLLECTION);
    cMapping.setMappings(new Mappings());
    cMapping.getMappings().getMapping().addAll(innerMapping1.getMappings().getMapping());
    cMapping.getMappings().getMapping().addAll(innerMapping2.getMappings().getMapping());
    cMapping.setCollectionType(CollectionType.LIST);
    cMapping.setCollectionSize(new BigInteger("2"));
    cMapping.setAlias("alias");
    cMapping.setDescription("description");
    AtlasMapping mapping = generateAtlasMapping();
    mapping.getMappings().getMapping().clear();
    mapping.getMappings().getMapping().add(cMapping);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) BigInteger(java.math.BigInteger)

Example 85 with Mappings

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

the class JavaValidationServiceTest method testValidateMappingSourceToTargetFormatConcerns.

@Test
public void testValidateMappingSourceToTargetFormatConcerns() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.json");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.STRING);
    in.setClassName("java.lang.String");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.LONG);
    out.setClassName("java.lang.Long");
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    if (LOG.isDebugEnabled()) {
        debugErrors(validations);
    }
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(3, validationHelper.getCount());
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("format")));
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("fractional part")));
}
Also used : DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) Disabled(org.junit.jupiter.api.Disabled) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) AtlasJavaModelFactory(io.atlasmap.java.v2.AtlasJavaModelFactory) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collector(java.util.stream.Collector) AtlasConstants(io.atlasmap.api.AtlasConstants) Logger(org.slf4j.Logger) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) MockField(io.atlasmap.v2.MockField) DefaultAtlasFieldActionService(io.atlasmap.core.DefaultAtlasFieldActionService) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) AtlasMapping(io.atlasmap.v2.AtlasMapping) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JavaField(io.atlasmap.java.v2.JavaField) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.jupiter.api.Test)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)86 Mapping (io.atlasmap.v2.Mapping)50 Test (org.junit.jupiter.api.Test)45 BaseMapping (io.atlasmap.v2.BaseMapping)26 File (java.io.File)20 Mappings (io.atlasmap.v2.Mappings)16 Test (org.junit.Test)15 JavaField (io.atlasmap.java.v2.JavaField)14 AtlasContext (io.atlasmap.api.AtlasContext)12 AtlasSession (io.atlasmap.api.AtlasSession)12 DataSource (io.atlasmap.v2.DataSource)12 Validation (io.atlasmap.v2.Validation)11 Field (io.atlasmap.v2.Field)10 JsonField (io.atlasmap.json.v2.JsonField)7 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)7 DataSourceType (io.atlasmap.v2.DataSourceType)7 FieldType (io.atlasmap.v2.FieldType)7 MappingType (io.atlasmap.v2.MappingType)7 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)7 ValidationScope (io.atlasmap.v2.ValidationScope)7