use of org.talend.daikon.properties.property.PropertyValueEvaluator in project tdi-studio-se by Talend.
the class Salesforce620Migration method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
String[] componentsName = new String[] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceConnection", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceBulkExec", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceGetDeleted", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceGetUpdated", "tSalesforceInput", "tSalesforceOutput", "tSalesforceOutputBulk", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"tSalesforceOutputBulkExec" };
IComponentConversion changeJDBCDriverJarType = new IComponentConversion() {
@Override
public void transform(NodeType node) {
ElementParameterType elemParamType = ComponentUtilities.getNodeProperty(node, "PROPERTIES");
String propertiesString = elemParamType.getValue();
SerializerDeserializer.Deserialized<ComponentProperties> fromSerialized = Properties.Helper.fromSerializedPersistent(propertiesString, ComponentProperties.class, new PostDeserializeSetup() {
@Override
public void setup(Object properties) {
((Properties) properties).setValueEvaluator(new PropertyValueEvaluator() {
@Override
public Object evaluate(Property property, Object storedValue) {
if (storedValue instanceof String) {
if (GenericTypeUtils.isEnumType(property)) {
ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
Property newProperty = (Property) newProperties.getProperty(property.getName());
if (newProperty == null) {
newProperty = (Property) newProperties.getProperty("connection.loginType");
}
if (newProperty != null) {
List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals(storedValue)) {
property.setStoredValue(possibleValue);
return possibleValue;
}
}
}
}
}
}
return storedValue;
}
});
}
});
ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
updateSubProperties(fromSerialized.object, newProperties);
newProperties.copyValuesFrom(fromSerialized.object, true, false);
NamedThing nt = newProperties.getProperty("module.moduleName");
if (nt != null && nt instanceof Property) {
Property moduleNameProperty = (Property) nt;
String moduleName = (String) moduleNameProperty.getValue();
if (ContextParameterUtils.isContainContextParam(moduleName)) {
moduleName = TalendQuoteUtils.removeQuotes(moduleName);
} else {
moduleName = TalendQuoteUtils.addPairQuotesIfNotExist(moduleName);
}
moduleNameProperty.setStoredValue(moduleName);
}
nt = newProperties.getProperty("upsertRelationTable.columnName");
if (nt != null && nt instanceof Property) {
Property moduleNameProperty = (Property) nt;
if (moduleNameProperty.getPossibleValues() == null || moduleNameProperty.getPossibleValues().isEmpty()) {
List<String> columns = new ArrayList<String>();
if (moduleNameProperty.getValue() instanceof String) {
String column = (String) moduleNameProperty.getValue();
columns.add(column);
} else if (moduleNameProperty.getValue() instanceof List) {
columns.addAll((Collection<? extends String>) moduleNameProperty.getValue());
}
moduleNameProperty.setPossibleValues(columns);
}
}
elemParamType.setValue(newProperties.toSerialized());
}
};
boolean modified = false;
for (Object obj : processType.getNode()) {
if (obj != null && obj instanceof NodeType) {
String componentName = ((NodeType) obj).getComponentName();
if (ArrayUtils.contains(componentsName, componentName)) {
IComponentFilter filter = new NameComponentFilter(componentName);
modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(changeJDBCDriverJarType)) || modified;
}
}
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
}
use of org.talend.daikon.properties.property.PropertyValueEvaluator in project tdi-studio-se by Talend.
the class DynamicComposite method resetParameters.
public List<ElementParameter> resetParameters() {
final List<ElementParameter> newParameters = new ArrayList<>();
List<ElementParameter> currentParameters = (List<ElementParameter>) element.getElementParameters();
List<ElementParameter> parameters = new ArrayList<>();
ComponentService componentService = internalService.getComponentService();
Connection theConnection = null;
if (connectionItem != null) {
theConnection = connectionItem.getConnection();
}
Properties properties = null;
PropertyValueEvaluator evaluator = null;
if (element instanceof FakeElement) {
properties = form.getProperties();
evaluator = new MetadataContextPropertyValueEvaluator(theConnection);
currentParameters.clear();
} else {
properties = ((INode) element).getComponentProperties();
evaluator = new ComponentContextPropertyValueEvaluator((INode) element);
}
if (properties instanceof ComponentProperties) {
if (form != null) {
properties.setValueEvaluator(evaluator);
properties.refreshLayout(form);
}
// For context display.
properties.setValueEvaluator(null);
boolean isInitializing = false;
if (element instanceof INode) {
INode node = (INode) element;
IComponent component = node.getComponent();
if (component instanceof AbstractBasicComponent) {
isInitializing = ((AbstractBasicComponent) component).isInitializing();
}
}
parameters = ComponentsUtils.getParametersFromForm(element, isInitializing, section, (ComponentProperties) properties, form);
addUpdateParameterIfNotExist(parameters);
properties.setValueEvaluator(evaluator);
}
for (ElementParameter parameter : parameters) {
if (parameter instanceof GenericElementParameter) {
GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
genericElementParameter.setComponentService(componentService);
genericElementParameter.setDrivedByForm(drivedByForm);
genericElementParameter.callBeforePresent();
genericElementParameter.removePropertyChangeListener(this);
genericElementParameter.addPropertyChangeListener(this);
if (wizardPropertyChangeListener != null && IGenericConstants.NAME_PROPERTY.equals(parameter.getName())) {
genericElementParameter.addPropertyChangeListener(wizardPropertyChangeListener);
}
if (EParameterFieldType.SCHEMA_REFERENCE.equals(genericElementParameter.getFieldType())) {
if (genericElementParameter.getChildParameters().size() == 0) {
IElementParameter schemaParameter = element.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE, section);
genericElementParameter.getChildParameters().putAll(schemaParameter.getChildParameters());
}
} else if (EParameterFieldType.NAME_SELECTION_AREA.equals(genericElementParameter.getFieldType()) && theConnection != null) {
List<NamedThing> values = new ArrayList<>();
List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(theConnection, SubContainer.class);
List<String> tableLabels = new ArrayList<>();
for (MetadataTable metaTable : metadataTables) {
tableLabels.add(metaTable.getLabel());
}
List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(genericElementParameter);
for (NamedThing possibleValue : possibleValues) {
if (tableLabels.contains(possibleValue.getName())) {
values.add(possibleValue);
}
}
genericElementParameter.setValue(values);
}
if (properties != null && isRepository(element)) {
String repositoryValue = genericElementParameter.getRepositoryValue();
if (genericElementParameter.isShow(currentParameters) && (repositoryValue != null) && (!genericElementParameter.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && genericElementParameter.getCategory() == section) {
org.talend.daikon.properties.property.Property property = properties.getValuedProperty(genericElementParameter.getName());
if (property != null && property.getTaggedValue(IGenericConstants.REPOSITORY_VALUE) != null) {
genericElementParameter.setRepositoryValueUsed(true);
genericElementParameter.setReadOnly(true);
}
}
}
}
}
boolean added = false;
for (ElementParameter currentParameter : currentParameters) {
if (EParameterName.UPDATE_COMPONENTS.getName().equals(currentParameter.getName())) {
currentParameter.setValue(true);
}
if (currentParameter.isSerialized() && currentParameter.getCategory().equals(section)) {
if (!added) {
newParameters.addAll(parameters);
added = true;
}
continue;
}
newParameters.add(currentParameter);
}
if (element instanceof FakeElement) {
newParameters.addAll(reverseParameters(parameters));
}
element.setElementParameters(newParameters);
return newParameters;
}
Aggregations