Package org.geoserver.importer

Examples of org.geoserver.importer.ImportContext


        assertEquals(201, resp.getStatusCode());
        assertNotNull(resp.getHeader("Location"));

        String[] split = resp.getHeader("Location").split("/");
        Integer id = Integer.parseInt(split[split.length-1]);
        ImportContext context = importer.getContext(id);

        MockHttpServletRequest req = createRequest("/rest/imports/" + id + "/tasks/" + file.getName());
        req.setContentType("application/zip");
        req.addHeader("Content-Type","application/zip");
        req.setMethod("PUT");
        req.setBodyContent(org.apache.commons.io.IOUtils.toByteArray(stream));
        resp = dispatch(req);
       
        assertEquals(201, resp.getStatusCode());
       
        context = importer.getContext(context.getId());
        assertNull(context.getData());
        assertEquals(1, context.getTasks().size());

        ImportTask task = context.getTasks().get(0);
        assertTrue(task.getData() instanceof SpatialFile);
       
        return id;
    }
View Full Code Here


        assertEquals(201, resp.getStatusCode());
        assertNotNull(resp.getHeader("Location"));

        String[] split = resp.getHeader("Location").split("/");
        Integer id = Integer.parseInt(split[split.length-1]);
        ImportContext context = importer.getContext(id);
       
        MockHttpServletRequest req = createRequest("/rest/imports/" + id + "/tasks/");
        Form form = new Form();
        form.add("url", new File(zip).getAbsoluteFile().toURI().toString());
        req.setBodyContent(form.encode());
        req.setMethod("POST");
        req.setContentType(MediaType.APPLICATION_WWW_FORM.toString());
        req.setHeader("Content-Type", MediaType.APPLICATION_WWW_FORM.toString());
        resp = dispatch(req);
       
        assertEquals(201, resp.getStatusCode());
       
        context = importer.getContext(context.getId());
        assertNull(context.getData());
        assertEquals(1, context.getTasks().size());

        ImportTask task = context.getTasks().get(0);
        assertTrue(task.getData() instanceof SpatialFile);
       
        return id;
    }
View Full Code Here

        assertNotNull(resp.getHeader("Location"));

        String[] split = resp.getHeader("Location").split("/");
        Integer id = Integer.parseInt(split[split.length-1]);
       
        ImportContext context = importer.getContext(id);

        File dir = unpack("shape/archsites_epsg_prj.zip");
        unpack("shape/bugsites_esri_prj.tar.gz", dir);
       
        new File(dir, "extra.file").createNewFile();
        File[] files = dir.listFiles();
        Part[] parts = new Part[files.length];
        for (int i = 0; i < files.length; i++) {
            parts[i] = new FilePart(files[i].getName(), files[i]);
        }

        MultipartRequestEntity multipart =
            new MultipartRequestEntity(parts, new PostMethod().getParams());

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        multipart.writeRequest(bout);

        MockHttpServletRequest req = createRequest("/rest/imports/" + id + "/tasks");
        req.setContentType(multipart.getContentType());
        req.addHeader("Content-Type", multipart.getContentType());
        req.setMethod("POST");
        req.setBodyContent(bout.toByteArray());
        resp = dispatch(req);

        context = importer.getContext(context.getId());
        assertEquals(2, context.getTasks().size());

        req = createRequest("/rest/imports/" + id + "/tasks/1");
        req.setMethod("DELETE");
        resp = dispatch(req);
        assertEquals(204, resp.getStatusCode());

        context = importer.getContext(context.getId());
        assertEquals(1, context.getTasks().size());
    }
View Full Code Here

        assertEquals(201, resp.getStatusCode());
        assertNotNull(resp.getHeader("Location"));

        String[] split = resp.getHeader("Location").split("/");
        Integer id = Integer.parseInt(split[split.length-1]);
        ImportContext context = importer.getContext(id);
        assertNull(context.getData());
        assertTrue(context.getTasks().isEmpty());

        File dir = unpack("shape/archsites_epsg_prj.zip");
       
        Part[] parts = new Part[]{new FilePart("archsites.shp", new File(dir, "archsites.shp")),
            new FilePart("archsites.dbf", new File(dir, "archsites.dbf")),
            new FilePart("archsites.shx", new File(dir, "archsites.shx")),
            new FilePart("archsites.prj", new File(dir, "archsites.prj"))};

        MultipartRequestEntity multipart =
            new MultipartRequestEntity(parts, new PostMethod().getParams());

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        multipart.writeRequest(bout);

        MockHttpServletRequest req = createRequest("/rest/imports/" + id + "/tasks");
        req.setContentType(multipart.getContentType());
        req.addHeader("Content-Type", multipart.getContentType());
        req.setMethod("POST");
        req.setBodyContent(bout.toByteArray());
        resp = dispatch(req);

        context = importer.getContext(context.getId());
        assertNull(context.getData());
        assertEquals(1, context.getTasks().size());

        ImportTask task = context.getTasks().get(0);
        assertTrue(task.getData() instanceof SpatialFile);
        assertEquals(ImportTask.State.READY, task.getState());
    }
