Search in sources :

Example 11 with JSONFileConnection

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

the class JSONFileStep3Form method refreshMetaDataTable.

/**
     * DOC ocarbone Comment method "refreshMetaData".
     * 
     * @param csvArray
     */
public void refreshMetaDataTable(final CsvArray csvArray, List<SchemaTarget> schemaTarget, Boolean flag) {
    informationLabel.setText("   " + "Guess successful");
    List mcolumns = new ArrayList();
    mcolumns.addAll(tableEditorView.getMetadataEditor().getMetadataColumnList());
    // clear all items
    tableEditorView.getMetadataEditor().removeAll();
    List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
    String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
    if (isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
        file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
    }
    if (csvArray == null || csvArray.getRows().isEmpty()) {
        return;
    } else {
        List<String[]> csvRows = csvArray.getRows();
        String[] fields = csvRows.get(0);
        int numberOfCol = fields.length;
        // define the label to the metadata width the content of the first row
        int firstRowToExtractMetadata = 0;
        // the first rows is used to define the label of any metadata
        String[] label = new String[numberOfCol];
        for (int i = 0; i < numberOfCol; i++) {
            label[i] = DEFAULT_LABEL + i;
            if (firstRowToExtractMetadata == 0) {
                if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
                    label[i] = MetadataToolHelper.validateColumnName(label[i], i);
                }
            }
        // if (firstRowToExtractMetadata == 1) {
        // String value = fields.get(i).getValue();
        // if (!value.equals("")) {
        // label[i] = value;
        // }
        // }
        }
        for (int i = 0; i < numberOfCol; i++) {
            // define the first currentType and assimile it to globalType
            String globalType = null;
            int lengthValue = 0;
            int precisionValue = 0;
            int current = firstRowToExtractMetadata;
            while (globalType == null) {
                if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "id_String";
                    } else {
                        globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    // if (current == csvRows.size()) {
                    // globalType = "id_String"; //$NON-NLS-1$
                    // }
                    }
                } else {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "String";
                    } else {
                        globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    // if (current == csvRows.size()) {
                    // globalType = "String"; //$NON-NLS-1$
                    // }
                    }
                }
            }
            // for another lines
            for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
                fields = csvRows.get(f);
                if (fields.length > i) {
                    String value = fields[i];
                    if (!value.equals("")) {
                        if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                            if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
                                globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
                            }
                        } else {
                            if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
                                globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
                            }
                        }
                        if (lengthValue < value.length()) {
                            lengthValue = value.length();
                        }
                        int positionDecimal = 0;
                        if (value.indexOf(',') > -1) {
                            positionDecimal = value.lastIndexOf(',');
                            precisionValue = lengthValue - positionDecimal;
                        } else if (value.indexOf('.') > -1) {
                            positionDecimal = value.lastIndexOf('.');
                            precisionValue = lengthValue - positionDecimal;
                        }
                    } else {
                        IPreferenceStore preferenceStore = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                            IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                            preferenceStore = designerCoreUiService.getPreferenceStore();
                        }
                        if (preferenceStore != null && preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
                            //$NON-NLS-1$
                            globalType = preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
                            if (preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
                                //$NON-NLS-1$
                                lengthValue = Integer.parseInt(preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
                            }
                        }
                    }
                }
            }
            // define the metadataColumn to field i
            MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
            // hshen bug7249
            //$NON-NLS-1$
            metadataColumn.setPattern("\"dd-MM-yyyy\"");
            // Convert javaType to TalendType
            String talendType = null;
            talendType = globalType;
            if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
                metadataColumn.setPrecision(precisionValue);
            } else {
                metadataColumn.setPrecision(0);
            }
            metadataColumn.setTalendType(talendType);
            metadataColumn.setLength(lengthValue);
            // Check the label and add it to the table
            metadataColumn.setLabel(tableEditorView.getMetadataEditor().getNextGeneratedColumnName(label[i]));
            columns.add(i, metadataColumn);
        }
    }
    if (!flag) {
        for (int i = 0; i < columns.size(); i++) {
            for (int j = 0; j < mcolumns.size(); j++) {
                if (columns.get(i).getLabel().equals(((MetadataColumn) mcolumns.get(j)).getLabel())) {
                    columns.remove(i);
                    columns.add(i, (MetadataColumn) mcolumns.get(j));
                }
            }
        }
    }
    tableEditorView.getMetadataEditor().addAll(columns);
    checkFieldsValue();
    tableEditorView.getTableViewerCreator().layout();
    tableEditorView.getTableViewerCreator().getTable().deselectAll();
    informationLabel.setText("Click to update schema preview");
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 12 with JSONFileConnection

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

the class JSONFileWizardPage method createControl.

/**
     * 
     * @see IDialogPage#createControl(Composite)
     */
