use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.
the class ComboController method createButtonCommand.
/**
* This method is used for "Guess Query" button.
*
* @return
*/
private Command createButtonCommand() {
IMetadataTable repositoryMetadata = null;
IMetadataTable newRepositoryMetadata = null;
String realTableName = null;
String realTableId = null;
// Only for getting the real table name.
if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
String paramName;
IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
Object repositoryControl = hashCurControls.get(repositorySchemaTypeParameter.getName());
paramName = EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
if (repositoryControl != null) {
String selectedComboItem = ((CCombo) repositoryControl).getText();
if (selectedComboItem != null && selectedComboItem.length() > 0) {
//$NON-NLS-1$
String value = new String("");
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getName().equals(paramName)) {
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (selectedComboItem.equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
}
}
if (elem instanceof Node) {
// this.dynamicProperty.updateRepositoryList();
String connectionId = value.toString().split(" - ")[0];
String tableLabel = value.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
}
// if (repositoryTableMap.containsKey(value)) {
// repositoryMetadata = repositoryTableMap.get(value);
// realTableName = repositoryMetadata.getTableName();
// realTableId = repositoryMetadata.getId();
// } else {
// repositoryMetadata = new MetadataTable();
// }
}
}
}
}
// Ends
QueryGuessCommand cmd = null;
INode node = null;
if (elem instanceof INode) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
newRepositoryMetadata = node.getMetadataList().get(0);
if (newRepositoryMetadata == null) {
String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (schemaSelected != null) {
String connectionId = schemaSelected.toString().split(" - ")[0];
String tableLabel = schemaSelected.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
}
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
} else if (newRepositoryMetadata == null) {
MessageDialog.openWarning(new Shell(), Messages.getString("ComboController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("ComboController.nothingGuess"));
return cmd;
}
}
cmd = new QueryGuessCommand(node, newRepositoryMetadata);
/* parameter can be null,the setMaps won't use the third parameter */
cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
//$NON-NLS-1$
String type = getValueFromRepositoryName("TYPE");
cmd.setParameters(realTableId, realTableName, type);
return cmd;
}
use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.
the class AbstractRepositoryController method getConnection.
/**
*
* DOC wzhang Comment method "getConnection".
*
* @return
*/
private Connection getConnection() {
if (this.elem == null) {
return null;
}
if (elem instanceof Node) {
IElementParameter elementParameter = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
if (elementParameter != null && !EmfComponent.BUILTIN.equals(elementParameter.getValue())) {
String propertyValue = (String) (((Node) elem).getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
if (lastVersion != null) {
final Item item = lastVersion.getProperty().getItem();
if (item != null && item instanceof ConnectionItem) {
Connection repositoryConn = ((ConnectionItem) item).getConnection();
return repositoryConn;
}
}
}
}
return null;
}
use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.
the class JsonPathMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
boolean modified = false;
if (item instanceof JSONFileConnectionItem) {
Connection conn = ((JSONFileConnectionItem) item).getConnection();
if (conn instanceof JSONFileConnection) {
((JSONFileConnection) conn).setReadbyMode(EJsonReadbyMode.XPATH.getValue());
modified = true;
}
}
try {
if (modified) {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
factory.save(item, true);
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.
the class ValidationRuleTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@Override
protected Command createComboCommand(CCombo combo) {
Connection repositoryConnection = null;
String paramName = (String) combo.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
String value = combo.getText();
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
if (value.equals(param.getValue())) {
return null;
}
ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, paramName, value);
return changeValuesFromRepository;
}
use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.
the class NewSalesforceWizardMigrationTask 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);
//$NON-NLS-1$
NamedThing nt = componentProperties.getProperty("loginType");
if (nt instanceof Property) {
Property property = (Property) nt;
if ("OAuth2".equals(property.getStoredValue())) {
//$NON-NLS-1$
List<?> propertyPossibleValues = property.getPossibleValues();
Object newValue = null;
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals("OAuth")) {
//$NON-NLS-1$
newValue = possibleValue;
break;
}
}
}
if (newValue == null) {
// set default value
newValue = propertyPossibleValues.get(0);
}
property.setValue(newValue);
Property<?> endpoint = componentProperties.getValuedProperty("endpoint");
SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) connection;
//$NON-NLS-1$
componentProperties.setValue("endpoint", sfConnection.getWebServiceUrlTextForOAuth());
}
if (GenericTypeUtils.isEnumType(property)) {
List<?> propertyPossibleValues = ((Property<?>) property).getPossibleValues();
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals(property.getStoredValue())) {
property.setStoredValue(possibleValue);
break;
}
}
}
}
}
// set empty value instead of default null value, this will add automatically the double quotes in the job
// when drag&drop metadata
//$NON-NLS-1$ //$NON-NLS-2$
componentProperties.setValue("userPassword.securityKey", "");
//$NON-NLS-1$
Property property = componentProperties.getValuedProperty("userPassword.securityKey");
//$NON-NLS-1$
property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "securityKey");
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_SALESFORCE_SCHEMA.getFolder(), ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
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;
}
Aggregations