Search in sources :

Example 1 with AtlasMapping

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

the class UiComplexSteps method processMapperSteps.

private void processMapperSteps() {
    List<StepDefinition> mappers = steps.getStepDefinitions().stream().filter(s -> s.getStep().getStepKind().equals(StepKind.mapper)).collect(Collectors.toList());
    if (mappers.isEmpty()) {
        log.debug("There are no mappers in this integration, proceeding...");
    } else {
        // mapping can be done on steps that preceed mapper step and the single step, which follows the mapper step.
        log.info("Found mapper step, creating new atlas mapping.");
        for (int i = 0; i < mappers.size(); i++) {
            List<StepDefinition> precedingSteps = steps.getStepDefinitions().subList(0, steps.getStepDefinitions().indexOf(mappers.get(i))).stream().filter(s -> s.getConnectorDescriptor().isPresent()).collect(Collectors.toList());
            StepDefinition followingStep = steps.getStepDefinitions().get(steps.getStepDefinitions().indexOf(mappers.get(i)) + 1);
            if (mappers.get(i).getStep().getConfiguredProperties().containsKey("atlasmapping")) {
                // TODO(tplevko): think of some way to substitute placeholders for the step ID's
                reflectStepIdsInAtlasMapping(mappers.get(i), precedingSteps, followingStep);
            } else {
                // TODO(tplevko): fix for more than one preceding step.
                mappers.get(i).setStep(atlasGenerator.getAtlasMappingStep(mappers.get(i), precedingSteps, followingStep));
            }
        }
    }
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Arrays(java.util.Arrays) Action(io.syndesis.common.model.action.Action) Step(io.syndesis.common.model.integration.Step) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingType(io.atlasmap.v2.MappingType) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Given(cucumber.api.java.en.Given) Assertions(org.assertj.core.api.Assertions) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) Connector(io.syndesis.common.model.connection.Connector) AtlasMapperGenerator(io.syndesis.qe.bdd.datamapper.AtlasMapperGenerator) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IntegrationOverview(io.syndesis.qe.model.IntegrationOverview) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) TestUtils(io.syndesis.qe.utils.TestUtils) DataMapperDefinition(io.syndesis.qe.bdd.entities.DataMapperDefinition) StepsStorage(io.syndesis.qe.bdd.storage.StepsStorage) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint)

Example 2 with AtlasMapping

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

the class AtlasMapperGenerator method getAtlasMappingStep.

public Step getAtlasMappingStep(StepDefinition mapping, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
    processPrecedingSteps(precedingSteps);
    processFolowingStep(followingStep);
    List<DataMapperStepDefinition> mappings = mapping.getDataMapperDefinition().get().getDataMapperStepDefinition();
    AtlasMapping atlasMapping = new AtlasMapping();
    atlasMapping.setMappings(new Mappings());
    for (DataSource s : processSources(precedingSteps)) {
        atlasMapping.getDataSource().add(s);
    }
    atlasMapping.setName("REST." + UUID.randomUUID().toString());
    atlasMapping.setLookupTables(new LookupTables());
    atlasMapping.setProperties(new Properties());
    atlasMapping.getDataSource().add(processTarget(followingStep));
    atlasMapping.getMappings().getMapping().addAll(generateBaseMappings(mappings, precedingSteps, followingStep));
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
    String mapperString = null;
    try {
        mapperString = mapper.writeValueAsString(atlasMapping);
        log.debug(mapperString);
    } catch (JsonProcessingException e) {
        log.error("error: {}" + e);
    }
    final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getConnectorDescriptor().get())).id(UUID.randomUUID().toString()).build();
    return mapperStep;
}
Also used : DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTables(io.atlasmap.v2.LookupTables) Step(io.syndesis.common.model.integration.Step) Properties(io.atlasmap.v2.Properties) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 3 with AtlasMapping

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

the class AtlasMapXmlToJson method testConvertXmlToJson.

