use of org.talend.components.api.service.ComponentService in project tdi-studio-se by Talend.
the class Component method addPropertyParameters.
private void addPropertyParameters(final List<ElementParameter> listParam, final INode node, String formName, EComponentCategory category) {
ComponentProperties props = node.getComponentProperties();
Form form = props.getForm(formName);
List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(node, this.isInitializing(), category, props, form);
props.setValueEvaluator(new ComponentContextPropertyValueEvaluator(node));
ComponentService componentService = ComponentsUtils.getComponentService();
for (ElementParameter parameter : parameters) {
if (parameter instanceof GenericElementParameter) {
GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
genericElementParameter.setComponentService(componentService);
}
}
listParam.addAll(parameters);
}
use of org.talend.components.api.service.ComponentService 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;
}
use of org.talend.components.api.service.ComponentService in project tdi-studio-se by Talend.
the class Salesforce620WizardMigration method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (GenericWizardServiceFactory.getGenericWizardService().isGenericItem(item)) {
try {
GenericConnectionItem connectionItem = (GenericConnectionItem) item;
GenericConnection connection = (GenericConnection) connectionItem.getConnection();
String serialized = connection.getCompProperties();
ComponentService service = ComponentsUtils.getComponentService();
ComponentWizard componentWizard = service.getComponentWizard(NewSalesforceWizardMigrationTask.TYPE_NAME, item.getProperty().getId());
ComponentProperties newProperties = (ComponentProperties) componentWizard.getForms().get(0).getProperties();
newProperties.init();
ComponentProperties properties = loadProperties(serialized, newProperties);
updateSubProperties(properties, newProperties);
newProperties.copyValuesFrom(properties, true, false);
connection.setCompProperties(newProperties.toSerialized());
Set<MetadataTable> tables = new HashSet<MetadataTable>();
PackageHelper.getAllTables(connection, tables);
for (MetadataTable table : tables) {
EList<TaggedValue> values = table.getTaggedValue();
for (TaggedValue value : values) {
if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(value.getTag())) {
Object object = ReflectionUtils.newInstance(NewSalesforceWizardMigrationTask.REFLECTION_SALESFORCE_MODULE_PROPERTIES, newProperties.getClass().getClassLoader(), new Object[] { table.getName() });
if (object != null && object instanceof ComponentProperties) {
ComponentProperties newSalesforceModuleProperties = (ComponentProperties) object;
ComponentProperties moduleProperties = loadProperties(value.getValue(), newSalesforceModuleProperties);
updateSubProperties(moduleProperties, newSalesforceModuleProperties);
newSalesforceModuleProperties.copyValuesFrom(moduleProperties, true, false);
value.setValue(newSalesforceModuleProperties.toSerialized());
}
}
}
}
ProxyRepositoryFactory.getInstance().save(connectionItem, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.components.api.service.ComponentService 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.components.api.service.ComponentService in project tdi-studio-se by Talend.
the class GenericWizardInternalService method getComponentService.
@Override
public ComponentService getComponentService() {
ComponentService compService = null;
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference<ComponentService> compServiceRef = bundleContext.getServiceReference(ComponentService.class);
if (compServiceRef != null) {
compService = bundleContext.getService(compServiceRef);
}
return compService;
}
Aggregations