use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class CreateFTPConnectionAction method doRun.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.actions.AContextualAction#doRun()
*/
@Override
protected void doRun() {
RepositoryNode dbConnectionNode = getCurrentRepositoryNode();
if (isToolbar()) {
if (dbConnectionNode != null && dbConnectionNode.getContentType() != ERepositoryObjectType.METADATA_FILE_FTP) {
dbConnectionNode = null;
}
if (dbConnectionNode == null) {
dbConnectionNode = getRepositoryNodeForDefault(ERepositoryObjectType.METADATA_FILE_FTP);
}
}
RepositoryNode metadataNode = dbConnectionNode.getParent();
if (metadataNode != null) {
// Force focus to the repositoryView and open Metadata and DbConnection nodes
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
viewPart.setFocus();
viewPart.expand(metadataNode, true);
viewPart.expand(dbConnectionNode, true);
}
}
FTPConnection connection = null;
IPath pathToSave = null;
// Define the RepositoryNode, by default Metadata/DbConnection
RepositoryNode node = dbConnectionNode;
ISelection selection = null;
// When the userSelection is an element of metadataNode, use it !
if (!isToolbar()) {
Object userSelection = ((IStructuredSelection) getSelection()).getFirstElement();
if (userSelection instanceof RepositoryNode) {
switch(((RepositoryNode) userSelection).getType()) {
case REPOSITORY_ELEMENT:
case SIMPLE_FOLDER:
case SYSTEM_FOLDER:
node = (RepositoryNode) userSelection;
break;
}
}
selection = getSelection();
}
boolean creation = false;
// Define the repositoryObject DatabaseConnection and his pathToSave
switch(node.getType()) {
case REPOSITORY_ELEMENT:
// pathToSave = null;
connection = (FTPConnection) ((ConnectionItem) node.getObject().getProperty().getItem()).getConnection();
creation = false;
break;
case SIMPLE_FOLDER:
pathToSave = RepositoryNodeUtilities.getPath(node);
connection = ConnectionFactory.eINSTANCE.createFTPConnection();
creation = true;
break;
case SYSTEM_FOLDER:
//$NON-NLS-1$
pathToSave = new Path("");
connection = ConnectionFactory.eINSTANCE.createFTPConnection();
creation = true;
break;
}
// Init the content of the Wizard
init(node);
FTPWizard ftpWizard;
if (isToolbar()) {
ftpWizard = new FTPWizard(PlatformUI.getWorkbench(), creation, node, getExistingNames());
ftpWizard.setToolBar(true);
} else {
ftpWizard = new FTPWizard(PlatformUI.getWorkbench(), creation, selection, getExistingNames());
}
// Open the Wizard
WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), ftpWizard);
wizardDialog.setPageSize(700, 550);
wizardDialog.create();
wizardDialog.open();
IRepositoryView view = getViewPart();
if (view != null) {
view.expand(dbConnectionNode, true);
}
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class NewDelimitedFileWizardMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
ComponentService service = ComponentsUtils.getComponentService();
Properties props = getPropertiesFromFile();
if (item instanceof ConnectionItem) {
boolean modify = false;
GenericConnectionItem genericConnectionItem = null;
ConnectionItem connectionItem = (ConnectionItem) item;
Connection connection = connectionItem.getConnection();
// Init
genericConnectionItem = initGenericConnectionItem(connectionItem);
genericConnectionItem.setTypeName(TYPE_NAME);
GenericConnection genericConnection = initGenericConnection(connection);
initProperty(connectionItem, genericConnectionItem);
ComponentWizard componentWizard = service.getComponentWizard(TYPE_NAME, genericConnectionItem.getProperty().getId());
ComponentProperties componentProperties = (ComponentProperties) componentWizard.getForms().get(0).getProperties();
componentProperties.init();
// Update
modify = updateComponentProperties(connection, componentProperties, props);
genericConnection.setCompProperties(componentProperties.toSerialized());
genericConnectionItem.setConnection(genericConnection);
updateMetadataTable(connection, genericConnection, componentProperties);
if (modify) {
try {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject object = factory.getLastVersion(item.getProperty().getId(), ERepositoryObjectType.METADATA_FILE_DELIMITED.getFolder(), ERepositoryObjectType.METADATA_FILE_DELIMITED);
if (object != null) {
factory.deleteObjectPhysical(object);
}
if (genericConnectionItem != null && connectionItem != null) {
factory.create(genericConnectionItem, new Path(connectionItem.getState().getPath()), true);
}
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class AddContextGroupNameMigrationTask method addContextGroupName.
private boolean addContextGroupName(Item item) throws PersistenceException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
if (item instanceof ConnectionItem) {
Connection con = ((ConnectionItem) item).getConnection();
ContextItem originalItem = ContextUtils.getContextItemById2(con.getContextId());
if (originalItem != null) {
if (con.getContextName() == null || "".equals(con.getContextName())) {
con.setContextName(originalItem.getDefaultContext());
factory.save(item);
modified = true;
}
}
}
return modified;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class AddCopyBookXc2jFileMigrationTask method updateXc2jFilePath.
private boolean updateXc2jFilePath(Item item) throws PersistenceException, IOException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean update = false;
if (item instanceof ConnectionItem) {
ConnectionItem connectionItem = (ConnectionItem) item;
Connection con = connectionItem.getConnection();
if (con instanceof EbcdicConnection) {
ReferenceFileItem createReferenceFileItem = null;
// the old copybook version depands MidFile
String midFile = ((EbcdicConnection) con).getMidFile();
if (midFile != null) {
File xc2jMidFile = new File(midFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (xc2jMidFile.exists()) {
readXc2jFile(xc2jMidFile, baos);
}
// create a referenceItem first,maybe it has content,maybe is empty,decide by the midFile
if (connectionItem.getReferenceResources().isEmpty()) {
createReferenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
createReferenceFileItem.setContent(byteArray);
createReferenceFileItem.setExtension("xc2j");
connectionItem.getReferenceResources().add(createReferenceFileItem);
} else {
createReferenceFileItem = (ReferenceFileItem) connectionItem.getReferenceResources().get(0);
}
createReferenceFileItem.getContent().setInnerContent(baos.toByteArray());
// create the phyhical x2cj file and set referenceFileItem content for it
String xc2jFilePath = getReferenceXc2jFile(connectionItem).getLocation().makeAbsolute().toFile().getAbsolutePath();
getXc2jFileFromBytes(createReferenceFileItem.getContent().getInnerContent(), xc2jFilePath);
update = true;
}
}
if (update) {
factory.save(connectionItem, true);
}
}
return update;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class ErDiagramComposite method getSqlStatement.
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private String getSqlStatement() {
//$NON-NLS-1$
String sql = "";
List<String> tables = new ArrayList<String>();
List<String> columns = new ArrayList<String>();
List<String> wheres = new ArrayList<String>();
if (editor != null) {
if (editor.getViewer().getContents() instanceof ErDiagramPart) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String schemaPrefix = "".equals(getSchema()) ? "" : getSchema() + ".";
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String schemaPrefixWithDoubleQuotes = "".equals(getSchema()) ? "" : "\"" + getSchema() + "\".";
ErDiagramPart er = (ErDiagramPart) editor.getViewer().getContents();
for (Object object : er.getChildren()) {
if (object instanceof TablePart) {
TablePart tablePart = (TablePart) object;
Table table = (Table) tablePart.getModel();
if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
//$NON-NLS-1$
tables.add(schemaPrefixWithDoubleQuotes + "\"" + table.getElementName() + "\"");
} else {
tables.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()));
}
boolean oracleDbType = TextUtil.isOracleDbType(getCurrentDbType());
for (Object obj : tablePart.getChildren()) {
if (obj instanceof ColumnPart) {
ColumnPart columnPart = (ColumnPart) obj;
Column column = (Column) columnPart.getModel();
CheckBox isSelected = columnPart.getPrimativeFigure().getFigureCustomColumnIsSelectedFigure();
if (isSelected != null && isSelected.isSelected() && !column.getElementName().equals("*")) {
//$NON-NLS-1$
if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
//$NON-NLS-1$
columns.add(schemaPrefixWithDoubleQuotes + "\"" + table.getElementName() + "\".\"" + column.getElementName() + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"\"");
} else {
// added by hyWang
String leftQuote = TalendTextUtils.getQuoteByDBType(getCurrentDbType(), true);
String rightQuote = TalendTextUtils.getQuoteByDBType(getCurrentDbType(), false);
String columnContent = column.getElementName();
//$NON-NLS-1$
Pattern pattern = Pattern.compile("\\w+");
Matcher matcher = pattern.matcher(columnContent);
EDatabaseTypeName dbType = EDatabaseTypeName.getTypeFromDbType(getCurrentDbType());
// modify for bug 12092
boolean sqlKeyword = KeywordsValidator.isSqlKeyword(column.getElementName(), dbType.getProduct());
if (!matcher.matches() || (sqlKeyword && oracleDbType)) {
columns.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(leftQuote + column.getElementName() + rightQuote, getCurrentDbType()));
} else {
columns.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(column.getElementName(), getCurrentDbType()));
}
}
}
for (Relation rel : (List<Relation>) column.getOutputs()) {
Column source = rel.getSource();
Column target = rel.getTarget();
if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
String where1 = schemaPrefixWithDoubleQuotes + "\"" + source.getTable().getElementName() + //$NON-NLS-1$ //$NON-NLS-2$
"\".\"" + source.getElementName() + "\"= " + schemaPrefixWithDoubleQuotes + "\"" + //$NON-NLS-1$
target.getTable().getElementName() + "\".\"" + target.getElementName() + //$NON-NLS-1$ //$NON-NLS-2$
"\"";
if (!wheres.contains(where1)) {
wheres.add(where1);
}
} else {
String where1 = schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(source.getTable().getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(source.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"=" + schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(target.getTable().getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(target.getElementName(), getCurrentDbType());
if (!wheres.contains(where1)) {
wheres.add(where1);
}
}
}
}
}
}
}
}
}
// Mssql query need add catalog and schema before the table, like this "catolog.schema.table"
Connection conn = null;
if (rootNode != null) {
Item connectionItem = rootNode.getObject().getProperty().getItem();
if (connectionItem instanceof ConnectionItem) {
conn = ((ConnectionItem) connectionItem).getConnection();
}
}
if (getCurrentDbType() != null && (getCurrentDbType().equals(EDatabaseTypeName.MSSQL.getDisplayName()) || getCurrentDbType().equals(EDatabaseTypeName.MSSQL.name())) && conn != null) {
List<String> newTables = new ArrayList<String>();
for (String str : tables) {
newTables.add(getMssqlCatalog(str, conn));
}
tables = newTables;
}
sql = getSelectStatement(tables, columns, wheres);
if (sql.endsWith(",")) {
//$NON-NLS-1$
return sql.substring(0, sql.length() - 1);
} else if (sql.endsWith(" and ")) {
//$NON-NLS-1$
return sql.substring(0, sql.length() - 5);
}
//$NON-NLS-1$
return "";
}
Aggregations