Search in sources :

Example 36 with NamedThing

use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.

the class ComponentsUtils method getFormalPossibleValues.

/**
     * Get formal possible values of the <code>param</code>. Every possible value will be {@link NamedThing} type.
     *
     * @param param
     * @return
     */
public static List<NamedThing> getFormalPossibleValues(GenericElementParameter param) {
    List<NamedThing> nals = new ArrayList<>();
    if (param == null) {
        return nals;
    }
    List<?> possibleValues = param.getPossibleValues();
    if (possibleValues != null) {
        for (Object object : possibleValues) {
            if (object instanceof NamedThing) {
                nals.add((NamedThing) object);
            } else if (object instanceof String) {
                String name = (String) object;
                Property property = param.getProperty();
                if (property != null) {
                    NamedThing nl = new SimpleNamedThing(name, property.getPossibleValuesDisplayName(name));
                    nals.add(nl);
                }
            }
        }
    }
    return nals;
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) Property(org.talend.daikon.properties.property.Property) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty)

Example 37 with NamedThing

use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.

the class ComponentsUtils method getCurrentProperties.

public static Properties getCurrentProperties(Properties componentProperties, String paramName) {
    if (componentProperties == null || paramName == null) {
        return null;
    }
    String compPropertiesPath = getPropertyPath(paramName);
    if (StringUtils.isEmpty(compPropertiesPath)) {
        return componentProperties;
    }
    NamedThing property = componentProperties.getProperty(compPropertiesPath);
    if (property == null) {
        return getCurrentPropertiesSpecial(componentProperties, paramName);
    }
    if (property instanceof Properties) {
        return (Properties) property;
    }
    return null;
}
Also used : NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Properties(org.talend.daikon.properties.Properties)

Example 38 with NamedThing

use of org.talend.daikon.NamedThing 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;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) PropertyValueEvaluator(org.talend.daikon.properties.property.PropertyValueEvaluator) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) NamedThing(org.talend.daikon.NamedThing) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) SerializerDeserializer(org.talend.daikon.serialize.SerializerDeserializer) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.talend.daikon.properties.property.Property) EnumProperty(org.talend.daikon.properties.property.EnumProperty) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion) PostDeserializeSetup(org.talend.daikon.serialize.PostDeserializeSetup)

Example 39 with NamedThing

use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.

the class ComponentsUtils method getCurrentPropertiesSpecial.

private static Properties getCurrentPropertiesSpecial(Properties componentProperties, String paramName) {
    Properties currentComponentProperties = null;
    if (componentProperties == null || paramName == null) {
        return null;
    }
    List<NamedThing> allProps = componentProperties.getProperties();
    for (NamedThing namedThing : allProps) {
        if (paramName.equals(namedThing.getName())) {
            currentComponentProperties = componentProperties;
            break;
        }
        if (namedThing instanceof Properties) {
            Properties childComponentProperties = (Properties) namedThing;
            currentComponentProperties = getCurrentProperties(childComponentProperties, paramName);
        }
        if (currentComponentProperties != null) {
            break;
        }
    }
    return currentComponentProperties;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Properties(org.talend.daikon.properties.Properties) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 40 with NamedThing

use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.

the class GenericElementParameter method updateProperty.

private void updateProperty(Object newValue) {
    if (getSubProperties() == null) {
        return;
    }
    NamedThing widgetProperty = widget.getContent();
    if (widgetProperty instanceof SchemaProperty) {
        if (newValue instanceof String) {
            ((SchemaProperty) widgetProperty).setValue(new Schema.Parser().parse((String) newValue));
        } else if (newValue instanceof Schema) {
            ((SchemaProperty) widgetProperty).setValue(((Schema) newValue));
        }
    } else if (widgetProperty instanceof Property) {
        Property se = (Property<?>) widgetProperty;
        Object oldValue = se.getStoredValue();
        Object value = newValue;
        List<?> propertyPossibleValues = ((Property<?>) widgetProperty).getPossibleValues();
        if (propertyPossibleValues != null) {
            for (Object possibleValue : propertyPossibleValues) {
                if (possibleValue.toString().equals(newValue)) {
                    value = possibleValue;
                    break;
                }
            }
        }
        if (value != null && !value.equals(oldValue)) {
            se = (Property<?>) getSubProperties().getProperty(se.getName());
            if (isDrivedByForm()) {
                form.setValue(se.getName(), value);
            } else {
                se.setStoredValue(value);
            }
            fireConnectionPropertyChangedEvent(newValue);
        }
    } else if (widgetProperty instanceof PresentationItem) {
        PresentationItem pi = (PresentationItem) widgetProperty;
        Form formtoShow = pi.getFormtoShow();
        if (formtoShow != null) {
            fireShowDialogEvent(getSubProperties().getForm(formtoShow.getName()));
        }
    } else if (widgetProperty instanceof ComponentProperties && Widget.TABLE_WIDGET_TYPE.equals(widget.getWidgetType())) {
        GenericTableUtils.setTableValues((ComponentProperties) widgetProperty, (List<Map<String, Object>>) newValue, this);
    }
}
Also used : SchemaProperty(org.talend.daikon.properties.property.SchemaProperty) ComponentProperties(org.talend.components.api.properties.ComponentProperties) PresentationItem(org.talend.daikon.properties.PresentationItem) Form(org.talend.daikon.properties.presentation.Form) Schema(org.apache.avro.Schema) List(java.util.List) NamedThing(org.talend.daikon.NamedThing) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty) Property(org.talend.daikon.properties.property.Property)

Aggregations

NamedThing (org.talend.daikon.NamedThing)71 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)34 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)21 Property (org.talend.daikon.properties.property.Property)17 ComponentProperties (org.talend.components.api.properties.ComponentProperties)15 ComponentException (org.talend.components.api.exception.ComponentException)14 Schema (org.apache.avro.Schema)11 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)9 ValidationResult (org.talend.daikon.properties.ValidationResult)8 Form (org.talend.daikon.properties.presentation.Form)8 List (java.util.List)7 IOException (java.io.IOException)6 PresentationItem (org.talend.daikon.properties.PresentationItem)6 Properties (org.talend.daikon.properties.Properties)6 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)5 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)5 PropertyPathConnector (org.talend.components.api.component.PropertyPathConnector)4 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)4 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)4