log.info("### Old gridset: " + oldGridSet);
log.info("### New gridset: " + newGridSet);
}
Map<TileLayer, GridSubset> affectedLayers = new HashMap<TileLayer, GridSubset>();
Lock lock = null;
try {
lock = lockProvider.getLock(GLOBAL_LOCK_KEY);
for (TileLayer layer : getTileLayers()) {
GridSubset gridSubet;
if (null != (gridSubet = layer.getGridSubset(oldGridSetName))) {
affectedLayers.put(layer, gridSubet);
layer.removeGridSubset(oldGridSetName);
if (needsTruncate) {
deleteCacheByGridSetId(layer.getName(), oldGridSetName);
}
}
}
// now no layer is referencing it
XMLConfiguration mainConfig = getXmlConfiguration();
mainConfig.removeGridset(oldGridSetName);
mainConfig.addOrReplaceGridSet(new XMLGridSet(newGridSet));
mainConfig.save();
getGridSetBroker().remove(oldGridSetName);
getGridSetBroker().put(newGridSet);
// tld.removeGridset(oldGridSetName);
// tld.addGridSet(newGridSet);
// if (isRename && !needsTruncate) {
// // /TODO: quotaStore.renameGridSet(oldGridSetName, newGidSetName);
// }
final boolean sameSRS = oldGridSet.getSrs().equals(newGridSet.getSrs());
final int maxZoomLevel = newGridSet.getNumLevels() - 1;
Set<Configuration> saveConfigurations = new HashSet<Configuration>();
// now restore the gridsubset for each layer
for (Map.Entry<TileLayer, GridSubset> entry : affectedLayers.entrySet()) {
TileLayer layer = entry.getKey();
GridSubset gsubset = entry.getValue();
BoundingBox gridSetExtent = gsubset.getOriginalExtent();
if (null != gridSetExtent && sameSRS) {
gridSetExtent = newGridSet.getOriginalExtent().intersection(gridSetExtent);
}
int zoomStart = gsubset.getZoomStart();
int zoomStop = gsubset.getZoomStop();
if (zoomStart > maxZoomLevel) {
zoomStart = maxZoomLevel;
}
if (zoomStop > maxZoomLevel || zoomStop < zoomStart) {
zoomStop = maxZoomLevel;
}
GridSubset newGridSubset = GridSubsetFactory.createGridSubSet(newGridSet,
gridSetExtent, zoomStart, zoomStop);
layer.removeGridSubset(oldGridSetName);
layer.addGridSubset(newGridSubset);
Configuration config = tld.getConfiguration(layer);
config.modifyLayer(layer);
saveConfigurations.add(config);
}
for (Configuration config : saveConfigurations) {
config.save();
}
} finally {
if(lock != null) {
lock.release();
}
}
}