Skip to content

Commit

Permalink
[GEOS-7403] TransactionPlugin can no longer alter transaction items -…
Browse files Browse the repository at this point in the history
… Apply Jody's feedback
  • Loading branch information
aaime committed Oct 31, 2017
1 parent 31550b3 commit 65ea527
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* @version $Id$
*
*/
public class GWCTransactionListener implements TransactionPlugin2 {
public class GWCTransactionListener implements TransactionCallback {

private static Logger log = Logging.getLogger(GWCTransactionListener.class);

Expand Down
11 changes: 5 additions & 6 deletions src/wfs/src/main/java/org/geoserver/wfs/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Transaction {
protected List<TransactionElementHandler> transactionElementHandlers = new ArrayList<>();
protected List<TransactionListener> transactionListeners = new ArrayList<>();
protected List<TransactionPlugin> transactionPlugins = new ArrayList<>();
protected List<TransactionPlugin2> transactionPlugins2 = new ArrayList<>();
protected List<TransactionCallback> transactionPlugins2 = new ArrayList<>();

public Transaction(WFSInfo wfs, Catalog catalog, ApplicationContext context) {
this.wfs = wfs;
Expand All @@ -84,7 +84,7 @@ public Transaction(WFSInfo wfs, Catalog catalog, ApplicationContext context) {
transactionElementHandlers.addAll(GeoServerExtensions.extensions(TransactionElementHandler.class));
transactionListeners.addAll(GeoServerExtensions.extensions(TransactionListener.class));
transactionPlugins.addAll(GeoServerExtensions.extensions(TransactionPlugin.class));
transactionPlugins2.addAll(GeoServerExtensions.extensions(TransactionPlugin2.class));
transactionPlugins2.addAll(GeoServerExtensions.extensions(TransactionCallback.class));
// plugins are listeners too, but I want to make sure they are notified
// of
// changes in the same order as the other plugin callbacks
Expand Down Expand Up @@ -447,7 +447,7 @@ private TransactionRequest fireBeforeTransaction(TransactionRequest request) {
tp.beforeTransaction(tx);
}
}
for (TransactionPlugin2 tp : transactionPlugins2) {
for (TransactionCallback tp : transactionPlugins2) {
request = tp.beforeTransaction(request);
}

Expand All @@ -462,7 +462,7 @@ private void fireAfterTransaction(TransactionRequest request, TransactionRespons
tp.afterTransaction(tx, tr, committed);
}
}
for (TransactionPlugin2 tp : transactionPlugins2) {
for (TransactionCallback tp : transactionPlugins2) {
tp.afterTransaction(request, result, committed);
}
}
Expand All @@ -475,7 +475,7 @@ private void fireBeforeCommit(TransactionRequest request) {
tp.beforeCommit(tx);
}
}
for (TransactionPlugin2 tp : transactionPlugins2) {
for (TransactionCallback tp : transactionPlugins2) {
tp.beforeCommit(request);
}
}
Expand Down Expand Up @@ -684,7 +684,6 @@ public void dataStoreChange(List listeners, TransactionEvent event)
public void dataStoreChange(TransactionEvent event)
throws WFSException {
dataStoreChange(transactionPlugins, event);
dataStoreChange(transactionPlugins2, event);
dataStoreChange(transactionListeners, event);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* A transaction plugin is able to listen to a transaction evolution, perform
* checks and throw exceptions, alter transaction requests, as well as
*/
public interface TransactionPlugin2 extends TransactionListener, ExtensionPriority {
public interface TransactionCallback extends ExtensionPriority {
/**
* Check/alter the transaction request elements
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* A transaction plugin is able to listen to a transaction evolution, perform
* checks and throw exceptions, alter transaction requests, as well as
* @deprecated Use {@link TransactionPlugin2 instead}
* @deprecated Use {@link TransactionCallback instead}
*/
@Deprecated
public interface TransactionPlugin extends TransactionListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="transactionPlugin2Tester" class="org.geoserver.wfs.TransactionPlugin2Tester">
<bean id="transactionCallbackTester" class="org.geoserver.wfs.TransactionCallbackTester">
<constructor-arg index="0" ref="catalog"/>
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTReader;
import net.opengis.wfs.*;
import org.geoserver.catalog.Catalog;
import org.geoserver.data.test.MockData;
import org.geoserver.wfs.request.*;
Expand All @@ -13,14 +12,12 @@
import org.opengis.feature.simple.SimpleFeatureType;

import javax.xml.namespace.QName;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

public class TransactionPlugin2Tester extends TransactionListenerTester implements TransactionPlugin2 {
public class TransactionCallbackTester implements TransactionCallback {

public static final String FOLSOM_STREET = "Folsom Street";

Expand Down Expand Up @@ -120,10 +117,10 @@ public static TransactionRequest replaceWithFixedRoadsDelete(Catalog catalog, Tr
boolean beforeCommitCalled;
TransactionRequest request;
BiFunction<Catalog, TransactionRequest, TransactionRequest> beforeTransaction =
TransactionPlugin2Tester::defaultTransformation;
TransactionCallbackTester::defaultTransformation;
Catalog catalog;

public TransactionPlugin2Tester(Catalog catalog) {
public TransactionCallbackTester(Catalog catalog) {
this.catalog = catalog;
}

Expand All @@ -148,12 +145,10 @@ public void afterTransaction(TransactionRequest request, TransactionResponse res
this.committed = committed;
}

@Override
public void clear() {
super.clear();
this.result = null;
this.committed = false;
this.beforeCommitCalled = false;
this.beforeTransaction = TransactionPlugin2Tester::defaultTransformation;
this.beforeTransaction = TransactionCallbackTester::defaultTransformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TransactionPluginWFS11Test extends WFSTestSupport {
public class TransactionCallbackWFS11Test extends WFSTestSupport {

public static final String DELETE_ROAD_102 = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\"" +
" xmlns:cite=\"http://www.opengis.net/cite\"" +
Expand All @@ -31,18 +31,18 @@ public class TransactionPluginWFS11Test extends WFSTestSupport {
" </ogc:Filter>" +
" </wfs:Delete>" +
"</wfs:Transaction>";
private TransactionPlugin2Tester plugin;
private TransactionCallbackTester plugin;

@Override
protected void setUpSpring(List<String> springContextLocations) {
super.setUpSpring(springContextLocations);
springContextLocations.add("classpath:/org/geoserver/wfs/TransactionPlugin2TestContext.xml");
springContextLocations.add("classpath:/org/geoserver/wfs/TransactionCallbackTestContext.xml");
}

@Before
public void clearState() throws Exception {
revertLayer(MockData.ROAD_SEGMENTS);
plugin = (TransactionPlugin2Tester) applicationContext.getBean("transactionPlugin2Tester");
plugin = (TransactionCallbackTester) applicationContext.getBean("transactionCallbackTester");
plugin.clear();
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public void testUpdate() throws Exception {
Document roadSegments = getAsDOM("wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=cite:RoadSegments" +
"&CQL_FILTER=FID=102");
// print(roadSegments);
assertXpathEvaluatesTo(TransactionPlugin2Tester.FOLSOM_STREET, "//cite:RoadSegments/cite:NAME", roadSegments);
assertXpathEvaluatesTo(TransactionCallbackTester.FOLSOM_STREET, "//cite:RoadSegments/cite:NAME", roadSegments);
}


Expand Down Expand Up @@ -165,7 +165,7 @@ public void testDelete() throws Exception {
@Test
public void testReplaceWithInsert() throws Exception {
// the plugin will remove all elements and replace it with an insert
plugin.beforeTransaction = TransactionPlugin2Tester::replaceWithFixedRoadsInsert;
plugin.beforeTransaction = TransactionCallbackTester::replaceWithFixedRoadsInsert;
String xml = DELETE_ROAD_102;

Document dom = postAsDOM("wfs", xml);
Expand All @@ -191,7 +191,7 @@ public void testReplaceWithInsert() throws Exception {
@Test
public void testReplaceWithUpdate() throws Exception {
// the plugin will remove all elements and replace it with a fixed delete on road 106
plugin.beforeTransaction = TransactionPlugin2Tester::replaceWithFixedRoadsUpdate;
plugin.beforeTransaction = TransactionCallbackTester::replaceWithFixedRoadsUpdate;
String xml = DELETE_ROAD_102;

Document dom = postAsDOM("wfs", xml);
Expand All @@ -217,7 +217,7 @@ public void testReplaceWithUpdate() throws Exception {
@Test
public void testReplaceWithDelete() throws Exception {
// the plugin will remove all elements and replace it with a fixed delete on road 106
plugin.beforeTransaction = TransactionPlugin2Tester::replaceWithFixedRoadsDelete;
plugin.beforeTransaction = TransactionCallbackTester::replaceWithFixedRoadsDelete;
String xml = DELETE_ROAD_102;

Document dom = postAsDOM("wfs", xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TransactionPluginWFS20Test extends WFS20TestSupport {
public class TransactionCallbackWFS20Test extends WFS20TestSupport {

public static final String DELETE_ROAD_102 = "<wfs:Transaction service=\"WFS\" version=\"2.0.0\" " +
"xmlns:cite=\"http://www.opengis.net/cite\" " +
Expand All @@ -35,18 +35,18 @@ public class TransactionPluginWFS20Test extends WFS20TestSupport {
" </fes:Filter>" +
" </wfs:Delete>" +
"</wfs:Transaction>";
private TransactionPlugin2Tester plugin;
private TransactionCallbackTester plugin;

@Override
protected void setUpSpring(List<String> springContextLocations) {
super.setUpSpring(springContextLocations);
springContextLocations.add("classpath:/org/geoserver/wfs/TransactionPlugin2TestContext.xml");
springContextLocations.add("classpath:/org/geoserver/wfs/TransactionCallbackTestContext.xml");
}

@Before
public void clearState() throws Exception {
revertLayer(MockData.ROAD_SEGMENTS);
plugin = (TransactionPlugin2Tester) applicationContext.getBean("transactionPlugin2Tester");
plugin = (TransactionCallbackTester) applicationContext.getBean("transactionCallbackTester");
plugin.clear();
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public void testUpdate() throws Exception {
// check the road name has been modified too
Document roadSegments = getAsDOM("wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=cite:RoadSegments&CQL_FILTER=FID=102");
// print(roadSegments);
assertXpathEvaluatesTo(TransactionPlugin2Tester.FOLSOM_STREET, "//cite:RoadSegments/cite:NAME", roadSegments);
assertXpathEvaluatesTo(TransactionCallbackTester.FOLSOM_STREET, "//cite:RoadSegments/cite:NAME", roadSegments);
}


Expand Down Expand Up @@ -169,7 +169,7 @@ public void testDelete() throws Exception {
@Test
public void testReplaceWithInsert() throws Exception {
// the plugin will remove all elements and replace it with an insert
plugin.beforeTransaction = TransactionPlugin2Tester::replaceWithFixedRoadsInsert;
plugin.beforeTransaction = TransactionCallbackTester::replaceWithFixedRoadsInsert;
String xml = DELETE_ROAD_102;

Document dom = postAsDOM("wfs", xml);
Expand All @@ -195,7 +195,7 @@ public void testReplaceWithInsert() throws Exception {
@Test
public void testReplaceWithUpdate() throws Exception {
// the plugin will remove all elements and replace it with a fixed update on Dirt road
plugin.beforeTransaction = TransactionPlugin2Tester::replaceWithFixedRoadsUpdate;
plugin.beforeTransaction = TransactionCallbackTester::replaceWithFixedRoadsUpdate;
String xml = DELETE_ROAD_102;
Document dom = postAsDOM("wfs", xml);
// print(dom);
Expand All @@ -220,7 +220,7 @@ public void testReplaceWithUpdate() throws Exception {
@Test
public void testReplaceWithDelete() throws Exception {
// the plugin will remove all elements and replace it with a fixed delete on road 106
plugin.beforeTransaction = TransactionPlugin2Tester::replaceWithFixedRoadsDelete;
plugin.beforeTransaction = TransactionCallbackTester::replaceWithFixedRoadsDelete;
String xml = DELETE_ROAD_102;

Document dom = postAsDOM("wfs", xml);
Expand Down

0 comments on commit 65ea527

Please sign in to comment.