Search in sources :

Example 11 with JSONXPathLoopDescriptor

use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method setJSONFilePropertiesForContextMode.

static void setJSONFilePropertiesForContextMode(String prefixName, JSONFileConnection conn) {
    if (conn == null || prefixName == null) {
        return;
    }
    prefixName = prefixName + LINE;
    String paramName = null;
    if (conn.isInputModel()) {
        paramName = prefixName + EParamName.FilePath;
        conn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
        paramName = prefixName + EParamName.Encoding;
        conn.setEncoding(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
        EList schema = conn.getSchema();
        if (schema != null) {
            if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
                JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
                paramName = prefixName + EParamName.XPathQuery;
                descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
            }
        }
    } else {
        paramName = prefixName + EParamName.OutputFilePath;
        conn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
    }
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) EList(org.eclipse.emf.common.util.EList)

Example 12 with JSONXPathLoopDescriptor

use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method setJSONFilePropertiesForExistContextMode.

static void setJSONFilePropertiesForExistContextMode(JSONFileConnection jsonConn, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
    if (jsonConn == null) {
        return;
    }
    String jsonVariableName = null;
    for (IConnParamName param : paramSet) {
        if (param instanceof EParamName) {
            EParamName jsonParam = (EParamName) param;
            if (map != null && map.size() > 0) {
                for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : map.entrySet()) {
                    List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                    for (ConectionAdaptContextVariableModel model : modelList) {
                        if (model.getValue().equals(jsonParam.name())) {
                            jsonVariableName = model.getName();
                            break;
                        }
                    }
                }
            }
            if (jsonConn.isInputModel()) {
                switch(jsonParam) {
                    case FilePath:
                        jsonConn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                        break;
                    case Encoding:
                        jsonConn.setEncoding(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                        break;
                    case XPathQuery:
                        EList schema = jsonConn.getSchema();
                        if (schema != null) {
                            if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
                                JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
                                descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                            }
                        }
                    default:
                }
            } else {
                if (jsonParam.equals(EParamName.OutputFilePath)) {
                    jsonConn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) EParamName(org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName) EList(org.eclipse.emf.common.util.EList) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with JSONXPathLoopDescriptor

use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.

the class JSONToXPathLinker method initLoopListeners.

/**
     * DOC amaumont Comment method "initListeners".
     */
private void initLoopListeners() {
    JSONExtractorLoopModel loopModel = this.loopTableEditorView.getModel();
    final Table loopTable = this.loopTableEditorView.getTableViewerCreator().getTable();
    loopModelModifiedBeanListener = new IModifiedBeanListener<JSONXPathLoopDescriptor>() {

        @Override
        public void handleEvent(ModifiedBeanEvent<JSONXPathLoopDescriptor> event) {
            handleModifiedBeanEvent(event);
        }

        private void handleModifiedBeanEvent(ModifiedBeanEvent<JSONXPathLoopDescriptor> event) {
            if (event.column == loopTableEditorView.getXPathColumn()) {
                onXPathValueChanged(loopTable, (String) event.newValue, event.index);
            }
        }
    };
    loopModel.addModifiedBeanListener(loopModelModifiedBeanListener);
    loopTableExtendedControlListener = new IExtendedControlListener() {

        @Override
        public void handleEvent(ExtendedControlEvent event) {
            if (event.getType() == EVENT_TYPE.MODEL_CHANGED) {
                nodeRetriever.setCurrentLoopXPath(getCurrentLoopXPath());
            }
        }
    };
    this.loopTableEditorView.getExtendedTableViewer().addListener(loopTableExtendedControlListener);
    SelectionHelper selectionHelper = this.loopTableEditorView.getTableViewerCreator().getSelectionHelper();
    afterLineSelectionListener = new ILineSelectionListener() {

        @Override
        public void handle(LineSelectionEvent e) {
            updateLinksStyleAndControlsSelection(e.source.getTable(), true);
        }
    };
    selectionHelper.addAfterSelectionListener(afterLineSelectionListener);
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) Table(org.eclipse.swt.widgets.Table) SelectionHelper(org.talend.commons.ui.runtime.swt.tableviewer.selection.SelectionHelper) ExtendedControlEvent(org.talend.commons.ui.swt.extended.table.ExtendedControlEvent) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) IExtendedControlListener(org.talend.commons.ui.swt.extended.table.IExtendedControlListener)

Example 14 with JSONXPathLoopDescriptor

use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.

the class JSONToXPathLinker 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 (path == null) {
        return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
    }
    boolean expressionIsAbsolute = false;
    if (path.trim().startsWith("/")) {
        //$NON-NLS-1$
        expressionIsAbsolute = true;
    }
    //$NON-NLS-1$
    String fullPath = "";
    if (!expressionIsAbsolute) {
        if (loopXpathNodes.size() > 0) {
            //$NON-NLS-1$
            fullPath = loopXpathNodes.get(0) + "/";
        }
        // adapt relative path
        //$NON-NLS-1$
        String[] relatedSplitedPaths = path.split("\\.\\./");
        if (relatedSplitedPaths.length > 1) {
            int pathsToRemove = relatedSplitedPaths.length - 1;
            //$NON-NLS-1$
            String[] fullPathSplited = fullPath.split("/");
            //$NON-NLS-1$
            fullPath = "";
            for (int j = 1; j < (fullPathSplited.length - pathsToRemove); j++) {
                //$NON-NLS-1$
                fullPath += "/" + fullPathSplited[j];
            }
            //$NON-NLS-1$
            fullPath += "/" + relatedSplitedPaths[pathsToRemove];
        } else {
            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) TreeItem(org.eclipse.swt.widgets.TreeItem) SchemaTarget(org.talend.repository.model.json.SchemaTarget)

Aggregations

JSONXPathLoopDescriptor (org.talend.repository.model.json.JSONXPathLoopDescriptor)14 EList (org.eclipse.emf.common.util.EList)8 ArrayList (java.util.ArrayList)5 SchemaTarget (org.talend.repository.model.json.SchemaTarget)5 List (java.util.List)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConvertJSONString (org.talend.repository.json.util.ConvertJSONString)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)2 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1