Search in sources :

Example 11 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class JSONToXPathLinker method createLinks.

/**
     * DOC amaumont Comment method "createLinks".
     */
public void createLinks() {
    removeAllLinks();
    getBackgroundRefresher().refreshBackground();
    ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) {
            TableItem[] loopTableItems = loopTableEditorView.getTable().getItems();
            TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
            monitorWrap = new EventLoopProgressMonitor(monitor);
            String taskName = "Loop links creation ...";
            int totalWork = loopTableItems.length + fieldsTableItems.length;
            monitorWrap.beginTask(taskName, totalWork);
            List<JSONXPathLoopDescriptor> xpathLoopDescriptorList = loopTableEditorView.getModel().getBeansList();
            for (int i = 0; i < loopTableItems.length; i++) {
                if (monitorWrap.isCanceled()) {
                    return;
                }
                TableItem tableItem = loopTableItems[i];
                JSONXPathLoopDescriptor xpathLoopDescriptor = xpathLoopDescriptorList.get(i);
                String originalValue = xpathLoopDescriptor.getAbsoluteXPathQuery();
                if (xpathLoopDescriptor.getConnection() != null) {
                    ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(xpathLoopDescriptor.getConnection(), xpathLoopDescriptor.getConnection().getContextName());
                    if (contextType != null) {
                        originalValue = ConnectionContextHelper.getOriginalValue(contextType, xpathLoopDescriptor.getAbsoluteXPathQuery());
                        originalValue = TalendQuoteUtils.removeQuotes(originalValue);
                    }
                }
                if (originalValue != null) {
                    createLoopLinks(originalValue, tableItem, monitorWrap);
                }
                monitorWrap.worked(1);
            }
            List<SchemaTarget> schemaTargetList = fieldsTableEditorView.getModel().getBeansList();
            createFieldsLinkWithProgressMonitor(monitorWrap, schemaTargetList.size() + loopTableItems.length, schemaTargetList, 0, fieldsTableItems.length);
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
    // Nothing to do
    }
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) TableItem(org.eclipse.swt.widgets.TableItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 12 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class JSONToJsonPathLinker method getTreeItem.

@Override
protected TreeItem getTreeItem(Tree tree, Object dataOfTreeItem, Object dataOfTableItem) {
    String path = null;
    if (dataOfTableItem instanceof SchemaTarget) {
        SchemaTarget target = (SchemaTarget) dataOfTableItem;
        path = target.getRelativeXPathQuery();
    } else if (dataOfTableItem instanceof JSONXPathLoopDescriptor) {
        JSONXPathLoopDescriptor target = (JSONXPathLoopDescriptor) dataOfTableItem;
        path = target.getAbsoluteXPathQuery();
        if (target.getConnection().isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(target.getConnection(), target.getConnection().getContextName());
            path = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, path));
        }
    }
    if (path == null) {
        return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
    }
    boolean expressionIsAbsolute = false;
    if (path.trim().startsWith(getRootSeperator())) {
        expressionIsAbsolute = true;
    }
    //$NON-NLS-1$
    String fullPath = "";
    if (!expressionIsAbsolute) {
        if (0 < loopXpathNodes.size()) {
            fullPath = loopXpathNodes.get(0) + getFieldSeperator();
        }
        fullPath = fullPath + path;
    } else {
        fullPath = path;
    }
    TreeItem treeItem = treePopulator.getTreeItem(fullPath);
    if (treeItem != null) {
        return treeItem;
    } else {
        return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
    }
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) TreeItem(org.eclipse.swt.widgets.TreeItem) SchemaTarget(org.talend.repository.model.json.SchemaTarget)