View Full Code Here

        assertEquals(201, resp.getStatusCode());
        assertNotNull(resp.getHeader("Location"));

        String[] split = resp.getHeader("Location").split("/");
        Integer id = Integer.parseInt(split[split.length-1]);
        ImportContext context = importer.getContext(id);

        MockHttpServletRequest req = createRequest("/rest/imports/" + id + "/tasks/" + taskName);
        req.setContentType(contentType);
        req.addHeader("Content-Type", contentType);
        req.setMethod("PUT");
        req.setBodyContent(org.apache.commons.io.IOUtils.toByteArray(geotiffResourceStream));
        resp = dispatch(req);

        assertEquals(201, resp.getStatusCode());

        context = importer.getContext(context.getId());
        assertNull(context.getData());
        assertEquals(1, context.getTasks().size());

        ImportTask task = context.getTasks().get(0);
        assertEquals(ImportTask.State.READY, task.getState());

        ImportData importData = task.getData();
        assertTrue(importData instanceof SpatialFile);
View Full Code Here

    @Test
    public void testUpdateMode() throws Exception {
        createH2DataStore(getCatalog().getDefaultWorkspace().getName(), "foo");

        ImportContext session = importer.getContext(0);
        assertEquals(UpdateMode.CREATE, session.getTasks().get(0).getUpdateMode());

        // change to append mode
        String update = "{\"task\": { \"updateMode\" : \"APPEND\" }}";
        put("/rest/imports/0/tasks/0", update, MediaType.APPLICATION_JSON.toString());
        session = importer.getContext(0);
        assertEquals(UpdateMode.APPEND, session.getTasks().get(0).getUpdateMode());

        // put a dumby and verify the modified updateMode remains
        update = "{\"task\": {}}";
        put("/rest/imports/0/tasks/0", update, MediaType.APPLICATION_JSON.toString());
        session = importer.getContext(0);
        assertEquals(UpdateMode.APPEND, session.getTasks().get(0).getUpdateMode());
    }
View Full Code Here

        resp = setSRSRequest("/rest/imports/1/tasks/0","EPSG:9838275");
        verifyInvalidCRSErrorResponse(resp);
       
        setSRSRequest("/rest/imports/1/tasks/0","EPSG:26713");
       
        ImportContext context = importer.getContext(1);
        ReferencedEnvelope latLonBoundingBox =
            context.getTasks().get(0).getLayer().getResource().getLatLonBoundingBox();
        assertFalse("expected not empty bbox",latLonBoundingBox.isEmpty());

        json = (JSONObject) getAsJSON("/rest/imports/1/tasks/0?expand=2");
        task = json.getJSONObject("task");
        assertEquals("READY", task.get("state"));
       
        assertEquals("EPSG:26713",
            task.getJSONObject("layer").getString("srs"));
        State state = context.getState();
        assertEquals("Invalid context state", State.PENDING, state);
    }
View Full Code Here

        }

    };

    Directory lookupDirectory() {
        ImportContext context = context();
        if (!(context.getData() instanceof Directory)) {
            throw new RestletException("Data is not a directory", Status.CLIENT_ERROR_BAD_REQUEST);   
        }

        return (Directory) context.getData();
    }
View Full Code Here

    @Override
    public boolean allowDelete() {
        boolean allowDelete = false;
        importContext = lookupContext(true, false);
        if (importContext instanceof ImportContext) {
            ImportContext ctx = (ImportContext) importContext;
            allowDelete = ctx.getState() != ImportContext.State.COMPLETE;
        } else {
            allowDelete = true;
        }
        return allowDelete;
    }
View Full Code Here

            contexts = Collections.singletonList((ImportContext) importContext).iterator();
        } else {
            contexts = (Iterator<ImportContext>) importContext;
        }
        while (contexts.hasNext()) {
            ImportContext ctx = contexts.next();
            if (ctx.getState() != ImportContext.State.COMPLETE) {
                try {
                    importer.delete(ctx);
                } catch (IOException ioe) {
                    throw new RestletException("Error deleting context " + ctx.getId(), Status.SERVER_ERROR_INTERNAL, ioe);
                }
            }
        }
        getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
    }
View Full Code Here

TOP

Related Classes of org.geoserver.importer.ImportContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.