Search in sources :

Example 1 with NamedThing

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

the class GenericUIBuilder method createWidgetUIByPropertyType.

private void createWidgetUIByPropertyType(Composite parent, Widget widget) {
    NamedThing property = getProperty(widget);
    if (property == null) {
        return;
    }
    int hSpan = widget.getOrder();
    if (property instanceof PresentationItem) {
        PresentationItem item = (PresentationItem) property;
        createLabel(parent, item.getDisplayName(), hSpan);
        return;
    } else if (property instanceof Property) {
        Property element = (Property) property;
        String displayName = element.getDisplayName();
        String type = element.getType();
        if (type == null) {
            createLabel(parent, displayName, hSpan);
            return;
        }
        if (GenericTypeUtils.isStringType(type)) {
            new LabelledText(parent, displayName, hSpan);
        } else if (GenericTypeUtils.isBooleanType(type)) {
        // nothing
        } else {
            new LabelledText(parent, element.getDisplayName(), hSpan);
        }
    }
}
Also used : LabelledText(org.talend.commons.ui.swt.formtools.LabelledText) PresentationItem(org.talend.daikon.properties.PresentationItem) NamedThing(org.talend.daikon.NamedThing) Property(org.talend.daikon.properties.property.Property)

Example 2 with NamedThing

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

the class Salesforce620Migration method updateSubProperties.

/**
     * DOC nrousseau Comment method "updateSubProperties".
     * 
     * @param properties
     * @param newProperties
     */
private void updateSubProperties(ComponentProperties properties, ComponentProperties newProperties) {
    if (newProperties == null) {
        return;
    }
    for (NamedThing nt : properties.getProperties()) {
        if (nt instanceof Property) {
            Property property = (Property) nt;
            Object storedValue = property.getStoredValue();
            if (storedValue instanceof String) {
                String stringValue = (String) storedValue;
                if (ContextParameterUtils.isContainContextParam(stringValue)) {
                    continue;
                }
                Property newProperty = (Property) newProperties.getProperty(property.getName());
                if (newProperty != null) {
                    if (GenericTypeUtils.isBooleanType(newProperty)) {
                        if (stringValue.isEmpty()) {
                            property.setValue(Boolean.FALSE);
                        } else {
                            property.setValue(new Boolean(stringValue));
                        }
                    } else if (GenericTypeUtils.isEnumType(newProperty) && (!(newProperty instanceof EnumProperty))) {
                        property.setStoredValue(TalendQuoteUtils.removeQuotes(stringValue));
                    } else if (GenericTypeUtils.isEnumType(newProperty)) {
                        List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
                        if (propertyPossibleValues != null) {
                            for (Object possibleValue : propertyPossibleValues) {
                                if (possibleValue.toString().equals(storedValue)) {
                                    property.setStoredValue(possibleValue);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        } else if (nt instanceof ComponentProperties) {
            updateSubProperties((ComponentProperties) nt, (ComponentProperties) newProperties.getProperty(nt.getName()));
        }
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) EnumProperty(org.talend.daikon.properties.property.EnumProperty) NamedThing(org.talend.daikon.NamedThing) Property(org.talend.daikon.properties.property.Property) EnumProperty(org.talend.daikon.properties.property.EnumProperty)

Example 3 with NamedThing

use of org.talend.daikon.NamedThing 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 4 with NamedThing

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

the class NewGenericWizardMigrationTask method updateComponentProperties.

protected boolean updateComponentProperties(Connection oldConnection, ComponentProperties componentProperties, Properties props) {
    boolean modified = false;
    if (props != null) {
        for (Object element : props.keySet()) {
            boolean changed = false;
            String propsKey = (String) element;
            String propsValue = props.getProperty(propsKey);
            if (propsValue != null && !"".equals(propsValue.trim())) {
                //$NON-NLS-1$
                Object value = getValueFromOldConnection(oldConnection, propsValue);
                if (value != null) {
                    NamedThing namedThing = componentProperties.getProperty(propsKey);
                    if (namedThing != null && namedThing instanceof org.talend.daikon.properties.property.Property) {
                        org.talend.daikon.properties.property.Property<?> property = (org.talend.daikon.properties.property.Property<?>) namedThing;
                        if (GenericTypeUtils.isEnumType(property)) {
                            //$NON-NLS-1$
                            Object obj = props.get(propsKey + "." + value);
                            if (obj != null) {
                                List<?> propertyPossibleValues = property.getPossibleValues();
                                Object newValue = null;
                                if (propertyPossibleValues != null) {
                                    for (Object possibleValue : propertyPossibleValues) {
                                        if (possibleValue.toString().equals(obj)) {
                                            newValue = possibleValue;
                                            break;
                                        }
                                    }
                                }
                                if (newValue == null) {
                                    // set default value
                                    newValue = propertyPossibleValues.get(0);
                                }
                                componentProperties.setValue(propsKey, newValue);
                                property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
                                changed = true;
                            }
                        }
                        if (GenericTypeUtils.isBooleanType(property)) {
                            if (value != null && value instanceof String) {
                                try {
                                    value = new Boolean((String) value);
                                } catch (Exception e) {
                                    value = Boolean.FALSE;
                                }
                            }
                        }
                        if (GenericTypeUtils.isIntegerType(property) && !oldConnection.isContextMode()) {
                            if (value != null && value instanceof String) {
                                try {
                                    value = new Integer((String) value);
                                } catch (Exception e) {
                                    value = 0;
                                }
                            }
                        }
                        if (property.isFlag(org.talend.daikon.properties.property.Property.Flags.ENCRYPT) && !oldConnection.isContextMode()) {
                            componentProperties.setValue(propsKey, CryptoHelper.getDefault().decrypt(String.valueOf(value)));
                            property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
                            modified = true;
                            changed = true;
                        }
                        if (!changed) {
                            property.setStoredValue(value);
                            property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    return modified;
}
Also used : NamedThing(org.talend.daikon.NamedThing) Property(org.talend.core.model.properties.Property)

Example 5 with NamedThing

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

the class WidgetFieldTypeMappingReaderTest method testGetFieldType.

@Test
public void testGetFieldType() {
    //$NON-NLS-1$//$NON-NLS-2$
    NamedThing nameAndLabel = new SimpleNamedThing("testName", "testLabel");
    //$NON-NLS-1$
    Assert.assertEquals("testName", nameAndLabel.getName());
    //$NON-NLS-1$
    Assert.assertEquals("testLabel", nameAndLabel.getDisplayName());
    Assert.assertNull(nameAndLabel.getTitle());
    WidgetFieldTypeMappingReader mappingReader = WidgetFieldTypeMappingReader.getInstance();
    //$NON-NLS-1$//$NON-NLS-2$
    String fieldType = mappingReader.getFieldType("widget.type.default", nameAndLabel, "java.lang.String");
    //$NON-NLS-1$
    Assert.assertEquals("TEXT", fieldType);
    //$NON-NLS-1$
    fieldType = mappingReader.getFieldType("widget.type.default", nameAndLabel, null);
    //$NON-NLS-1$
    Assert.assertEquals("LABEL", fieldType);
    //$NON-NLS-1$//$NON-NLS-2$
    fieldType = mappingReader.getFieldType("widget.type.hidden.text", nameAndLabel, "widget.type.hidden.text");
    //$NON-NLS-1$
    Assert.assertEquals("HIDDEN_TEXT", fieldType);
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) NamedThing(org.talend.daikon.NamedThing) Test(org.junit.Test)

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