Package com.boundlessgeo.geoserver.json

Examples of com.boundlessgeo.geoserver.json.JSONObj


    public static JSONObj param(JSONObj json, Parameter<?> p) {
        if (p != null) {
            String title = p.getTitle() != null ? p.getTitle().toString() : WordUtils.capitalize(p.getName());
            String description = p.getDescription() != null ? p.getDescription().toString() : null;

            JSONObj def = json.putObject(p.getName());
            def.put("title", title)
                .put("description",  description)
                .put("type", p.getType().getSimpleName())
                .put("default", safeValue(p.getDefaultValue()))
                .put("level", p.getLevel())
                .put("required", p.isRequired());
           
            if( !(p.getMinOccurs() == 1 && p.getMaxOccurs() == 1)){
                def.putArray("occurs")
                    .add( p.getMinOccurs())
                    .add(p.getMaxOccurs());
            }

           
            if (p.metadata != null) {
                for (String key : p.metadata.keySet()) {
                    if (Parameter.LEVEL.equals(key)) {
                        continue;
                    }
                    def.put(key, p.metadata.get(key));
                }
            }
        }
        return json;
    }
View Full Code Here


    JSONArr list() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd'T'HH:mm:ssZ");

        JSONArr arr = new JSONArr();
        for (HttpSession session : AppSessionDebugger.list()) {
            JSONObj obj = arr.addObject();
            obj.put("id", session.getId())
               .put("created", dateFormat.format(new Date(session.getCreationTime())))
               .put("updated", dateFormat.format(new Date(session.getLastAccessedTime())))
               .put("timeout", session.getMaxInactiveInterval());

            @SuppressWarnings("unchecked")
            Enumeration<String> attNames = session.getAttributeNames();
            JSONObj atts = obj.putObject("attributes");
            while (attNames.hasMoreElements()) {
                String attName = attNames.nextElement();
                atts.put(attName, session.getAttribute(attName).toString());
            }
        }

        return arr;
    }
View Full Code Here

            @RequestParam(value="page", required=false) Integer page,
            @RequestParam(value="count", required=false, defaultValue=""+DEFAULT_PAGESIZE) Integer count,
            @RequestParam(value="sort", required=false) String sort,
            @RequestParam(value="filter", required=false) String textFilter,
            HttpServletRequest req) {
        JSONObj obj = new JSONObj();

        Catalog cat = geoServer.getCatalog();

        if ("default".equals(wsName)) {
            WorkspaceInfo def = cat.getDefaultWorkspace();
            if (def != null) {
                wsName = def.getName();
            }
        }
        Filter filter = equal("resource.namespace.prefix", wsName);
        if (textFilter != null) {
            filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter));
        }
        Integer total = cat.count(LayerInfo.class, filter);

        SortBy sortBy = null;
        if (sort != null) {
            String[] sortArr = sort.split(":", 2);
            if (sortArr.length == 2) {
                if (sortArr[1].equals("asc")) {
                    sortBy = Predicates.asc(sortArr[0]);
                } else if (sortArr[1].equals("desc")) {
                    sortBy = Predicates.desc(sortArr[0]);
                } else {
                    throw new BadRequestException("Sort order must be \"asc\" or \"desc\"");
                }
            } else {
                sortBy = Predicates.asc(sortArr[0]);
            }
        }

        obj.put("total", total);
        obj.put("page", page != null ? page : 0);
        obj.put("count", Math.min(total, count != null ? count : total));

        JSONArr arr = obj.putArray("layers");
        try (
            CloseableIterator<LayerInfo> it = cat.list(LayerInfo.class, filter, offset(page, count), count, sortBy);
        ) {
            while (it.hasNext()) {
                layer(arr.addObject(), it.next(), req);
View Full Code Here

        catch(IOException e) {
            throw new RuntimeException("Failed to create layer: " + e.getMessage(), e);
        }

        // proj specified?
        JSONObj proj = obj.object("proj");
        if (proj != null) {
            String srs = null;
            try {
                srs = IO.srs(proj);
            } catch (IllegalArgumentException e) {
                throw new BadRequestException(e.getMessage(), e);
            }

            ResourceInfo r = l.getResource();
            r.setSRS(srs);
            try {
                new CatalogBuilder(cat).setupBounds(r);
            } catch (IOException e) {
                throw new RuntimeException("Unable to set projection on resource: " + e.getMessage(), e);
            }
        }

        // restore name in case it was replaced by duplicate
        l.getResource().setName(name);
        l.setName(name);

        // title
        String title = obj.str("title");
        if (title == null) {
            title = WordUtils.capitalize(name);
        }

        l.getResource().setTitle(title);
        l.setTitle(title);

        // description
        String desc = obj.str("description");
        if (desc != null) {
            l.getResource().setAbstract(desc);
            l.setAbstract(desc);
        }

        // copy the style into it's own unique
        try {
            l.setDefaultStyle(copyStyle(l, ws, cat));
        } catch (IOException e) {
            throw new RuntimeException("Error copying style: " + e.getMessage(), e);
        }

        Date created = new Date();
        Metadata.created(l, created);

        cat.add(l.getDefaultStyle());
        cat.add(l.getResource());
        cat.add(l);

        Metadata.modified(ws, created);
        cat.save(ws);

        return IO.layer(new JSONObj(), l, req);
    }
View Full Code Here


    @RequestMapping(value="/{wsName}/{name}", method = RequestMethod.GET)
    public @ResponseBody JSONObj get(@PathVariable String wsName, @PathVariable String name, HttpServletRequest req) {
        LayerInfo l = findLayer(wsName, name, geoServer.getCatalog());
        return layer(new JSONObj(), l, req);
    }
View Full Code Here

            if ("title".equals(prop)) {
                layer.setTitle(obj.str("title"));
            } else if ("description".equals(prop)) {
                layer.setAbstract(obj.str("description"));
            } else if ("bbox".equals(prop)) {
                JSONObj bbox = obj.object("bbox");
                if (bbox.has("native")) {
                    resource.setNativeBoundingBox(
                        new ReferencedEnvelope(IO.bounds(bbox.object("native")), resource.getCRS()));
                }
                if (bbox.has("lonlat")) {
                    resource.setNativeBoundingBox(
                        new ReferencedEnvelope(IO.bounds(bbox.object("lonlat")), DefaultGeographicCRS.WGS84));
                }
            } else if ("proj".equals(prop)) {
                JSONObj proj = obj.object("proj");
                if (!proj.has("srs")) {
                    throw new BadRequestException("proj property must contain a 'srs' property");
                }
                String srs = proj.str("srs");
                try {
                    CRS.decode(srs);
                } catch (Exception e) {
                    throw new BadRequestException("Unknown spatial reference identifier: " + srs);
                }
                resource.setSRS(srs);
            }
        }

        Metadata.modified(layer, new Date());
        Catalog cat = geoServer.getCatalog();
        cat.save(resource);
        cat.save(layer);
        return IO.layer(new JSONObj(), layer, req);
    }
