/** * Adds nearest match support to the specified layer. * * @param layer The layer name * @param dimensionName The dimension name (key in the resource metadata map) * @param nearestMatch Whether to enable or disable nearest match */ protected void setupNearestMatch( QName layer, String dimensionName, boolean nearestMatch, String acceptableInterval) { ResourceInfo info = getCatalog().getResourceByName(getLayerId(layer), ResourceInfo.class); DimensionInfo di = info.getMetadata().get(dimensionName, DimensionInfo.class); di.setNearestMatchEnabled(nearestMatch); di.setAcceptableInterval(acceptableInterval); getCatalog().save(info); }
/** Returns the max age for the specified layer */ private int getLayerMaxAge(LayerInfo li) { MetadataMap metadata = li.getResource().getMetadata(); Object enabled = metadata.get(ResourceInfo.CACHING_ENABLED); if (enabled != null && enabled.toString().equalsIgnoreCase("true")) { Integer maxAge = metadata.get(ResourceInfo.CACHE_AGE_MAX, Integer.class); if (maxAge != null) { return maxAge; } else { return 0; } } return 0; }
Set<String> getEnabledDimensionNames(LayerInfo layer) { Set<String> dimensionNames = new HashSet<String>(); for (Map.Entry<String, Serializable> entry : layer.getResource().getMetadata().entrySet()) { String key = entry.getKey(); Serializable md = entry.getValue(); if (md instanceof DimensionInfo) { // skip disabled dimensions DimensionInfo di = (DimensionInfo) md; if (!di.isEnabled()) { continue; } // get the dimension name String dimensionName; if (key.startsWith(ResourceInfo.CUSTOM_DIMENSION_PREFIX)) { dimensionName = key.substring(ResourceInfo.CUSTOM_DIMENSION_PREFIX.length()); } else { dimensionName = key; } dimensionNames.add(dimensionName); } } return dimensionNames; }
/** * This value is added the headers of generated maps, marking them as being both "cache-able" * and designating the time for which they are to remain valid. The specific header added is * "Cache-Control: max-age=" * * @return the number of seconds to be added to the "Cache-Control: max-age=" header, or {@code * 0} if not set */ public int getCacheMaxAge() { if (layerInfo == null) { return 0; } ResourceInfo resource = layerInfo.getResource(); Integer val = resource.getMetadata().get(ResourceInfo.CACHE_AGE_MAX, Integer.class); return val == null ? 0 : val; }
private Object getCacheAge(TileLayer layer) { Object cacheAge = null; if (layer instanceof GeoServerTileLayer) { LayerInfo layerInfo = ((GeoServerTileLayer) layer).getLayerInfo(); // configuring caching does not appear possible for layergroup if (layerInfo != null) { MetadataMap metadata = layerInfo.getResource().getMetadata(); Object enabled = metadata.get("cachingEnabled"); // do a string comparison since if set via REST, it will be a // string, if set via the web UI and fresh in the cache, it // will be a boolean ... if (enabled != null && enabled.toString().equalsIgnoreCase("true")) { cacheAge = layerInfo.getResource().getMetadata().get("cacheAgeMax"); } } } return cacheAge; }
private Integer getCacheAge(TileLayer layer) { Integer cacheAge = null; if (layer instanceof GeoServerTileLayer) { LayerInfo layerInfo = ((GeoServerTileLayer) layer).getLayerInfo(); // configuring caching does not appear possible for layergroup if (layerInfo != null) { MetadataMap metadata = layerInfo.getResource().getMetadata(); Boolean enabled = metadata.get(ResourceInfo.CACHING_ENABLED, Boolean.class); if (enabled != null && enabled) { cacheAge = layerInfo .getResource() .getMetadata() .get(ResourceInfo.CACHE_AGE_MAX, Integer.class); } } } return cacheAge; }
/** * Looks up the elevation configuration, throws an exception if not found * * @param resourceInfo * @param dimensionName */ public DimensionInfo getDimensionInfo(ResourceInfo resourceInfo, String dimensionName) { DimensionInfo info = resourceInfo.getMetadata().get(dimensionName, DimensionInfo.class); if (info == null || !info.isEnabled()) { throw new ServiceException( "Layer " + resourceInfo.prefixedName() + " does not have " + dimensionName + " support enabled"); } return info; }
private void checkTimeDimension(LayerInfo layer) { ResourceInfo resource = layer.getResource(); MetadataMap metadata = resource.getMetadata(); DimensionInfo timeDimension = (DimensionInfo) metadata.get("time"); assertNotNull(timeDimension); }
/** * Returns the default value for time dimension. * * @param resourceInfo */ public Object getDefaultTime(ResourceInfo resourceInfo) { // check the time metadata DimensionInfo time = resourceInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class); if (time == null || !time.isEnabled()) { throw new ServiceException( "Layer " + resourceInfo.prefixedName() + " does not have time support enabled"); } DimensionDefaultValueSelectionStrategy strategy = this.getDefaultValueStrategy(resourceInfo, ResourceInfo.TIME, time); return strategy.getDefaultValue(resourceInfo, ResourceInfo.TIME, time, Date.class); }
@Override protected void onSetUp(SystemTestData testData) throws Exception { // insert extra metadata ResourceInfo forestInfo = getCatalog().getLayerByName("Forests").getResource(); forestInfo.getMetadata().put("date", "09/10/2012"); forestInfo.setLatLonBoundingBox(new ReferencedEnvelope(-200, -180, -100, -90, CRS .decode("EPSG:4326"))); getCatalog().save(forestInfo); }
protected void setupDynamicDimensions( String resourceName, DefaultValueConfiguration... configurations) { ResourceInfo info = getCatalog().getResourceByName(resourceName, ResourceInfo.class); DefaultValueConfigurations configs = new DefaultValueConfigurations(Arrays.asList(configurations)); info.getMetadata().put(DefaultValueConfigurations.KEY, configs); getCatalog().save(info); }
@Override protected void onSetUp(SystemTestData testData) throws Exception { // insert extra metadata ResourceInfo forestInfo = getCatalog().getLayerByName("Forests").getResource(); forestInfo.getMetadata().put("date", "09/10/2012"); forestInfo.setLatLonBoundingBox(new ReferencedEnvelope(-200, -180, -100, -90, CRS .decode("EPSG:4326"))); forestInfo.getKeywords().add(new Keyword ("CustomKeyWord-1")); forestInfo.getKeywords().add(new Keyword ("CustomKeyWord-2")); forestInfo.setDescription("Land with lots of trees on."); forestInfo.getAlias().add("Bush"); forestInfo.getAlias().add("Woods"); getCatalog().save(forestInfo); }
@Before public void setUpInternal() throws Exception { // Creatign models LayerInfo layerInfo = getCatalog().getLayerByName(getLayerId(MockData.TASMANIA_DEM)); layerModel = new Model<LayerInfo>(layerInfo); ResourceInfo resource = layerInfo.getResource(); resourceModel = new Model<CoverageInfo>((CoverageInfo) resource); // Add Element to MetadataMap MetadataMap metadata = resource.getMetadata(); if (!metadata.containsKey(NetCDFSettingsContainer.NETCDFOUT_KEY)) { metadata.put(NetCDFSettingsContainer.NETCDFOUT_KEY, new NetCDFLayerSettingsContainer()); } }
/** * Enables the ResourceInfo time dimension, defaulting it to the highest available value TODO: * it's probably useful to make this configurable */ private void timeEnableResource(ResourceInfo resource) { DimensionInfo dimension = new DimensionInfoImpl(); dimension.setEnabled(true); dimension.setAttribute(TIME_START); dimension.setUnits(DimensionInfo.TIME_UNITS); dimension.setPresentation(DimensionPresentation.CONTINUOUS_INTERVAL); DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting(); defaultValueSetting.setStrategyType(Strategy.MAXIMUM); dimension.setDefaultValue(defaultValueSetting); resource.getMetadata().put(ResourceInfo.TIME, dimension); }
@Before public void setUpInternal() throws Exception { // Creatign models LayerInfo layerInfo = getCatalog().getLayerByName(getLayerId(MockData.TASMANIA_DEM)); layerModel = new Model<LayerInfo>(layerInfo); ResourceInfo resource = layerInfo.getResource(); resourceModel = new Model<ResourceInfo>(resource); // Add Element to MetadataMap MetadataMap metadata = resource.getMetadata(); if (!metadata.containsKey(NetCDFSettingsContainer.NETCDFOUT_KEY)) { metadata.put(NetCDFSettingsContainer.NETCDFOUT_KEY, new NetCDFLayerSettingsContainer()); } }
public void removeDynamicDimensions(String resourceName) throws Exception { ResourceInfo ri = getCatalog().getResourceByName(resourceName, ResourceInfo.class); ri.getMetadata().remove(DefaultValueConfigurations.KEY); getCatalog().save(ri); }
@Override public List<ImportTask> list(ImportData data, Catalog catalog, ProgressMonitor monitor) throws IOException { List<ImportTask> tasks = super.list(data, catalog, monitor); Mosaic m = (Mosaic) data; if (m.getTimeMode() != TimeMode.NONE) { //set up the time dimension object for (ImportTask task : tasks) { DimensionInfo dim = new DimensionInfoImpl(); dim.setEnabled(true); dim.setAttribute("time"); dim.setPresentation(DimensionPresentation.LIST); dim.setUnits("ISO8601"); //TODO: is there an enumeration for this? ResourceInfo r = task.getLayer().getResource(); r.getMetadata().put(ResourceInfo.TIME, dim); } } return tasks; } }
@Override public List<ImportTask> list(ImportData data, Catalog catalog, ProgressMonitor monitor) throws IOException { List<ImportTask> tasks = super.list(data, catalog, monitor); Mosaic m = (Mosaic) data; if (m.getTimeMode() != TimeMode.NONE) { // set up the time dimension object for (ImportTask task : tasks) { DimensionInfo dim = new DimensionInfoImpl(); dim.setEnabled(true); dim.setAttribute("time"); dim.setPresentation(DimensionPresentation.LIST); dim.setUnits("ISO8601"); // TODO: is there an enumeration for this? ResourceInfo r = task.getLayer().getResource(); r.getMetadata().put(ResourceInfo.TIME, dim); } } return tasks; } }
protected void setupResourceDimensionDefaultValue( QName name, String dimensionName, DimensionDefaultValueSetting defaultValue, String... startEndAttribute) { ResourceInfo info = getCatalog().getResourceByName(name.getLocalPart(), ResourceInfo.class); if (info == null) { throw new RuntimeException("Unable to get resource by name " + name.getLocalPart()); } DimensionInfo di = new DimensionInfoImpl(); di.setEnabled(true); di.setPresentation(DimensionPresentation.LIST); di.setDefaultValue(defaultValue); if (startEndAttribute != null && startEndAttribute.length > 0) { di.setAttribute(startEndAttribute[0]); if (startEndAttribute.length > 1) { di.setEndAttribute(startEndAttribute[1]); } } info.getMetadata().put(dimensionName, di); getCatalog().save(info); }
@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); runChecks(l.getName()); Document dom = getAsDOM( String.format( "/%s/%s/wms?request=getcapabilities", r.getStore().getWorkspace().getName(), l.getName())); XMLAssert.assertXpathExists( "//wms:Layer[wms:Name = '" + m.getName() + "']/wms:Dimension[@name = 'time']", dom); }