Search in sources :

Example 6 with Property

use of org.talend.daikon.properties.property.Property 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;
}
Also used : Path(org.eclipse.core.runtime.Path) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ComponentService(org.talend.components.api.service.ComponentService) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Property(org.talend.daikon.properties.property.Property)

Example 7 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class ComponentsUtilsTest method checkParameterInitializationStatus.

private void checkParameterInitializationStatus(List<ElementParameter> parameters, boolean isInitializing) {
    for (ElementParameter parameter : parameters) {
        if (parameter instanceof GenericElementParameter) {
            GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
            Property property = genericElementParameter.getProperty();
            if (property != null) {
                if (GenericTypeUtils.isStringType(property)) {
                    String propertyValue = (String) property.getValue();
                    String parameterValue = (String) parameter.getValue();
                    // If value is empty (from default value or input) add double quotes.
                    if (StringUtils.isEmpty(propertyValue)) {
                        //$NON-NLS-1$
                        assertTrue("\"\"".equals(parameterValue));
                    } else {
                        // Else value is not empty.
                        if (isInitializing) {
                            // If isInitializing is true value will be surrounded with quotes if not exist.
                            //$NON-NLS-1$ //$NON-NLS-2$
                            assertTrue(parameterValue.startsWith("\"") && parameterValue.endsWith("\""));
                        } else if (!propertyValue.startsWith("\"") || !propertyValue.endsWith("\"")) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            // Else shouldn't add quotes to the value.
                            //$NON-NLS-1$ //$NON-NLS-2$
                            assertFalse(parameterValue.startsWith("\"") && parameterValue.endsWith("\""));
                        }
                    }
                }
            }
        }
    }
}
Also used : GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) StringProperty(org.talend.daikon.properties.property.StringProperty) Property(org.talend.daikon.properties.property.Property)

Example 8 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class TestComponentDefinition method getReturnProperties.

@Override
public Property[] getReturnProperties() {
    StringProperty return1 = newProperty("return1");
    setupI18N(new Property<?>[] { return1 });
    return new Property[] { return1, RETURN_ERROR_MESSAGE_PROP, RETURN_TOTAL_RECORD_COUNT_PROP, RETURN_SUCCESS_RECORD_COUNT_PROP, RETURN_REJECT_RECORD_COUNT_PROP };
}
Also used : StringProperty(org.talend.daikon.properties.property.StringProperty) StringProperty(org.talend.daikon.properties.property.StringProperty) Property(org.talend.daikon.properties.property.Property)

Example 9 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class ComponentsUtils method getAllValuedProperties.

/**
     * looks for all Property type properties of the given properties and all is nested Properties.
     */
public static List<Property> getAllValuedProperties(Properties properties) {
    List<Property> allValuedProperties = new ArrayList<>();
    if (properties == null) {
        return Collections.EMPTY_LIST;
    }
    List<NamedThing> namedThings = properties.getProperties();
    for (NamedThing namedThing : namedThings) {
        if (namedThing instanceof Properties) {
            Properties childComponentProperties = (Properties) namedThing;
            allValuedProperties.addAll(getAllValuedProperties(childComponentProperties));
        } else if (namedThing instanceof Property) {
            allValuedProperties.add((Property) namedThing);
        }
    // else other type not yet handled
    }
    return allValuedProperties;
}
Also used : ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Properties(org.talend.daikon.properties.Properties) Property(org.talend.daikon.properties.property.Property) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty)

Example 10 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class ComponentsUtils method getParametersFromForm.

/**
     * DOC ycbai Comment method "loadParametersFromForm".
     * <p>
     * Get element parameters of <code>element</code> from <code>form</code>.
     *
     * @param node optional, used if there is a component setting up the properties
     * @param element
     * @param category
     * @param form
     * @return parameters list
     */