View Full Code Here

   
    @ExceptionHandler(InvalidYsldException.class)
    public @ResponseBody JSONObj error(InvalidYsldException e, HttpServletResponse response) {
        response.setStatus(HttpStatus.BAD_REQUEST.value());
       
        JSONObj obj = IO.error(new JSONObj(), e);
        JSONArr errors = obj.putArray("errors");
        for (MarkedYAMLException error : e.errors()) {
            JSONObj err = errors.addObject()
                .put("problem", error.getProblem());
            Mark mark = error.getProblemMark();
            if (mark != null) {
                err.put("line", mark.getLine()).put("column", mark.getColumn());
            }
        }
        return obj;
    }
View Full Code Here

    @RequestMapping(value = "/{name}", method = RequestMethod.GET)
    public @ResponseBody
    JSONObj get(@PathVariable String name) {
        DataFormat<DataAccessFactory> f = findVectorFormat(name);
        if( f != null ){
            JSONObj obj = encode(new JSONObj(), f);
            JSONObj params = obj.putObject("params");
            for(Param p : f.real.getParametersInfo()){
                IO.param(params, p);
            }
            return obj;
        }

        DataFormat<Format> g = findRasterFormat(name);
        if( g != null ){
            JSONObj obj = encode(new JSONObj(), g);

            obj.put("vendor", g.real.getVendor())
               .put("version", g.real.getVersion());

            JSONArr connection = obj.putArray("params");
            IO.param(connection.addObject(), g.real);

            return obj;
        }

        DataFormat<Class<?>> s = findServiceFormat(name);
        if ( s != null) {
            JSONObj obj = encode(new JSONObj(), s);

            obj.putArray("params").addObject()
                .put("name","wms")
                .put("title","URL")
                .put("description","GetCapabilities URL for WMS Service")
                .put("type",URL.class.getSimpleName())
                .put("default",null)
View Full Code Here

    }

    @RequestMapping(method= RequestMethod.GET)
    public @ResponseBody
    JSONObj get() {
        JSONObj obj = new JSONObj();
        obj.toObject();

        SettingsInfo settings = geoServer.getGlobal().getSettings();
        obj.putObject("service")
           .put("title", settings.getTitle());

        JSONObj services = obj.putObject("services");
        for (ServiceInfo service : geoServer.getServices()) {
            JSONArr versions = services.putObject(service.getName())
               .put("title", service.getTitle())
               .putArray("versions");

            for (Version ver : service.getVersions()) {
                versions.add(ver.toString());
            }
        }

        Catalog cat = geoServer.getCatalog();
        obj.put("workspaces", cat.count(WorkspaceInfo.class, Filter.INCLUDE))
           .put("layers", cat.count(LayerInfo.class, Filter.INCLUDE))
           .put("maps", cat.count(LayerGroupInfo.class, Filter.INCLUDE));

        JSONObj cache = obj.putObject("recent");

        JSONArr recentMaps = cache.putArray("maps");
        for (Ref ref : recent.list(LayerGroupInfo.class)) {
            IO.ref(recentMaps.addObject(), ref);
        }

        return obj;
View Full Code Here

    @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));
            }
View Full Code Here

TOP

Related Classes of com.boundlessgeo.geoserver.json.JSONObj

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.