use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class AbstractJobSettingsPage method save.
protected void save() {
List<String> checkedObjects = new ArrayList<String>();
List<IRepositoryViewObject> allProcess = null;
try {
allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
for (IRepositoryViewObject object : allProcess) {
if (isStatUseProjectSetting(object)) {
if (!checkedObjects.contains(object.getProperty().getId())) {
checkedObjects.add(object.getProperty().getId());
if (!checkedNodeObject.contains(object)) {
checkedNodeObject.add(object);
}
}
}
}
List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
if (allOpenedProcessList != null) {
for (int i = 0; i < allOpenedProcessList.size(); i++) {
if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
openedProcessList.add(allOpenedProcessList.get(i));
}
}
}
//
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
// must init this
addContextModel = false;
if (!contextVars.isEmpty()) {
// boolean showDialog = false;
Set<String> contextSet = new HashSet<String>();
for (String key : contextVars.keySet()) {
contextSet = contextVars.get(key);
break;
}
Connection connection = null;
IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (ptParam != null) {
IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
Object proValue = propertyElem.getValue();
if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String value = (String) repositoryElem.getValue();
ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
connection = connectionItem.getConnection();
if (connection != null && connection.isContextMode()) {
addContextModel = true;
// ContextItem contextItem =
// ContextUtils.getContextItemById(connection.getContextId());
// for (IProcess process : openedProcessList) {
// Set<String> addedContext =
// ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, process.getContextManager(), false);
// if (addedContext != null && !addedContext.isEmpty()) {
// showDialog = true;
// break;
// }
// }
}
}
}
if (addContextModel) {
// if the context is not existed in job, will add or not.
Display disp = Display.getCurrent();
if (disp == null) {
disp = Display.getDefault();
}
if (disp != null) {
disp.syncExec(new Runnable() {
@Override
public void run() {
showContextAndCheck(contextVars);
}
});
} else {
showContextAndCheck(contextVars);
}
}
}
monitor.worked(10);
IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (IRepositoryViewObject object : checkedNodeObject) {
saveProcess(object, addContextModel, contextVars, monitor);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
monitor.done();
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class DynamicComposite method getConnectionItems.
/**
* DOC qzhang Comment method "getConnectionItems".
*
* @return
* @throws PersistenceException
*/
private List<ConnectionItem> getConnectionItems() throws PersistenceException {
List<ConnectionItem> list = new ArrayList<ConnectionItem>();
IRepositoryView repositoryView = RepositoryManagerHelper.findRepositoryView();
if (repositoryView != null) {
TreeViewer viewer = (TreeViewer) repositoryView.getViewer();
IContentProvider contentProvider = viewer.getContentProvider();
if (contentProvider instanceof RepositoryContentProvider) {
RepositoryContentProvider provider = (RepositoryContentProvider) contentProvider;
RepositoryNode metadataConNode = provider.getRootRepositoryNode(ERepositoryObjectType.METADATA);
for (IRepositoryNode connectionItem : metadataConNode.getChildren()) {
if (viewer.isExpandable(connectionItem)) {
provider.getChildren(connectionItem);
}
for (IRepositoryNode node : connectionItem.getChildren()) {
addConnectionItem(viewer, provider, list, (RepositoryNode) node);
}
}
}
}
return list;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class DynamicComposite method updateRepositoryListExtra.
/**
* for job settings extra (feature 2710).
*
*/
private void updateRepositoryListExtra(IElementParameter param, List<String> repositoryConnectionNameList, List<String> repositoryConnectionValueList, boolean extra) {
String repositoryValue = param.getParentParameter().getRepositoryValue();
if (repositoryValue != null) {
List<String> connectionNamesList = new ArrayList<String>();
List<String> connectionValuesList = new ArrayList<String>();
for (String key : repositoryConnectionItemMap.keySet()) {
ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
Connection connection = connectionItem.getConnection();
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel();
if ((connection instanceof DelimitedFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.DELIMITED.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof PositionalFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.POSITIONAL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof RegexpFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.REGEX.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof XmlFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.XML.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof FileExcelConnection) && (repositoryValue.equals(ERepositoryCategoryType.EXCEL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof GenericSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.GENERIC.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof LDAPSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.LDAP.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof SalesforceSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.SALESFORCE.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof WSDLSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.WSDL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof DatabaseConnection) && (repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName()))) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
if (repositoryValue.contains(":")) {
// database //$NON-NLS-1$
// is
// specified
// //$NON-NLS-1$
//$NON-NLS-1$
String neededDbType = repositoryValue.substring(repositoryValue.indexOf(":") + 1);
if (neededDbType.equals(currentDbType)) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
} else {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
}
}
repositoryConnectionNameList.addAll(connectionNamesList);
repositoryConnectionValueList.addAll(connectionValuesList);
} else {
List<String> connectionValuesList = new ArrayList<String>();
List<String> connectionStringList = new ArrayList<String>();
for (String key : repositoryConnectionItemMap.keySet()) {
ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
String name = connectionItem.getProperty().getLabel();
addOrderDisplayNames(connectionValuesList, connectionStringList, key, name);
}
repositoryConnectionNameList.addAll(connectionStringList);
repositoryConnectionValueList.addAll(connectionValuesList);
}
param.setListItemsDisplayName(repositoryConnectionNameList.toArray(new String[0]));
param.setListItemsValue(repositoryConnectionValueList.toArray(new String[0]));
if (!repositoryConnectionItemMap.keySet().contains(param.getValue())) {
if (repositoryConnectionNameList.size() > 0) {
param.setValue(repositoryConnectionValueList.get(0));
}
}
}
use of org.talend.core.model.properties.ConnectionItem 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.properties.ConnectionItem in project tdi-studio-se by Talend.
the class MergeTosMetadataMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ConnectionItem) {
try {
URI itemURI = getItemURI(item);
if (itemURI != null) {
URI itemResourceURI = getItemResourceURI(itemURI);
if (metadata400to410 == null) {
metadata400to410 = new TosMetadataMigrationFrom400to410();
}
Resource migratedResource = metadata400to410.migrate(itemResourceURI.toString(), new NullProgressMonitor());
HashMap<String, Object> xmlSaveOtions = XML_SAVE_OTIONS_1_0;
if (migratedResource != null) {
// check for DB connection caus we need to setup Schema and Catalog properly
EObject content = migratedResource.getContents().get(0);
if (content != null && "DatabaseConnection".equals(content.eClass().getName())) {
// resource is dynamic EMF so convert it to static model by serialising it and reloading it
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
try {
// serialize into memory
try {
migratedResource.save(tempStream, XML_SAVE_OTIONS_1_0);
} catch (Exception e) {
// try with version 1.1
tempStream = new ByteArrayOutputStream();
xmlSaveOtions = XML_SAVE_OTIONS_1_1;
migratedResource.save(tempStream, xmlSaveOtions);
} finally {
tempStream.close();
}
// create a resource to laod the inmemory resource that should be a static EMF model
migratedResource = resourceSet.createResource(URI.createURI(//$NON-NLS-1$
"http://talend/dummy_static.metadata"));
migratedResource.load(new ByteArrayInputStream(tempStream.toByteArray()), xmlSaveOtions);
// check that DBConnection is firdt element
DatabaseConnection databaseConnection = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(migratedResource.getContents().get(0));
// do not check for null caus DB connection is already check above
String databaseType = databaseConnection.getDatabaseType();
databaseConnection.setDriverClass(ExtractMetaDataUtils.getInstance().getDriverClassByDbType(databaseType));
EDatabaseTypeName currentType = EDatabaseTypeName.getTypeFromDbType(databaseType);
EDatabaseSchemaOrCatalogMapping curCatalog = currentType.getCatalogMappingField();
EDatabaseSchemaOrCatalogMapping curSchema = currentType.getSchemaMappingField();
// all the DB connection are migrated with a Schema by default
if (!curCatalog.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
// we need to place the current schemas into a catalogs
ConnectionHelper.removeSchemas(schemas, databaseConnection);
for (Schema schema : schemas) {
// compute the name of the schema and the catalogs
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
String catalogName = computeCatalogName(databaseConnection, curCatalog);
schema.setName(schemaName);
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
// add the schema to the catalog and the the catalog to the connection
CatalogHelper.addSchemas(Collections.singleton(schema), catalog);
ConnectionHelper.addCatalog(catalog, databaseConnection);
}
} else {
// we need to replace the Schemas with a Catalogs
for (Schema schema : schemas) {
// compute the name the catalog
String catalogName = computeCatalogName(databaseConnection, curCatalog);
// use owned elements to get everything regardless of tables or views or
// else
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
catalog.getOwnedElement().addAll(schema.getOwnedElement());
ConnectionHelper.addCatalog(catalog, databaseConnection);
ConnectionHelper.removeSchemas(Collections.singleton(schema), databaseConnection);
}
}
} else if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
for (Schema schema : schemas) {
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
schema.setName(schemaName);
}
}
// else no catalog so we keep the schema as is
} catch (Exception e) {
// we have an exception finalising the migration but we trap it caus we still try to
// save it
log.error("Cannot complete merge metadata migration on file:" + itemResourceURI.toString(), e);
ExceptionHandler.process(e);
} finally {
tempStream.close();
}
}
// else not a DB connection so persist
OutputStream outputStream = item.eResource().getResourceSet().getURIConverter().createOutputStream(itemResourceURI, null);
try {
migratedResource.save(outputStream, xmlSaveOtions);
} finally {
outputStream.close();
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
}
} catch (ATLCoreException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (IOException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} finally {
resourceSet.getResources().clear();
}
}
return ExecutionResult.NOTHING_TO_DO;
}
Aggregations