use of io.atlasmap.core.ADMArchiveHandler in project atlasmap by atlasmap.
the class NestedCollectionJavaTest method processNestedJavaCollection.
private TargetClass processNestedJavaCollection(List<String> mappingsToProcess) throws AtlasException {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mappings/atlasmapping-nested-collection-java.json");
ADMArchiveHandler admHandler = new ADMArchiveHandler(Thread.currentThread().getContextClassLoader());
admHandler.load(AtlasContextFactory.Format.JSON, in);
AtlasMapping mapping = admHandler.getMappingDefinition();
mapping.getMappings().getMapping().removeIf(m -> !mappingsToProcess.contains(((Mapping) m).getId()));
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
AtlasSession session = context.createSession();
SourceClass sc = newSourceClass();
session.setSourceDocument("io.atlasmap.itests.core.SourceClass", sc);
context.process(session);
assertFalse(session.hasErrors(), TestHelper.printAudit(session));
return (TargetClass) session.getTargetDocument("io.atlasmap.itests.core.TargetClass");
}
use of io.atlasmap.core.ADMArchiveHandler in project atlasmap by atlasmap.
the class NestedCollectionJsonTest method processJsonNestedCollection.
private JsonNode processJsonNestedCollection(List<String> mappingsToProcess, boolean assertNoWarnings) throws AtlasException, IOException, URISyntaxException {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mappings/atlasmapping-nested-collection-json.json");
ADMArchiveHandler admHandler = new ADMArchiveHandler(Thread.currentThread().getContextClassLoader());
admHandler.load(AtlasContextFactory.Format.JSON, in);
AtlasMapping mapping = admHandler.getMappingDefinition();
mapping.getMappings().getMapping().removeIf(m -> !mappingsToProcess.contains(((Mapping) m).getId()));
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
AtlasSession session = context.createSession();
String source = new String(Files.readAllBytes(Paths.get(Thread.currentThread().getContextClassLoader().getResource("mappings/document-nested-collection.json").toURI())));
session.setSourceDocument("JSONInstanceNestedCollection", source);
context.process(session);
assertFalse(session.hasErrors(), TestHelper.printAudit(session));
if (assertNoWarnings) {
assertFalse(session.hasWarns(), TestHelper.printAudit(session));
}
Object output = session.getTargetDocument("JSONInstanceNestedCollection");
return mapper.readTree((String) output);
}
use of io.atlasmap.core.ADMArchiveHandler in project atlasmap by atlasmap.
the class CsvMappingTest method createContext.
public AtlasContext createContext(String file, String... mappingIds) throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
ADMArchiveHandler admHandler = new ADMArchiveHandler(Thread.currentThread().getContextClassLoader());
admHandler.load(AtlasContextFactory.Format.JSON, in);
AtlasMapping mapping = admHandler.getMappingDefinition();
List<String> ids = Arrays.asList(mappingIds);
mapping.getMappings().getMapping().removeIf(m -> {
if (m instanceof Mapping) {
return !ids.contains(((Mapping) m).getId());
} else if (m instanceof Collection) {
Collection col = (Collection) m;
col.getMappings().getMapping().removeIf(map -> !ids.contains(((Mapping) map).getId()));
return col.getMappings().getMapping().isEmpty();
} else {
return false;
}
});
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
return context;
}
use of io.atlasmap.core.ADMArchiveHandler in project atlasmap by atlasmap.
the class E2ETest method test.
@Test
public void test() throws Exception {
driver.get("http://127.0.0.1:" + port);
WebDriverWait waitForLoad = new WebDriverWait(driver, Duration.ofSeconds(30));
waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//article[@aria-label='Properties']")));
WebElement atlasmapMenuBtn = driver.findElement(By.xpath("//button[@data-testid='atlasmap-menu-button']"));
atlasmapMenuBtn.click();
waitForLoad.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@data-testid='import-mappings-button']")));
WebElement importBtn = driver.findElement(By.xpath("//a[@data-testid='import-mappings-button']"));
importBtn.click();
WebElement fileInput = driver.findElement(By.xpath("//div[@id='data-toolbar']//input[@type='file']"));
String cwd = System.getProperty("user.dir");
fileInput.sendKeys(cwd + "/src/test/resources/json-schema-source-to-xml-schema-target.adm");
WebElement confirmBtn = driver.findElement(By.xpath("//button[@data-testid='confirmation-dialog-confirm-button']"));
confirmBtn.click();
waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//article[@aria-label='JSONSchemaSource']")));
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
// Check custom action param
WebElement orderBtn = driver.findElement(By.xpath("//button[@id='sources-field-atlas:json:JSONSchemaSource:source:/order-toggle']"));
orderBtn.click();
By addressToggle = By.xpath("//button[@id='sources-field-atlas:json:JSONSchemaSource:source:/order/address-toggle']");
waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(addressToggle));
WebElement addrBtn = driver.findElement(addressToggle);
addrBtn.click();
By addrDivPath = By.xpath("//button[@id='sources-field-atlas:json:JSONSchemaSource:source:/order/address-toggle']/../..");
waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(addrDivPath));
WebElement addrDiv = driver.findElement(addrDivPath);
By cityDivPath = By.xpath(".//button[@data-testid='grip-city-button']/../../../..");
waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(cityDivPath));
WebElement cityDiv = addrDiv.findElement(cityDivPath);
Actions action = new Actions(driver);
action.moveToElement(cityDiv).perform();
waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@data-testid='show-mapping-details-button']")));
WebElement showDetailsBtn = cityDiv.findElement(By.xpath(".//button[@data-testid='show-mapping-details-button']"));
showDetailsBtn.click();
WebElement detailsCity = waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@role='dialog']//div[@aria-labelledby='mapping-field-city']")));
assertNotNull(detailsCity);
WebElement customActionParamInput = driver.findElement(By.id("user-field-action-io.atlasmap.service.my.MyFieldActionsModel-transformation-0"));
assertEquals("testparam", customActionParamInput.getAttribute("value"));
// Check custom source class mapping
WebElement customClassDoc = driver.findElement(By.xpath("//article[@aria-label='MyFieldActionsModel']"));
WebElement paramDiv = customClassDoc.findElement(By.xpath(".//button[@data-testid='grip-param-button']/../../../.."));
action = new Actions(driver);
action.moveToElement(paramDiv).perform();
waitForLoad.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@data-testid='show-mapping-details-button']")));
showDetailsBtn = paramDiv.findElement(By.xpath(".//button[@data-testid='show-mapping-details-button']"));
showDetailsBtn.click();
WebElement detailsPhotoUrl = waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@data-testid='column-mapping-details-area']" + "//div[@data-testid='mapping-field-photoUrl']")));
assertNotNull(detailsPhotoUrl);
atlasmapMenuBtn = driver.findElement(By.xpath("//button[@data-testid='atlasmap-menu-button']"));
atlasmapMenuBtn.click();
waitForLoad.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@data-testid='export-mappings-button']")));
WebElement exportBtn = driver.findElement(By.xpath("//a[@data-testid='export-mappings-button']"));
exportBtn.click();
WebElement dialogDiv = driver.findElement(By.xpath("//div[@data-testid='export-catalog-dialog']/.."));
WebElement exportInput = dialogDiv.findElement(By.id("filename"));
String exportAdmFileName = UUID.randomUUID().toString() + "-exported.adm";
exportInput.clear();
exportInput.sendKeys(exportAdmFileName);
confirmBtn = dialogDiv.findElement(By.xpath(".//button[@data-testid='confirmation-dialog-confirm-button']"));
WatchService watcher = FileSystems.getDefault().newWatchService();
Executors.newSingleThreadExecutor().execute(() -> {
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 300000) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
try {
watcher.close();
} catch (Exception e) {
fail("Failed to close file watcher");
}
});
Path dirPath = Paths.get(DLDIR);
dirPath.register(watcher, StandardWatchEventKinds.ENTRY_CREATE);
confirmBtn.click();
WatchKey key = watcher.take();
while (key.isValid()) {
List<WatchEvent<?>> events = key.pollEvents();
if (events.isEmpty()) {
Thread.sleep(1000);
continue;
}
for (WatchEvent<?> event : events) {
if (!StandardWatchEventKinds.ENTRY_CREATE.name().equals(event.kind().name())) {
continue;
}
;
Path eventPath = (Path) event.context();
LOG.info("File '{}' is created", eventPath.getFileName().toString());
if (!exportAdmFileName.equals(eventPath.getFileName().toString())) {
continue;
}
ADMArchiveHandler handler = new ADMArchiveHandler(getClass().getClassLoader());
handler.setLibraryDirectory(Paths.get(DLDIR + File.separator + "lib"));
handler.load(Paths.get(DLDIR + File.separator + exportAdmFileName));
assertEquals("UI.0", handler.getMappingDefinition().getName());
DataSourceMetadata sourceMeta = handler.getDataSourceMetadata(true, "JSONSchemaSource");
assertEquals(true, sourceMeta.getIsSource());
assertEquals("JSONSchemaSource", sourceMeta.getName());
assertEquals("JSON", sourceMeta.getDataSourceType());
DataSourceMetadata targetMeta = handler.getDataSourceMetadata(false, "XMLSchemaSource");
assertEquals(false, targetMeta.getIsSource());
assertEquals("XMLSchemaSource", targetMeta.getName());
assertEquals("XML", targetMeta.getDataSourceType());
return;
}
;
}
fail("exported.adm was not created");
}
use of io.atlasmap.core.ADMArchiveHandler in project atlasmap by atlasmap.
the class AtlasService method getMappingRequest.
/**
* Retrieve a mapping file saved on the server.
* @param mappingFormat file type
* @param mappingDefinitionId mapping definition ID
* @return file
*/
@GET
@Path("/mapping/{mappingFormat}/{mappingDefinitionId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
@Operation(summary = "Get Mapping", description = "Retrieve a mapping file saved on the server")
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AtlasMapping.class)), description = "Return a mapping file content"), @ApiResponse(responseCode = "204", description = "Mapping file was not found"), @ApiResponse(responseCode = "500", description = "Mapping file access error") })
public Response getMappingRequest(@Parameter(description = "Mapping Format") @PathParam("mappingFormat") MappingFileType mappingFormat, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
LOG.debug("getMappingRequest: {} '{}'", mappingFormat, mappingDefinitionId);
ADMArchiveHandler admHandler = loadExplodedMappingDirectory(mappingDefinitionId);
switch(mappingFormat) {
case JSON:
byte[] serialized = null;
try {
serialized = admHandler.getMappingDefinitionBytes();
} catch (Exception e) {
LOG.error("Error retrieving mapping definition file for ID:" + mappingDefinitionId, e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
if (LOG.isDebugEnabled() && serialized != null) {
LOG.debug(new String(serialized));
}
if (serialized == null) {
LOG.debug("Mapping definition not found for ID:{}", mappingDefinitionId);
return Response.noContent().build();
}
return Response.ok().entity(serialized).build();
case GZ:
try {
if (admHandler.getGzippedADMDigestBytes() == null) {
LOG.debug("ADM Digest file not found for ID:{}", mappingDefinitionId);
return Response.noContent().build();
}
return Response.ok().entity(admHandler.getGzippedADMDigestBytes()).build();
} catch (Exception e) {
LOG.error("Error getting compressed ADM digest file.\n" + e.getMessage(), e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
case ZIP:
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
admHandler.setIgnoreLibrary(false);
admHandler.setLibraryDirectory(Paths.get(this.libFolder));
admHandler.export(out);
return Response.ok().entity(out.toByteArray()).build();
} catch (Exception e) {
LOG.error("Error getting ADM archive file.\n" + e.getMessage(), e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
default:
throw new WebApplicationException("Unrecognized mapping format: " + mappingFormat, Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations