Beispiel #1
0
        public void GeoserverServiceLayerTest()
        {
            ModulesFactory modulesFactory = new ModulesFactory();

            LayersBuilder builder = new LayersBuilder();

            builder.LayerName   = "constanta:coasta_constanta_labeled";
            builder.SingleLayer = true;


            GeoserverClient geoserverClient = new GeoserverClient("http://localhost:8080", "admin", "geoserver");


            var result = geoserverClient.Get <Layer>(modulesFactory.CreateLayerModule(builder));
        }
Beispiel #2
0
        /// <summary>
        /// Use this method to associate a style with a layer in geoserver or to validate a layer
        /// </summary>
        /// <param name="datasetId"></param>
        /// <param name="paletteName"></param>
        /// <param name="paletteUsername"></param>
        /// <returns></returns>
        public bool ValidateGeoserverLayer(string datasetName, string datasetUsername, string paletteName, string paletteUsername)
        {
            /**
             * Steps: 1. check if palette is already asociated. If yes, return true
             *        2. if the palette is not associated, retrieve it from db and associate it with layer.
             *        3. if insert succeed, count the palette in the database and return true
             *        4. if insert fail, return false
             */

            try
            {
                if (string.IsNullOrEmpty(paletteName) || string.IsNullOrEmpty(paletteUsername))
                {
                    return(false);
                }

                int datasetId   = userRepository.GetDatasetID(datasetUsername, datasetName);
                int geoserverId = userRepository.GetGeoserverDatasetID(datasetId);

                if (geoserverId == -1)
                {
                    return(false);
                }

                var datasetHeader     = userRepository.GetDatasetHeader(datasetId);
                var geoserverPalettes = userRepository.GetGeoserverColorMaps(geoserverId);

                var selectedPalette = geoserverPalettes.Where(p => p.Item1 == paletteUsername && p.Item2.Name == paletteName).FirstOrDefault();
                if (selectedPalette != null)
                {
                    return(true);
                }
                selectedPalette = getUserColorMap(paletteUsername, paletteName);

                string serverUrl = Helper.GetSourceFromUrl((datasetHeader.OptionalData as GeoserverOptionalData).ServerUrl);

                GeoserverClient client = geoserverClient(
                    serverUrl,
                    null,
                    null);

                if (!insertGeoserverStyle(client, selectedPalette.Item1, selectedPalette.Item2))
                {
                    CoreContainers.LogsRepository.LogWarning($"Failed to associate palette {selectedPalette.Item2.Name} with the dataset found at {serverUrl}");
                }

                ModulesFactory modulesFactory = new ModulesFactory();

                LayersBuilder builder = new LayersBuilder();
                builder.LayerName   = userRepository.GetDatasetHeader(datasetId).Name;
                builder.SingleLayer = true;

                builder.Styles = geoserverPalettes.Select(p => p.Item1 + '_' + p.Item2.Name).ToList();
                builder.Styles.Add(paletteUsername + '_' + paletteName);

                return(client.Put(modulesFactory.CreateLayerModule(builder)) ?
                       userRepository.InsertGeoserverColorMap(
                           geoserverId,
                           paletteName,
                           paletteUsername
                           ) != -1
                    : false);
            }
            catch (Exception exception)
            {
                return(false);
            }
        }