public void createControl(final Composite parent) {
    currentComposite = null;
    if (step == 1) {
        currentComposite = new JSONFileStep1Form(creation, parent, connectionItem, existingNames, (JSONWizard) getWizard());
    } else if (step == 2) {
        currentComposite = new JSONFileStep2Form(parent, connectionItem, (JSONWizard) getWizard());
    } else if (step == 3) {
        MetadataTable metadataTable = ConnectionHelper.getTables(connectionItem.getConnection()).toArray(new MetadataTable[0])[0];
        currentComposite = new JSONFileStep3Form(parent, connectionItem, metadataTable, (JSONWizard) getWizard(), TableHelper.getTableNames(((JSONFileConnection) connectionItem.getConnection()), metadataTable.getLabel()));
    }
    currentComposite.setReadOnly(!isRepositoryObjectEditable);
    currentComposite.setPage(this);
    AbstractForm.ICheckListener listener = new AbstractForm.ICheckListener() {

        public void checkPerformed(final AbstractForm source) {
            if (source.isStatusOnError()) {
                JSONFileWizardPage.this.setPageComplete(false);
                setErrorMessage(source.getStatus());
            } else {
                JSONFileWizardPage.this.setPageComplete(isRepositoryObjectEditable);
                setErrorMessage(null);
                setMessage(source.getStatus());
            }
        }
    };
    currentComposite.setListener(listener);
    setControl((Composite) currentComposite);
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) AbstractForm(org.talend.metadata.managment.ui.wizard.AbstractForm)

Example 13 with JSONFileConnection

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

the class JSONWizard method resetMetadata.

