@Test public void testCreateAsJSON() throws Exception { GeoServer geoServer = getGeoServer(); geoServer.remove(geoServer.getSettings(geoServer.getCatalog().getWorkspaceByName("sf"))); String json = "{'settings':{'workspace':{'name':'sf'}," + "'contact':{'addressCity':'Alexandria','addressCountry':'Egypt','addressType':'Work'," + "'contactEmail':'*****@*****.**','contactOrganization':'The ancient geographes INC'," + "'contactPerson':'Claudius Ptolomaeus','contactPosition':'Chief geographer'}," + "'charset':'UTF-8','numDecimals':10,'onlineResource':'http://geoserver.org'," + "'proxyBaseUrl':'http://proxy.url','verbose':false,'verboseExceptions':'true'}}"; MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/sf/settings", json, "text/json"); assertEquals(200, response.getStatusCode()); JSON jsonMod = getAsJSON("/rest/workspaces/sf/settings.json"); JSONObject jsonObject = (JSONObject) jsonMod; assertNotNull(jsonObject); JSONObject settings = jsonObject.getJSONObject("settings"); assertNotNull(settings); JSONObject workspace = settings.getJSONObject("workspace"); assertNotNull(workspace); assertEquals("sf", workspace.get("name")); assertEquals("10", settings.get("numDecimals").toString().trim()); assertEquals("http://geoserver.org", settings.get("onlineResource")); assertEquals("http://proxy.url", settings.get("proxyBaseUrl")); JSONObject contact = settings.getJSONObject("contact"); assertEquals("Claudius Ptolomaeus", contact.get("contactPerson")); assertEquals("The ancient geographes INC", contact.get("contactOrganization")); assertEquals("Work", contact.get("addressType")); assertEquals("*****@*****.**", contact.get("contactEmail")); }
/** Creates a new WFSCapsTransformer object. */ public Wcs10CapsTransformer(GeoServer geoServer) { super(); this.geoServer = geoServer; this.wcs = geoServer.getService(WCSInfo.class); this.catalog = geoServer.getCatalog(); setNamespaceDeclarationEnabled(false); }
/** * Reads all the common attributes from the service info class. * * <p>This method is intended to be called by subclasses after creating an instance of * ServiceInfo. Example: * * <pre> * // read properties * Map<String,Object> props = reader.wfs(); * * // create config object * WFSInfo wfs = new WFSInfoImpl(); * * //load common properties * load( wfs, reader ); * * //load wfs specific properties * wfs.setServiceLevel( map.get( "serviceLevel") ); * ... * </pre> */ protected void readCommon(ServiceInfo service, Map<String, Object> properties, GeoServer gs) throws Exception { service.setEnabled((Boolean) properties.get("enabled")); service.setName((String) properties.get("name")); service.setTitle((String) properties.get("title")); service.setAbstract((String) properties.get("abstract")); Map metadataLink = (Map) properties.get("metadataLink"); if (metadataLink != null) { MetadataLinkInfo ml = gs.getCatalog().getFactory().createMetadataLink(); ml.setAbout((String) metadataLink.get("about")); ml.setMetadataType((String) metadataLink.get("metadataType")); ml.setType((String) metadataLink.get("type")); service.setMetadataLink(ml); } List<String> keywords = (List<String>) properties.get("keywords"); if (keywords != null) { for (String kw : keywords) { service.getKeywords().add(new Keyword(kw)); } } service.setOnlineResource((String) properties.get("onlineResource")); service.setFees((String) properties.get("fees")); service.setAccessConstraints((String) properties.get("accessConstraints")); service.setCiteCompliant((Boolean) properties.get("citeConformanceHacks")); service.setMaintainer((String) properties.get("maintainer")); service.setSchemaBaseURL((String) properties.get("SchemaBaseUrl")); }
/** * Looks up a {@link LayerInfo} or {@link LayerGroupInfo} named after the {@code <layer>} in the * requested resource {@code <layer>.kml} name * * @see org.restlet.Finder#findTarget(org.restlet.data.Request, org.restlet.data.Response) */ @Override public Resource findTarget(final Request request, Response response) { if (!Method.GET.equals(request.getMethod())) { response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); return null; } final String name = RESTUtils.getAttribute(request, "layer"); if (name == null) { throw new RestletException("No layer name specified", Status.CLIENT_ERROR_BAD_REQUEST); } final Catalog catalog = geoserver.getCatalog(); CatalogInfo layer = catalog.getLayerByName(name); MetadataMap mdmap; if (layer == null) { layer = catalog.getLayerGroupByName(name); if (layer == null) { throw new RestletException("Layer " + name + " not found", Status.CLIENT_ERROR_NOT_FOUND); } mdmap = ((LayerGroupInfo) layer).getMetadata(); } else { mdmap = ((LayerInfo) layer).getMetadata(); } Boolean enabled = mdmap.get(Properties.INDEXING_ENABLED, Boolean.class); if (enabled == null || !enabled.booleanValue()) { throw new RestletException("Layer " + name + " not found", Status.CLIENT_ERROR_NOT_FOUND); } final Context context = getContext(); return new GeoSearchLayer(context, request, response, layer, geoserver); }
/** * Adds a settings configuration to the test setup. If the settings object already exists it is * simply reverted to its original state. * * @param workspace The optional workspace for the settings, may be <code>null</code> * @param geoServer The GeoServer configuration object. */ public void addSettings(String workspace, GeoServer geoServer) { WorkspaceInfo ws = workspace != null ? geoServer.getCatalog().getWorkspaceByName(workspace) : null; GeoServerInfo global = geoServer.getGlobal(); SettingsInfo settings = ws != null ? geoServer.getSettings(ws) : global.getSettings(); if (settings == null) { settings = geoServer.getFactory().createSettings(); } settings.setWorkspace(ws); settings.getContact().setContactPerson("Andrea Aime"); settings.setNumDecimals(8); settings.setOnlineResource("http://geoserver.org"); settings.setVerbose(false); settings.setVerboseExceptions(false); settings.setLocalWorkspaceIncludesPrefix(false); if (ws != null) { if (settings.getId() != null) { geoServer.save(settings); } else { geoServer.add(settings); } } else { // global geoServer.save(global); } }
/** * Adds a service configuration to the test setup. If the service object already exists it is * simply reverted to its original state. * * @param serviceClass The class of the service * @param workspace The optional workspace for the service, may be <code>null</code> * @param geoServer The GeoServer configuration object. */ public <T extends ServiceInfo> void addService( Class<T> serviceClass, String workspace, GeoServer geoServer) { Catalog catalog = geoServer.getCatalog(); List<XStreamServiceLoader> loaders = GeoServerExtensions.extensions(XStreamServiceLoader.class); for (XStreamServiceLoader loader : loaders) { if (serviceClass.equals(loader.getServiceClass())) { // create a new one T created = (T) loader.create(geoServer); // grab the old one, if it exists T old = null; WorkspaceInfo ws = null; if (workspace != null) { ws = catalog.getWorkspaceByName(workspace); old = geoServer.getService(ws, serviceClass); } else { old = geoServer.getService(serviceClass); } if (old != null) { // update the old copy OwsUtils.copy(created, old, serviceClass); geoServer.save(old); } else { // add the new one created.setWorkspace(ws); geoServer.add(created); } break; } } }
public Data getRawData() { Catalog catalog = gs.getCatalog(); if (catalog instanceof Wrapper && ((Wrapper) catalog).isWrapperFor(Catalog.class)) { catalog = ((Wrapper) catalog).unwrap(Catalog.class); } return new Data(gs, catalog); }
public void initialize(GeoServer geoServer) throws Exception { this.geoServer = geoServer; // we need the original catalog, not a wrapper Catalog catalog = geoServer.getCatalog(); if (catalog instanceof Wrapper) { catalog = ((Wrapper) catalog).unwrap(Catalog.class); } this.catalog = catalog; active = true; }
@BeforeClass public static void setUpData() throws Exception { MonitorDAO dao = new MemoryMonitorDAO(); new MonitorTestData(dao).setup(); MonitorConfig mc = new MonitorConfig() { @Override public MonitorDAO createDAO() { MonitorDAO dao = new MemoryMonitorDAO(); try { new MonitorTestData(dao).setup(); return dao; } catch (java.text.ParseException e) { throw new RuntimeException(e); } } @Override public BboxMode getBboxMode() { return BboxMode.FULL; } }; GeoServer gs = createMock(GeoServer.class); monitor = new Monitor(mc); monitor.setServer(gs); catalog = new CatalogImpl(); expect(gs.getCatalog()).andStubReturn(catalog); replay(gs); NamespaceInfo ns = catalog.getFactory().createNamespace(); ns.setPrefix("acme"); ns.setURI("http://acme.org"); catalog.add(ns); DataStoreInfo ds = catalog.getFactory().createDataStore(); FeatureTypeInfo ftFoo = catalog.getFactory().createFeatureType(); ftFoo.setName("foo"); ftFoo.setSRS("EPSG:4326"); ftFoo.setNamespace(ns); ftFoo.setStore(ds); catalog.add(ftFoo); FeatureTypeInfo ftBar = catalog.getFactory().createFeatureType(); ftBar.setName("bar"); ftBar.setSRS("EPSG:3348"); ftBar.setNamespace(ns); ftBar.setStore(ds); catalog.add(ftBar); }
@Test public void testCreateAsXML() throws Exception { GeoServer geoServer = getGeoServer(); geoServer.remove(geoServer.getSettings(geoServer.getCatalog().getWorkspaceByName("sf"))); String xml = "<settings>" + "<workspace><name>sf</name></workspace>" + "<contact>" + "<addressCity>Alexandria</addressCity>" + "<addressCountry>Egypt</addressCountry>" + "<addressType>Work</addressType>" + "<contactEmail>[email protected]</contactEmail>" + "<contactOrganization>The ancient geographes INC</contactOrganization>" + "<contactPerson>Claudius Ptolomaeus</contactPerson>" + "<contactPosition>Chief geographer</contactPosition>" + "</contact>" + "<charset>UTF-8</charset>" + "<numDecimals>8</numDecimals>" + "<onlineResource>http://geoserver.org</onlineResource>" + "<proxyBaseUrl>http://proxy.url</proxyBaseUrl>" + "<verbose>false</verbose>" + "<verboseExceptions>false</verboseExceptions>" + "</settings>"; MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/sf/settings", xml, "text/xml"); assertEquals(200, response.getStatusCode()); Document dom = getAsDOM("/rest/workspaces/sf/settings.xml"); assertEquals("settings", dom.getDocumentElement().getLocalName()); assertXpathEvaluatesTo("sf", "/settings/workspace/name", dom); assertXpathEvaluatesTo("false", "/settings/verbose", dom); assertXpathEvaluatesTo("false", "/settings/verboseExceptions", dom); assertXpathEvaluatesTo("http://geoserver.org", "/settings/onlineResource", dom); assertXpathEvaluatesTo("http://proxy.url", "/settings/proxyBaseUrl", dom); assertXpathEvaluatesTo("Claudius Ptolomaeus", "/settings/contact/contactPerson", dom); assertXpathEvaluatesTo("*****@*****.**", "/settings/contact/contactEmail", dom); assertXpathEvaluatesTo("Chief geographer", "/settings/contact/contactPosition", dom); assertXpathEvaluatesTo( "The ancient geographes INC", "/settings/contact/contactOrganization", dom); assertXpathEvaluatesTo("Egypt", "/settings/contact/addressCountry", dom); }
public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { final FeatureDiffReader[] diffReaders = (FeatureDiffReader[]) value; // create a new feature collcetion type with just the numbers VersioningTransactionConverter converter = new VersioningTransactionConverter(); final TransactionType transaction = converter.convert(diffReaders, TransactionType.class); // declare wfs schema location BaseRequestType gft = (BaseRequestType) operation.getParameters()[0]; Encoder encoder = new Encoder(configuration, configuration.schema()); encodeWfsSchemaLocation(encoder, gft.getBaseUrl()); encoder.setIndenting(true); encoder.setEncoding(Charset.forName(geoServer.getSettings().getCharset())); // set up schema locations // round up the info objects for each feature collection HashMap /* <String,Set> */ ns2metas = new HashMap(); for (int i = 0; i < diffReaders.length; i++) { final FeatureDiffReader diffReader = diffReaders[i]; final SimpleFeatureType featureType = diffReader.getSchema(); // load the metadata for the feature type String namespaceURI = featureType.getName().getNamespaceURI(); FeatureTypeInfo meta = geoServer .getCatalog() .getFeatureTypeByName(namespaceURI, featureType.getName().getLocalPart()); // add it to the map Set metas = (Set) ns2metas.get(namespaceURI); if (metas == null) { metas = new HashSet(); ns2metas.put(namespaceURI, metas); } metas.add(meta); } // declare application schema namespaces for (Iterator i = ns2metas.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); String namespaceURI = (String) entry.getKey(); Set metas = (Set) entry.getValue(); StringBuffer typeNames = new StringBuffer(); for (Iterator m = metas.iterator(); m.hasNext(); ) { FeatureTypeInfo meta = (FeatureTypeInfo) m.next(); typeNames.append(meta.getName()); if (m.hasNext()) { typeNames.append(","); } } // set the schema location encodeTypeSchemaLocation(encoder, gft.getBaseUrl(), namespaceURI, typeNames); } try { encoder.encode(transaction, element, output); } finally { for (int i = 0; i < diffReaders.length; i++) { diffReaders[i].close(); } } }
/** * @param readLimits * @param writeLimits * @param hardOutputLimit * @param geoserver */ public DownloadEstimatorProcess( DownloadServiceConfigurationGenerator downloadServiceConfigurationGenerator, GeoServer geoserver) { this.catalog = geoserver.getCatalog(); this.downloadServiceConfigurationGenerator = downloadServiceConfigurationGenerator; }
public Catalog getCatalog() { return geoserver.getCatalog(); }