@Test public void testRunScriptOnConnector() { final OracleERPConfiguration cfg = getConfiguration(CONFIG_SYSADM); final String scriptText = IOUtil.getResourceAsString(this.getClass(), USER_AFTER_ACTION); final ScriptBuilder sb = new ScriptBuilder().setScriptLanguage(GROOVY).setScriptText(scriptText); cfg.setUserAfterActionScript(sb.build()); final OracleERPConnector c = getConnector(cfg); final Set<Attribute> attrs = getAttributeSet(ACCOUNT_ALL_ATTRS); replaceNameByRandom(attrs); final Uid uid = c.create(ObjectClass.ACCOUNT, attrs, null); AssertJUnit.assertNotNull(uid); List<ConnectorObject> results = TestHelpers.searchToList(c, ObjectClass.ACCOUNT, FilterBuilder.equalTo(uid)); AssertJUnit.assertTrue("expect 1 connector object", results.size() == 1); final ConnectorObject co = results.get(0); final Set<Attribute> returned = co.getAttributes(); final Attribute find = AttributeUtil.find(HR_EMP_NUM, returned); AssertJUnit.assertNotNull(HR_EMP_NUM, find); final List<Object> value = find.getValue(); AssertJUnit.assertEquals(HR_EMP_NUM, 1, value.size()); AssertJUnit.assertEquals(HR_EMP_NUM, "5", value.get(0)); }
public ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob) { final Map<String, Object> changedAttributes = new HashMap<String, Object>(); final Map<String, Object> actionContext = new HashMap<String, Object>(); final Map<String, Object> inputMap = new HashMap<String, Object>(); final List<String> errorList = new ArrayList<String>(); actionContext.put(CONN, getConn().getConnection()); actionContext.put(ACTION, OP_GET_USER); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(cob.build().getAttributes()); actionContext.put(CURRENT_ATTRIBUTES, scriptAttributes); actionContext.put(CHANGED_ATTRIBUTES, changedAttributes); actionContext.put(ID, userName); actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, ID: {1}, scriptAttributes: {2}", OP_GET_USER, userName, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = getCfg().getUserAfterActionScript().getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final String scriptText = getCfg().getUserAfterActionScript().getScriptText(); LOG.ok("execute GetUserAfterAction script: {0}", scriptText); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); scripEx.execute(inputMap); StringBuilder errorBld = new StringBuilder(); for (String s : errorList) { errorBld.append(s); errorBld.append("; "); } if (errorBld.length() != 0) { final String msg = errorBld.toString(); LOG.error("errors in script: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { LOG.error(e, "error in script"); SQLUtil.rollbackQuietly(getConn()); throw ConnectorException.wrap(e); } for (Entry<String, Object> entry : changedAttributes.entrySet()) { cob.addAttribute(entry.getKey(), entry.getValue()); } return cob; }
AccountOperationGetUserAfterAction extends Operation { public ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob) { final Map<String, Object> changedAttributes = new HashMap<String, Object>(); final Map<String, Object> actionContext = new HashMap<String, Object>(); final Map<String, Object> inputMap = new HashMap<String, Object>(); final List<String> errorList = new ArrayList<String>(); actionContext.put(CONN, getConn().getConnection()); actionContext.put(ACTION, OP_GET_USER); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(cob.build().getAttributes()); actionContext.put(CURRENT_ATTRIBUTES, scriptAttributes); actionContext.put(CHANGED_ATTRIBUTES, changedAttributes); actionContext.put(ID, userName); actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, ID: {1}, scriptAttributes: {2}", OP_GET_USER, userName, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = getCfg().getUserAfterActionScript().getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final String scriptText = getCfg().getUserAfterActionScript().getScriptText(); LOG.ok("execute GetUserAfterAction script: {0}", scriptText); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); scripEx.execute(inputMap); StringBuilder errorBld = new StringBuilder(); for (String s : errorList) { errorBld.append(s); errorBld.append("; "); } if (errorBld.length() != 0) { final String msg = errorBld.toString(); LOG.error("errors in script: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { LOG.error(e, "error in script"); SQLUtil.rollbackQuietly(getConn()); throw ConnectorException.wrap(e); } for (Entry<String, Object> entry : changedAttributes.entrySet()) { cob.addAttribute(entry.getKey(), entry.getValue()); } return cob; } }
AccountOperationGetUserAfterAction extends Operation { public ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob) { final Map<String, Object> changedAttributes = new HashMap<String, Object>(); final Map<String, Object> actionContext = new HashMap<String, Object>(); final Map<String, Object> inputMap = new HashMap<String, Object>(); final List<String> errorList = new ArrayList<String>(); actionContext.put(CONN, getConn().getConnection()); actionContext.put(ACTION, OP_GET_USER); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(cob.build().getAttributes()); actionContext.put(CURRENT_ATTRIBUTES, scriptAttributes); actionContext.put(CHANGED_ATTRIBUTES, changedAttributes); actionContext.put(ID, userName); actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, ID: {1}, scriptAttributes: {2}", OP_GET_USER, userName, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = getCfg().getUserAfterActionScript().getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final String scriptText = getCfg().getUserAfterActionScript().getScriptText(); LOG.ok("execute GetUserAfterAction script: {0}", scriptText); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); scripEx.execute(inputMap); StringBuilder errorBld = new StringBuilder(); for (String s : errorList) { errorBld.append(s); errorBld.append("; "); } if (errorBld.length() != 0) { final String msg = errorBld.toString(); LOG.error("errors in script: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { LOG.error(e, "error in script"); SQLUtil.rollbackQuietly(getConn()); throw ConnectorException.wrap(e); } for (Entry<String, Object> entry : changedAttributes.entrySet()) { cob.addAttribute(entry.getKey(), entry.getValue()); } return cob; } AccountOperationGetUserAfterAction(OracleERPConnection conn, OracleERPConfiguration cfg); }
AccountOperationGetUserAfterAction extends Operation { public ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob) { final Map<String, Object> changedAttributes = new HashMap<String, Object>(); final Map<String, Object> actionContext = new HashMap<String, Object>(); final Map<String, Object> inputMap = new HashMap<String, Object>(); final List<String> errorList = new ArrayList<String>(); actionContext.put(CONN, getConn().getConnection()); actionContext.put(ACTION, OP_GET_USER); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(cob.build().getAttributes()); actionContext.put(CURRENT_ATTRIBUTES, scriptAttributes); actionContext.put(CHANGED_ATTRIBUTES, changedAttributes); actionContext.put(ID, userName); actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, ID: {1}, scriptAttributes: {2}", OP_GET_USER, userName, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = getCfg().getUserAfterActionScript().getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final String scriptText = getCfg().getUserAfterActionScript().getScriptText(); LOG.ok("execute GetUserAfterAction script: {0}", scriptText); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); scripEx.execute(inputMap); StringBuilder errorBld = new StringBuilder(); for (String s : errorList) { errorBld.append(s); errorBld.append("; "); } if (errorBld.length() != 0) { final String msg = errorBld.toString(); LOG.error("errors in script: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { LOG.error(e, "error in script"); SQLUtil.rollbackQuietly(getConn()); throw ConnectorException.wrap(e); } for (Entry<String, Object> entry : changedAttributes.entrySet()) { cob.addAttribute(entry.getKey(), entry.getValue()); } return cob; } AccountOperationGetUserAfterAction(OracleERPConnection conn, OracleERPConfiguration cfg); ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob); }
AccountOperationGetUserAfterAction extends Operation { public ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob) { final Map<String, Object> changedAttributes = new HashMap<String, Object>(); final Map<String, Object> actionContext = new HashMap<String, Object>(); final Map<String, Object> inputMap = new HashMap<String, Object>(); final List<String> errorList = new ArrayList<String>(); actionContext.put(CONN, getConn().getConnection()); actionContext.put(ACTION, OP_GET_USER); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(cob.build().getAttributes()); actionContext.put(CURRENT_ATTRIBUTES, scriptAttributes); actionContext.put(CHANGED_ATTRIBUTES, changedAttributes); actionContext.put(ID, userName); actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, ID: {1}, scriptAttributes: {2}", OP_GET_USER, userName, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = getCfg().getUserAfterActionScript().getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final String scriptText = getCfg().getUserAfterActionScript().getScriptText(); LOG.ok("execute GetUserAfterAction script: {0}", scriptText); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); scripEx.execute(inputMap); StringBuilder errorBld = new StringBuilder(); for (String s : errorList) { errorBld.append(s); errorBld.append("; "); } if (errorBld.length() != 0) { final String msg = errorBld.toString(); LOG.error("errors in script: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { LOG.error(e, "error in script"); SQLUtil.rollbackQuietly(getConn()); throw ConnectorException.wrap(e); } for (Entry<String, Object> entry : changedAttributes.entrySet()) { cob.addAttribute(entry.getKey(), entry.getValue()); } return cob; } AccountOperationGetUserAfterAction(OracleERPConnection conn, OracleERPConfiguration cfg); ConnectorObjectBuilder runScriptOnConnector(Object userName, ConnectorObjectBuilder cob);  }