Search in sources :

Example 36 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class GuessSchemaController method runShadowProcess.

private void runShadowProcess(final Property property, final Node inputNode, final IContext selectContext, final IElementParameter switchParam) {
    DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
    String dbmsId = connt.getDbmsId();
    if (dbmsId == null) {
        Shell shell = Display.getCurrent().getActiveShell();
        MessageDialog.openError(shell, "No info about DB found !", "Please choose the correct mapping file.\n Note: This is normal when using JDBC component");
        MappingFileSelectDialog dialog = new MappingFileSelectDialog(shell);
        dialog.open();
        dbmsId = dialog.getSelectId();
    }
    GuessSchemaProcess gsp = new GuessSchemaProcess(property, inputNode, selectContext, memoSQL, info, part.getProcess());
    try {
        List<Integer> indexsForSameNamedColumn = new ArrayList<Integer>();
        CsvArray array = gsp.run();
        List<String[]> schemaContent = array.getRows();
        List<String> columnLabels = new ArrayList<String>();
        if (columns != null) {
            columns.clear();
        }
        if (!schemaContent.isEmpty()) {
            int numbOfColumn = schemaContent.get(0).length;
            for (int i = 1; i <= numbOfColumn; i++) {
                indexsForSameNamedColumn.clear();
                Boolean b = false;
                IMetadataColumn oneColum = new MetadataColumn();
                // get the column name from the temp file genenrated by GuessSchemaProcess.java
                String labelName = (schemaContent.get(0))[i - 1];
                if (info != null && info.isHive()) {
                    if (labelName != null && labelName.indexOf(TalendTextUtils.JAVA_END_STRING) != -1) {
                        labelName = labelName.substring(labelName.lastIndexOf(TalendTextUtils.JAVA_END_STRING) + 1, labelName.length());
                    }
                }
                String name = labelName;
                String sub = "";
                String sub2 = "";
                if (labelName != null && labelName.length() > 0 && labelName.startsWith("_")) {
                    //$NON-NLS-1$
                    sub = labelName.substring(1);
                    if (sub != null && sub.length() > 0) {
                        sub2 = sub.substring(1);
                    }
                }
                if (KeywordsValidator.isKeyword(labelName) || KeywordsValidator.isKeyword(sub) || KeywordsValidator.isKeyword(sub2)) {
                    labelName = "_" + labelName;
                    b = true;
                }
                // String label = labelName;
                // findSameNamedColumnAndReplaceTheIndex(indexsForSameNamedColumn, i, oneColum, labelName);
                oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName, i, columnLabels));
                //                    if (b && label != null && label.length() > 0 && label.startsWith("_")) { //$NON-NLS-1$
                // String substring = label.substring(1);
                // if (label.startsWith("_")
                // && (KeywordsValidator.isKeyword(substring) || KeywordsValidator.isKeyword(sub) ||
                // KeywordsValidator
                // .isKeyword(sub2))) {
                // label = substring;
                // }
                // }
                oneColum.setOriginalDbColumnName(name);
                if (schemaContent.size() > 5) {
                    oneColum.setPrecision(Integer.parseInt(schemaContent.get(2)[i - 1]));
                    oneColum.setLength(Integer.parseInt(schemaContent.get(3)[i - 1]));
                }
                try {
                    String talendType = null;
                    // to see if the language is java or perl
                    if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                        if (schemaContent.size() >= 5) {
                            talendType = MetadataTalendType.getMappingTypeRetriever(dbmsId).getDefaultSelectedTalendType(schemaContent.get(4)[i - 1]);
                        } else {
                            talendType = JavaTypesManager.STRING.getId();
                        }
                    } else {
                        if (schemaContent.size() >= 5) {
                            talendType = PerlDataTypeHelper.getNewTalendTypeOfValue(schemaContent.get(4)[i - 1]);
                        } else {
                            talendType = PerlTypesManager.STRING;
                        }
                    }
                    oneColum.setTalendType(talendType);
                    if (dbmsId != null) {
                        if (!TypesManager.checkDBType(dbmsId, oneColum.getTalendType(), oneColum.getType())) {
                            oneColum.setType(TypesManager.getDBTypeFromTalendType(dbmsId, oneColum.getTalendType()));
                        }
                    }
                // oneColum.setTalendType(JavaTypesManager.STRING.getId());
                } catch (Exception e) {
                    /*
                         * the table have no data at all ,to do nothing
                         */
                    ExceptionHandler.process(e);
                }
                // get if a column is nullable from the temp file genenrated by GuessSchemaProcess.java
                oneColum.setNullable((schemaContent.get(1))[i - 1].equals(Boolean.TRUE.toString()) ? true : false);
                columns.add(oneColum);
                columnLabels.add(oneColum.getLabel());
            }
            if (columns.size() > 0) {
                IElementParameter dqRule = elem.getElementParameter("DQRULES_LIST");
                if (dqRule != null) {
                    ITDQRuleService ruleService = null;
                    try {
                        ruleService = (ITDQRuleService) GlobalServiceRegister.getDefault().getService(ITDQRuleService.class);
                    } catch (RuntimeException e) {
                    // nothing to do
                    }
                    IElementParameter queryParam = elem.getElementParameter("QUERY");
                    if (ruleService != null && queryParam != null) {
                        ruleService.updateOriginalColumnNames(columns, queryParam);
                    }
                }
            }
            IMetadataTable tempMetatable = new MetadataTable();
            /* for bug 20973 */
            if (tempMetatable.getTableName() == null) {
                tempMetatable.setTableName(inputNode.getUniqueName());
            }
            IMetadataTable outputMetaCopy, originaleOutputTable;
            String propertyName = "";
            if (!btn.isDisposed()) {
                propertyName = (String) btn.getData(PARAMETER_NAME);
            }
            IElementParameter param = inputNode.getElementParameter(propertyName);
            for (IElementParameter eParam : elem.getElementParameters()) {
                if (eParam.getContext() != null) {
                    param = eParam;
                }
            }
            originaleOutputTable = inputNode.getMetadataFromConnector(param.getContext());
            if (originaleOutputTable != null) {
                outputMetaCopy = originaleOutputTable.clone();
            }
            tempMetatable.setListColumns(columns);
            tempMetatable.setDbms(dbmsId);
            MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), tempMetatable, inputNode, getCommandStack());
            if (metaDialog != null) {
                //$NON-NLS-1$
                metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", inputNode.getLabel()));
            }
            // ok pressed
            if (metaDialog.open() == MetadataDialog.OK) {
                outputMetaCopy = metaDialog.getOutputMetaData();
                boolean modified = false;
                if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                    modified = true;
                }
                if (modified) {
                    if (switchParam != null) {
                        switchParam.setValue(Boolean.FALSE);
                    }
                    changeMetadataCommand = new ChangeMetadataCommand(inputNode, param, originaleOutputTable, outputMetaCopy);
                    changeMetadataCommand.execute();
                }
            }
        }
    } catch (ProcessorException e) {
        ExtractMetaDataUtils.getInstance().closeConnection();
        final String strExcepton = e.getMessage();
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connectionError"), //$NON-NLS-1$
                strExcepton);
            }
        });
        ExceptionHandler.process(e);
    }
}
Also used : ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) Shell(org.eclipse.swt.widgets.Shell) CsvArray(org.talend.core.utils.CsvArray) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MappingFileSelectDialog(org.talend.metadata.managment.ui.dialog.MappingFileSelectDialog) ITDQRuleService(org.talend.core.ITDQRuleService) ProcessorException(org.talend.designer.runprocess.ProcessorException) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable)