private static List<ElementParameter> getParametersFromForm(IElement element, boolean isInitializing, EComponentCategory category, ComponentProperties rootProperty, Properties compProperties, String parentPropertiesPath, Form form, Widget parentWidget, AtomicInteger lastRowNum) {
    List<ElementParameter> elementParameters = new ArrayList<>();
    List<String> parameterNames = new ArrayList<>();
    EComponentCategory compCategory = category;
    if (compCategory == null) {
        compCategory = EComponentCategory.BASIC;
    }
    AtomicInteger lastRN = lastRowNum;
    if (lastRN == null) {
        lastRN = new AtomicInteger();
    }
    if (form == null) {
        return elementParameters;
    }
    Properties componentProperties = compProperties;
    if (componentProperties == null) {
        componentProperties = form.getProperties();
    }
    if (element instanceof INode) {
        INode node = (INode) element;
        // Set the properties only one time to get the top-level properties object
        if (node.getComponentProperties() == null) {
            node.setComponentProperties(rootProperty);
        }
    }
    // Have to initialize for the messages
    Collection<Widget> formWidgets = form.getWidgets();
    for (Widget widget : formWidgets) {
        NamedThing widgetProperty = widget.getContent();
        String propertiesPath = getPropertiesPath(parentPropertiesPath, null);
        if (widgetProperty instanceof Form) {
            Form subForm = (Form) widgetProperty;
            Properties subProperties = subForm.getProperties();
            // Reset properties path
            if (!isSameComponentProperties(componentProperties, widgetProperty)) {
                propertiesPath = getPropertiesPath(parentPropertiesPath, subProperties.getName());
            }
            elementParameters.addAll(getParametersFromForm(element, isInitializing, compCategory, rootProperty, subProperties, propertiesPath, subForm, widget, lastRN));
            continue;
        }
        GenericElementParameter param = new GenericElementParameter(element, rootProperty, form, widget, getComponentService());
        String parameterName = propertiesPath.concat(param.getName());
        param.setName(parameterName);
        param.setCategory(compCategory);
        param.setShow(parentWidget == null ? !widget.isHidden() : !parentWidget.isHidden() && !widget.isHidden());
        int rowNum = 0;
        if (widget.getOrder() != 1) {
            rowNum = lastRN.get();
        } else {
            rowNum = widget.getRow();
            if (parentWidget != null) {
                rowNum += parentWidget.getRow();
            }
            rowNum = rowNum + lastRN.get();
        }
        param.setNumRow(rowNum);
        lastRN.set(rowNum);
        // handle form...
        EParameterFieldType fieldType = getFieldType(widget, widgetProperty);
        param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
        if (widgetProperty instanceof SchemaProperty) {
            boolean found = false;
            // set a default connector
            param.setContext(EConnectionType.FLOW_MAIN.getName());
            for (Connector connector : rootProperty.getPossibleConnectors(true)) {
                if (!(((SchemaProperty) widgetProperty).getValue() instanceof Schema)) {
                    continue;
                }
                if (connector instanceof PropertyPathConnector) {
                    //$NON-NLS-1$
                    String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
                    if (parameterName.equals(linkedSchema)) {
                        found = true;
                        param.setContext(connector.getName());
                        IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
                        Schema schema = ((SchemaProperty) widgetProperty).getValue();
                        defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
                        param.getDefaultValues().add(defaultValue);
                    }
                }
            }
            if (!found) {
                // compatibility.
                for (Connector connector : rootProperty.getPossibleConnectors(false)) {
                    if (!(((SchemaProperty) widgetProperty).getValue() instanceof Schema)) {
                        continue;
                    }
                    if (connector instanceof PropertyPathConnector) {
                        //$NON-NLS-1$
                        String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
                        if (parameterName.equals(linkedSchema)) {
                            if (GenericNodeConnector.INPUT_CONNECTOR.equals(connector.getName())) {
                                param.setContext(EConnectionType.FLOW_MAIN.getName());
                            } else {
                                param.setContext(connector.getName());
                            }
                            IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
                            Schema schema = ((SchemaProperty) widgetProperty).getValue();
                            defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
                            param.getDefaultValues().add(defaultValue);
                        }
                    }
                }
            }
        }
        if (widgetProperty instanceof PresentationItem) {
            param.setValue(widgetProperty.getDisplayName());
        } else if (widgetProperty instanceof Property) {
            Property property = (Property) widgetProperty;
            param.setRequired(property.isRequired());
            param.setValue(getParameterValue(element, property, fieldType));
            boolean isNameProperty = IGenericConstants.NAME_PROPERTY.equals(param.getParameterName());
            if (EParameterFieldType.NAME_SELECTION_AREA.equals(fieldType) || EParameterFieldType.JSON_TABLE.equals(fieldType) || EParameterFieldType.CLOSED_LIST.equals(fieldType) || EParameterFieldType.CHECK.equals(fieldType) || isNameProperty) {
                // Disable context support for those filed types and name parameter.
                param.setSupportContext(false);
            } else {
                param.setSupportContext(isSupportContext(property));
            }
            property.setTaggedValue(IComponentConstants.SUPPORT_CONTEXT, param.isSupportContext());
            Object cmTV = property.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE);
            param.setReadOnly(Boolean.valueOf(String.valueOf(cmTV)));
            boolean isDynamic = Boolean.valueOf(String.valueOf(property.getTaggedValue(IGenericConstants.IS_DYNAMIC)));
            param.setContextMode(isDynamic);
            List<?> values = property.getPossibleValues();
            if (values != null || EParameterFieldType.CLOSED_LIST.equals(fieldType)) {
                if (values == null) {
                    values = Collections.emptyList();
                }
                param.setPossibleValues(values);
                List<String> possVals = new ArrayList<>();
                List<String> possValsDisplay = new ArrayList<>();
                for (Object obj : values) {
                    String value = null;
                    String valueDisplay = null;
                    if (obj instanceof NamedThing) {
                        NamedThing nal = (NamedThing) obj;
                        value = nal.getName();
                        valueDisplay = nal.getDisplayName();
                    } else {
                        value = String.valueOf(obj);
                        valueDisplay = String.valueOf(obj);
                    }
                    String pvDisplayName = property.getPossibleValuesDisplayName(obj);
                    if (StringUtils.isNotBlank(pvDisplayName) && !"null".equals(pvDisplayName)) {
                        //$NON-NLS-1$
                        valueDisplay = pvDisplayName;
                    }
                    possVals.add(value);
                    possValsDisplay.add(valueDisplay);
                }
                param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
                param.setListItemsDisplayCodeName(possValsDisplay.toArray(new String[0]));
                param.setListItemsValue(possVals.toArray(new String[0]));
            }
        } else if (fieldType != null && fieldType.equals(EParameterFieldType.TABLE) && widgetProperty instanceof Properties) {
            Properties table = (Properties) widgetProperty;
            Form mainForm = table.getForm(Form.MAIN);
            param.setDisplayName(mainForm.getTitle());
            //$NON-NLS-1$
            List<ElementParameter> parameters = getParametersFromForm(new FakeElement("table"), mainForm);
            // table is always empty by default
            param.setSupportContext(false);
            List<String> codeNames = new ArrayList<>();
            List<String> possValsDisplay = new ArrayList<>();
            for (ElementParameter curParam : parameters) {
                curParam.setFilter(null);
                curParam.setContext(null);
                curParam.setShowIf(null);
                curParam.setNotShowIf(null);
                curParam.setReadOnlyIf(null);
                curParam.setNotReadOnlyIf(null);
                curParam.setNoContextAssist(false);
                curParam.setRaw(false);
                curParam.setReadOnly(false);
                fillDefaultValsForListType(curParam);
                codeNames.add(curParam.getName());
                possValsDisplay.add(curParam.getDisplayName());
            }
            param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
            param.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
            param.setListItemsValue(parameters.toArray(new ElementParameter[0]));
            String[] listItemsShowIf = new String[parameters.size()];
            String[] listItemsNotShowIf = new String[parameters.size()];
            param.setListItemsShowIf(listItemsShowIf);
            param.setListItemsNotShowIf(listItemsNotShowIf);
            param.setValue(GenericTableUtils.getTableValues(table, param));
            param.setBasedOnSchema(Boolean.valueOf(String.valueOf(widget.getConfigurationValue(Widget.HIDE_TOOLBAR_WIDGET_CONF))));
        }
        if (!param.isReadOnly()) {
            param.setReadOnly(widget.isReadonly() || element.isReadOnly());
        }
        // For issue TUP-16139
        if (EParameterFieldType.COMPONENT_REFERENCE.equals(fieldType) && param.getNumRow() == 2 && EComponentCategory.BASIC.equals(compCategory)) {
            param.setNumRow(1);
        }
        param.setSerialized(true);
        param.setDynamicSettings(true);
        // Avoid adding duplicate prameter.
        if (!parameterNames.contains(parameterName)) {
            elementParameters.add(param);
            parameterNames.add(parameterName);
        }
    }
    return elementParameters;
}
Also used : PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) INodeConnector(org.talend.core.model.process.INodeConnector) GenericNodeConnector(org.talend.designer.core.generic.model.GenericNodeConnector) Connector(org.talend.components.api.component.Connector) INode(org.talend.core.model.process.INode) PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) Form(org.talend.daikon.properties.presentation.Form) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) Widget(org.talend.daikon.properties.presentation.Widget) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Properties(org.talend.daikon.properties.Properties) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) Property(org.talend.daikon.properties.property.Property) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty) EComponentCategory(org.talend.core.model.process.EComponentCategory) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty) PresentationItem(org.talend.daikon.properties.PresentationItem) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) FakeElement(org.talend.designer.core.model.FakeElement) EParameterFieldType(org.talend.core.model.process.EParameterFieldType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) ElementParameterDefaultValue(org.talend.designer.core.model.components.ElementParameterDefaultValue)

Aggregations

Property (org.talend.daikon.properties.property.Property)24 ComponentProperties (org.talend.components.api.properties.ComponentProperties)14 NamedThing (org.talend.daikon.NamedThing)12 ArrayList (java.util.ArrayList)8 SchemaProperty (org.talend.daikon.properties.property.SchemaProperty)7 List (java.util.List)5 HashMap (java.util.HashMap)4 Schema (org.apache.avro.Schema)4 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)4 Properties (org.talend.daikon.properties.Properties)4 EnumProperty (org.talend.daikon.properties.property.EnumProperty)4 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)4 Map (java.util.Map)3 PresentationItem (org.talend.daikon.properties.PresentationItem)3 Form (org.talend.daikon.properties.presentation.Form)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)2 ComponentService (org.talend.components.api.service.ComponentService)2