Search in sources :

Example 1 with StringMapEntry

use of io.atlasmap.v2.StringMapEntry 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 2 with StringMapEntry

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

the class AtlasServiceTest method testListMappings.

@Test
public void testListMappings() throws Exception {
    Response resp = service.listMappings(generateTestUriInfo("http://localhost:8686/v2/atlas", "http://localhost:8686/v2/atlas/mappings"), null);
    StringMap sMap = Json.mapper().readValue((byte[]) resp.getEntity(), StringMap.class);
    System.out.println("Found " + sMap.getStringMapEntry().size() + " objects");
    for (StringMapEntry s : sMap.getStringMapEntry()) {
        System.out.println("\t n: " + s.getName() + " v: " + s.getValue());
    }
}
Also used : Response(javax.ws.rs.core.Response) StringMap(io.atlasmap.v2.StringMap) StringMapEntry(io.atlasmap.v2.StringMapEntry) Test(org.junit.Test)

Aggregations

StringMap (io.atlasmap.v2.StringMap)2 StringMapEntry (io.atlasmap.v2.StringMapEntry)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 ApplicationPath (javax.ws.rs.ApplicationPath)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 JAXBException (javax.xml.bind.JAXBException)1 Test (org.junit.Test)1