Search in sources :

Example 11 with ProxyRepositoryFactory

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

the class JSONConnectionContextHelper method convertContextLabel.

/**
     * 
     * change the mode of lebel to Context mode
     * 
     * @param label which you want to convert(it is the name of connection normal)
     * @return Context mode label
     */
public static String convertContextLabel(String label) {
    if (label != null) {
        //$NON-NLS-1$ //$NON-NLS-2$
        String newLabel = label.replaceAll("[\\.\\-\\ \\(\\)\\[\\]=]", "_");
        //$NON-NLS-1$
        Pattern pattern = Pattern.compile("^[0-9]+.*$");
        Matcher m = pattern.matcher(newLabel);
        if (m.matches()) {
            //$NON-NLS-1$
            newLabel = "_" + newLabel;
        }
        //
        try {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
            int i = 1;
            String tmpLabel = newLabel;
            while (!isValidContextName(contextObjectList, tmpLabel)) {
                tmpLabel = newLabel + i;
                i++;
            }
            return tmpLabel;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        return newLabel;
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) Matcher(java.util.regex.Matcher) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 12 with ProxyRepositoryFactory

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

the class ExcleGenerationModeMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    FileExcelConnection fileExcelConn = null;
    if (item instanceof ExcelFileConnectionItem) {
        ExcelFileConnectionItem exelConnItem = (ExcelFileConnectionItem) item;
        if (exelConnItem.getConnection() instanceof FileExcelConnection) {
            fileExcelConn = (FileExcelConnection) exelConnItem.getConnection();
        }
    }
    if (fileExcelConn == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        boolean isXsls = false;
        String filePath = fileExcelConn.getFilePath();
        if (filePath.endsWith(".xlsx")) {
            isXsls = true;
        }
        String genMode = fileExcelConn.getGenerationMode();
        if (isXsls && genMode == null) {
            fileExcelConn.setGenerationMode("USER_MODE");
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.NOTHING_TO_DO;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ExcelFileConnectionItem(org.talend.core.model.properties.ExcelFileConnectionItem) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection)

Example 13 with ProxyRepositoryFactory

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

the class FileInputRegexContextVariableMigrationTask method addQuote.

private boolean addQuote(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return false;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    EList nodes = processType.getNode();
    for (Object n : nodes) {
        NodeType type = (NodeType) n;
        if (type.getComponentName().equals("tFileInputRegex")) {
            //$NON-NLS-1$
            EList elementParameterList = type.getElementParameter();
            for (Object elem : elementParameterList) {
                ElementParameterType elemType = (ElementParameterType) elem;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                elemType.getName().equals("HEADER") || elemType.getName().equals("FOOTER") || elemType.getName().equals("LIMIT")) {
                    //$NON-NLS-1$
                    String oldV = elemType.getValue();
                    if (oldV == null || oldV.length() == 0) {
                        if (elemType.getName().equals("LIMIT")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            oldV = "-1";
                        } else {
                            //$NON-NLS-1$
                            oldV = "0";
                        }
                    }
                    if (!oldV.contains("\"")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$ //$NON-NLS-2$
                        elemType.setValue("\"" + oldV + "\"");
                    }
                    modified = true;
                }
            }
        }
    }
    return modified;
}
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) EList(org.eclipse.emf.common.util.EList) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Example 14 with ProxyRepositoryFactory

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

the class FileInputRegexContextVariableMigrationTaskForSave method removeQuote.

private boolean removeQuote(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    EList nodes = processType.getNode();
    for (Object n : nodes) {
        NodeType type = (NodeType) n;
        if (type.getComponentName().equals("tFileInputRegex")) {
            //$NON-NLS-1$
            EList elementParameterList = type.getElementParameter();
            for (Object elem : elementParameterList) {
                ElementParameterType elemType = (ElementParameterType) elem;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                elemType.getName().equals("HEADER") || elemType.getName().equals("FOOTER") || elemType.getName().equals("LIMIT")) {
                    //$NON-NLS-1$
                    String oldV = elemType.getValue();
                    if (oldV != null && oldV.startsWith("\"") && oldV.endsWith("\"")) {
                        //$NON-NLS-1$ //$NON-NLS-2$
                        elemType.setValue(oldV.substring(1, oldV.length() - 1));
                        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) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Example 15 with ProxyRepositoryFactory

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

the class MigrateOracleJobSettingsParameterMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType != null) {
        boolean modified = false;
        final ParametersType parameters = processType.getParameters();
        if (parameters != null) {
            EList elementParameters = parameters.getElementParameter();
            for (int i = 0; i < elementParameters.size(); i++) {
                ElementParameterType param = (ElementParameterType) elementParameters.get(i);
                if (param.getName().equals("DB_TYPE_IMPLICIT_CONTEXT") || param.getName().equals("DB_TYPE")) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    if (ORACLE_INPUT.equals(param.getValue())) {
                        param.setValue(ORACLE_INPUT + ORACLE_SID);
                        modified = true;
                    } else if (ORACLE_OUTPUT.equals(param.getValue())) {
                        param.setValue(ORACLE_OUTPUT + ORACLE_SID);
                        modified = true;
                    }
                }
            }
        }
        if (modified) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

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