@Test
public void testConvertXmlToJson() throws Exception {
    String sourceXmlPath = "src/test/resources/atlasmapping.xml";
    String destJsonPath = "src/test/resources/atlasmapping.json";
    AtlasMappingService atlasMappingService = DefaultAtlasContextFactory.getInstance().getMappingService();
    AtlasMapping mappingFromXml = atlasMappingService.loadMapping(sourceXmlPath, AtlasMappingFormat.XML);
    atlasMappingService.saveMappingAsFile(mappingFromXml, new File(destJsonPath), AtlasMappingFormat.JSON);
    AtlasMapping mappingFromJson = atlasMappingService.loadMapping(destJsonPath, AtlasMappingFormat.JSON);
    assertEquals(mappingFromXml.getName(), mappingFromJson.getName());
    assertEquals(mappingFromXml.getDataSource().size(), mappingFromJson.getDataSource().size());
    assertEquals(mappingFromXml.getMappings().getMapping().size(), mappingFromJson.getMappings().getMapping().size());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasMappingService(io.atlasmap.core.AtlasMappingService) File(java.io.File) Test(org.junit.Test)

Example 4 with AtlasMapping

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

the class AtlasService method listMappings.

@GET
@Path("/mappings")
@Produces(MediaType.APPLICATION_JSON)
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter) {
    StringMap sMap = new StringMap();
    java.nio.file.Path mappingFolder = Paths.get(baseFolder);
    File[] mappings = mappingFolder.toFile().listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            if (filter != null && name != null && !name.toLowerCase().contains(filter.toLowerCase())) {
                return false;
            }
            return (name != null ? name.matches("atlasmapping-[a-zA-Z0-9\\.\\-]+.xml") : false);
        }
    });
    if (mappings == null) {
        return Response.ok().entity(toJson(sMap)).build();
    }
    try {
        for (File mapping : mappings) {
            AtlasMapping map = getMappingFromFile(mapping.getAbsolutePath());
            StringMapEntry mapEntry = new StringMapEntry();
            mapEntry.setName(map.getName());
            UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
            mapEntry.setValue(builder.build().toString());
            sMap.getStringMapEntry().add(mapEntry);
        }
    } catch (JAXBException e) {
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
    return Response.ok().entity(toJson(sMap)).build();
}
Also used : StringMap(io.atlasmap.v2.StringMap) WebApplicationException(javax.ws.rs.WebApplicationException) JAXBException(javax.xml.bind.JAXBException) FilenameFilter(java.io.FilenameFilter) AtlasMapping(io.atlasmap.v2.AtlasMapping) StringMapEntry(io.atlasmap.v2.StringMapEntry) UriBuilder(javax.ws.rs.core.UriBuilder) File(java.io.File) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with AtlasMapping

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

the class AtlasService method getMappingFromFile.

public AtlasMapping getMappingFromFile(String fileName) throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance("io.atlasmap.v2:io.atlasmap.java.v2:io.atlasmap.xml.v2:io.atlasmap.json.v2");
    Marshaller marshaller = null;
    Unmarshaller unmarshaller = null;
    marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    unmarshaller = jaxbContext.createUnmarshaller();
    StreamSource fileSource = new StreamSource(new File(fileName));
    JAXBElement<AtlasMapping> mappingElem = unmarshaller.unmarshal(fileSource, AtlasMapping.class);
    if (mappingElem != null) {
        return mappingElem.getValue();
    }
    return null;
}
Also used : Marshaller(javax.xml.bind.Marshaller) AtlasMapping(io.atlasmap.v2.AtlasMapping) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)168 Mapping (io.atlasmap.v2.Mapping)79 Test (org.junit.jupiter.api.Test)77 File (java.io.File)43 Test (org.junit.Test)31 DataSource (io.atlasmap.v2.DataSource)28 BaseMapping (io.atlasmap.v2.BaseMapping)24 Validation (io.atlasmap.v2.Validation)23 AtlasContext (io.atlasmap.api.AtlasContext)21 AtlasSession (io.atlasmap.api.AtlasSession)21 JavaField (io.atlasmap.java.v2.JavaField)18 Mappings (io.atlasmap.v2.Mappings)15 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)11 JsonField (io.atlasmap.json.v2.JsonField)11 MockField (io.atlasmap.v2.MockField)11 Field (io.atlasmap.v2.Field)10 Action (io.atlasmap.v2.Action)9 MappingType (io.atlasmap.v2.MappingType)9 DataSourceType (io.atlasmap.v2.DataSourceType)8 LookupTable (io.atlasmap.v2.LookupTable)8