Skip to content

Commit

Permalink
[GEOS-7096] Deprecate SOLR data store per attribute layer generation,…
Browse files Browse the repository at this point in the history
… along with core web module changes to make it possible
  • Loading branch information
aaime committed Jul 12, 2015
1 parent e5f5f1c commit d513a85
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 55 deletions.
4 changes: 3 additions & 1 deletion src/community/solr/src/main/java/applicationContext.xml
Expand Up @@ -8,7 +8,9 @@ This code is licensed under the GPL 2.0 license, available at the root applicati


<bean id="solrXStreamInitializer" class="org.geoserver.solr.SolrXStreamInitializer" /> <bean id="solrXStreamInitializer" class="org.geoserver.solr.SolrXStreamInitializer" />


<bean id="solrFeatureTypeCallback" class="org.geoserver.solr.SolrFeatureTypeCallback" /> <bean id="solrFeatureTypeCallback" class="org.geoserver.solr.SolrFeatureTypeCallback" >
<constructor-arg index="0" ref="catalog" />
</bean>


<bean id="solrConfigPanel" class="org.geoserver.solr.SolrConfigurationPanelInfo"> <bean id="solrConfigPanel" class="org.geoserver.solr.SolrConfigurationPanelInfo">
<property name="id" value="solr" /> <property name="id" value="solr" />
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved /* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */
Expand Down Expand Up @@ -31,13 +31,9 @@
import org.apache.wicket.model.IModel; import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model; import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel; import org.apache.wicket.model.PropertyModel;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogBuilder;
import org.geoserver.catalog.DataStoreInfo; import org.geoserver.catalog.DataStoreInfo;
import org.geoserver.catalog.FeatureTypeInfo; import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.ResourceInfo; import org.geoserver.catalog.ResourceInfo;
import org.geoserver.web.GeoServerApplication;
import org.geoserver.web.wicket.GeoServerDataProvider.Property; import org.geoserver.web.wicket.GeoServerDataProvider.Property;
import org.geoserver.web.wicket.GeoServerTablePanel; import org.geoserver.web.wicket.GeoServerTablePanel;
import org.geoserver.web.wicket.ParamResourceModel; import org.geoserver.web.wicket.ParamResourceModel;
Expand Down Expand Up @@ -82,7 +78,8 @@ public abstract class SolrConfigurationPage extends Panel {
* @see {@link SolrAttribute} * @see {@link SolrAttribute}
* *
*/ */
public SolrConfigurationPage(String panelId, final IModel model) { public SolrConfigurationPage(String panelId,
final IModel model) {
super(panelId, model); super(panelId, model);


ResourceInfo ri = (ResourceInfo) model.getObject(); ResourceInfo ri = (ResourceInfo) model.getObject();
Expand Down Expand Up @@ -130,7 +127,7 @@ protected void onSubmit(AjaxRequestTarget target, Form form) {
* Do nothing * Do nothing
*/ */
protected void onCancel(AjaxRequestTarget target) { protected void onCancel(AjaxRequestTarget target) {
done(target, null, null); done(target, null);
} }


/** /**
Expand Down Expand Up @@ -178,29 +175,9 @@ protected void onSave(AjaxRequestTarget target) {
target.addComponent(feedbackPanel); target.addComponent(feedbackPanel);
return; return;
} }

ri.getMetadata().put(SolrLayerConfiguration.KEY, layerConfiguration);
Catalog catalog = ((GeoServerApplication) this.getPage().getApplication()).getCatalog();
LayerInfo layerInfo = catalog.getLayerByName(ri.getQualifiedName()); done(target, ri);
FeatureTypeInfo typeInfo;
Boolean isNew = true;
if (layerInfo == null) {
// New
DataStoreInfo dsInfo = catalog.getStore(ri.getStore().getId(), DataStoreInfo.class);
SolrDataStore ds = (SolrDataStore) dsInfo.getDataStore(null);
CatalogBuilder builder = new CatalogBuilder(catalog);
builder.setStore(dsInfo);
ds.setSolrConfigurations(layerConfiguration);
typeInfo = builder.buildFeatureType(ds.getFeatureSource(ri.getQualifiedName()));
typeInfo.getMetadata().put(SolrLayerConfiguration.KEY, layerConfiguration);
layerInfo = builder.buildLayer(typeInfo);
} else {
// Update
isNew = false;
ResourceInfo resourceInfo = layerInfo.getResource();
FeatureTypeInfo featureTypeInfo = (FeatureTypeInfo) resourceInfo;
featureTypeInfo.getMetadata().put(SolrLayerConfiguration.KEY, layerConfiguration);
}
done(target, layerInfo, isNew);


} catch (Exception e) { } catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
Expand Down Expand Up @@ -354,6 +331,6 @@ public String getIdValue(Object object, int index) {
* @see {@link #onCancel} * @see {@link #onCancel}
* *
*/ */
abstract void done(AjaxRequestTarget target, LayerInfo layerInfo, Boolean isNew); abstract void done(AjaxRequestTarget target, ResourceInfo layerInfo);


} }
@@ -1,13 +1,10 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved /* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */


package org.geoserver.solr; package org.geoserver.solr;


import java.io.IOException;
import java.util.logging.Level;

import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand All @@ -22,7 +19,6 @@
import org.geoserver.web.data.resource.ResourceConfigurationPage; import org.geoserver.web.data.resource.ResourceConfigurationPage;
import org.geoserver.web.data.resource.ResourceConfigurationPanel; import org.geoserver.web.data.resource.ResourceConfigurationPanel;
import org.geoserver.web.wicket.ParamResourceModel; import org.geoserver.web.wicket.ParamResourceModel;
import org.geotools.data.solr.SolrLayerConfiguration;


/** /**
* Resource configuration panel to show a link to open SOLR attribute modal dialog <br> * Resource configuration panel to show a link to open SOLR attribute modal dialog <br>
Expand All @@ -49,7 +45,6 @@ public class SolrConfigurationPanel extends ResourceConfigurationPanel {
public SolrConfigurationPanel(final String panelId, final IModel model) { public SolrConfigurationPanel(final String panelId, final IModel model) {
super(panelId, model); super(panelId, model);
final FeatureTypeInfo fti = (FeatureTypeInfo) model.getObject(); final FeatureTypeInfo fti = (FeatureTypeInfo) model.getObject();
final ResourceConfigurationPanel current = this;


final ModalWindow modal = new ModalWindow("modal"); final ModalWindow modal = new ModalWindow("modal");
modal.setInitialWidth(800); modal.setInitialWidth(800);
Expand All @@ -75,15 +70,16 @@ public void onClose(AjaxRequestTarget target) {
} }
}); });


if (fti.getMetadata().get(SolrLayerConfiguration.KEY) == null) { if (fti.getId() == null) {
modal.add(new OpenWindowOnLoadBehavior()); modal.add(new OpenWindowOnLoadBehavior());
} }


modal.setContent(new SolrConfigurationPage(panelId, model) { modal.setContent(new SolrConfigurationPage(panelId, model) {
@Override @Override
void done(AjaxRequestTarget target, LayerInfo layerInfo, Boolean isNew) { void done(AjaxRequestTarget target, ResourceInfo resource) {
_layerInfo = layerInfo; ResourceConfigurationPage page = (ResourceConfigurationPage) SolrConfigurationPanel.this
_isNew = isNew; .getPage();
page.updateResource(resource, target);
modal.close(target); modal.close(target);
} }
}); });
Expand All @@ -105,10 +101,15 @@ public void onClick(AjaxRequestTarget target) {
* Open modal dialog on window load * Open modal dialog on window load
*/ */
private class OpenWindowOnLoadBehavior extends AbstractDefaultAjaxBehavior { private class OpenWindowOnLoadBehavior extends AbstractDefaultAjaxBehavior {
boolean first = true;

@Override @Override
protected void respond(AjaxRequestTarget target) { protected void respond(AjaxRequestTarget target) {
ModalWindow window = (ModalWindow) getComponent(); if (first) {
window.show(target); ModalWindow window = (ModalWindow) getComponent();
window.show(target);
first = false;
}
} }


@Override @Override
Expand Down
@@ -1,13 +1,21 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved /* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */
package org.geoserver.solr; package org.geoserver.solr;


import java.io.IOException; import java.io.IOException;
import java.io.Serializable;


import org.geoserver.catalog.FeatureTypeInfo; import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogException;
import org.geoserver.catalog.FeatureTypeCallback; import org.geoserver.catalog.FeatureTypeCallback;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.event.CatalogAddEvent;
import org.geoserver.catalog.event.CatalogListener;
import org.geoserver.catalog.event.CatalogModifyEvent;
import org.geoserver.catalog.event.CatalogPostModifyEvent;
import org.geoserver.catalog.event.CatalogRemoveEvent;
import org.geotools.data.DataAccess; import org.geotools.data.DataAccess;
import org.geotools.data.solr.SolrDataStore; import org.geotools.data.solr.SolrDataStore;
import org.geotools.data.solr.SolrLayerConfiguration; import org.geotools.data.solr.SolrLayerConfiguration;
Expand All @@ -22,7 +30,14 @@
* @see {@link FeatureTypeCallback} * @see {@link FeatureTypeCallback}
* *
*/ */
public class SolrFeatureTypeCallback implements FeatureTypeCallback { public class SolrFeatureTypeCallback implements FeatureTypeCallback, CatalogListener {

Catalog catalog;

public SolrFeatureTypeCallback(Catalog catalog) {
this.catalog = catalog;
catalog.addListener(this);
}


@Override @Override
public boolean canHandle(FeatureTypeInfo info, public boolean canHandle(FeatureTypeInfo info,
Expand Down Expand Up @@ -64,4 +79,90 @@ public void flush(FeatureTypeInfo info,
// nothing to do // nothing to do
} }


@Override
public void handleAddEvent(CatalogAddEvent event) throws CatalogException {
if (event.getSource() instanceof FeatureTypeInfo) {
FeatureTypeInfo ft = (FeatureTypeInfo) event.getSource();
Serializable config = ft.getMetadata().get(SolrLayerConfiguration.KEY);
if (config instanceof SolrLayerConfiguration) {
updateSolrConfiguration(ft, (SolrLayerConfiguration) config);
}
}
}

@Override
public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException {
// remove the configuration if the layer is a SOLR one
if (event.getSource() instanceof FeatureTypeInfo) {
FeatureTypeInfo ft = (FeatureTypeInfo) event.getSource();
Serializable config = ft.getMetadata().get(SolrLayerConfiguration.KEY);
if (config instanceof SolrLayerConfiguration) {
SolrLayerConfiguration slc = (SolrLayerConfiguration) config;
// go directly to the resource pool to avoid security wrappers
try {
DataAccess<? extends FeatureType, ? extends Feature> dataStore = catalog
.getResourcePool()
.getDataStore(ft.getStore());
if (dataStore instanceof SolrDataStore) {
SolrDataStore solr = (SolrDataStore) dataStore;
solr.getSolrConfigurations().remove(slc.getLayerName());
}
} catch (IOException e) {
throw new CatalogException(
"Failed to remove layer configuration from data store", e);
}
}
}

}

@Override
public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException {
// nothing to do
System.out.println(event);
}

@Override
public void handlePostModifyEvent(CatalogPostModifyEvent event) throws CatalogException {
// remove the configuration if the layer is a SOLR one
if (event.getSource() instanceof FeatureTypeInfo) {
FeatureTypeInfo ft = (FeatureTypeInfo) event.getSource();
Serializable config = ft.getMetadata().get(SolrLayerConfiguration.KEY);
if (config instanceof SolrLayerConfiguration) {
SolrLayerConfiguration slc = (SolrLayerConfiguration) config;
if (!ft.getName().equals(slc.getLayerName())) {
updateSolrConfiguration(ft, slc);
}

}
}

}

private void updateSolrConfiguration(FeatureTypeInfo ft, SolrLayerConfiguration slc) {
// go directly to the resource pool to avoid security wrappers
try {
DataAccess<? extends FeatureType, ? extends Feature> dataStore = catalog
.getResourcePool().getDataStore(ft.getStore());
if (dataStore instanceof SolrDataStore) {
SolrDataStore solr = (SolrDataStore) dataStore;
solr.getSolrConfigurations().remove(slc.getLayerName());
slc.setLayerName(ft.getName());
solr.setSolrConfigurations(slc);
}
} catch (IOException e) {
throw new CatalogException(
"Failed to remove layer configuration from data store", e);
}
FeatureTypeInfo proxy = catalog.getFeatureType(ft.getId());
proxy.setNativeName(ft.getName());
proxy.getMetadata().put(SolrLayerConfiguration.KEY, slc);
catalog.save(proxy);
}

@Override
public void reloaded() {
// nothing to do
}

} }
Expand Up @@ -61,6 +61,10 @@ public class FeatureResourceConfigurationPanel extends ResourceConfigurationPane
static final Logger LOGGER = Logging.getLogger(FeatureResourceConfigurationPanel.class); static final Logger LOGGER = Logging.getLogger(FeatureResourceConfigurationPanel.class);


ModalWindow reloadWarningDialog; ModalWindow reloadWarningDialog;

ListView attributes;

private Fragment attributePanel;


public FeatureResourceConfigurationPanel(String id, final IModel model) { public FeatureResourceConfigurationPanel(String id, final IModel model) {
super(id, model); super(id, model);
Expand All @@ -71,7 +75,7 @@ public FeatureResourceConfigurationPanel(String id, final IModel model) {
TextField<Measure> tolerance = new TextField<Measure>("linearizationTolerance", Measure.class); TextField<Measure> tolerance = new TextField<Measure>("linearizationTolerance", Measure.class);
add(tolerance); add(tolerance);


final Fragment attributePanel = new Fragment("attributePanel", "attributePanelFragment", this); attributePanel = new Fragment("attributePanel", "attributePanelFragment", this);
attributePanel.setOutputMarkupId(true); attributePanel.setOutputMarkupId(true);
add(attributePanel); add(attributePanel);


Expand All @@ -81,7 +85,7 @@ public FeatureResourceConfigurationPanel(String id, final IModel model) {
// to the ResourcePoool // to the ResourcePoool


// just use the direct attributes, this is not editable atm // just use the direct attributes, this is not editable atm
ListView attributes = new ListView("attributes", new AttributeListModel()) { attributes = new ListView("attributes", new AttributeListModel()) {
@Override @Override
protected void populateItem(ListItem item) { protected void populateItem(ListItem item) {


Expand Down Expand Up @@ -199,6 +203,11 @@ public void onClick() {
cascadedStoredQueryContainer.setVisible(typeInfo.getMetadata().get(FeatureTypeInfo.STORED_QUERY_CONFIGURATION, StoredQueryConfiguration.class) != null); cascadedStoredQueryContainer.setVisible(typeInfo.getMetadata().get(FeatureTypeInfo.STORED_QUERY_CONFIGURATION, StoredQueryConfiguration.class) != null);
} }


@Override
public void resourceUpdated(AjaxRequestTarget target) {
target.addComponent(attributePanel);
}

static class ReloadWarningDialog extends WebPage { static class ReloadWarningDialog extends WebPage {
public ReloadWarningDialog(StringResourceModel message) { public ReloadWarningDialog(StringResourceModel message) {
add(new Label("message", message)); add(new Label("message", message));
Expand Down

0 comments on commit d513a85

Please sign in to comment.