use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.
the class CassandraConnForm method collectNoSqlAttributesForContext.
/*
* (non-Javadoc)
*
* @see org.talend.repository.nosql.ui.common.AbstractNoSQLConnForm#collectAttributesForContext()
*/
@Override
protected void collectNoSqlAttributesForContext() {
NoSQLConnection conn = getConnection();
conn.getAttributes().put(INoSQLCommonAttributes.HOST, serverText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.PORT, portText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.DATABASE, databaseText.getText());
if (checkRequireAuthBtn.getSelection()) {
conn.getAttributes().put(INoSQLCommonAttributes.USERNAME, userText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.PASSWORD, pwdText.getText());
}
}
use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.
the class MongoDBConnForm method saveAttributes.
@Override
protected void saveAttributes() {
super.saveAttributes();
NoSQLConnection conn = getConnection();
conn.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, repositoryTranslator.getValue(dbVersionCombo.getText()));
conn.getAttributes().put(INoSQLCommonAttributes.HOST, serverText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.PORT, portText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.DATABASE, databaseText.getText());
conn.getAttributes().put(IMongoDBAttributes.USE_CONN_STRING, String.valueOf(checkUseConnStringBtn.getSelection()));
conn.getAttributes().put(IMongoDBAttributes.CONN_STRING, connStringText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.REQUIRED_AUTHENTICATION, String.valueOf(checkRequireAuthBtn.getSelection()));
conn.getAttributes().put(INoSQLCommonAttributes.USERNAME, userText.getText());
conn.getAttributes().put(INoSQLCommonAttributes.PASSWORD, conn.getValue(pwdText.getText(), true));
conn.getAttributes().put(IMongoDBAttributes.REQUIRED_ENCRYPTION, String.valueOf(checkRequireEncryptionBtn.getSelection()));
conn.getAttributes().put(IMongoDBAttributes.USE_REPLICA_SET, String.valueOf(checkUseReplicaBtn.getSelection()));
conn.getAttributes().put(IMongoDBAttributes.AUTHENTICATION_MECHANISM, getAuthMechanismValue(authMechanismCombo.getText()));
conn.getAttributes().put(IMongoDBAttributes.SET_AUTHENTICATION_DATABASE, String.valueOf(checkSetAuthDatabaseBtn.getSelection()));
conn.getAttributes().put(IMongoDBAttributes.AUTHENTICATION_DATABASE, authDatabaseText.getText());
conn.getAttributes().put(IMongoDBAttributes.KRB_USER_PRINCIPAL, authKrbUserPrincipalText.getText());
conn.getAttributes().put(IMongoDBAttributes.KRB_REALM, authKrbRealmText.getText());
conn.getAttributes().put(IMongoDBAttributes.KRB_KDC, authKrbKdcText.getText());
conn.getAttributes().put(IMongoDBAttributes.X509_CERT, certificateField.getText());
conn.getAttributes().put(IMongoDBAttributes.X509_CERT_KEYSTORE_PASSWORD, conn.getValue(keyStorePassText.getText(), true));
conn.getAttributes().put(IMongoDBAttributes.X509_USE_CERT_AUTH, String.valueOf(checkUseCertAuthBtn.getSelection()));
conn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH, authCertificateField.getText());
conn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH_TRUSTSTORE_PASSWORD, conn.getValue(trustStorePassText.getText(), true));
saveReplicaModel();
}
use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.
the class MongoDBConnectionUtilTest method testIsUpgradeVersion.
@Test
public void testIsUpgradeVersion() {
NoSQLConnection connection = NosqlFactory.eINSTANCE.createNoSQLConnection();
connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, VersionUtils.DEFAULT_VERSION);
Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_2_5_X");
Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_2_6_X");
Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_3_2_X");
Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_3_5_X");
Assert.assertTrue(MongoDBConnectionUtil.isUpgradeVersion(connection));
connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_4_5_X");
Assert.assertTrue(MongoDBConnectionUtil.isUpgradeVersion(connection));
}
use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method getMongo4ConnStringVersion.
public static synchronized Object getMongo4ConnStringVersion(NoSQLConnection connection, ContextType contextType, ClassLoader classLoader, boolean requireAuth, boolean requireEncryption) throws NoSQLServerException {
Object mongo = null;
String user = connection.getAttributes().get(IMongoDBAttributes.USERNAME);
String pass = connection.getAttributes().get(IMongoDBAttributes.PASSWORD);
if (contextType != null) {
user = ContextParameterUtils.getOriginalValue(contextType, user);
pass = ContextParameterUtils.getOriginalValue(contextType, pass);
} else {
pass = connection.getValue(pass, false);
}
try {
String connString = extractFromContext(connection, IMongoDBAttributes.CONN_STRING);
Object clientSettingsBuilder = // $NON-NLS-1$ //$NON-NLS-2$
NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
"com.mongodb.MongoClientSettings", // $NON-NLS-1$ //$NON-NLS-2$
"builder", new Object[0], classLoader);
Object connectionString = NoSQLReflection.newInstance("com.mongodb.ConnectionString", new Object[] { connString }, classLoader, String.class);
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyConnectionString", new Object[] { connectionString }, connectionString.getClass());
Object mongoCredential = getCredential(connection, contextType, user, pass, classLoader);
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "credential", new Object[] { mongoCredential }, Class.forName("com.mongodb.MongoCredential", true, classLoader));
String authMechanism = connection.getAttributes().get(IMongoDBAttributes.AUTHENTICATION_MECHANISM);
//
if ((requireAuth && authMechanism.equals(IMongoConstants.X509)) || requireEncryption) {
// enable ssl & context
// $NON-NLS-1$
Class<?> blockClasszz = Class.forName("com.mongodb.Block", false, classLoader);
Class[] interfaces = new Class[1];
interfaces[0] = blockClasszz;
Object block = Proxy.newProxyInstance(classLoader, interfaces, (proxy, method, args) -> {
switch(method.getName()) {
case // $NON-NLS-1$
"apply":
if (args[0] != null) {
SSLContext sslContext = null;
if (requireAuth && authMechanism.equals(IMongoConstants.X509)) {
sslContext = mongoX509SSLContext(connection);
} else if (requireEncryption) {
sslContext = StudioSSLContextProvider.getContext();
}
// $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
args[0], // $NON-NLS-1$
"context", // $NON-NLS-1$
new Object[] { sslContext }, // $NON-NLS-1$
SSLContext.class);
}
return null;
default:
throw new NoSQLServerException(// $NON-NLS-1$
Messages.getString("MongoDBConnectionUtil.CannotFindMethod", method.getName()));
}
});
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyToSslSettings", new Object[] { block }, blockClasszz);
// $NON-NLS-1$
blockClasszz = Class.forName("com.mongodb.Block", false, classLoader);
interfaces = new Class[1];
interfaces[0] = blockClasszz;
block = Proxy.newProxyInstance(classLoader, interfaces, (proxy, method, args) -> {
switch(method.getName()) {
case // $NON-NLS-1$
"apply":
if (args[0] != null) {
// $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
args[0], // $NON-NLS-1$
"enabled", // $NON-NLS-1$
new Object[] { true }, boolean.class);
}
return null;
default:
throw new Exception(// $NON-NLS-1$
"MongoDBConnectionUtil.CannotFindMethod" + method.getName());
}
});
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyToSslSettings", new Object[] { block }, blockClasszz);
}
Object mongoClientSettings = NoSQLReflection.invokeMethod(clientSettingsBuilder, "build", new Object[0]);
mongo = // $NON-NLS-1$ //$NON-NLS-2$
NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
"com.mongodb.client.MongoClients", // $NON-NLS-1$ //$NON-NLS-2$
"create", new Object[] { mongoClientSettings }, classLoader, // $NON-NLS-1$
Class.forName("com.mongodb.MongoClientSettings", true, classLoader));
mongos.add(mongo);
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return mongo;
}
use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.
the class NoSQLRepositoryTypeProcessor method selectRepositoryNode.
/*
* (non-Javadoc)
*
* @see
* org.talend.repository.ui.processor.SingleTypeProcessor#selectRepositoryNode(org.eclipse.jface.viewers.Viewer,
* org.talend.repository.model.RepositoryNode, org.talend.repository.model.RepositoryNode)
*/
@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
final String repositoryType = getRepositoryType();
if (node == null || repositoryType == null) {
return false;
}
ERepositoryObjectType repObjType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
if (repObjType == ERepositoryObjectType.REFERENCED_PROJECTS) {
return true;
}
if (node.getType() == ENodeType.SYSTEM_FOLDER) {
return true;
}
IRepositoryViewObject object = node.getObject();
if (object == null || object.getProperty().getItem() == null) {
return false;
}
if (object instanceof MetadataTable) {
return false;
}
Item item = object.getProperty().getItem();
if (item instanceof FolderItem) {
return true;
}
if (item instanceof NoSQLConnectionItem) {
NoSQLConnectionItem connectionItem = (NoSQLConnectionItem) item;
NoSQLConnection connection = (NoSQLConnection) connectionItem.getConnection();
if (repositoryType.startsWith(INoSQLConstants.NOSQL_TYPE_PREFIX)) {
// $NON-NLS-1$
String realDbType = repositoryType.substring(repositoryType.indexOf(":") + 1);
if (!StringUtils.equalsIgnoreCase(realDbType, connection.getDbType())) {
return false;
}
}
}
return true;
}
Aggregations