@Test(expectedExceptions = ConnectorException.class) public void testRunScriptOnConnectorError() { final OracleERPConfiguration cfg = getConfiguration(CONFIG_SYSADM); final String scriptText = IOUtil.getResourceAsString(this.getClass(), RUN_ERROR_ACTION); 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); Map<String, Object> scriptArguments = new HashMap<String, Object>(); scriptArguments.put(Name.NAME, AttributeUtil.getNameFromAttributes(attrs)); scriptArguments.put(OperationalAttributes.PASSWORD_NAME, AttributeUtil.find( OperationalAttributes.PASSWORD_NAME, attrs)); scriptArguments.put(ACTION, "update"); scriptArguments.put(TIMING, "after"); scriptArguments.put(ATTRIBUTES, AttributeUtil.toMap(attrs)); ScriptContext request = new ScriptContext(GROOVY, scriptText, scriptArguments); final Object ret = c.runScriptOnConnector(request, null); AssertJUnit.assertNotNull("mail not returned", ret); AssertJUnit.assertEquals("mail value", EXPECTED_MAIL, ret); }
public Object runScriptOnConnector(ScriptContext request, OperationOptions options) { final Map<String, Object> scriptArguments = request.getScriptArguments(); 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>(); Assertions.nullCheck(scriptArguments, "scriptArguments"); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(scriptArguments.get(ATTRIBUTES)); Object value = scriptAttributes.get(Uid.NAME); if (value == null) { value = scriptAttributes.get(Name.NAME); } Assertions.nullCheck(value, ID); final String id = (String) value; final Object pwdArg = scriptAttributes.get(OperationalAttributes.PASSWORD_NAME); actionContext.put(CONN, getConn().getConnection()); final Object action = scriptArguments.get(ACTION); actionContext.put(ACTION, action); final Object timing = scriptArguments.get(TIMING); actionContext.put(TIMING, timing); actionContext.put(ATTRIBUTES, scriptAttributes); actionContext.put(ID, id); if (pwdArg != null && pwdArg instanceof GuardedString) { final GuardedString password = ((GuardedString) pwdArg); password.access(new GuardedString.Accessor() { public void access(char[] clearChars) { actionContext.put(PASSWORD, new String(clearChars)); } }); } actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, timing: {1}, ID: {2}, scriptAttributes: {3}", action, timing, id, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); Object ret; final String scriptText = request.getScriptText(); LOG.ok("runScriptOnConnector execute script: {0}", scriptText); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = request.getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); ret = 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("script errors: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { final String msg = getCfg().getMessage(MSG_COULD_NOT_EXECUTE, scriptText); LOG.error(e, msg); SQLUtil.rollbackQuietly(getConn()); throw new ConnectorException(msg, e); } return ret; }
OracleERPOperationRunScriptOnConnector extends Operation implements ScriptOnConnectorOp { public Object runScriptOnConnector(ScriptContext request, OperationOptions options) { final Map<String, Object> scriptArguments = request.getScriptArguments(); 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>(); Assertions.nullCheck(scriptArguments, "scriptArguments"); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(scriptArguments.get(ATTRIBUTES)); Object value = scriptAttributes.get(Uid.NAME); if (value == null) { value = scriptAttributes.get(Name.NAME); } Assertions.nullCheck(value, ID); final String id = (String) value; final Object pwdArg = scriptAttributes.get(OperationalAttributes.PASSWORD_NAME); actionContext.put(CONN, getConn().getConnection()); final Object action = scriptArguments.get(ACTION); actionContext.put(ACTION, action); final Object timing = scriptArguments.get(TIMING); actionContext.put(TIMING, timing); actionContext.put(ATTRIBUTES, scriptAttributes); actionContext.put(ID, id); if (pwdArg != null && pwdArg instanceof GuardedString) { final GuardedString password = ((GuardedString) pwdArg); password.access(new GuardedString.Accessor() { public void access(char[] clearChars) { actionContext.put(PASSWORD, new String(clearChars)); } }); } actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, timing: {1}, ID: {2}, scriptAttributes: {3}", action, timing, id, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); Object ret; final String scriptText = request.getScriptText(); LOG.ok("runScriptOnConnector execute script: {0}", scriptText); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = request.getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); ret = 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("script errors: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { final String msg = getCfg().getMessage(MSG_COULD_NOT_EXECUTE, scriptText); LOG.error(e, msg); SQLUtil.rollbackQuietly(getConn()); throw new ConnectorException(msg, e); } return ret; } }
OracleERPOperationRunScriptOnConnector extends Operation implements ScriptOnConnectorOp { public Object runScriptOnConnector(ScriptContext request, OperationOptions options) { final Map<String, Object> scriptArguments = request.getScriptArguments(); 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>(); Assertions.nullCheck(scriptArguments, "scriptArguments"); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(scriptArguments.get(ATTRIBUTES)); Object value = scriptAttributes.get(Uid.NAME); if (value == null) { value = scriptAttributes.get(Name.NAME); } Assertions.nullCheck(value, ID); final String id = (String) value; final Object pwdArg = scriptAttributes.get(OperationalAttributes.PASSWORD_NAME); actionContext.put(CONN, getConn().getConnection()); final Object action = scriptArguments.get(ACTION); actionContext.put(ACTION, action); final Object timing = scriptArguments.get(TIMING); actionContext.put(TIMING, timing); actionContext.put(ATTRIBUTES, scriptAttributes); actionContext.put(ID, id); if (pwdArg != null && pwdArg instanceof GuardedString) { final GuardedString password = ((GuardedString) pwdArg); password.access(new GuardedString.Accessor() { public void access(char[] clearChars) { actionContext.put(PASSWORD, new String(clearChars)); } }); } actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, timing: {1}, ID: {2}, scriptAttributes: {3}", action, timing, id, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); Object ret; final String scriptText = request.getScriptText(); LOG.ok("runScriptOnConnector execute script: {0}", scriptText); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = request.getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); ret = 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("script errors: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { final String msg = getCfg().getMessage(MSG_COULD_NOT_EXECUTE, scriptText); LOG.error(e, msg); SQLUtil.rollbackQuietly(getConn()); throw new ConnectorException(msg, e); } return ret; } OracleERPOperationRunScriptOnConnector(OracleERPConnection conn, OracleERPConfiguration cfg); }
OracleERPOperationRunScriptOnConnector extends Operation implements ScriptOnConnectorOp { public Object runScriptOnConnector(ScriptContext request, OperationOptions options) { final Map<String, Object> scriptArguments = request.getScriptArguments(); 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>(); Assertions.nullCheck(scriptArguments, "scriptArguments"); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(scriptArguments.get(ATTRIBUTES)); Object value = scriptAttributes.get(Uid.NAME); if (value == null) { value = scriptAttributes.get(Name.NAME); } Assertions.nullCheck(value, ID); final String id = (String) value; final Object pwdArg = scriptAttributes.get(OperationalAttributes.PASSWORD_NAME); actionContext.put(CONN, getConn().getConnection()); final Object action = scriptArguments.get(ACTION); actionContext.put(ACTION, action); final Object timing = scriptArguments.get(TIMING); actionContext.put(TIMING, timing); actionContext.put(ATTRIBUTES, scriptAttributes); actionContext.put(ID, id); if (pwdArg != null && pwdArg instanceof GuardedString) { final GuardedString password = ((GuardedString) pwdArg); password.access(new GuardedString.Accessor() { public void access(char[] clearChars) { actionContext.put(PASSWORD, new String(clearChars)); } }); } actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, timing: {1}, ID: {2}, scriptAttributes: {3}", action, timing, id, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); Object ret; final String scriptText = request.getScriptText(); LOG.ok("runScriptOnConnector execute script: {0}", scriptText); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = request.getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); ret = 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("script errors: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { final String msg = getCfg().getMessage(MSG_COULD_NOT_EXECUTE, scriptText); LOG.error(e, msg); SQLUtil.rollbackQuietly(getConn()); throw new ConnectorException(msg, e); } return ret; } OracleERPOperationRunScriptOnConnector(OracleERPConnection conn, OracleERPConfiguration cfg); Object runScriptOnConnector(ScriptContext request, OperationOptions options); }
OracleERPOperationRunScriptOnConnector extends Operation implements ScriptOnConnectorOp { public Object runScriptOnConnector(ScriptContext request, OperationOptions options) { final Map<String, Object> scriptArguments = request.getScriptArguments(); 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>(); Assertions.nullCheck(scriptArguments, "scriptArguments"); final Map<String, Object> scriptAttributes = OracleERPUtil.getScriptAttributes(scriptArguments.get(ATTRIBUTES)); Object value = scriptAttributes.get(Uid.NAME); if (value == null) { value = scriptAttributes.get(Name.NAME); } Assertions.nullCheck(value, ID); final String id = (String) value; final Object pwdArg = scriptAttributes.get(OperationalAttributes.PASSWORD_NAME); actionContext.put(CONN, getConn().getConnection()); final Object action = scriptArguments.get(ACTION); actionContext.put(ACTION, action); final Object timing = scriptArguments.get(TIMING); actionContext.put(TIMING, timing); actionContext.put(ATTRIBUTES, scriptAttributes); actionContext.put(ID, id); if (pwdArg != null && pwdArg instanceof GuardedString) { final GuardedString password = ((GuardedString) pwdArg); password.access(new GuardedString.Accessor() { public void access(char[] clearChars) { actionContext.put(PASSWORD, new String(clearChars)); } }); } actionContext.put(TRACE, LOG); actionContext.put(ERRORS, errorList); LOG.ok("runScriptOnConnector action: {0}, timing: {1}, ID: {2}, scriptAttributes: {3}", action, timing, id, scriptAttributes); inputMap.put(ACTION_CONTEXT, actionContext); Object ret; final String scriptText = request.getScriptText(); LOG.ok("runScriptOnConnector execute script: {0}", scriptText); try { final ClassLoader loader = getClass().getClassLoader(); final String scriptLanguage = request.getScriptLanguage(); final ScriptExecutorFactory scriptExFact = ScriptExecutorFactory.newInstance(scriptLanguage); final ScriptExecutor scripEx = scriptExFact.newScriptExecutor(loader, scriptText, true); ret = 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("script errors: {0}", msg); throw new ConnectorException(msg); } getConn().commit(); } catch (Exception e) { final String msg = getCfg().getMessage(MSG_COULD_NOT_EXECUTE, scriptText); LOG.error(e, msg); SQLUtil.rollbackQuietly(getConn()); throw new ConnectorException(msg, e); } return ret; } OracleERPOperationRunScriptOnConnector(OracleERPConnection conn, OracleERPConfiguration cfg); Object runScriptOnConnector(ScriptContext request, OperationOptions options);  }