public void testHookExecution() throws Exception { File script = copyOverFile("tx"); TransactionRequest tx = new TransactionRequest.WFS11(null); TransactionResponse res = new TransactionResponse.WFS11(null); Map context = new HashMap(); ScriptEngine eng = scriptMgr.createNewEngine(script); eng.eval(new FileReader(script)); WfsTxHook hook = getScriptManager().lookupWfsTxHook(script); hook.handleBefore(eng, tx, context); hook.handlePreInsert(eng, null, tx, context); hook.handlePostInsert(eng, null, tx, context); hook.handlePreUpdate(eng, null, null, tx, context); hook.handlePostUpdate(eng, null, null, tx, context); hook.handlePreDelete(eng, null, tx, context); hook.handlePostDelete(eng, null, tx, context); hook.handlePreCommit(eng, tx, context); hook.handlePostCommit(eng, tx, res, context); hook.handleAbort(eng, tx, res, context); assertTrue(context.containsKey("before")); assertTrue(context.containsKey("preInsert")); assertTrue(context.containsKey("postInsert")); assertTrue(context.containsKey("preUpdate")); assertTrue(context.containsKey("postUpdate")); assertTrue(context.containsKey("preDelete")); assertTrue(context.containsKey("postDelete")); assertTrue(context.containsKey("preCommit")); assertTrue(context.containsKey("postCommit")); assertTrue(context.containsKey("abort")); }
public void addInsertedFeature(String handle, FeatureId featureId) { InsertedFeatureType insertedFeature = ((WfsFactory) getFactory()).createInsertedFeatureType(); insertedFeature.setHandle(handle); insertedFeature.getFeatureId().add(featureId); ((TransactionResponseType) adaptee) .getInsertResults() .getFeature() .add(insertedFeature); }
public void testHookError() throws Exception { File script = copyOverFile("tx-error"); TransactionRequest tx = new TransactionRequest.WFS11(null); TransactionResponse res = new TransactionResponse.WFS11(null); Map context = new HashMap(); ScriptEngine eng = scriptMgr.createNewEngine(script); eng.eval(new FileReader(script)); WfsTxHook hook = getScriptManager().lookupWfsTxHook(script); try { hook.handleBefore(eng, tx, context); fail("exected WFS exception"); } catch (WFSException e) { assertEquals("before exception", e.getMessage()); } } }
@Override public void setHandle(String handle) { eSet(adaptee, "transactionResults.handle", handle); }
private void fireAfterTransaction( TransactionRequest request, TransactionResponse result, boolean committed) { TransactionType tx = TransactionRequest.WFS11.unadapt(request); TransactionResponseType tr = TransactionResponse.WFS11.unadapt(result); if (tx != null && tr != null) { for (TransactionPlugin tp : transactionPlugins) { tp.afterTransaction(tx, tr, committed); } } for (TransactionCallback tp : transactionPlugins2) { tp.afterTransaction(request, result, committed); } }
@Override public TransactionResponse createResponse() { WfsFactory factory = (WfsFactory) getFactory(); TransactionResponseType tr = factory.createTransactionResponseType(); tr.setTransactionSummary(factory.createTransactionSummaryType()); tr.getTransactionSummary().setTotalInserted(BigInteger.valueOf(0)); tr.getTransactionSummary().setTotalUpdated(BigInteger.valueOf(0)); tr.getTransactionSummary().setTotalDeleted(BigInteger.valueOf(0)); tr.setTransactionResults(factory.createTransactionResultsType()); tr.setInsertResults(factory.createInsertResultsType()); return new TransactionResponse.WFS11(tr); }
public static TransactionResponse adapt(Object request) { if (request instanceof TransactionResponseType) { return new WFS11((EObject) request); } else if (request instanceof net.opengis.wfs20.TransactionResponseType) { return new WFS20((EObject) request); } return null; }
@Override public void addAction(String code, String locator, String message) { // transaction failed, rollback ActionType action = ((WfsFactory) getFactory()).createActionType(); action.setCode(code); action.setLocator(locator); action.setMessage(message); ((TransactionResponseType) adaptee).getTransactionResults().getAction().add(action); }