private void resetMetadata(List<SchemaTarget> schemaTarget, boolean flag) {
    // TODO
    JSONFileConnection connection2 = JSONConnectionContextUtils.getJSONOriginalValueConnection(connection, this.connectionItem, connection.isContextMode(), true);
    ProcessDescription processDescription = JSONShadowProcessHelper.getProcessDescription(connection2, getTempJsonPath());
    CsvArray csvArray = null;
    try {
        if (EJsonReadbyMode.JSONPATH.getValue().equals(getReadbyMode())) {
            //$NON-NLS-1$
            csvArray = JSONShadowProcessHelper.getCsvArray(processDescription, "FILE_JSON");
        } else {
            //$NON-NLS-1$
            csvArray = JSONShadowProcessHelper.getCsvArray(processDescription, "FILE_XML");
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
    List<MetadataColumn> newColumns = new ArrayList<MetadataColumn>();
    String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
    if (connection.isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
        file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
    }
    if (file != null) {
        // prepareColumnsFromXSD(file, newColumns, schemaTarget);
        return;
    }
    if (csvArray == null || csvArray.getRows().isEmpty()) {
        return;
    } else {
        List<String[]> csvRows = csvArray.getRows();
        String[] fields = csvRows.get(0);
        int numberOfCol = fields.length;
        // define the label to the metadata width the content of the first row
        int firstRowToExtractMetadata = 0;
        // the first rows is used to define the label of any metadata
        String[] label = new String[numberOfCol];
        for (int i = 0; i < numberOfCol; i++) {
            label[i] = DEFAULT_LABEL + i;
            if (firstRowToExtractMetadata == 0) {
                if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
                    label[i] = MetadataToolHelper.validateColumnName(label[i], i);
                }
            }
        }
        for (int i = 0; i < numberOfCol; i++) {
            // define the first currentType and assimile it to globalType
            String globalType = null;
            int lengthValue = 0;
            int precisionValue = 0;
            int current = firstRowToExtractMetadata;
            while (globalType == null) {
                if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "id_String";
                    } else {
                        globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    // if (current == csvRows.size()) {
                    // globalType = "id_String"; //$NON-NLS-1$
                    // }
                    }
                } else {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "String";
                    } else {
                        globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    // if (current == csvRows.size()) {
                    // globalType = "String"; //$NON-NLS-1$
                    // }
                    }
                }
            }
            // for another lines
            for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
                fields = csvRows.get(f);
                if (fields.length > i) {
                    String value = fields[i];
                    if (!value.equals("")) {
                        if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                            if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
                                globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
                            }
                        } else {
                            if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
                                globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
                            }
                        }
                        if (lengthValue < value.length()) {
                            lengthValue = value.length();
                        }
                        int positionDecimal = 0;
                        if (value.indexOf(',') > -1) {
                            positionDecimal = value.lastIndexOf(',');
                            precisionValue = lengthValue - positionDecimal;
                        } else if (value.indexOf('.') > -1) {
                            positionDecimal = value.lastIndexOf('.');
                            precisionValue = lengthValue - positionDecimal;
                        }
                    } else {
                        IPreferenceStore corePreferenceStore = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                            IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                            corePreferenceStore = designerCoreUiService.getPreferenceStore();
                        }
                        if (corePreferenceStore != null && corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
                            //$NON-NLS-1$
                            globalType = corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
                            if (corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
                                //$NON-NLS-1$
                                lengthValue = Integer.parseInt(corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
                            }
                        }
                    }
                }
            }
            // define the metadataColumn to field i
            MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
            // hshen bug7249
            //$NON-NLS-1$
            metadataColumn.setPattern("\"dd-MM-yyyy\"");
            // Convert javaType to TalendType
            String talendType = null;
            talendType = globalType;
            if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
                metadataColumn.setPrecision(precisionValue);
            } else {
                metadataColumn.setPrecision(0);
            }
            metadataColumn.setTalendType(talendType);
            metadataColumn.setLength(lengthValue);
            metadataColumn.setLabel(label[i]);
            newColumns.add(i, metadataColumn);
        }
    }
    EList columns = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0].getColumns();
    if (!flag) {
        for (int i = 0; i < newColumns.size(); i++) {
            for (int j = 0; j < columns.size(); j++) {
                if (newColumns.get(i).getLabel().equals(((MetadataColumn) columns.get(j)).getLabel())) {
                    newColumns.remove(i);
                    newColumns.add(i, (MetadataColumn) columns.get(j));
                }
            }
        }
    }
    columns.clear();
    columns.addAll(newColumns);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) ArrayList(java.util.ArrayList) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) ProcessDescription(org.talend.metadata.managment.ui.preview.ProcessDescription) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) CsvArray(org.talend.core.utils.CsvArray) EList(org.eclipse.emf.common.util.EList) CoreException(org.eclipse.core.runtime.CoreException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 14 with JSONFileConnection

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

the class JSONFileOutputWizardPage method createControl.

public void createControl(final Composite parent) {
    currentComposite = null;
    if (step == 1) {
        currentComposite = new JSONFileOutputStep1Form(creation, parent, connectionItem, existingNames);
    } else if (step == 2) {
        currentComposite = new JSONFileOutputStep2Form(creation, parent, connectionItem);
    } else if (step == 3) {
        MetadataTable metadataTable = (MetadataTable) ConnectionHelper.getTables((JSONFileConnection) connectionItem.getConnection()).toArray(new MetadataTable[0])[0];
        currentComposite = new JSONFileOutputStep3Form(parent, connectionItem, metadataTable, TableHelper.getTableNames(((JSONFileConnection) connectionItem.getConnection()), metadataTable.getLabel()));
    }
    currentComposite.setReadOnly(!isRepositoryObjectEditable);
    currentComposite.setPage(this);
    AbstractForm.ICheckListener listener = new AbstractForm.ICheckListener() {

        public void checkPerformed(final AbstractForm source) {
            if (source.isStatusOnError()) {
                JSONFileOutputWizardPage.this.setPageComplete(false);
                setErrorMessage(source.getStatus());
            } else {
                JSONFileOutputWizardPage.this.setPageComplete(isRepositoryObjectEditable);
                setErrorMessage(null);
                setMessage(source.getStatus());
            }
        }
    };
    currentComposite.setListener(listener);
    setControl((Composite) currentComposite);
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) AbstractForm(org.talend.metadata.managment.ui.wizard.AbstractForm)

Example 15 with JSONFileConnection

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

the class JSONFileSelectWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 10;
    layout.marginHeight = 10;
    layout.numColumns = 1;
    composite.setLayout(layout);
    label = new Label(composite, SWT.NONE);
    GridData labelData = new GridData();
    labelData.verticalSpan = 8;
    label.setLayoutData(labelData);
    label.setText("Select one model to create Json metadata");
    boolean inputModel = ((JSONFileConnection) connectionItem.getConnection()).isInputModel();
    inputModeButton = new Button(composite, SWT.RADIO);
    inputModeButton.setText("Input Json");
    if (creation) {
        inputModeButton.setSelection(isInputModel);
    } else {
        inputModeButton.setSelection(inputModel);
    }
    inputModeButton.setEnabled(creation);
    outputModeButton = new Button(composite, SWT.RADIO);
    outputModeButton.setText("Output Json");
    if (creation) {
        outputModeButton.setSelection(!isInputModel);
    } else {
        outputModeButton.setSelection(!inputModel);
    }
    outputModeButton.setEnabled(creation);
    setControl(composite);
    addListeners();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData)

Aggregations

JSONFileConnection (org.talend.repository.model.json.JSONFileConnection)21 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 ArrayList (java.util.ArrayList)4 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)4 EList (org.eclipse.emf.common.util.EList)3 ProcessDescription (org.talend.metadata.managment.ui.preview.ProcessDescription)3 AbstractForm (org.talend.metadata.managment.ui.wizard.AbstractForm)3 JSONFileConnectionItem (org.talend.repository.model.json.JSONFileConnectionItem)3 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 Composite (org.eclipse.swt.widgets.Composite)2 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 IDesignerCoreUIService (org.talend.core.ui.services.IDesignerCoreUIService)2 CsvArray (org.talend.core.utils.CsvArray)2 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)2 JSONXPathLoopDescriptor (org.talend.repository.model.json.JSONXPathLoopDescriptor)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GridData (org.eclipse.swt.layout.GridData)1