Search in sources :

Example 41 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class MdmConceptMigrationTask 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 (item instanceof MDMConnectionItem) {
        boolean modify = false;
        MDMConnectionItem mdmConnItem = (MDMConnectionItem) item;
        if (mdmConnItem.getConnection() instanceof MDMConnection) {
            MDMConnection mdmConnection = (MDMConnection) mdmConnItem.getConnection();
            final EList<Concept> schemas = mdmConnection.getSchemas();
            for (Concept concept : schemas) {
                if (!concept.isInputModel()) {
                    concept.setConceptType(MdmConceptType.OUTPUT);
                    modify = true;
                }
            }
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : Concept(org.talend.core.model.metadata.builder.connection.Concept) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection)

Example 42 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class EncryptPasswordInComponentsMigrationTask 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);
    try {
        boolean modified = false;
        ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
        for (Object nodeObjectType : processType.getNode()) {
            NodeType nodeType = (NodeType) nodeObjectType;
            IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), category.getName());
            if (component == null) {
                continue;
            }
            FakeNode fNode = new FakeNode(component);
            for (Object paramObjectType : nodeType.getElementParameter()) {
                ElementParameterType param = (ElementParameterType) paramObjectType;
                IElementParameter paramFromEmf = fNode.getElementParameter(param.getName());
                if (paramFromEmf == null) {
                    // might be some deprecated / removed parameter.
                    continue;
                }
                EParameterFieldType paramFromComponent = paramFromEmf.getFieldType();
                if (EParameterFieldType.PASSWORD == paramFromComponent && param.getValue() != null) {
                    boolean encrypted = true;
                    try {
                        int ind = param.getValue().lastIndexOf(PasswordEncryptUtil.ENCRYPT_KEY);
                        if (ind == -1) {
                            encrypted = false;
                        } else {
                            String value = new StringBuilder(param.getValue()).replace(ind, ind + PasswordEncryptUtil.ENCRYPT_KEY.length(), "").toString();
                            PasswordEncryptUtil.decryptPassword(value);
                        }
                    } catch (Exception e) {
                        encrypted = false;
                    }
                    if (!encrypted) {
                        param.setValue(PasswordEncryptUtil.encryptPassword(param.getValue()) + PasswordEncryptUtil.ENCRYPT_KEY);
                        modified = true;
                    }
                }
            }
        }
        if (modified) {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            factory.save(item, true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IComponent(org.talend.core.model.components.IComponent) ComponentCategory(org.talend.core.model.components.ComponentCategory) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EParameterFieldType(org.talend.core.model.process.EParameterFieldType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 43 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class ConnectionAddUniqueNameMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    try {
        uniqueConnectionNameList.clear();
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        ProcessType processType = getProcessType(item);
        boolean modified = false;
        if (processType != null) {
            for (Object o : processType.getConnection()) {
                ConnectionType currentConnection = (ConnectionType) o;
                ElementParameterType uniqueNameParam = null;
                for (Object paramObject : currentConnection.getElementParameter()) {
                    ElementParameterType paramType = (ElementParameterType) paramObject;
                    if (UNIQUE_NAME.equals(paramType.getName())) {
                        uniqueNameParam = paramType;
                    }
                }
                if (uniqueNameParam == null) {
                    uniqueNameParam = TalendFileFactory.eINSTANCE.createElementParameterType();
                    uniqueNameParam.setName("UNIQUE_NAME");
                    uniqueNameParam.setField(EParameterFieldType.TEXT.getName());
                    uniqueNameParam.setContextMode(false);
                    currentConnection.getElementParameter().add(uniqueNameParam);
                }
                String value = uniqueNameParam.getValue();
                String baseName = "";
                if (value == null || "".equals(value)) {
                    modified = true;
                    EConnectionType connectionType = EConnectionType.getTypeFromId(currentConnection.getLineStyle());
                    if (connectionType.hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connectionType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                        baseName = null;
                    } else if (connectionType.equals(EConnectionType.ITERATE)) {
                        baseName = "iterate";
                    } else if (connectionType.equals(EConnectionType.TABLE)) {
                        baseName = null;
                    } else if (connectionType.equals(EConnectionType.SYNCHRONIZE) || connectionType.equals(EConnectionType.PARALLELIZE)) {
                        baseName = null;
                    } else {
                        baseName = connectionType.getDefaultLinkName();
                    }
                    String uniqueName = "";
                    if (connectionType.equals(EConnectionType.TABLE)) {
                        uniqueName = currentConnection.getMetaname();
                    } else {
                        uniqueName = currentConnection.getLabel();
                    }
                    if (baseName != null && !"".equals(baseName)) {
                        uniqueName = generateUniqueConnectionName(baseName);
                    }
                    uniqueNameParam.setValue(uniqueName);
                    uniqueConnectionNameList.add(uniqueName);
                }
            }
        }
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 44 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method getRepositoryContext.

private static ISelection getRepositoryContext(final String contextNameOrId, boolean isId) {
    if (contextNameOrId == null || "".equals(contextNameOrId.trim())) {
        //$NON-NLS-1$
        return null;
    }
    if (isId && RepositoryNode.NO_ID.equals(contextNameOrId.trim())) {
        return null;
    }
    IRepositoryViewObject contextObject = null;
    try {
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
        if (contextObjectList != null) {
            for (IRepositoryViewObject object : contextObjectList) {
                Item item = object.getProperty().getItem();
                if (item != null && item instanceof ContextItem) {
                    String itemNameOrId = null;
                    if (isId) {
                        itemNameOrId = item.getProperty().getId();
                    } else {
                        itemNameOrId = item.getProperty().getLabel();
                    }
                    if (contextNameOrId.equals(itemNameOrId)) {
                        contextObject = object;
                        break;
                    }
                }
            }
        }
    } catch (PersistenceException e) {
    //
    }
    StructuredSelection selection = new StructuredSelection();
    if (contextObject != null) {
        RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(contextObject);
        if (repositoryNode != null) {
            selection = new StructuredSelection(repositoryNode);
        }
    }
    return selection;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ContextItem(org.talend.core.model.properties.ContextItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 45 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class RenametForCurrentIterationMigrationTask method convertItem.

private boolean convertItem(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    ECodeLanguage language = getProject().getLanguage();
    EList node = processType.getNode();
    for (Object n : node) {
        NodeType type = (NodeType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (!elemType.getField().equals("CHECK")) {
                //$NON-NLS-1$
                if (language.equals(ECodeLanguage.JAVA)) {
                    if (elemType.getValue() != null && elemType.getValue().contains(TFOR) && elemType.getValue().contains(CURRENT_ITER)) {
                        elemType.setValue(elemType.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
                    }
                }
                if (elemType.getValue() != null && elemType.getValue().contains(TFOR)) {
                    elemType.setValue(elemType.getValue().replaceAll(TFOR, TLOOP));
                    modified = true;
                }
                // for table
                EList elemValue = elemType.getElementValue();
                for (Object elemV : elemValue) {
                    ElementValueType elemVal = (ElementValueType) elemV;
                    if (language.equals(ECodeLanguage.JAVA)) {
                        if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR) && elemVal.getValue().contains(CURRENT_ITER)) {
                            elemVal.setValue(elemVal.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
                        }
                    }
                    if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR)) {
                        elemVal.setValue(elemVal.getValue().replaceAll(TFOR, TLOOP));
                        modified = true;
                    }
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
    return modified;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)74 PersistenceException (org.talend.commons.exception.PersistenceException)32 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 EList (org.eclipse.emf.common.util.EList)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Project (org.talend.core.model.general.Project)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 ArrayList (java.util.ArrayList)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Path (org.eclipse.core.runtime.Path)6 EConnectionType (org.talend.core.model.process.EConnectionType)6 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 List (java.util.List)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5