Skip to content

Commit

Permalink
applied feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shadabgada committed Sep 9, 2022
1 parent c2c6b82 commit 52eb26f
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@
<form>
<wicket:panel>
<ul>
<li >
<li>
<fieldset>
<legend><span><wicket:message key="cacheSettings">Caching Settings</wicket:message></span></legend>
<ul>
<li class="choiceItem">
<input id="cachingEnabled" wicket:id="cachingEnabled" type="checkbox">
<label for="cachingEnabled"><wicket:message key="cachingEnabled">Enable Cache</wicket:message></label>
<label for="cachingEnabled">
<wicket:message key="cachingEnabled">Use cache for this layer</wicket:message>
</label>
</li>
<li>
<label for="datastoreName"><wicket:message key="datastoreName">Choose Datastore:</wicket:message></label>
<select class="select" id="datastoreName" wicket:id="datastoreName"></select>
</li>
<li>
<label for="schemaName"><wicket:message key="schemaName">Schema name</wicket:message></label>
<input id="schemaName" class="text" type="text" wicket:id="schemaName">
<li wicket:id="configContainer">
<ul wicket:id="configs">
<li>
<label for="datastoreName">
<wicket:message key="datastoreName">Choose cache datastore:</wicket:message>
</label>
<select class="select" id="datastoreName" wicket:id="datastoreName"></select>
</li>
<li>
<label for="schemaName">
<wicket:message key="schemaName">Choose cache feature type:</wicket:message>
</label>
<select class="select" id="schemaName" wicket:id="schemaName"></select>
</li>
</ul>
</li>
</ul>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package org.geoserver.databricks.ng.cache.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.DataStoreInfo;
import org.geoserver.catalog.StoreInfo;
import org.geoserver.platform.GeoServerExtensions;
import org.geotools.data.DataStore;
import org.geotools.util.logging.Logging;
import org.opengis.feature.type.Name;

/** A panel to configure the cache setting */
public class CachePanel extends Panel {
Expand All @@ -19,36 +29,81 @@ public class CachePanel extends Panel {
public static final String DATASTORE_NAME = "datastoreName";
public static final String SCHEMA_NAME = "schemaName";

DropDownChoice<String> storeChoice;
DropDownChoice<String> featureTypeChoice;

private static final Logger LOGGER = Logging.getLogger(CachePanel.class);

public CachePanel(String id, IModel<?> model) {
super(id, model);

final WebMarkupContainer configsContainer = new WebMarkupContainer("configContainer");
configsContainer.setOutputMarkupId(true);
add(configsContainer);
final WebMarkupContainer configs = new WebMarkupContainer("configs");
configs.setOutputMarkupId(true);
configs.setVisible(true);
configsContainer.add(configs);

final PropertyModel<Boolean> cacheEnabledModel =
new PropertyModel<>(model, CACHING_ENABLED);
if (cacheEnabledModel.getObject() == null) {
cacheEnabledModel.setObject(false);
}

// checkbox to 'enable cache'
add(new CheckBox(CACHING_ENABLED, cacheEnabledModel));
CheckBox enabled = new CheckBox(CACHING_ENABLED, cacheEnabledModel);
add(enabled);
enabled.add(
new AjaxFormComponentUpdatingBehavior("click") {

List<String> options = getDataStores();
@Override
protected void onUpdate(AjaxRequestTarget target) {
Boolean visible = enabled.getModelObject();
configs.setVisible(visible);
target.add(configsContainer);
}
});

List<String> dataStores = getDataStores();
final PropertyModel<String> storeNameModel = new PropertyModel<>(model, DATASTORE_NAME);
if (storeNameModel.getObject() == null) {
storeNameModel.setObject("");
}

// dropdown to choose datastore name
DropDownChoice<String> choice =
new DropDownChoice<>(DATASTORE_NAME, storeNameModel, options);
add(choice);
storeChoice = new DropDownChoice<>(DATASTORE_NAME, storeNameModel, dataStores);
add(storeChoice);
storeChoice.add(
new AjaxFormComponentUpdatingBehavior("change") {

@Override
protected void onUpdate(AjaxRequestTarget target) {
updateFeatureTypes(target);
}
});
configs.add(storeChoice);

List<String> featureTypes = new ArrayList<>();
final PropertyModel<String> schemaNameModel = new PropertyModel<>(model, SCHEMA_NAME);
if (schemaNameModel.getObject() == null) {
schemaNameModel.setObject("");
} else {
featureTypes = getFeatureTypes(storeChoice.getModelObject());
}

// text field to specify the schema name
add(new TextField<>(SCHEMA_NAME, schemaNameModel));
// dropdown to choose feature type name
featureTypeChoice = new DropDownChoice<>(SCHEMA_NAME, schemaNameModel, featureTypes);
featureTypeChoice.setOutputMarkupId(true);
add(featureTypeChoice);
configs.add(featureTypeChoice);
}

private void updateFeatureTypes(AjaxRequestTarget target) {
featureTypeChoice.setChoices(getFeatureTypes(storeChoice.getModelObject()));
if (target != null) {
target.add(featureTypeChoice);
}
}

private List<String> getDataStores() {
Expand All @@ -57,4 +112,21 @@ private List<String> getDataStores() {
.map(StoreInfo::getName)
.collect(Collectors.toList());
}

private List<String> getFeatureTypes(String storeName) {
Catalog catalog = (Catalog) GeoServerExtensions.bean("catalog");
DataStoreInfo dataStoreInfo;
List<String> featureTypes = new ArrayList<>();
try {
dataStoreInfo = catalog.getDataStoreByName(storeName);
if (dataStoreInfo != null) {
DataStore ds = (DataStore) dataStoreInfo.getDataStore(null);
featureTypes =
ds.getNames().stream().map(Name::getLocalPart).collect(Collectors.toList());
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Unable to load feature types for store " + storeName, e);
}
return featureTypes;
}
}
10 changes: 5 additions & 5 deletions src/web/core/src/main/resources/GeoServerApplication.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1071,12 +1071,12 @@ NDLayerEditTabPanelInfo.shortDescription = Resource Dimensions
LayerAccessDataRulePanel.title = Security
LayerAccessDataRulePanel.shortDescription = Security Rules

CacheTabPanel.title = Caching
CacheTabPanel.cacheSettings = Cache Setting
CacheTabPanel.title = Databricks
CacheTabPanel.cacheSettings = Cache settings

CachePanel.cachingEnabled = Enable Cache
CachePanel.datastoreName = Choose Datastore:
CachePanel.schemaName = Schema name
CachePanel.cachingEnabled = Use cache for this layer
CachePanel.datastoreName = Choose cache datastore:
CachePanel.schemaName = Choose cache feature type:

ResourceDimensionsTabPanelInfo.dimensions = Dimensions
ResourceDimensionsTabPanelInfo.timeDimension = Time
Expand Down

0 comments on commit 52eb26f

Please sign in to comment.