Search in sources :

Example 1 with JSONXPathLoopDescriptor

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

the class JSONConnectionContextUtils method cloneOriginalValueJSONFileConnection.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
public static JSONFileConnection cloneOriginalValueJSONFileConnection(JSONFileConnection fileConn, ContextType contextType) {
    if (fileConn == null) {
        return null;
    }
    JSONFileConnection cloneConn = JsonFactory.eINSTANCE.createJSONFileConnection();
    String filePath = ConnectionContextHelper.getOriginalValue(contextType, fileConn.getJSONFilePath());
    String encoding = ConnectionContextHelper.getOriginalValue(contextType, fileConn.getEncoding());
    filePath = TalendQuoteUtils.removeQuotes(filePath);
    cloneConn.setJSONFilePath(filePath);
    encoding = TalendQuoteUtils.removeQuotes(encoding);
    cloneConn.setEncoding(encoding);
    //
    cloneConn.setMaskXPattern(fileConn.getMaskXPattern());
    cloneConn.setGuess(fileConn.isGuess());
    ConnectionContextHelper.cloneConnectionProperties(fileConn, cloneConn);
    cloneConn.getSchema().clear();
    List<JSONXPathLoopDescriptor> descs = (List<JSONXPathLoopDescriptor>) fileConn.getSchema();
    for (JSONXPathLoopDescriptor desc : descs) {
        JSONXPathLoopDescriptor cloneDesc = JsonFactory.eINSTANCE.createJSONXPathLoopDescriptor();
        cloneDesc.setLimitBoucle(desc.getLimitBoucle().intValue());
        String xPathQuery = ConnectionContextHelper.getOriginalValue(contextType, desc.getAbsoluteXPathQuery());
        xPathQuery = TalendQuoteUtils.removeQuotes(xPathQuery);
        cloneDesc.setAbsoluteXPathQuery(xPathQuery);
        cloneDesc.getSchemaTargets().clear();
        List<org.talend.repository.model.json.SchemaTarget> schemaTargets = (List<org.talend.repository.model.json.SchemaTarget>) desc.getSchemaTargets();
        for (org.talend.repository.model.json.SchemaTarget schemaTarget : schemaTargets) {
            org.talend.repository.model.json.SchemaTarget cloneSchemaTarget = JsonFactory.eINSTANCE.createSchemaTarget();
            cloneSchemaTarget.setRelativeXPathQuery(schemaTarget.getRelativeXPathQuery());
            cloneSchemaTarget.setTagName(schemaTarget.getTagName());
            cloneSchemaTarget.setSchema(cloneDesc);
            cloneDesc.getSchemaTargets().add(cloneSchemaTarget);
        }
        cloneDesc.setConnection(cloneConn);
        cloneConn.getSchema().add(cloneDesc);
    }
    return cloneConn;
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) List(java.util.List)

Example 2 with JSONXPathLoopDescriptor

use of org.talend.repository.model.json.JSONXPathLoopDescriptor 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 3 with JSONXPathLoopDescriptor

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

the class ExtractionLoopWithJSONXPathEditorView method createColumns.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.commons.ui.swt.advanced.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
     * .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
     */
@Override
protected void createColumns(TableViewerCreator<JSONXPathLoopDescriptor> tableViewerCreator, final Table table) {
    CellEditorValueAdapter intValueAdapter = new CellEditorValueAdapter() {

        @Override
        public Object getOriginalTypedValue(final CellEditor cellEditor, Object value) {
            try {
                return new Integer(value.toString());
            } catch (Exception ex) {
                return null;
            }
        }

        @Override
        public Object getCellEditorTypedValue(final CellEditor cellEditor, Object value) {
            if (value != null) {
                return String.valueOf(value);
            }
            //$NON-NLS-1$
            return "";
        }
    };
    // //////////////////////////////////////////////////////////////////////////////////////
    // column for mouse selection
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle("");
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    column.setWidth(15);
    // //////////////////////////////////////////////////////////////////////////////////////
    // X Path Query
    column = new TableViewerCreatorColumn(tableViewerCreator);
    xPathColumn = column;
    column.setTitle("Absolute path expression");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<JSONXPathLoopDescriptor, String>() {

        @Override
        public String get(JSONXPathLoopDescriptor bean) {
            return bean.getAbsoluteXPathQuery();
        }

        @Override
        public void set(JSONXPathLoopDescriptor bean, String value) {
            String currentFlag = ConvertJSONString.getCurrentFlag();
            bean.setAbsoluteXPathQuery(value);
            bean.setFlag(currentFlag);
        }
    });
    xPathCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.NONE, column);
    column.setCellEditor(xPathCellEditor);
    xPathCellEditor.addListener(new DialogErrorForCellEditorListener(xPathCellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
            if (state == CELL_EDITOR_STATE.APPLYING) {
            // linker.onXPathValueChanged(table, newValue.toString(), itemIndex);
            }
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            return linker.validateXPathExpression(newValue);
        }
    });
    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    // //////////////////////////////////////////////////////////////////////////////////////
    // //////////////////////////////////////////////////////////////////////////////////////
    // Loop limit
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Loop limit");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<JSONXPathLoopDescriptor, Integer>() {

        @Override
        public Integer get(JSONXPathLoopDescriptor bean) {
            return bean.getLimitBoucle();
        }

        @Override
        public void set(JSONXPathLoopDescriptor bean, Integer value) {
            if (value != null) {
                bean.setLimitBoucle(value.intValue());
            } else {
                bean.setLimitBoucle(0);
            }
        }
    });
    column.setModifiable(true);
    column.setWidth(59);
    column.setCellEditor(new TextCellEditor(table), intValueAdapter);
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) ConvertJSONString(org.talend.repository.json.util.ConvertJSONString) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 4 with JSONXPathLoopDescriptor

use of org.talend.repository.model.json.JSONXPathLoopDescriptor 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 5 with JSONXPathLoopDescriptor

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

the class JSONConnectionContextHelper method revertJSONFilePropertiesForContextMode.

static void revertJSONFilePropertiesForContextMode(JSONFileConnection conn, ContextType contextType) {
    if (conn == null || contextType == null) {
        return;
    }
    if (!conn.isInputModel()) {
        String outputFilePath = getOriginalValue(contextType, conn.getOutputFilePath());
        outputFilePath = TalendQuoteUtils.removeQuotes(outputFilePath);
        conn.setOutputFilePath(outputFilePath);
    } else {
        String filePath = getOriginalValue(contextType, conn.getJSONFilePath());
        String encoding = getOriginalValue(contextType, conn.getEncoding());
        filePath = TalendQuoteUtils.removeQuotes(filePath);
        conn.setJSONFilePath(filePath);
        encoding = TalendQuoteUtils.removeQuotes(encoding);
        conn.setEncoding(encoding);
        EList schema = conn.getSchema();
        if (schema != null) {
            if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
                JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
                String xPahtQuery = getOriginalValue(contextType, descriptor.getAbsoluteXPathQuery());
                xPahtQuery = TalendQuoteUtils.removeQuotes(xPahtQuery);
                descriptor.setAbsoluteXPathQuery(xPahtQuery);
            }
        }
    }
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) EList(org.eclipse.emf.common.util.EList)

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