Search in sources :

Example 21 with Json

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

the class AtlasMapperGenerator method createDataSource.

/**
 * Used to generate data source elements for atlasMapping. There are three types of them: Java, Json, XML.
 *
 * @param dataShape datashape of the processed step
 * @param step step definition
 * @param dataSourceType datasource type
 * @return datasource
 */
private DataSource createDataSource(DataShape dataShape, StepDefinition step, DataSourceType dataSourceType) {
    DataShapeKinds dataShapeKind = dataShape.getKind();
    DataSource source = null;
    if (dataShapeKind.toString().contains("json")) {
        source = new JsonDataSource();
        source.setUri("atlas:" + "json:" + step.getStep().getId().get());
    } else if (dataShapeKind.toString().contains("java")) {
        source = new DataSource();
        source.setUri("atlas:" + "java:" + step.getStep().getId().get() + "?className=" + dataShape.getType());
    } else if (dataShapeKind.toString().contains("xml")) {
        source = new XmlDataSource();
        source.setUri("atlas:xml:" + step.getStep().getId().get());
        XmlNamespaces xmlNamespaces = new XmlNamespaces();
        // Init the array, so that we don't have the null value
        xmlNamespaces.getXmlNamespace();
        ((XmlDataSource) source).setXmlNamespaces(xmlNamespaces);
    } else {
        fail("Unknown datashape kind " + dataShapeKind.toString());
    }
    source.setId(step.getStep().getId().get());
    source.setDataSourceType(dataSourceType);
    return source;
}
Also used : JsonDataSource(io.atlasmap.json.v2.JsonDataSource) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 22 with Json

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

the class JavaToXMLJSONMarshallingTest method testCombineMappingDemarshaller.

@Test
public void testCombineMappingDemarshaller() throws Exception {
    // this test is for AT-466: issue saving mappings in combine mode (parser
    // complaining about strategy property)
    // the json has been changed from what the UI was sending, now the "actions"
    // property on the output field is "null" rather than "[]"
    String filename = "src/test/resources/javaToXml/javaToXmlMapping-combine.json";
    AtlasMapping uMapping = mapper.readValue(new File(filename), AtlasMapping.class);
    assertNotNull(uMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 23 with Json

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

the class AtlasServiceTest method testADMUpload.

@Test
public void testADMUpload() throws Exception {
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("json-schema-source-to-xml-schema-target.adm");
    Response res = service.createMappingRequest(in, MappingFileType.ZIP, 0, generateTestUriInfo("http://localhost:8686/v2/atlas", "http://localhost:8686/v2/atlas/mapping/ZIP/0"));
    assertEquals(200, res.getStatus());
    res = service.getMappingRequest(MappingFileType.JSON, 0);
    assertEquals(200, res.getStatus());
    AtlasMapping mappings = mapper.readValue((byte[]) res.getEntity(), AtlasMapping.class);
    assertEquals(4, mappings.getMappings().getMapping().size());
}
Also used : ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Response(javax.ws.rs.core.Response) AtlasMapping(io.atlasmap.v2.AtlasMapping) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Test(org.junit.jupiter.api.Test)

Example 24 with Json

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

the class AtlasServiceTest method testProcessMapping3064.

@Test
public void testProcessMapping3064() throws Exception {
    Response res = service.processMappingRequest(this.getClass().getClassLoader().getResourceAsStream("mappings/process-mapping-request-3064.json"), generateTestUriInfo("http://localhost:8686/v2/atlas", "http://localhost:8686/v2/atlas/mapping/process"));
    ProcessMappingResponse resp = Json.mapper().readValue((byte[]) res.getEntity(), ProcessMappingResponse.class);
    assertEquals(0, resp.getAudits().getAudit().size(), printAudit(resp.getAudits()));
    Field field = resp.getMapping().getInputField().get(0);
    assertEquals("/primitives/stringPrimitive", field.getPath());
}
Also used : ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Response(javax.ws.rs.core.Response) Field(io.atlasmap.v2.Field) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Test(org.junit.jupiter.api.Test)

Example 25 with Json

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

the class AtlasService method listFieldActions.

/**
 * Retrieves a list of available field action.
 * @param uriInfo URI info
 * @return {@link ActionDetails} serialized to JSON
 */
@GET
@Path("/fieldActions")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List FieldActions", description = "Retrieves a list of available field action")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ActionDetails.class)), description = "Return a list of field action detail"))
public Response listFieldActions(@Context UriInfo uriInfo) {
    ActionDetails details = new ActionDetails();
    if (atlasContextFactory == null || atlasContextFactory.getFieldActionService() == null) {
        return Response.ok().entity(toJson(details)).build();
    }
    details.getActionDetail().addAll(atlasContextFactory.getFieldActionService().listActionDetails());
    byte[] serialized = toJson(details);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : ActionDetails(io.atlasmap.v2.ActionDetails) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Test (org.junit.jupiter.api.Test)15 Field (io.atlasmap.v2.Field)12 AtlasMapping (io.atlasmap.v2.AtlasMapping)11 JsonField (io.atlasmap.json.v2.JsonField)7 File (java.io.File)7 FieldGroup (io.atlasmap.v2.FieldGroup)6 AtlasException (io.atlasmap.api.AtlasException)5 AtlasValidationException (io.atlasmap.api.AtlasValidationException)4 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)4 Response (javax.ws.rs.core.Response)4 AtlasPath (io.atlasmap.core.AtlasPath)3 JavaField (io.atlasmap.java.v2.JavaField)3 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)3 DataSource (io.atlasmap.v2.DataSource)3 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)2 JsonDocument (io.atlasmap.json.v2.JsonDocument)2