Example 37 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class GuessSchemaController method refreshMetaDataTable.

/**
     * DOC ocarbone Comment method "refreshMetaData".
     *
     * @param csvArray
     */
public void refreshMetaDataTable(ResultSetMetaData rsmd, final List<String[]> csvRows) throws SQLException {
    if (csvRows == null) {
        return;
    } else {
        List<String> allNames = new ArrayList<String>();
        if (csvRows.isEmpty()) {
            int numbOfColumn = rsmd.getColumnCount();
            for (int i = 1; i <= numbOfColumn; i++) {
                IMetadataColumn oneColum = new MetadataColumn();
                String labelName = rsmd.getColumnLabel(i);
                labelName = ColumnNameValidator.validateColumnNameFormat(labelName, i);
                oneColum.setLabel(getNextGeneratedColumnName(labelName, allNames));
                oneColum.setOriginalDbColumnName(rsmd.getColumnName(i));
                oneColum.setNullable(rsmd.isNullable(i) == 0 ? false : true);
                oneColum.setTalendType(JavaTypesManager.STRING.getId());
                columns.add(oneColum);
            }
            return;
        }
        String[] fields = csvRows.get(0);
        Integer numberOfCol = getRightFirstRow(csvRows);
        // define the label to the metadata width the content of the first row
        int firstRowToExtractMetadata = 0;
        for (int i = 0; i < numberOfCol.intValue(); 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 && current < csvRows.size()) {
                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++;
                    }
                } else {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "String";
                    } else {
                        // globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        globalType = PerlDataTypeHelper.getNewTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    }
                }
            }
            // 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 != null && !value.equals("")) {
                        //$NON-NLS-1$
                        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)) {
                            if (!PerlDataTypeHelper.getNewTalendTypeOfValue(value).equals(globalType)) {
                                // globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper
                                // .getTalendTypeOfValue(value));
                                globalType = PerlDataTypeHelper.getNewCommonType(globalType, PerlDataTypeHelper.getNewTalendTypeOfValue(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 {
                        if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                            globalType = JavaTypesManager.STRING.getId();
                        } else {
                            globalType = PerlTypesManager.STRING;
                        }
                    }
                }
            }
            IMetadataColumn oneColum = new MetadataColumn();
            // Convert javaType to TalendType
            String talendType = null;
            if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                talendType = globalType;
                if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
                    oneColum.setPrecision(precisionValue);
                } else {
                    oneColum.setPrecision(0);
                }
            } else {
                talendType = PerlTypesManager.getNewTypeName(MetadataTalendType.loadTalendType(globalType, "TALENDDEFAULT", //$NON-NLS-1$
                false));
                if (globalType.equals("FLOAT") || globalType.equals("DOUBLE")) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    oneColum.setPrecision(precisionValue);
                } else {
                    oneColum.setPrecision(0);
                }
            }
            String labelName = rsmd.getColumnLabel(i + 1);
            labelName = ColumnNameValidator.validateColumnNameFormat(labelName, i);
            oneColum.setTalendType(talendType);
            oneColum.setLength(lengthValue);
            oneColum.setLabel(getNextGeneratedColumnName(labelName, allNames));
            oneColum.setOriginalDbColumnName(rsmd.getColumnName(i + 1));
            oneColum.setNullable(rsmd.isNullable(i + 1) == 0 ? false : true);
            columns.add(oneColum);
        }
    }
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.swt.graphics.Point)

