use of org.talend.utils.json.JSONObject in project tbd-studio-se by Talend.
the class NoSQLRepositoryContextHandler method matchContextForAttribues.
@Override
protected void matchContextForAttribues(Connection conn, IConnParamName param, String noSqlVariableName) {
NoSQLConnection noSqlConn = (NoSQLConnection) conn;
EHadoopParamName noSqlParam = (EHadoopParamName) param;
switch(noSqlParam) {
case Server:
noSqlConn.getAttributes().put(INoSQLCommonAttributes.HOST, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case ConnectionString:
noSqlConn.getAttributes().put(IMongoDBAttributes.CONN_STRING, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Port:
noSqlConn.getAttributes().put(INoSQLCommonAttributes.PORT, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Database:
noSqlConn.getAttributes().put(INoSQLCommonAttributes.DATABASE, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Keyspace:
noSqlConn.getAttributes().put(INoSQLCommonAttributes.DATABASE, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Databasepath:
noSqlConn.getAttributes().put(INeo4jAttributes.DATABASE_PATH, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case ServerUrl:
noSqlConn.getAttributes().put(INeo4jAttributes.SERVER_URL, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case UserName:
noSqlConn.getAttributes().put(INoSQLCommonAttributes.USERNAME, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Password:
noSqlConn.getAttributes().put(INoSQLCommonAttributes.PASSWORD, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Keystore:
noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case KeystorePass:
noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT_KEYSTORE_PASSWORD, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Truststore:
noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case TruststorePass:
noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH_TRUSTSTORE_PASSWORD, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case AuthenticationDatabase:
noSqlConn.getAttributes().put(IMongoDBAttributes.AUTHENTICATION_DATABASE, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case UserPrincipal:
noSqlConn.getAttributes().put(IMongoDBAttributes.KRB_USER_PRINCIPAL, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case Realm:
noSqlConn.getAttributes().put(IMongoDBAttributes.KRB_REALM, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case KDCServer:
noSqlConn.getAttributes().put(IMongoDBAttributes.KRB_KDC, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
break;
case ReplicaSets:
String replicaSets = noSqlConn.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
try {
JSONArray jsa = new JSONArray(replicaSets);
for (int i = 0; i < jsa.length(); i++) {
JSONObject jso = jsa.getJSONObject(i);
int paramNum = i + 1;
String hostParamName = noSqlVariableName + ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaHost, paramNum);
String portParamName = noSqlVariableName + ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaPort, paramNum);
jso.put(IMongoConstants.REPLICA_HOST_KEY, ContextParameterUtils.getNewScriptCode(hostParamName, LANGUAGE));
jso.put(IMongoConstants.REPLICA_PORT_KEY, ContextParameterUtils.getNewScriptCode(portParamName, LANGUAGE));
}
noSqlConn.getAttributes().put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
} catch (JSONException e) {
ExceptionHandler.process(e);
}
break;
default:
}
}
use of org.talend.utils.json.JSONObject in project tbd-studio-se by Talend.
the class NoSQLRepositoryContextHandler method setPropertiesForExistContextMode.
@Override
public void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
if (connection == null) {
return;
}
if (connection instanceof NoSQLConnection) {
NoSQLConnection noSqlConn = (NoSQLConnection) connection;
ContextItem currentContext = null;
for (IConnParamName param : paramSet) {
if (param instanceof EHadoopParamName) {
String noSqlVariableName = null;
EHadoopParamName noSqlParam = (EHadoopParamName) param;
if (noSqlParam == EHadoopParamName.ReplicaSets) {
String replicaSets = noSqlConn.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
try {
JSONArray jsa = new JSONArray(replicaSets);
for (int i = 0; i < jsa.length(); i++) {
JSONObject jso = jsa.getJSONObject(i);
int paramNum = i + 1;
String hostParamName = ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaHost, paramNum);
String portParamName = ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaPort, paramNum);
String hostVariableName = null;
String portVariableName = null;
if (adaptMap != null && adaptMap.size() > 0) {
for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
currentContext = entry.getKey();
List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
for (ConectionAdaptContextVariableModel model : modelList) {
if (model.getValue().equals(hostParamName)) {
hostVariableName = model.getName();
} else if (model.getValue().equals(portParamName)) {
portVariableName = model.getName();
}
if (hostVariableName != null && portVariableName != null) {
break;
}
}
}
}
if (hostVariableName != null && portVariableName != null) {
hostVariableName = getCorrectVariableName(currentContext, hostVariableName, hostParamName);
portVariableName = getCorrectVariableName(currentContext, portVariableName, portParamName);
jso.put(IMongoConstants.REPLICA_HOST_KEY, ContextParameterUtils.getNewScriptCode(hostVariableName, LANGUAGE));
jso.put(IMongoConstants.REPLICA_PORT_KEY, ContextParameterUtils.getNewScriptCode(portVariableName, LANGUAGE));
}
}
noSqlConn.getAttributes().put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
} catch (JSONException e) {
ExceptionHandler.process(e);
}
} else {
if (adaptMap != null && adaptMap.size() > 0) {
for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
currentContext = entry.getKey();
List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
for (ConectionAdaptContextVariableModel model : modelList) {
if (model.getValue().equals(noSqlParam.name())) {
noSqlVariableName = model.getName();
break;
}
}
}
}
if (noSqlVariableName != null) {
noSqlVariableName = getCorrectVariableName(currentContext, noSqlVariableName, noSqlParam);
matchContextForAttribues(noSqlConn, noSqlParam, noSqlVariableName);
}
}
}
}
}
}
use of org.talend.utils.json.JSONObject 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.JSONObject 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);
}
use of org.talend.utils.json.JSONObject in project tbd-studio-se by Talend.
the class NoSQLRepositoryContextHandlerTest method validateResult.
private void validateResult() throws Exception {
String dbName = noSqlConnection.getAttributes().get(INoSQLCommonAttributes.DATABASE);
assertEquals("context.Mongo_Database", dbName);
String replicaSet = noSqlConnection.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
assertNotNull(replicaSet);
JSONArray jsa = new JSONArray(replicaSet);
assertTrue(jsa.length() > 0);
JSONObject jso = jsa.getJSONObject(0);
String contextHostName = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
String contextPortName = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
assertEquals("context.Mongo_ReplicaHost_1", contextHostName);
assertEquals("context.Mongo_ReplicaPort_1", contextPortName);
}
Aggregations