private Instance getConnectorConfiguration(Model model, StringToExpressionConverter converter) { final Instance configuration = model.newInstance("connectorconfiguration.ConnectorConfiguration"); configuration.set("definitionId", getDefinitionId()); configuration.set("version", getDefinitionVersion()); final Map<String, Object> additionalInputs = definitionMapper.getAdditionalInputs(inputs); final Map<String, Object> allInput = new HashMap<String, Object>(inputs); allInput.putAll(additionalInputs); for (Entry<String, Object> input : allInput.entrySet()) { final String parameterKeyFor = getParameterKeyFor(input.getKey()); if (parameterKeyFor != null) { final Instance parameter = model.newInstance("connectorconfiguration.ConnectorParameter"); parameter.set("key", parameterKeyFor); parameter.set( "expression", getParameterExpressionFor( model, parameterKeyFor, converter, definitionMapper.transformParameterValue(parameterKeyFor, input.getValue(), inputs), getReturnType(parameterKeyFor))); configuration.add("parameters", parameter); } else { if (BonitaStudioLog.isLoggable(IStatus.OK)) { BonitaStudioLog.debug( input.getKey() + " not mapped for " + getDefinitionId(), BarImporterPlugin.PLUGIN_ID); } } } return configuration; }
private Instance getParameterExpressionFor( Model model, String input, StringToExpressionConverter converter, Object value, String returnType) { if (value instanceof String || value instanceof Boolean || value instanceof Number) { String type = definitionMapper.getExpectedExpresstionType(input, value); if (type == null) { return converter.parse(value.toString(), returnType, true); } else { return converter.parse(value.toString(), returnType, true, type); } } else if (value instanceof List) { List<Object> listValue = (List<Object>) value; if (!listValue.isEmpty()) { Instance expression = null; Object row = listValue.get(0); if (row instanceof List) { expression = model.newInstance("expression.TableExpression"); addRow(model, converter, expression, row); for (int i = 1; i < listValue.size(); i++) { row = listValue.get(i); addRow(model, converter, expression, row); } } else { expression = model.newInstance("expression.ListExpression"); for (int i = 0; i < listValue.size(); i++) { Object v = listValue.get(i); expression.add( "expressions", converter.parse(v.toString(), String.class.getName(), false)); } } return expression; } } else { if (BonitaStudioLog.isLoggable(IStatus.OK)) { String valueString = "null"; if (value != null) { valueString = value.toString(); } BonitaStudioLog.debug( input + " value " + valueString + " cannot be transform to an expression", BarImporterPlugin.PLUGIN_ID); } } return null; }