use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class DynamicComposite method getRepositoryAliasName.
// /**
// * ftang Comment method "updateContextList".
// */
// public void updateContextList(IElementParameter jobParam) {
// if (jobParam == null || jobParam.getField() != EParameterFieldType.PROCESS_TYPE) {
// return;
// }
// // for context type
// List<String> contextNameList = new ArrayList<String>();
// List<String> contextValueList = new ArrayList<String>();
//
// IElementParameter jobNameParam =
// jobParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
//
// Item item = jobNameParam.getLinkedRepositoryItem();
// final String jobValue = (String) jobNameParam.getValue();
// if (jobValue != null) {
// if (item == null || (item != null && !item.getProperty().getId().equals(jobValue))) {
// item = ProcessorUtilities.getProcessItemById(jobValue);
// }
// } else {
// item = null;
// }
// if (item != null) {
// if (item instanceof ProcessItem) {
// for (Object o : ((ProcessItem) item).getProcess().getContext()) {
// if (o instanceof ContextType) {
// ContextType context = (ContextType) o;
// contextNameList.add(context.getName());
// contextValueList.add(context.getName());
// }
// }
// }
// jobNameParam.setLabelFromRepository(item.getProperty().getLabel());
// }
// jobNameParam.setLinkedRepositoryItem(item);
// // set default context
// String defalutValue = null;
// if (item != null && item instanceof ProcessItem) {
// defalutValue = ((ProcessItem) item).getProcess().getDefaultContext();
// }
// setProcessTypeRelatedValues(jobParam, contextNameList, contextValueList,
// EParameterName.PROCESS_TYPE_CONTEXT.getName(),
// defalutValue);
//
// // for version type
// List<String> versionNameList = new ArrayList<String>();
// List<String> versionValueList = new ArrayList<String>();
//
// if (item != null) { // existed item
// List<IRepositoryObject> allVersion = ProcessorUtilities.getAllRepositoryObjectById(item.getProperty().getId());
// for (IRepositoryObject obj : allVersion) {
// String version = obj.getVersion();
// versionNameList.add(version);
// versionValueList.add(version);
// }
// }
// setProcessTypeRelatedValues(jobParam, versionNameList, versionValueList,
// EParameterName.PROCESS_TYPE_VERSION.getName(),
// null);
//
// }
//
// /**
// *
// * ggu Comment method "setProcessTypeRelatedValues".
// *
// *
// */
// private void setProcessTypeRelatedValues(IElementParameter parentParam, List<String> nameList, List<String>
// valueList,
// final String childName, final String defaultValue) {
// if (parentParam == null || childName == null) {
// return;
// }
// final String fullChildName = parentParam.getName() + ":" + childName;
// IElementParameter childParam = parentParam.getChildParameters().get(childName);
// if (nameList == null) {
// childParam.setListItemsDisplayName(new String[0]);
// } else {
// childParam.setListItemsDisplayName(nameList.toArray(new String[0]));
// }
// if (valueList == null) {
// childParam.setListItemsValue(new String[0]);
// } else {
// childParam.setListItemsValue(valueList.toArray(new String[0]));
// }
// // set default value
// if (defaultValue != null) {
// childParam.setValue(defaultValue);
// }
// if (elem != null) {
// if (valueList != null && !valueList.contains(childParam.getValue())) {
// if (nameList != null && nameList.size() > 0) {
// elem.setPropertyValue(fullChildName, valueList.get(valueList.size() - 1));
// }
// } else {
// // force to store the value again to activate the code
// // generation in Node.setPropertyValue
// elem.setPropertyValue(fullChildName, childParam.getValue());
// }
// }
// }
public String getRepositoryAliasName(ConnectionItem connectionItem) {
ERepositoryObjectType repositoryObjectType = ERepositoryObjectType.getItemType(connectionItem);
String aliasName = repositoryObjectType.getAlias();
Connection connection = connectionItem.getConnection();
if (connection instanceof DatabaseConnection) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
//$NON-NLS-1$ //$NON-NLS-2$
aliasName += " (" + currentDbType + ")";
}
return aliasName;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class MultipleThreadDynamicComposite method updateRepositoryList.
public void updateRepositoryList() {
ProgressDialog progressDialog = new ProgressDialog(this.getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitorWrap = new EventLoopProgressMonitor(monitor);
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
List<IRepositoryViewObject> repositoryObjects = getAllRepositoryMetadata();
// + elem.getElementParameters().size();
int total = repositoryObjects.size();
//$NON-NLS-1$
monitorWrap.beginTask(Messages.getString("MultipleThreadDynamicComposite.gatherInformation"), total);
IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, section);
String repositoryValue = null;
if (propertyParam != null) {
repositoryValue = propertyParam.getRepositoryValue();
}
if (repositoryObjects != null && (repositoryObjects.size() != 0)) {
tableIdAndDbTypeMap.clear();
tableIdAndDbSchemaMap.clear();
for (IRepositoryViewObject curObject : repositoryObjects) {
Item item = curObject.getProperty().getItem();
if (item instanceof ConnectionItem) {
ConnectionItem connectionItem = (ConnectionItem) item;
Connection connection = connectionItem.getConnection();
if (connection == null || connection.isReadOnly()) {
continue;
}
for (Object tableObj : ConnectionHelper.getTables(connection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
IMetadataTable newTable = ConvertionHelper.convert(table);
// newTable);
if (connection instanceof DatabaseConnection) {
String dbType = ((DatabaseConnection) connection).getDatabaseType();
String schema = ((DatabaseConnection) connection).getUiSchema();
tableIdAndDbTypeMap.put(newTable.getId(), dbType);
if (schema != null && !schema.equals("")) {
//$NON-NLS-1$
tableIdAndDbSchemaMap.put(newTable.getId(), schema);
}
}
}
}
}
monitorWrap.worked(1);
}
// hywang add for feature 6484
if (item instanceof FileItem) {
FileItem FileItem = (FileItem) item;
if (repositoryValue != null) {
if (repositoryValue.equals("RULE")) {
//$NON-NLS-1$
repositoryFileItemMap.put(FileItem.getProperty().getId(), FileItem);
}
}
monitorWrap.worked(1);
}
if (item instanceof LinkRulesItem) {
LinkRulesItem linkItem = (LinkRulesItem) item;
if (repositoryValue != null) {
if (repositoryValue.equals("RULE")) {
//$NON-NLS-1$
repositoryLinkRulesItemMap.put(linkItem.getProperty().getId(), linkItem);
}
}
monitorWrap.worked(1);
}
}
}
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
return;
} catch (Exception e) {
ExceptionHandler.process(e);
return;
}
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class TOPRepositoryServiceTest method testRemoveAliasInSQLExplorer.
/**
* Test method for
* {@link org.talend.dataprofiler.core.service.TOPRepositoryService#removeAliasInSQLExplorer(org.talend.repository.model.IRepositoryNode)}
* .
*/
public void testRemoveAliasInSQLExplorer() {
IRepositoryNode child = mock(IRepositoryNode.class);
IRepositoryViewObject obj = mock(IRepositoryViewObject.class);
when(child.getObject()).thenReturn(obj);
Property pro = mock(Property.class);
when(obj.getProperty()).thenReturn(pro);
ConnectionItem item = mock(ConnectionItem.class);
when(pro.getItem()).thenReturn(item);
MDMConnection mdm = mock(MDMConnection.class);
DelimitedFileConnection dfile = mock(DelimitedFileConnection.class);
DatabaseConnection dbc = mock(DatabaseConnection.class);
when(item.getConnection()).thenReturn(dbc).thenReturn(dfile).thenReturn(mdm);
List<ModelElement> dependencyClients = new ArrayList<ModelElement>();
ModelElement m1 = mock(ModelElement.class);
dependencyClients.add(m1);
PowerMockito.mockStatic(EObjectHelper.class);
when(EObjectHelper.getDependencyClients(dbc)).thenReturn(dependencyClients);
when(EObjectHelper.getDependencyClients(mdm)).thenReturn(dependencyClients);
when(EObjectHelper.getDependencyClients(dfile)).thenReturn(dependencyClients);
Assert.assertFalse(tdqRepService.removeAliasInSQLExplorer(child));
Assert.assertFalse(tdqRepService.removeAliasInSQLExplorer(child));
Assert.assertFalse(tdqRepService.removeAliasInSQLExplorer(child));
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ExportConnectionToTOSActionRealTest method createConnectionItem.
private static DatabaseConnectionItem createConnectionItem(String name, IFolder folder, Boolean isDelete, boolean isSave) {
IPath createPath = Path.EMPTY;
if (folder != null) {
createPath = new Path(folder.getFullPath().lastSegment());
}
// connection
DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
createConnection.setName(name);
createConnection.setLabel(name);
// $NON-NLS-1$
createConnection.setUsername("UserName");
// $NON-NLS-1$
createConnection.setRawPassword("Password");
// $NON-NLS-1$
createConnection.setURL("URL");
createConnection.setDatabaseType(EDatabaseTypeName.MYSQL.getXmlName());
createConnection.setContextMode(true);
// ~connection
DatabaseConnectionItem createDatabaseConnectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
org.talend.core.model.properties.Property createDatabaseConnectionProperty = PropertiesFactory.eINSTANCE.createProperty();
createDatabaseConnectionProperty.setId(EcoreUtil.generateUUID());
createDatabaseConnectionProperty.setItem(createDatabaseConnectionItem);
createDatabaseConnectionProperty.setLabel(createConnection.getName());
createDatabaseConnectionItem.setProperty(createDatabaseConnectionProperty);
createDatabaseConnectionItem.setConnection(createConnection);
try {
if (isSave) {
factory.create(createDatabaseConnectionItem, createPath, false);
}
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
return createDatabaseConnectionItem;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ExportConnectionToTOSActionRealTest method testRuncase3.
/**
* Test method for {@link org.talend.dataprofiler.core.ui.action.actions.ExportConnectionToTOSAction#run()}.
*
* @throws PersistenceException
*
* case3: create new connection from only schema case
*/
@Test
public void testRuncase3() throws PersistenceException {
// connectionNode
DatabaseConnectionItem createOldConnectionItem = createConnectionItem("ExportConnectionToTOSActionRealTest3", null, false, // $NON-NLS-1$
true);
DatabaseConnection oldConnection = ((DatabaseConnection) createOldConnectionItem.getConnection());
// $NON-NLS-1$
oldConnection.setSID("orcl");
initSchemaList(createOldConnectionItem);
IRepositoryViewObject createdByUs = factory.getLastVersion(createOldConnectionItem.getProperty().getId());
Assert.assertTrue(createdByUs != null);
// $NON-NLS-1$
Assert.assertTrue("ExportConnectionToTOSActionRealTest3".equals(createdByUs.getLabel()));
// ~connectionNode
List<Package> packageList = new ArrayList<Package>();
packageList.add(schema1);
createAction = PowerMockito.spy(new ExportConnectionToTOSAction(packageList));
PowerMockito.doNothing().when(createAction).openSuccessInformation();
PowerMockito.doNothing().when(createAction).refreshViewerAndNode();
createAction.run();
IRepositoryViewObject createByAction = getNewCreatedConnectionByName(createOldConnectionItem.getConnection().getLabel() + "_" + // $NON-NLS-1$
schema1.getName());
DatabaseConnectionItem item = (DatabaseConnectionItem) createByAction.getProperty().getItem();
DatabaseConnection newConnection = (DatabaseConnection) item.getConnection();
Assert.assertTrue(newConnection.getSID().equalsIgnoreCase(oldConnection.getSID()));
Assert.assertTrue(newConnection.getUiSchema().equalsIgnoreCase(schema1.getName()));
Schema exportedSchema = SchemaHelper.getSchema(newConnection, schema1.getName());
Assert.assertTrue(exportedSchema != null);
Assert.assertTrue(newConnection.getLabel().equals(// $NON-NLS-1$
createOldConnectionItem.getConnection().getLabel() + "_" + schema1.getName()));
Assert.assertTrue(exportedSchema != schema1);
factory.deleteObjectPhysical(createByAction);
factory.deleteObjectPhysical(createdByUs);
}
Aggregations