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; }
protected void addRow( Model model, StringToExpressionConverter converter, Instance expression, Object row) { Instance listExpression = model.newInstance("expression.ListExpression"); for (Object v : (List<Object>) row) { listExpression.add( "expressions", converter.parse(v.toString(), String.class.getName(), false)); } expression.add("expressions", listExpression); }
private Instance getOriginalVariable(final Model model, final String variableToSet) { for (Instance variable : model.getAllInstances("process.Data")) { String varName = (String) variable.get("name"); if (varName != null && varName.equals(variableToSet)) { return variable; } } return null; }
private void createOperation( Model model, Instance connectorInstance, StringToExpressionConverter converter, final String variableToSet, final String varValue) { Instance operationContainerInstance = connectorInstance.getContainer(); Instance originalVariable = getOriginalVariable(model, variableToSet); // set variable dependency of left operand String returnType = Object.class.getName(); Instance leftOperand = null; if (originalVariable != null) { returnType = StringToExpressionConverter.getDataReturnType(originalVariable); leftOperand = StringToExpressionConverter.createExpressionInstanceWithDependency( model, variableToSet, variableToSet, returnType, ExpressionConstants.VARIABLE_TYPE, true, originalVariable); } else { leftOperand = StringToExpressionConverter.createExpressionInstance( model, variableToSet, variableToSet, returnType, ExpressionConstants.VARIABLE_TYPE, true); } Instance rightOperand = converter.parse(varValue, returnType, false); Instance operatorInstance = model.newInstance("expression.Operator"); operatorInstance.set("type", ExpressionConstants.ASSIGNMENT_OPERATOR); Instance operationInstance = model.newInstance("expression.Operation"); operationInstance.set("leftOperand", leftOperand); operationInstance.set("rightOperand", rightOperand); operationInstance.set("operator", operatorInstance); operationContainerInstance.add("operations", operationInstance); }
private void convertToAnOperation( Model model, Instance connectorInstance, StringToExpressionConverter converter) { if ("SetVariable".equals(connectorId)) { final String variableToSet = (String) inputs.get("setVariableName"); final String varValue = (String) inputs.get("setValue"); createOperation(model, connectorInstance, converter, variableToSet, varValue); } else if ("SetVariables".equals(connectorId)) { final List<List<String>> inputToParse = (List<List<String>>) inputs.get("setVariables"); for (List<String> line : inputToParse) { final String variableToSet = line.get(0); final String varValue = line.get(1); createOperation(model, connectorInstance, converter, variableToSet, varValue); } } model.delete(connectorInstance); }