Example 38 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class RetrieveSchemaHelper method retrieveSchemasCommand.

public static Command retrieveSchemasCommand(Node node) {
    IElementParameter param = node.getElementParameter("SCHEMA");
    IMetadataTable inputMeta = node.getMetadataFromConnector("FLOW");
    IMetadataTable inputMetaCopy = inputMeta.clone(true);
    IElementParameter outParam = node.getElementParameter("SCHEMA_OUT");
    IMetadataTable outputMeta = node.getMetadataFromConnector(outParam.getContext());
    IMetadataTable outputMetaCopy = outputMeta.clone(true);
    File xmlFile = new File(TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString()));
    if (!xmlFile.exists())
        try {
            xmlFile.createNewFile();
        } catch (IOException e1) {
            ExceptionHandler.process(e1);
        }
    SAXReader saxReader = new SAXReader();
    Document document;
    AutoApi a = null;
    try {
        // get the schema file from server
        a = new AutoApi();
        String hostName = TalendTextUtils.removeQuotes(node.getElementParameter("HOSTNAME").getValue().toString());
        int port = Integer.parseInt(TalendTextUtils.removeQuotes(node.getElementParameter("PORT").getValue().toString()));
        String mandant = TalendTextUtils.removeQuotes(node.getElementParameter("MANDANT").getValue().toString());
        String userName = TalendTextUtils.removeQuotes(node.getElementParameter("USERNAME").getValue().toString());
        String passWord = TalendTextUtils.removeQuotes(node.getElementParameter("PASSWORD").getValue().toString());
        String jobDir = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_DIR").getValue().toString());
        String jobName = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_NAME").getValue().toString());
        String jobDef = TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString());
        a.openConnection(hostName, port, mandant, userName, passWord);
        a.getJobDefinitionFile(jobDir, jobName, jobDef);
        document = saxReader.read(xmlFile);
        List inputList = document.selectNodes("//Job//Lines//Line//Steps//Input//Sources//Source//Format//Fields//Field");
        List inputMetaColumnList = new ArrayList<MetadataColumn>();
        for (int i = 0; i < inputList.size(); i++) {
            IMetadataColumn imc = new MetadataColumn();
            DefaultElement de = (DefaultElement) inputList.get(i);
            Element nameElement = de.element("Name");
            imc.setLabel(nameElement.getData().toString());
            Element lengthElement = de.element("Length");
            if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) {
                imc.setLength(Integer.parseInt(lengthElement.getData().toString()));
            }
            Element typeElement = de.element("Type");
            JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString());
            if (javaType != null) {
                imc.setTalendType(javaType.getId());
            } else {
                imc.setTalendType(JavaTypesManager.STRING.getId());
            }
            inputMetaColumnList.add(imc);
        }
        inputMetaCopy.setListColumns(inputMetaColumnList);
        List outputList = document.selectNodes("//Job//Lines//Line//Steps//Output//Targets//Target//Format//Fields//Field");
        List outputMetaColumnList = new ArrayList<MetadataColumn>();
        for (int i = 0; i < outputList.size(); i++) {
            IMetadataColumn imc = new MetadataColumn();
            DefaultElement de = (DefaultElement) outputList.get(i);
            Element nameElement = de.element("Name");
            imc.setLabel(nameElement.getData().toString());
            Element lengthElement = de.element("Length");
            if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) {
                imc.setLength(Integer.parseInt(lengthElement.getData().toString()));
            }
            Element typeElement = de.element("Type");
            JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString());
            if (javaType != null) {
                imc.setTalendType(javaType.getId());
            } else {
                imc.setTalendType(JavaTypesManager.STRING.getId());
            }
            outputMetaColumnList.add(imc);
        }
        outputMetaCopy.setListColumns(outputMetaColumnList);
        // set advanced setting info
        DefaultElement de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//FieldSeparator");
        int separator = Integer.parseInt(de.getData().toString());
        node.getElementParameter("IN_FIELD_SEP").setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//HeaderRecordCount");
        node.getElementParameter("IN_HEADER_COUNT").setValue(de.getData().toString());
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//Directory");
        node.getElementParameter("IN_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//FileName");
        node.getElementParameter("IN_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation");
        node.getElementParameter("IN_MODE").setValue(de.attribute("Mode").getValue());
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//FieldSeparator");
        separator = Integer.parseInt(de.getData().toString());
        node.getElementParameter("OUT_FIELD_SEP").setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//HeaderRecordCount");
        node.getElementParameter("OUT_HEADER_COUNT").setValue(de.getData().toString());
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//Directory");
        node.getElementParameter("OUT_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//FileName");
        node.getElementParameter("OUT_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation");
        node.getElementParameter("OUT_MODE").setValue(de.attribute("Mode").getValue());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        try {
            a.closeConnection();
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    CompoundCommand cc = new CompoundCommand();
    cc.add(new ChangeMetadataCommand(node, param, inputMeta, inputMetaCopy));
    cc.add(new ChangeMetadataCommand(node, param, outputMeta, outputMetaCopy));
    return cc;
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) SAXReader(org.dom4j.io.SAXReader) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Document(org.dom4j.Document) IOException(java.io.IOException) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) JavaType(org.talend.core.model.metadata.types.JavaType) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) AutoApi(org.talend.uniserv.AutoApi) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 39 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class CompleteDropTargetListener method insertOutpuEntryCopyToOtherOutput.

