Package org.geoserver.importer

Examples of org.geoserver.importer.ImportContext


        return map;
    }

    JSONObj doImport(ImportData data, WorkspaceInfo ws) throws Exception {
        // run the import
        ImportContext imp = importer.createContext(data, ws);
        importer.run(imp);

        for (ImportTask t : imp.getTasks()) {
            if (t.getState() == ImportTask.State.COMPLETE) {
                touch(t);
            }
        }
        return get(ws.getName(), imp.getId());
    }
View Full Code Here


        return get(ws.getName(), imp.getId());
    }

    @RequestMapping(value = "/{wsName}/{id}", method = RequestMethod.GET)
    public @ResponseBody JSONObj get(@PathVariable String wsName, @PathVariable Long id) throws Exception {
        ImportContext imp = findImport(id);

        JSONObj result = new JSONObj();
        result.put("id", imp.getId());

        JSONArr imported = result.putArray("imported");
        JSONArr pending = result.putArray("pending");
        JSONArr failed = result.putArray("failed");
        JSONArr ignored = result.putArray("ignored");

        for (ImportTask task : imp.getTasks()) {
            if (task.getState() == ImportTask.State.COMPLETE) {
                imported.add(complete(task));
            }
            else {
                switch(task.getState()) {
View Full Code Here

    @RequestMapping(value = "/{wsName}/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody JSONObj update(@PathVariable String wsName, @PathVariable Long id, @RequestBody JSONObj obj)
        throws Exception {

        ImportContext imp = findImport(id);

        Integer t = obj.integer("task");
        if (t == null) {
            throw new BadRequestException("Request must contain task identifier");
        }

        final ImportTask task = imp.task(t);
        if (task == null) {
            throw new NotFoundException("No such task: " + t + " for import: " + id);
        }

        ResourceInfo resource = task.getLayer().getResource();
View Full Code Here

            }
        }
    }

    ImportContext findImport(Long id) {
        ImportContext imp = importer.getContext(id);
        if (imp == null) {
            throw new NotFoundException("No such import: " + id);
        }
        return imp;
    }
View Full Code Here

public class ImporterMosaicTest extends ImporterTestSupport {

    @Test
    public void testSimpleMosaic() throws Exception {
        File dir = unpack("mosaic/bm.zip");
        ImportContext context = importer.createContext(new Mosaic(dir));
        assertEquals(1, context.getTasks().size());

        ImportTask task = context.getTasks().get(0);
        assertTrue(task.getData() instanceof Mosaic);
        assertTrue(task.getData().getFormat() instanceof MosaicFormat);

        importer.run(context);
View Full Code Here

        m.setTimeMode(TimeMode.FILENAME);
        FilenameTimeHandler th = (FilenameTimeHandler) m.getTimeHandler();
        th.setFilenameRegex("(\\d){6}");
        th.setTimeFormat("yyyyMM");

        ImportContext context = importer.createContext(m);
        assertEquals(1, context.getTasks().size());
       
        importer.run(context);

        LayerInfo l = context.getTasks().get(0).getLayer();
        ResourceInfo r = l.getResource();
        assertTrue(r.getMetadata().containsKey("time"));

        DimensionInfo d = (DimensionInfo) r.getMetadata().get("time");
        assertNotNull(d);
View Full Code Here

    @Test
    public void testTimeMosaicAuto() throws Exception {
        Mosaic m = new Mosaic(unpack("mosaic/bm_time.zip"));
        m.setTimeMode(TimeMode.AUTO);

        ImportContext context = importer.createContext(m);
        assertEquals(1, context.getTasks().size());

        importer.run(context);

        LayerInfo l = context.getTasks().get(0).getLayer();
        ResourceInfo r = l.getResource();
        assertTrue(r.getMetadata().containsKey("time"));

        DimensionInfo d = (DimensionInfo) r.getMetadata().get("time");
        assertNotNull(d);
View Full Code Here

                               }
                               else if (t.isCancelled()) {
                                   //do nothing
                               }
                               else {
                                   ImportContext imp = t.get();
                                  
                                   //check the import for actual things to do
                                   boolean proceed = !imp.getTasks().isEmpty();
                                 
                                   if (proceed) {
                                       imp.setArchive(false);
                                       importer.changed(imp);
          
                                       PageParameters pp = new PageParameters();
                                       pp.put("id", imp.getId());
          
                                       setResponsePage(ImportPage.class, pp);
                                   }
                                   else {
                                       info("No data to import was found");
View Full Code Here

        headerTable.setOutputMarkupId(true);
        headerTable.setFilterable(false);
        headerTable.setPageable(false);
        add(headerTable);
   
        final ImportContext imp = model.getObject();
        boolean selectable = imp.getState() != ImportContext.State.COMPLETE;
        final ImportTaskTable taskTable = new ImportTaskTable("tasks",
            new ImportTaskProvider(model), selectable) {
            @Override
            protected void onSelectionUpdate(AjaxRequestTarget target) {
                updateImportLink((AjaxLink) ImportPage.this.get("import"), this, target);
            }
        }.setFeedbackPanel(feedbackPanel);
        taskTable.setOutputMarkupId(true);
        taskTable.setFilterable(false);
        add(taskTable);
   
        final AjaxLink<Long> importLink = new AjaxLink<Long>("import",
                new Model<Long>()) {
            @Override
            protected void disableLink(ComponentTag tag) {
                super.disableLink(tag);
                ImporterWebUtils.disableLink(tag);
            }
   
            @Override
            public void onClick(AjaxRequestTarget target) {
                ImportContext imp = model.getObject();
   
                BasicImportFilter filter = new BasicImportFilter();
                for (ImportTask t : taskTable.getSelection()) {
                    filter.add(t);
                }

                //set running flag and update cancel link
                running.set(true);
                target.addComponent(cancelLink(this));

                final Long jobid = importer().runAsync(imp, filter);
                setDefaultModelObject(jobid);
   
                final AjaxLink self = this;
   
                // create a timer to update the table and reload the page when
                // necessary
                taskTable.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(500)) {
                    @Override
                    protected void onTimer(AjaxRequestTarget target) {
                        Task<ImportContext> job = importer().getTask(jobid);
                        if (job == null || job.isDone()) {
                            // remove the timer
                            stop();
   
                            self.setEnabled(true);
                            target.addComponent(self);
   
                            running.set(false);
                            target.addComponent(cancelLink(self));
                           
                            /*ImportContext imp = model.getObject();
                            if (imp.getState() == ImportContext.State.COMPLETE) {
                                // enable cancel, which will not be "done"
                                setLinkEnabled(cancelLink(self), true, target);
                            } else {
                                // disable cancel, import is not longer running, but
                                // also
                                // not complete
                                setLinkEnabled(cancelLink(self), false, target);
                            }*/
                        }
   
                        // update the table
                        target.addComponent(taskTable);
                        target.addComponent(headerTable);
                    }
                });
                target.addComponent(taskTable);
   
                // disable import button
                setLinkEnabled(this, false, target);
                // enable cancel button
                //setLinkEnabled(cancelLink(this), true, target);
            }
        };
        importLink.setOutputMarkupId(true);
        importLink.setEnabled(doSelectReady(imp, taskTable, null));
        add(importLink);
   
        final AjaxLink cancelLink = new AjaxLink("cancel") {
            @Override
            protected void disableLink(ComponentTag tag) {
                super.disableLink(tag);
                ImporterWebUtils.disableLink(tag);
            }
   
            @Override
            public void onClick(AjaxRequestTarget target) {
                ImportContext imp = model.getObject();
                if (!running.get()) {
                //if (imp.getState() == ImportContext.State.COMPLETE) {
                    setResponsePage(ImportDataPage.class);
                    return;
                }
   
                Long jobid = importLink.getModelObject();
                if (jobid == null) {
                    return;
                }
   
                Task<ImportContext> task = importer().getTask(jobid);
                if (task == null || task.isDone()) {
                    return;
                }
   
                task.getMonitor().setCanceled(true);
                task.cancel(false);
                try {
                    task.get();
                } catch (Exception e) {
                }
   
                // enable import button
                setLinkEnabled(importLink, true, target);
                // disable cancel button
                //setLinkEnabled(cancelLink(importLink), false, target);
            }
   
        };
        //cancelLink.setEnabled(imp.getState() == ImportContext.State.COMPLETE);
        cancelLink.add(new Label("text", new CancelTitleModel()));
        add(cancelLink);
       
        WebMarkupContainer selectPanel = new WebMarkupContainer("select");
        selectPanel.add(new AjaxLink<ImportContext>("select-all", model) {
            @Override
            public void onClick(AjaxRequestTarget target) {
                taskTable.selectAll();
                target.addComponent(taskTable);
                updateImportLink(importLink, taskTable, target);
            }
        });
        selectPanel.add(new AjaxLink<ImportContext>("select-none", model) {
            @Override
            public void onClick(AjaxRequestTarget target) {
                taskTable.clearSelection();
                target.addComponent(taskTable);
                updateImportLink(importLink, taskTable, target);
            }
        });
        selectPanel.add(new AjaxLink<ImportContext>("select-ready", model) {
            @Override
            public void onClick(AjaxRequestTarget target) {
                doSelectReady(getModelObject(), taskTable, target);
                target.addComponent(taskTable);
                updateImportLink(importLink, taskTable, target);
            }
        });
        add(selectPanel);

        add(new Icon("icon",new DataIconModel(imp.getData())));
        add(new Label("title", new DataTitleModel(imp))
          .add(new AttributeModifier("title", new DataTitleModel(imp, false))));
       
        add(dialog = new GeoServerDialog("dialog"));
    }
View Full Code Here

            this.abbrev = abbrev;
        }

        @Override
        protected String load() {
            ImportContext ctx = importer().getContext(contextId);
            ImportData data = ctx.getData();
            String title =  data != null ? data.toString() : ctx.toString();

            if (abbrev && title.length() > 70) {
                //shorten it
                title = title.substring(0,20) + "[...]" + title.substring(title.length()-50);
            }
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.