Search in sources :

Example 1 with GenericConnectionItem

use of org.talend.repository.generic.model.genericMetadata.GenericConnectionItem in project tdi-studio-se by Talend.

the class GenericConnWizard method addPages.

@Override
public void addPages() {
    ERepositoryObjectType repObjType = (ERepositoryObjectType) repNode.getProperties(EProperties.CONTENT_TYPE);
    String typeName = repObjType.getType();
    setWindowTitle(typeName);
    Image wiardImage = wizardService.getWiardImage(typeName);
    setDefaultPageImageDescriptor(ImageDescriptor.createFromImage(wiardImage));
    ((GenericConnectionItem) connectionItem).setTypeName(typeName);
    IGenericWizardInternalService internalService = new GenericWizardInternalService();
    ComponentWizard componentWizard = null;
    if (creation) {
        componentWizard = internalService.getComponentWizard(typeName, connectionProperty.getId());
    } else {
        String compPropertiesStr = connection.getCompProperties();
        if (compPropertiesStr != null) {
            ComponentProperties properties = ComponentsUtils.getComponentPropertiesFromSerialized(compPropertiesStr, connection, false);
            if (properties != null) {
                componentWizard = internalService.getTopLevelComponentWizard(properties, repNode.getId());
            }
        }
    }
    if (componentWizard == null) {
        return;
    }
    List<Form> forms = componentWizard.getForms();
    for (int i = 0; i < forms.size(); i++) {
        Form form = forms.get(i);
        boolean addContextSupport = false;
        if (i == 0) {
            // Add context support in the first form.
            addContextSupport = true;
        }
        wizPage = new GenericConnWizardPage(connectionItem, isRepositoryObjectEditable(), existingNames, creation, form, compService, addContextSupport);
        if (wizPage != null) {
            wizPage.setTitle(form.getTitle());
            wizPage.setDescription(form.getSubtitle());
            if (creation) {
                wizPage.setPageComplete(false);
            } else {
                wizPage.setPageComplete(isRepositoryObjectEditable());
            }
        }
        addPage(wizPage);
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) GenericWizardInternalService(org.talend.repository.generic.internal.service.GenericWizardInternalService) IGenericWizardInternalService(org.talend.repository.generic.internal.IGenericWizardInternalService) Image(org.eclipse.swt.graphics.Image) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) IGenericWizardInternalService(org.talend.repository.generic.internal.IGenericWizardInternalService) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem)

Example 2 with GenericConnectionItem

use of org.talend.repository.generic.model.genericMetadata.GenericConnectionItem in project tdi-studio-se by Talend.

the class GenericRepository method storeProperties.

@Override
public String storeProperties(ComponentProperties properties, String name, String repositoryLocation, String schemaPropertyName) {
    if (properties == null) {
        //$NON-NLS-1$
        throw new RuntimeException("Properties argument cannot be null!");
    }
    // Add repository value if it is from repository
    List<org.talend.daikon.properties.property.Property> propertyValues = ComponentsUtils.getAllValuedProperties(properties);
    for (org.talend.daikon.properties.property.Property property : propertyValues) {
        property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
    }
    String serializedProperties = properties.toSerialized();
    if (repositoryLocation.contains(IGenericConstants.REPOSITORY_LOCATION_SEPARATOR)) {
        // nested properties to be
        GenericConnectionItem item = getGenericConnectionItem(repositoryLocation.substring(0, repositoryLocation.indexOf(IGenericConstants.REPOSITORY_LOCATION_SEPARATOR)));
        if (item == null) {
            //$NON-NLS-1$
            throw new RuntimeException("Failed to find the GenericConnectionItem for location:" + repositoryLocation);
        }
        GenericConnection connection = (GenericConnection) item.getConnection();
        orgomg.cwm.objectmodel.core.Package parentContainer = null;
        if (repositoryLocation.endsWith(IGenericConstants.REPOSITORY_LOCATION_SEPARATOR)) {
            // first nested property
            parentContainer = connection;
        } else {
            parentContainer = getContainer(connection, repositoryLocation);
        }
        ModelElement childElement = null;
        if (schemaPropertyName == null) {
            // If schema property name is not provided, then create the subcontainer.
            childElement = createContainer(name, serializedProperties);
        } else {
            // Remove Repository Value tag value for schema property.
            org.talend.daikon.properties.property.Property<?> schemaProperty = properties.getValuedProperty(schemaPropertyName);
            if (schemaProperty != null) {
                schemaProperty.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, null);
            }
            childElement = SchemaUtils.createSchema(name, properties, schemaPropertyName);
        }
        parentContainer.getOwnedElement().add(childElement);
        return repositoryLocation + IGenericConstants.REPOSITORY_LOCATION_SEPARATOR + name;
    } else {
        // simple properties to be set
        GenericConnectionItem item = getGenericConnectionItem(repositoryLocation);
        if (item != null) {
            GenericConnection connection = (GenericConnection) item.getConnection();
            connection.setCompProperties(serializedProperties);
            connection.getOwnedElement().clear();
            return repositoryLocation + IGenericConstants.REPOSITORY_LOCATION_SEPARATOR;
        } else {
            //$NON-NLS-1$
            throw new RuntimeException("Failed to find the GenericConnectionItem for location:" + repositoryLocation);
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Property(org.talend.core.model.properties.Property)

Example 3 with GenericConnectionItem

use of org.talend.repository.generic.model.genericMetadata.GenericConnectionItem 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 GenericConnectionItem

use of org.talend.repository.generic.model.genericMetadata.GenericConnectionItem 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;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) ComponentService(org.talend.components.api.service.ComponentService) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) HashSet(java.util.HashSet)

Example 5 with GenericConnectionItem

use of org.talend.repository.generic.model.genericMetadata.GenericConnectionItem 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;
}
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) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) IOException(java.io.IOException) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) 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)

Aggregations

GenericConnectionItem (org.talend.repository.generic.model.genericMetadata.GenericConnectionItem)18 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)9 ComponentProperties (org.talend.components.api.properties.ComponentProperties)5 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 Property (org.talend.core.model.properties.Property)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 ArrayList (java.util.ArrayList)3 Path (org.eclipse.core.runtime.Path)3 ComponentService (org.talend.components.api.service.ComponentService)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 IComponent (org.talend.core.model.components.IComponent)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 Item (org.talend.core.model.properties.Item)2 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)2 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)2 HashSet (java.util.HashSet)1 List (java.util.List)1