Example 13 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class FixUnevenItemContextParametersMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    String defualtGroupName = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
        defualtGroupName = processItem.getProcess().getDefaultContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
        defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
        defualtGroupName = contextItem.getDefaultContext();
    }
    try {
        ContextType defaultGroup = null;
        for (ContextType context : contexts) {
            if (context.getName().equals(defualtGroupName)) {
                defaultGroup = context;
                break;
            }
        }
        if (defaultGroup == null && contexts.size() > 0) {
            defaultGroup = contexts.get(0);
        }
        boolean contextChanged = false;
        if (defaultGroup != null) {
            Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
            List<String> paramNameList = new ArrayList<String>();
            paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
            for (ContextType context : contexts) {
                if (context == defaultGroup) {
                    continue;
                }
                Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
                for (String paramName : otherGroupParam.keySet()) {
                    if (!paramMap.containsKey(paramName)) {
                        paramMap.put(paramName, otherGroupParam.get(paramName));
                    }
                }
            }
            // make sure all groups have the same param list
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<String> paramNames = new ArrayList<String>(paramNameList);
                for (ContextParameterType param : params) {
                    if (paramNames.contains(param.getName())) {
                        paramNames.remove(param.getName());
                    }
                }
                if (!paramNames.isEmpty()) {
                    contextChanged = true;
                    for (String paramToAdd : paramNames) {
                        ContextParameterType toAdd = paramMap.get(paramToAdd);
                        context.getContextParameter().add(EcoreUtil.copy(toAdd));
                    }
                }
            }
            // change param order if needed
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
                for (int i = 0; i < copyOfParam.size(); i++) {
                    ContextParameterType param = copyOfParam.get(i);
                    int indexOf = paramNameList.indexOf(param.getName());
                    if (i != indexOf) {
                        contextChanged = true;
                        params.remove(param);
                        params.add(indexOf, param);
                    }
                }
            }
            // make sure params in different groups have the same repository id and type as default group
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                for (ContextParameterType param : params) {
                    ContextParameterType paramDefault = paramMap.get(param.getName());
                    if (!paramDefault.getType().equals(param.getType())) {
                        contextChanged = true;
                        param.setType(paramDefault.getType());
                    }
                    if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
                        contextChanged = true;
                        param.setRepositoryContextId(paramDefault.getRepositoryContextId());
                    }
                }
            }
        }
        if (contextChanged) {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 14 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class MergeTosMetadataMigrationTask method computeCatalogName.

/**
     * compute the catalog name.
     * 
     * @param databaseConnection the DB connection caus some of the name are issued from the DB connection
     * @param catalogNameType, the type of name for the catalog
     * @return the string corresponding to the naming convention of catalogNameType
     */
private String computeCatalogName(DatabaseConnection connection, EDatabaseSchemaOrCatalogMapping catalogNameType) {
    //$NON-NLS-1$
    String result = "";
    ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(null, connection, null, true);
    switch(catalogNameType) {
        case Login:
            result = connection.getUsername();
            break;
        case Sid:
            if (contextType != null) {
                result = ConnectionContextHelper.getOriginalValue(contextType, connection.getSID());
            } else {
                result = connection.getSID();
            }
            break;
        case Default_Name:
            result = connection.getName();
            break;
        case Schema:
        case None:
        default:
            // return an empty string
            break;
    }
    return result;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 15 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class MergeTosMetadataMigrationTask method computeSchemaName.

/**
     * compute the schema name.
     * 
     * @param schema the schema to compute the name from
     * @param databaseConnection the DB connection caus some of the name are issued from the DB connection
     * @param curSchema, the type of name for the schema
     * @return string corresponding to the naming convention of schemaNameType
     */
private String computeSchemaName(Schema schema, DatabaseConnection connection, EDatabaseSchemaOrCatalogMapping schemaNameType) {
    //$NON-NLS-1$
    String result = "";
    ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(null, connection, null, true);
    switch(schemaNameType) {
        case Login:
            result = connection.getUsername();
            break;
        case Schema:
            if (contextType != null) {
                result = ConnectionContextHelper.getOriginalValue(contextType, schema.getName());
            } else {
                /* if schema name is null,return a empty string is required,bug 0017244 */
                if (schema.getName() != null) {
                    result = schema.getName();
                }
            }
            break;
        case Sid:
            result = connection.getSID();
            break;
        case Default_Name:
            result = connection.getName();
            break;
        case None:
            // return an empty string
            break;
        default:
            // return an empty string
            break;
    }
    return result;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)58 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)19 PersistenceException (org.talend.commons.exception.PersistenceException)16 ArrayList (java.util.ArrayList)15 File (java.io.File)13 ContextItem (org.talend.core.model.properties.ContextItem)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProject (org.eclipse.core.resources.IProject)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 BufferedReader (java.io.BufferedReader)3 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3