private void insertOutpuEntryCopyToOtherOutput(ArrayList<ITableEntry> sources, ArrayList<IMetadataColumn> metadataColumnsBeingAdded, // MetadataEditorEvent metadataEditorEvent,
ITableEntry tableEntrySource, IMetadataColumn metadataColumnDragged, String columnName) {
    MetadataColumn metadataColumn = new MetadataColumn(metadataColumnDragged);
    metadataColumn.setLabel(columnName);
    metadataColumnsBeingAdded.add(metadataColumn);
    // metadataEditorEvent.entries.add(metadataColumn);
    sources.add(tableEntrySource);
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn)

Example 40 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class XmlMapInputZoneToolBar method changProperty.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.newabstractmap.figures.treetools.zone.InputZoneTooBar#changProperty()
     */
@Override
public void changProperty() {
    boolean dieOnError = mapperManger.isDieOnError();
    PropertySetDialog propertySet = new PropertySetDialog(null, dieOnError);
    if (propertySet.open() == Window.OK) {
        if (graphicViewer != null && propertySet.isValueChanged()) {
            final boolean newValue = !dieOnError;
            CommandStack commandStack = graphicViewer.getEditDomain().getCommandStack();
            commandStack.execute(new Command() {

                @Override
                public void execute() {
                    mapperManger.setDieOnError(newValue);
                    if (newValue) {
                        if (!externalData.getOutputTrees().isEmpty()) {
                            OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
                            if (outputTree.isErrorReject()) {
                                // mapperComponent.getMetadataList().add(metadataTable);
                                externalData.getOutputTrees().remove(0);
                                mapperComponent.getProcess().removeUniqueConnectionName(outputTree.getName());
                                removeMetadataTableByName(outputTree.getName());
                                if (!externalData.getOutputTrees().isEmpty()) {
                                    int indexOf = externalPart.getModelChildren().indexOf(externalData.getOutputTrees().get(0));
                                    if (indexOf != -1) {
                                        graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
                                    }
                                }
                            }
                        }
                    } else {
                        boolean hasRejectTable = false;
                        if (!externalData.getOutputTrees().isEmpty()) {
                            OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
                            if (outputTree.isErrorReject()) {
                                hasRejectTable = true;
                            }
                        }
                        if (!hasRejectTable) {
                            String baseName = MapperManager.ERROR_REJECT;
                            IProcess process = mapperComponent.getProcess();
                            String tableName = baseName;
                            if (!process.checkValidConnectionName(baseName) && process instanceof IProcess2) {
                                final String uniqueName = ((IProcess2) process).generateUniqueConnectionName("row", baseName);
                                tableName = uniqueName;
                                ((IProcess2) process).addUniqueConnectionName(uniqueName);
                            } else if (process instanceof IProcess2) {
                                tableName = baseName;
                                ((IProcess2) process).addUniqueConnectionName(baseName);
                            }
                            OutputXmlTree outputXmlTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
                            outputXmlTree.setErrorReject(true);
                            outputXmlTree.setName(tableName);
                            externalData.getOutputTrees().add(0, outputXmlTree);
                            MetadataTable metadataTable = new MetadataTable();
                            metadataTable.setLabel(tableName);
                            metadataTable.setTableName(tableName);
                            MetadataColumn errorMessageCol = new MetadataColumn();
                            errorMessageCol.setLabel(MapperManager.ERROR_REJECT_MESSAGE);
                            errorMessageCol.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
                            errorMessageCol.setNullable(true);
                            errorMessageCol.setOriginalDbColumnName(MapperManager.ERROR_REJECT_MESSAGE);
                            errorMessageCol.setReadOnly(true);
                            errorMessageCol.setCustom(true);
                            metadataTable.getListColumns().add(errorMessageCol);
                            MetadataColumn errorStackTrace = new MetadataColumn();
                            errorStackTrace.setLabel(MapperManager.ERROR_REJECT_STACK_TRACE);
                            errorStackTrace.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
                            errorStackTrace.setNullable(true);
                            errorStackTrace.setOriginalDbColumnName(MapperManager.ERROR_REJECT_STACK_TRACE);
                            errorStackTrace.setReadOnly(true);
                            errorStackTrace.setCustom(true);
                            metadataTable.getListColumns().add(errorStackTrace);
                            mapperComponent.getMetadataList().add(metadataTable);
                            OutputTreeNode errorMessageNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                            errorMessageNode.setName(MapperManager.ERROR_REJECT_MESSAGE);
                            errorMessageNode.setType(errorMessageCol.getTalendType());
                            errorMessageNode.setNullable(true);
                            outputXmlTree.getNodes().add(errorMessageNode);
                            OutputTreeNode errorStackTraceNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                            errorStackTraceNode.setName(MapperManager.ERROR_REJECT_STACK_TRACE);
                            errorStackTraceNode.setType(errorStackTrace.getTalendType());
                            errorStackTraceNode.setNullable(true);
                            outputXmlTree.getNodes().add(errorStackTraceNode);
                            int indexOf = externalPart.getModelChildren().indexOf(outputXmlTree);
                            if (indexOf != -1) {
                                graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) PropertySetDialog(org.talend.designer.xmlmap.ui.dialog.PropertySetDialog) XmlMapDataEditPart(org.talend.designer.xmlmap.parts.XmlMapDataEditPart) InputXmlTreeEditPart(org.talend.designer.xmlmap.parts.InputXmlTreeEditPart) EditPart(org.eclipse.gef.EditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) Command(org.eclipse.gef.commands.Command) IProcess2(org.talend.core.model.process.IProcess2) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IProcess(org.talend.core.model.process.IProcess)

Aggregations

MetadataColumn (org.talend.core.model.metadata.MetadataColumn)44 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)35 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)20 ArrayList (java.util.ArrayList)14 MetadataTable (org.talend.core.model.metadata.MetadataTable)13 Test (org.junit.Test)6 MetadataColumnExt (org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)6 IElementParameter (org.talend.core.model.process.IElementParameter)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 IComponent (org.talend.core.model.components.IComponent)3 IConnection (org.talend.core.model.process.IConnection)3 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)3 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)3 List (java.util.List)2 Schema (org.apache.avro.Schema)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 Point (org.eclipse.swt.graphics.Point)2