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")); }
@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); }
private TransactionRequest fireBeforeTransaction(TransactionRequest request) { TransactionType tx = TransactionRequest.WFS11.unadapt(request); if (tx != null) { // TransactionPlugin cannot alter transactions since the advent of WFS 2.0, it's left // like that and // will be deprecated for (TransactionPlugin tp : transactionPlugins) { tp.beforeTransaction(tx); } } for (TransactionCallback tp : transactionPlugins2) { request = tp.beforeTransaction(request); } return request; }
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()); } } }
public TransactionType getRequest() { return TransactionRequest.WFS11.unadapt(request); }
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); } }
/** * WFS transaction operation. * * @param request The transaction request. * @return A transaction response instance. * @throws WFSException Any service exceptions. */ public TransactionResponseType transaction(TransactionType request) throws WFSException { Transaction transaction = new Transaction(getServiceInfo(), catalog, context); transaction.setFilterFactory(filterFactory); return (TransactionResponseType) transaction.transaction(new TransactionRequest.WFS11(request)).getAdaptee(); }
@Override public Delete createDelete() { WfsFactory factory = (WfsFactory) getFactory(); return new Delete.WFS11(factory.createDeleteElementType()); }
public static TransactionRequest adapt(Object request) { if (request instanceof TransactionType) { return new WFS11((EObject) request); } else if (request instanceof net.opengis.wfs20.TransactionType) { return new WFS20((EObject) request); } return null; }
@Override public Update createUpdate() { WfsFactory factory = (WfsFactory) getFactory(); return new Update.WFS11(factory.createUpdateElementType()); }
@Override public Insert createInsert() { WfsFactory factory = (WfsFactory) getFactory(); return new Insert.WFS11(factory.createInsertElementType()); }
private void fireBeforeCommit(TransactionRequest request) { // inform plugins we're about to commit for (TransactionPlugin tp : transactionPlugins) { TransactionType tx = TransactionRequest.WFS11.unadapt(request); if (tx != null) { tp.beforeCommit(tx); } } for (TransactionCallback tp : transactionPlugins2) { tp.beforeCommit(request); } }