Package it.geosolutions.geoserver.rest

Examples of it.geosolutions.geoserver.rest.GeoServerRESTPublisher


        if (!enabled())
            return;
        deleteAll();

        GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
                           
        String storeName = "resttestshp";
        String layerName = "cities";
       
        publisher.createWorkspace(DEFAULT_WS);

        File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();

        // test insert
        boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
        assertTrue("publish() failed", published);
        assertTrue(existsLayer(layerName));

        publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),
                "default_point.sld"));

        GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
        fte.setNativeName(layerName);
        fte.setName(layerName + "_NEW");
        fte.setTitle("title");
        // fte.addKeyword("TODO");
        fte.setNativeCRS("EPSG:4326");
        fte.setDescription("desc");
        fte.setEnabled(true);

        // metadataLink
        GSMetadataLinkInfoEncoder metadatalink = new GSMetadataLinkInfoEncoder("text/xml",
                "ISO19115:2003", "http://www.organization.org/metadata1");
        fte.addMetadataLinkInfo(metadatalink);

        GSLayerEncoder layerEncoder = null;
        if (VERSION.getVersion(GS_VERSION).compareTo(VERSION.UNRECOGNIZED) > 0) {
            layerEncoder = new GSLayerEncoder();
        } else if (VERSION.getVersion(GS_VERSION).compareTo(VERSION.UNRECOGNIZED) == 0) {
            layerEncoder = new GSLayerEncoder21();
        }
        layerEncoder.setEnabled(true);
        layerEncoder.setQueryable(true);
        layerEncoder.setAdvertised(true);

        layerEncoder.setDefaultStyle("point");
        layerEncoder.addStyle("point2");
        layerEncoder.addStyle("point3");

        // authorityURL
        GSAuthorityURLInfoEncoder authorityURL = new GSAuthorityURLInfoEncoder("authority1",
                "http://www.authority1.org");
        layerEncoder.addAuthorityURL(authorityURL);

        // identifier
        GSIdentifierInfoEncoder identifier1 = new GSIdentifierInfoEncoder("authority1",
                "identifier1");
        GSIdentifierInfoEncoder identifier2 = new GSIdentifierInfoEncoder("authority1",
                "another_identifier");
        layerEncoder.addIdentifier(identifier1);
        layerEncoder.addIdentifier(identifier2);


        // optionally select the attributes to publish
        RESTLayer layer = reader.getLayer(DEFAULT_WS, layerName);
        RESTFeatureType resource = reader.getFeatureType(layer);
        List<GSAttributeEncoder> attrs = resource.getEncodedAttributeList();
        assertNotNull(attrs);
        for (GSAttributeEncoder enc : attrs) {
            fte.setAttribute(enc);
        }

        assertTrue(publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder));

    }
View Full Code Here


        if (!enabled())
            return;
        deleteAll();
       
        GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);

        String storeName = "resttestshp";
        String layerName = "cities";
       
        // build the store
        publisher.createWorkspace(DEFAULT_WS);
       
        // test insert
        File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
        boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
        assertTrue("publish() failed", published);

        publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),
                "default_point.sld"));

        String nativeName = layerName;
        layerName=layerName+"_NEW";
       
        GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
        fte.setName(layerName);
        fte.setNativeName(nativeName);
        fte.setTitle("title");

        fte.addKeyword("keyword1");
        fte.addKeyword("keyword2");
        fte.setNativeCRS("EPSG:4326");
        fte.setDescription("desc");
        fte.setEnabled(true);

        // virtual table
        // -------------
        // Set-up the vtGeom
        final VTGeometryEncoder vtGeom = new VTGeometryEncoder("the_geom", "Point", "4326");

        // Set-up 2 virtual table parameters
        final VTParameterEncoder vtParam1 = new VTParameterEncoder("high", "100000000", "^[\\d]+$");
        final VTParameterEncoder vtParam2 = new VTParameterEncoder("low", "0", "^[\\d]+$");

        // sql
        String sql = "select gid, state_name, the_geom from pgstates where persons between %low% and %high% and state_abbr = '%state%'";

        // set-up the virtual table
        final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
        vte.setName(nativeName);
        vte.setSql(sql);
        vte.addVirtualTableGeometry(vtGeom);
        vte.addVirtualTableParameter(vtParam1);
        vte.addVirtualTableParameter(vtParam2);

        // modif the vte
        vte.delVirtualTableGeometry("the_geom");
        vte.addVirtualTableGeometry("the_geom", "MultiPolygon", "4326");

        final VTParameterEncoder vtParam3 = new VTParameterEncoder("state", "FL", "^[\\w\\d\\s]+$");
        vte.addVirtualTableParameter(vtParam3);
        vte.addKeyColumn("gid");

        fte.setMetadataVirtualTable(vte); // Set the virtual table

        // Layer encoder
        // -------------
        GSLayerEncoder layerEncoder = new GSLayerEncoder();
        layerEncoder.setEnabled(true);
        layerEncoder.setQueryable(true);
        layerEncoder.setDefaultStyle("polygon");
       
        // test insert
        // ------------
        publisher.createWorkspace(DEFAULT_WS);
        published = publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder);
        assertTrue("Publication unsuccessful", published);
        assertTrue("Layer does not exist", existsLayer(layerName));

    }
View Full Code Here

TOP

Related Classes of it.geosolutions.geoserver.rest.GeoServerRESTPublisher

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.