use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class NoSqlContextUpdateService method updateContextParameter.
@Override
public boolean updateContextParameter(Connection conn, String oldValue, String newValue) {
boolean isModified = false;
if (conn.isContextMode()) {
if (conn instanceof NoSQLConnection) {
NoSQLConnection connection = (NoSQLConnection) conn;
EMap<String, String> connAttributes = (EMap<String, String>) connection.getAttributes();
if (connAttributes == null) {
return isModified;
}
for (Map.Entry<String, String> attr : connection.getAttributes()) {
if (attr.equals(IMongoDBAttributes.REPLICA_SET)) {
String replicaSets = connAttributes.get(IMongoDBAttributes.REPLICA_SET);
try {
JSONArray jsa = new JSONArray(replicaSets);
for (int i = 0; i < jsa.length(); i++) {
JSONObject jso = jsa.getJSONObject(i);
String hostValue = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
if (hostValue != null && hostValue.equals(oldValue)) {
jso.put(IMongoConstants.REPLICA_HOST_KEY, newValue);
connAttributes.put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
isModified = true;
}
String portValue = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
if (portValue != null && portValue.equals(oldValue)) {
jso.put(IMongoConstants.REPLICA_PORT_KEY, newValue);
connAttributes.put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
isModified = true;
}
}
} catch (JSONException e) {
ExceptionHandler.process(e);
}
} else if (attr.getValue().equals(oldValue)) {
attr.setValue(newValue);
isModified = true;
}
}
}
}
return isModified;
}
use of org.talend.utils.json.JSONArray in project tdi-studio-se by Talend.
the class JsonTableHandler method getDataRowList.
private List<List<Object>> getDataRowList(JSONObject rootObj, AtomicInteger columnsCount) throws JSONException {
List<List<Object>> rows = new ArrayList<>();
AtomicInteger count = columnsCount;
if (count == null) {
count = new AtomicInteger();
}
JSONArray jsonArr = rootObj.getJSONArray(DATA_KEY);
for (int i = 0; i < jsonArr.length(); i++) {
List<Object> row = new ArrayList<>();
JSONArray rowArray = jsonArr.getJSONArray(i);
for (int j = 0; j < rowArray.length(); j++) {
row.add(rowArray.get(j));
}
if (row.size() > count.get()) {
count.set(row.size());
}
rows.add(row);
}
return rows;
}
use of org.talend.utils.json.JSONArray in project tdi-studio-se by Talend.
the class FunctionManagerExt method getFunctionFromColumn.
public Function getFunctionFromColumn(MetadataColumnExt column) {
Function function = null;
String functionInfo = column.getFunctionInfo();
if (functionInfo != null) {
try {
JSONObject functionObj = new JSONObject(functionInfo);
String functionName = functionObj.getString(Function.NAME);
int functionSize = 0;
JSONArray parametersArray = functionObj.getJSONArray(Function.PARAMETERS);
if (parametersArray != null) {
functionSize = parametersArray.length();
}
List<Function> funcs = getFunctionsByType(column.getTalendType());
for (Function func : funcs) {
if (func.getName().equals(functionName) && func.getParameters().size() == functionSize) {
function = func;
break;
}
}
if (function != null) {
function = function.clone(parametersArray);
}
} catch (JSONException e) {
ExceptionHandler.process(e);
}
}
return function;
}
use of org.talend.utils.json.JSONArray in project tdi-studio-se by Talend.
the class ColumnListController method reUsedColumnFunctionArrayCheck.
private static void reUsedColumnFunctionArrayCheck(Map<String, Object> newLine, IElement element, String[] codes) {
if (element instanceof INode && ((INode) element).getMetadataList().size() > 0 && ((INode) element).getComponent().getName().equals("tRowGenerator")) {
IMetadataTable table = ((INode) element).getMetadataList().get(0);
//$NON-NLS-1$
String lineName = (String) newLine.get("SCHEMA_COLUMN");
for (IMetadataColumn column : table.getListColumns()) {
if (lineName != null && lineName.equals(column.getLabel()) && "".equals(newLine.get("ARRAY"))) {
Map<String, String> columnFunction = column.getAdditionalField();
String functionInfo = columnFunction.get(FUNCTION_INFO);
if (functionInfo != null) {
try {
JSONObject functionInfoObj = new JSONObject(functionInfo);
String functionExpression = "";
String functionName = functionInfoObj.getString(Function.NAME);
if (!functionName.equals("...")) {
String className = functionInfoObj.getString(Function.PARAMETER_CLASS_NAME);
String parmValueApend = "";
functionExpression = className + '.' + functionName + "(";
JSONArray parametersArray = functionInfoObj.getJSONArray(Function.PARAMETERS);
if (parametersArray != null) {
for (int i = 0; i < parametersArray.length(); i++) {
JSONObject parameterObj = parametersArray.getJSONObject(i);
String paramValue = parameterObj.getString(Function.PARAMETER_VALUE);
parmValueApend = parmValueApend + paramValue.trim() + ',';
}
}
if (parmValueApend.endsWith(",")) {
parmValueApend = parmValueApend.substring(0, parmValueApend.lastIndexOf(","));
}
functionExpression = functionExpression + parmValueApend + ')';
newLine.put("ARRAY", functionExpression);
}
} catch (JSONException e) {
ExceptionHandler.process(e);
}
}
}
}
}
}
use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class NoSQLConnectionContextManager method revertPropertiesForContextMode.
/**
* DOC PLV Comment method "revertPropertiesForContextMode".
*
* @param connectionItem
* @param contextType
* @param attributes
*/
public void revertPropertiesForContextMode(ContextType contextType) {
EMap<String, String> connAttributes = connection.getAttributes();
if (connAttributes == null) {
return;
}
for (String attributeName : attributes) {
if (attributeName.equals(IMongoDBAttributes.REPLICA_SET)) {
String replicaSets = connAttributes.get(IMongoDBAttributes.REPLICA_SET);
try {
JSONArray jsa = new JSONArray(replicaSets);
for (int i = 0; i < jsa.length(); i++) {
JSONObject jso = jsa.getJSONObject(i);
String hostValue = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
String portValue = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
String originalHostValue = ContextParameterUtils.getOriginalValue(contextType, hostValue);
String originalPortValue = ContextParameterUtils.getOriginalValue(contextType, portValue);
jso.put(IMongoConstants.REPLICA_HOST_KEY, originalHostValue);
jso.put(IMongoConstants.REPLICA_PORT_KEY, originalPortValue);
}
connAttributes.put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
} catch (JSONException e) {
ExceptionHandler.process(e);
}
} else {
String originalValue = ContextParameterUtils.getOriginalValue(contextType, connAttributes.get(attributeName));
connAttributes.put(attributeName, originalValue);
}
}
// set connection for context mode
connection.setContextMode(false);
connection.setContextId(ConnectionContextHelper.EMPTY);
}
Aggregations