Search in sources :

Example 21 with ContextType

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

the class JSONFileStep2Form method checkFieldsValue.

/**
     * Ensures that fields are set. Update checkEnable / use to checkConnection().
     * 
     * @return
     */
@Override
protected boolean checkFieldsValue() {
    previewInformationLabel.setText("   " + "The settings must be completed to show the preview");
    updateStatus(IStatus.OK, null);
    previewButton.setEnabled(false);
    String msg = fieldsTableEditorView.checkColumnNames();
    if (!StringUtils.isEmpty(msg)) {
        updateStatus(IStatus.ERROR, msg);
        return false;
    } else {
        previewButton.setEnabled(true);
    }
    // Labelled Checkbox Combo (Row to Skip and Limit)
    ArrayList<LabelledCheckboxCombo> labelledCheckboxCombo2Control = new ArrayList<LabelledCheckboxCombo>();
    Iterator<LabelledCheckboxCombo> iCheckboxCombo;
    LabelledCheckboxCombo labelledCheckboxCombo;
    for (iCheckboxCombo = labelledCheckboxCombo2Control.iterator(); iCheckboxCombo.hasNext(); ) {
        labelledCheckboxCombo = iCheckboxCombo.next();
        // if the checkbox is checked, check Numeric value
        if (labelledCheckboxCombo.getCheckbox().getSelection()) {
            if (labelledCheckboxCombo.getText() == "") {
                updateStatus(IStatus.ERROR, labelledCheckboxCombo.getLabelText() + "must be specified");
                return false;
            }
        }
    }
    //$NON-NLS-1$
    previewInformationLabel.setText("");
    String pathStr = getConnection().getJSONFilePath();
    if (isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
        pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
    }
    previewButton.setEnabled(true);
    updateStatus(IStatus.OK, null);
    return true;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) LabelledCheckboxCombo(org.talend.commons.ui.swt.formtools.LabelledCheckboxCombo)

Example 22 with ContextType

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

the class JSONFileStep2Form method checkFilePathAndManageIt.

/**
     * checkFileFieldsValue active fileViewer if file exist.
     * 
     * @throws IOException
     */
private void checkFilePathAndManageIt() {
    updateStatus(IStatus.OK, null);
    filePathIsDone = false;
    if (getConnection().getJSONFilePath() == "") {
        //$NON-NLS-1$
        fileJSONText.setText("When Filepath is specified, you can read here the" + " " + TreePopulator.getMaximumRowsToPreview() + " " + "first rows of the file.");
    } else {
        fileJSONText.setText("Check if the file exist ...");
        StringBuilder previewRows = new StringBuilder();
        BufferedReader in = null;
        //$NON-NLS-1$
        String pathStr = "";
        try {
            if (tempJSONXsdPath != null) {
                pathStr = tempJSONXsdPath;
            } else {
                pathStr = getConnection().getJSONFilePath();
            }
            if (isContextMode()) {
                ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
                pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
            }
            File file = new File(pathStr);
            if (!file.exists()) {
                file.createNewFile();
                FileOutputStream outStream;
                try {
                    outStream = new FileOutputStream(file);
                    outStream.write(getConnection().getFileContent());
                    outStream.close();
                } catch (FileNotFoundException e1) {
                    ExceptionHandler.process(e1);
                } catch (IOException e) {
                    ExceptionHandler.process(e);
                }
            }
            Charset guessedCharset = CharsetToolkit.guessEncoding(file, 4096);
            String str;
            in = new BufferedReader(new InputStreamReader(new FileInputStream(pathStr), guessedCharset.displayName()));
            while ((str = in.readLine()) != null) {
                //$NON-NLS-1$
                previewRows.append(str + "\n");
            }
            // show lines
            fileJSONText.setText(new String(previewRows));
            filePathIsDone = true;
        } catch (Exception e) {
            String msgError = "File" + " \"" + fileJSONText.getText().replace("\\\\", "\\") + "\"\n";
            if (e instanceof FileNotFoundException) {
                msgError = msgError + "is not found";
            } else if (e instanceof EOFException) {
                msgError = msgError + "have an incorrect character EOF";
            } else if (e instanceof IOException) {
                msgError = msgError + "is locked by another soft";
            } else {
                msgError = msgError + "doesn't exist";
            }
            fileJSONText.setText(msgError);
            if (!isReadOnly()) {
                updateStatus(IStatus.ERROR, msgError);
            }
            //$NON-NLS-1$
            log.error(msgError + " " + e.getMessage());
        } finally {
            String msgError = "File" + " \"" + fileJSONText.getText().replace("\\\\", "\\") + "\"\n";
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                msgError = msgError + "is locked by another soft";
            }
        }
        checkFieldsValue();
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) Charset(java.nio.charset.Charset) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) EOFException(java.io.EOFException) File(java.io.File)

Example 23 with ContextType

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

the class JSONFileStep2Form method resetStatusIfNecessary.

/**
     * see bug 0004206: bug on the loop limit case in JSONfile source metadata defining
     */
private void resetStatusIfNecessary() {
    String curJSONPath = getConnection().getJSONFilePath();
    //$NON-NLS-1$
    String oraginalPath = "";
    if (jsonFilePath != null && curJSONPath != null) {
        // change JSON file
        if (isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
            oraginalPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, curJSONPath));
        }
        if ((!jsonFilePath.equals(curJSONPath) && !jsonFilePath.equals(oraginalPath)) || !this.wizard.getReadbyMode().equals(currentReadbyMode)) {
            currentReadbyMode = this.wizard.getReadbyMode();
            // clear command stack
            CommandStackForComposite commandStack = new CommandStackForComposite(schemaTargetGroup);
            loopTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
            fieldsTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
            getConnection().getSchema().remove(jsonXPathLoopDescriptor);
            jsonXPathLoopDescriptor = JsonFactory.eINSTANCE.createJSONXPathLoopDescriptor();
            getConnection().getSchema().add(jsonXPathLoopDescriptor);
            loopModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor);
            XmlArray.setLimitToDefault();
            jsonXPathLoopDescriptor.setLimitBoucle(XmlArray.getRowLimit());
            fieldsModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor.getSchemaTargets());
            fieldsTableEditorView.getTableViewerCreator().layout();
            initTreePopulator();
            prepareJsonLinker();
            // reset linker
            linker.init(treePopulator);
            loopTableEditorView.setLinker(linker);
            fieldsTableEditorView.setLinker(linker);
            jsonFilePreview.removePreviewContent();
        }
    }
    if (isContextMode()) {
        jsonFilePath = oraginalPath;
    } else {
        jsonFilePath = curJSONPath;
    }
}
Also used : CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 24 with ContextType

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

the class ChangeValuesFromRepository method execute.

@SuppressWarnings("unchecked")
@Override
public void execute() {
    // Force redraw of Commponents propoerties
    elem.setPropertyValue(updataComponentParamName, new Boolean(true));
    boolean allowAutoSwitch = true;
    IElementParameter elemParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (elemParam != null) {
        // add for TDI-8053
        elemParam.setValue(Boolean.FALSE);
        allowAutoSwitch = (Boolean) elemParam.getValue();
    }
    if (!allowAutoSwitch && (elem instanceof Node)) {
        // force the autoSwitch to true if the schema is empty and if the
        // query is not set.
        Node node = (Node) elem;
        boolean isSchemaEmpty = false;
        if (node.getMetadataList().size() > 0) {
            isSchemaEmpty = node.getMetadataList().get(0).getListColumns().size() == 0;
        } else {
            isSchemaEmpty = true;
        }
        for (IElementParameter curParam : node.getElementParameters()) {
            if (curParam.getFieldType().equals(EParameterFieldType.MEMO_SQL)) {
                if (curParam.getDefaultValues().size() > 0) {
                }
            }
        }
        if (isSchemaEmpty) {
            allowAutoSwitch = true;
        }
        if (((INode) elem).getComponent().getName().equals("tWebService")) {
            //$NON-NLS-1$
            allowAutoSwitch = true;
        }
    }
    if (propertyName.split(":")[1].equals(propertyTypeName)) {
        //$NON-NLS-1$
        elem.setPropertyValue(propertyName, value);
        if (allowAutoSwitch) {
            // Update spark mode to YARN_CLIENT if repository
            if (elem instanceof IProcess) {
                if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(((IProcess) elem).getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(((IProcess) elem).getComponentsType())) {
                    if (EmfComponent.REPOSITORY.equals(value)) {
                        IElementParameter sparkLocalParam = ((IProcess) elem).getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
                        IElementParameter sparkParam = ((IProcess) elem).getElementParameter(HadoopConstants.SPARK_MODE);
                        if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
                            sparkLocalParam.setValue(false);
                        }
                        if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
                            sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
                        }
                    }
                }
            }
            setOtherProperties();
        }
    } else {
        oldMetadata = (String) elem.getPropertyValue(propertyName);
        elem.setPropertyValue(propertyName, value);
        if (allowAutoSwitch) {
            setOtherProperties();
        }
    }
    String propertyParamName = null;
    if (elem.getElementParameter(propertyName).getParentParameter() != null) {
        IElementParameter param = elem.getElementParameter(propertyName).getParentParameter();
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            propertyParamName = param.getName();
        }
    }
    if (propertyName.split(":")[1].equals(propertyTypeName) && (EmfComponent.BUILTIN.equals(value))) {
        //$NON-NLS-1$
        for (IElementParameter param : elem.getElementParameters()) {
            if (param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                continue;
            }
            boolean paramFlag = JobSettingsConstants.isExtraParameter(param.getName());
            //$NON-NLS-1$
            boolean extraFlag = JobSettingsConstants.isExtraParameter(propertyName.split(":")[0]);
            if (paramFlag == extraFlag) {
                // for memo sql
                if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
                    IElementParameter querystoreParam = elem.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE, param.getCategory());
                    if (querystoreParam != null) {
                        Map<String, IElementParameter> childParam = querystoreParam.getChildParameters();
                        if (childParam != null) {
                            IElementParameter queryTypeParam = childParam.get(EParameterName.QUERYSTORE_TYPE.getName());
                            if (queryTypeParam != null && EmfComponent.REPOSITORY.equals(queryTypeParam.getValue())) {
                                continue;
                            }
                        }
                    }
                }
                if (param.getRepositoryValue() != null) {
                    param.setReadOnly(false);
                    // for job settings extra.(feature 2710)
                    param.setRepositoryValueUsed(false);
                }
            }
        }
    } else {
        oldValues.clear();
        List<ComponentProperties> componentProperties = null;
        IGenericWizardService wizardService = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
            wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
        }
        if (wizardService != null && wizardService.isGenericConnection(connection)) {
            componentProperties = wizardService.getAllComponentProperties(connection, null);
        }
        IElementParameter propertyParam = elem.getElementParameter(propertyName);
        List<IElementParameter> elementParameters = new ArrayList<>(elem.getElementParameters());
        for (IElementParameter param : elementParameters) {
            String repositoryValue = param.getRepositoryValue();
            if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                continue;
            }
            boolean isGenericRepositoryValue = RepositoryToComponentProperty.isGenericRepositoryValue(connection, componentProperties, param.getName());
            if (repositoryValue == null && isGenericRepositoryValue) {
                repositoryValue = param.getName();
                param.setRepositoryValue(repositoryValue);
                param.setRepositoryValueUsed(true);
            }
            if (repositoryValue == null || param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                continue;
            }
            String componentName = elem instanceof INode ? (((INode) elem).getComponent().getName()) : null;
            boolean b = elem instanceof INode && (//$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tHL7Input") || //$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tAdvancedFileOutputXML") || ((INode) elem).getComponent().getName().equals("tMDMOutput") || ((INode) elem).getComponent().getName().equals("tWebService") || ((INode) elem).getComponent().getName().equals("tCreateTable") || //$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tWriteJSONField"));
            if ((//$NON-NLS-1$
            "TYPE".equals(repositoryValue) || (isGenericRepositoryValue || param.isShow(elem.getElementParameters())) || b) && (!param.getName().equals(propertyTypeName))) {
                if (param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                    continue;
                }
                Object objectValue = null;
                if (connection instanceof XmlFileConnection && this.dragAndDropAction == true && repositoryValue.equals("FILE_PATH") && reOpenXSDBool == true) {
                    objectValue = RepositoryToComponentProperty.getXmlAndXSDFileValue((XmlFileConnection) connection, repositoryValue);
                } else if (connection instanceof SalesforceSchemaConnection && "MODULENAME".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    if (this.moduleUnit != null) {
                        objectValue = moduleUnit.getModuleName();
                    } else {
                        objectValue = null;
                    }
                } else // module which was the last one be retrived
                if (connection instanceof SalesforceSchemaConnection && "CUSTOM_MODULE_NAME".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    if (this.moduleUnit != null) {
                        objectValue = moduleUnit.getModuleName();
                    } else {
                        objectValue = null;
                    }
                } else if (connection instanceof MDMConnection) {
                    if (table == null) {
                        IMetadataTable metaTable = null;
                        if (((Node) elem).getMetadataList().size() > 0) {
                            metaTable = ((Node) elem).getMetadataList().get(0);
                        }
                        objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, metaTable);
                    } else {
                        objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, table);
                    }
                } else if (connection instanceof WSDLSchemaConnection && "USE_PROXY".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    objectValue = ((WSDLSchemaConnection) connection).isUseProxy();
                } else {
                    IMetadataTable metaTable = table;
                    if (metaTable == null && elem instanceof Node) {
                        INodeConnector conn = ((Node) elem).getConnectorFromType(EConnectionType.FLOW_MAIN);
                        if (conn != null && conn.getMaxLinkOutput() == 1) {
                            metaTable = ((Node) elem).getMetadataFromConnector(conn.getName());
                        }
                    }
                    objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, metaTable, componentName);
                }
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IJsonFileService.class)) {
                    IJsonFileService jsonService = (IJsonFileService) GlobalServiceRegister.getDefault().getService(IJsonFileService.class);
                    boolean paramChanged = jsonService.changeFilePathFromRepository(connection, param, elem, objectValue);
                    if (paramChanged) {
                        continue;
                    }
                }
                if (objectValue != null) {
                    oldValues.put(param.getName(), param.getValue());
                    if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("TYPE")) {
                        //$NON-NLS-1$
                        String dbVersion = "";
                        if (connection instanceof DatabaseConnection) {
                            dbVersion = ((DatabaseConnection) connection).getDbVersionString();
                        }
                        boolean found = false;
                        String[] list = param.getListRepositoryItems();
                        for (int i = 0; (i < list.length) && (!found); i++) {
                            if (objectValue.equals(list[i])) {
                                found = true;
                                elem.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                            }
                        }
                        IElementParameter elementParameter = null;
                        IElementParameter elementParameter2 = null;
                        if (EParameterName.DB_TYPE.getName().equals(param.getName())) {
                            elementParameter = elem.getElementParameter(EParameterName.DB_VERSION.getName());
                            elementParameter2 = elem.getElementParameter(EParameterName.SCHEMA_DB.getName());
                        } else {
                            elementParameter = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName()));
                            elementParameter2 = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName()));
                        }
                        String dbType = "";
                        if (param.getValue() != null) {
                            int indexOfItemFromList = param.getIndexOfItemFromList(param.getValue().toString());
                            if (indexOfItemFromList != -1) {
                                dbType = param.getListItemsDisplayCodeName()[indexOfItemFromList];
                            }
                        }
                        // Some DB not need fill the schema parameter for the JobSetting View "Extra" ,"Stats&Logs"
                        if (elementParameter2 != null && !elementParameter2.isShow(elem.getElementParameters()) && !elementParameter2.getValue().equals("")) {
                            elementParameter2.setValue("");
                        }
                        if (StatsAndLogsConstants.JDBC.equals(dbType)) {
                            IElementParameter dbNameParm = elem.getElementParameter(EParameterName.DBNAME.getName());
                            if (dbNameParm != null) {
                                dbNameParm.setValue("");
                            }
                        } else {
                            IElementParameter rulParam = elem.getElementParameter(EParameterName.URL.getName());
                            if (rulParam != null) {
                                rulParam.setValue("");
                            }
                            IElementParameter classParam = elem.getElementParameter(EParameterName.DRIVER_CLASS.getName());
                            if (classParam != null) {
                                classParam.setValue("");
                            }
                            IElementParameter jarParam = elem.getElementParameter(EParameterName.DRIVER_JAR.getName());
                            if (jarParam != null) {
                                jarParam.setValue(new ArrayList<Map<String, Object>>());
                            }
                        }
                        JobSettingVersionUtil.setDbVersion(elementParameter, dbVersion, false);
                        DesignerUtilities.setSchemaDB(elementParameter2, param.getValue());
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("FRAMEWORK_TYPE")) {
                        //$NON-NLS-1$
                        String[] list = param.getListItemsDisplayName();
                        for (int i = 0; i < list.length; i++) {
                            if (objectValue.equals(list[i])) {
                                elem.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("EDI_VERSION")) {
                        String[] list = param.getListItemsDisplayName();
                        for (String element : list) {
                            if (objectValue.toString().toUpperCase().equals(element)) {
                                elem.setPropertyValue(param.getName(), objectValue);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("DRIVER")) {
                        String[] list = param.getListItemsDisplayCodeName();
                        for (String element : list) {
                            if (objectValue.toString().toUpperCase().equals(element)) {
                                elem.setPropertyValue(param.getName(), objectValue);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("CONNECTION_MODE")) {
                        //$NON-NLS-1$
                        if (!objectValue.equals(param.getValue())) {
                            //$NON-NLS-1$
                            PropertyChangeCommand cmd = new PropertyChangeCommand(elem, "CONNECTION_MODE", objectValue);
                            cmd.execute();
                        }
                    } else {
                        if (repositoryValue.equals("ENCODING")) {
                            //$NON-NLS-1$
                            IElementParameter paramEncoding = param.getChildParameters().get(EParameterName.ENCODING_TYPE.getName());
                            if (connection instanceof FTPConnection) {
                                if (((FTPConnection) connection).getEcoding() != null) {
                                    paramEncoding.setValue(((FTPConnection) connection).getEcoding());
                                } else {
                                    paramEncoding.setValue(EmfComponent.ENCODING_TYPE_CUSTOM);
                                }
                            } else {
                                if (objectValue instanceof String) {
                                    String str = TalendTextUtils.removeQuotes((String) objectValue);
                                    if (str.equals(EmfComponent.ENCODING_TYPE_UTF_8)) {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_UTF_8);
                                    } else if (str.equals(EmfComponent.ENCODING_TYPE_ISO_8859_15)) {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_ISO_8859_15);
                                    } else {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_CUSTOM);
                                    // paramEncoding.setRepositoryValueUsed(true);
                                    }
                                }
                            }
                        } else if (repositoryValue.equals("CSV_OPTION")) {
                            //$NON-NLS-1$
                            setOtherProperties();
                        }
                        if (repositoryValue.equals("MODULENAME")) {
                            //$NON-NLS-1$
                            List list = new ArrayList();
                            Object[] listItemsValue = elem.getElementParameter("MODULENAME").getListItemsValue();
                            for (Object element : listItemsValue) {
                                list.add(element);
                            }
                            if (list != null && !list.contains(objectValue)) {
                                //$NON-NLS-1$
                                objectValue = "CustomModule";
                            }
                        }
                        // hywang add for excel 2007
                        if (repositoryValue.equals(EParameterName.FILE_PATH.getName())) {
                            String filePath = "";
                            if (connection.isContextMode()) {
                                ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
                                if (contextItem != null) {
                                    String selectedContext = contextItem.getDefaultContext();
                                    final ContextType contextTypeByName = ContextUtils.getContextTypeByName(contextItem, selectedContext, true);
                                    filePath = ConnectionContextHelper.getOriginalValue(contextTypeByName, objectValue.toString());
                                }
                            } else {
                                filePath = TalendTextUtils.removeQuotes(objectValue.toString());
                            }
                            boolean versionCheckFor2007 = false;
                            if (filePath != null && filePath.endsWith(".xlsx")) {
                                versionCheckFor2007 = true;
                            }
                            if (elem.getElementParameter("VERSION_2007") != null) {
                                elem.setPropertyValue("VERSION_2007", versionCheckFor2007);
                            }
                        }
                        if (param.getFieldType().equals(EParameterFieldType.FILE)) {
                            if (objectValue != null) {
                                objectValue = objectValue.toString().replace("\\", "/");
                            }
                        }
                        elem.setPropertyValue(param.getName(), objectValue);
                    }
                    param.setRepositoryValueUsed(true);
                } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
                    //$NON-NLS-1$
                    List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                    if (((Node) elem).getMetadataList().size() > 0) {
                        IMetadataTable metaTable = ((Node) elem).getMetadataList().get(0);
                        //$NON-NLS-1$
                        RepositoryToComponentProperty.getTableXmlFileValue(//$NON-NLS-1$
                        connection, //$NON-NLS-1$
                        "XML_MAPPING", //$NON-NLS-1$
                        param, table, metaTable);
                        param.setRepositoryValueUsed(true);
                    }
                } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("WSDL_PARAMS") && connection != null) {
                    //$NON-NLS-1$
                    List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                    table.clear();
                    ArrayList parameters = ((WSDLSchemaConnection) connection).getParameters();
                    if (parameters != null) {
                        for (Object object : parameters) {
                            Map<String, Object> map2 = new HashMap<String, Object>();
                            //$NON-NLS-1$
                            map2.put("VALUE", TalendTextUtils.addQuotes(object.toString()));
                            table.add(map2);
                        }
                    }
                    param.setRepositoryValueUsed(true);
                } else if (param.getFieldType().equals(EParameterFieldType.TEXT) && "XPATH_QUERY".equals(param.getRepositoryValue())) {
                    //$NON-NLS-1$
                    param.setRepositoryValueUsed(true);
                } else {
                    // For SAP
                    String paramName = param.getName();
                    if ("SAP_PROPERTIES".equals(paramName) || "MAPPING_INPUT".equals(paramName) || // INPUT_PARAMS should be MAPPING_INPUT,bug16426
                    "SAP_FUNCTION".equals(paramName) || "OUTPUT_PARAMS".equals(paramName) || "SAP_ITERATE_OUT_TYPE".equals(paramName) || "SAP_ITERATE_OUT_TABLENAME".equals(paramName)) {
                        SAPParametersUtils.retrieveSAPParams(elem, connection, param, getSapFunctionLabel());
                    }
                    if ("GATEWAYSERVICE".equals(paramName) || "PROGRAMID".equals(paramName) || "FORMAT_XML".equals(paramName) || "FILE_IDOC_XML".equals(paramName) || "FORMAT_HTML".equals(paramName) || "FILE_IDOC_HTML".equals(paramName)) {
                        SAPParametersUtils.getSAPIDocParams(elem, connection, param, getSapIDocLabel());
                    }
                }
                if (param.isRepositoryValueUsed()) {
                    if (("GENERATION_MODE").equals(param.getName())) {
                        param.setReadOnly(true);
                    } else {
                        param.setReadOnly(false);
                    }
                }
            }
        }
        // (bug 5198)
        IElementParameter parentParameter = propertyParam.getParentParameter();
        if (parentParameter != null) {
            IElementParameter param = parentParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            if (param != null && propertyParam == param) {
                // avoid to process twice.
                ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) param.getValue());
                if (connItem != null) {
                    if (elem instanceof Node) {
                        ConnectionContextHelper.addContextForNodeParameter((Node) elem, connItem, ignoreContextMode);
                    } else if (elem instanceof Process) {
                        ConnectionContextHelper.addContextForProcessParameter((Process) elem, connItem, param.getCategory(), ignoreContextMode);
                    }
                }
            }
        }
    }
    toUpdate = false;
    // change AS400 value
    for (IElementParameter curParam : elem.getElementParameters()) {
        if (curParam.getFieldType().equals(EParameterFieldType.AS400_CHECK)) {
            setOtherProperties();
        }
        // change the HL7 Version
        if (connection instanceof HL7Connection) {
            if (curParam.getName().equals("HL7_VER")) {
                String hl7VersionString = connection.getVersion();
                if (hl7VersionString != null) {
                    hl7VersionString = hl7VersionString.replace(".", "");
                    curParam.setValue(hl7VersionString);
                }
            }
        }
        setDefaultValues(curParam, elem);
    }
    if (elem instanceof Node) {
        // Xstream Cdc Type Mode
        boolean isXstreamCdcTypeMode = false;
        if (connection != null && connection instanceof DatabaseConnection) {
            String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
            if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
                isXstreamCdcTypeMode = true;
            }
        }
        if (isXstreamCdcTypeMode && ((Node) elem).getComponent().getName().equals("tOracleCDC")) {
            //$NON-NLS-1$
            IMetadataTable table = ((Node) elem).getMetadataList().get(0);
            IElementParameter schemaParam = elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
            schemaParam.setValueToDefault(elem.getElementParameters());
            table.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
        }
        ((Process) ((Node) elem).getProcess()).checkProcess();
        // Added TDQ-11688 show regex when "built-in"
        ITDQPatternService service = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
            service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
        }
        if (service != null && service.isSinglePatternNode(elem)) {
            IElementParameter regexParameter = ((Node) elem).getElementParameter("PATTERN_REGEX");
            if (regexParameter != null) {
                regexParameter.setShow(EmfComponent.BUILTIN.equals(this.value));
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList) ITDQPatternService(org.talend.core.ITDQPatternService) IProcess(org.talend.core.model.process.IProcess) WSDLSchemaConnection(org.talend.core.model.metadata.builder.connection.WSDLSchemaConnection) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) FTPConnection(org.talend.core.model.metadata.builder.connection.FTPConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) IJsonFileService(org.talend.core.service.IJsonFileService) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Map(java.util.Map) HashMap(java.util.HashMap) HL7Connection(org.talend.core.model.metadata.builder.connection.HL7Connection)

Example 25 with ContextType

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

the class HTMLDocGenerator method generateContextInfo.

/**
     * DOC YeXiaowei Comment method "generateContextInfo".
     * 
     * @return
     */
private void generateContextInfo(final Item item, final Element element) {
    EList contexts = null;
    if (item instanceof ProcessItem) {
        contexts = ((ProcessItem) item).getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        contexts = ((JobletProcessItem) item).getJobletProcess().getContext();
    }
    if (contexts == null || contexts.isEmpty()) {
        return;
    }
    // Context root //$NON-NLS-1$
    Element contextListElement = DocumentHelper.createElement("contextList");
    for (int i = 0, n = contexts.size(); i < n; i++) {
        // export single context infomation
        //$NON-NLS-1$
        Element contextElement = DocumentHelper.createElement("context");
        ContextType context = (ContextType) contexts.get(i);
        // Attributes
        //$NON-NLS-1$
        contextElement.addAttribute("name", HTMLDocUtils.checkString(context.getName()));
        IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
        // Context parameters as children
        EList params = context.getContextParameter();
        if (params != null && !params.isEmpty()) {
            for (int j = 0, k = params.size(); j < k; j++) {
                /*
                     * <contextParameter comment="Give server name" name="server" prompt="Default Server "
                     * promptNeeded="false" repositoryContextId="_crJMkCCQEd2Oweh7yRMWjQ" type=""
                     * value="'192.168.0.109'"/>
                     */
                ContextParameterType param = (ContextParameterType) params.get(j);
                //$NON-NLS-1$
                Element contextParamElement = DocumentHelper.createElement("contextParameter");
                //$NON-NLS-1$
                contextParamElement.addAttribute("name", HTMLDocUtils.checkString(param.getName()));
                //$NON-NLS-1$
                contextParamElement.addAttribute("prompt", HTMLDocUtils.checkString(param.getPrompt()));
                contextParamElement.addAttribute("promptNeeded", HTMLDocUtils.checkString(Boolean.toString(//$NON-NLS-1$
                param.isPromptNeeded())));
                //$NON-NLS-1$
                contextParamElement.addAttribute("type", HTMLDocUtils.checkString(param.getType()));
                //$NON-NLS-1$ 
                contextParamElement.addAttribute("value", ParameterValueUtil.getValue4Doc(param));
                // replace repository id with context label
                if (param.getRepositoryContextId() != null) {
                    ContextItem contextItem = ContextUtils.getContextItemById2(param.getRepositoryContextId());
                    if (contextItem != null) {
                        // bug 5978: repository link to context item might be lost.
                        String label = contextItem.getProperty().getLabel();
                        //$NON-NLS-1$
                        contextParamElement.addAttribute("source", HTMLDocUtils.checkString(label));
                    }
                }
                contextElement.add(contextParamElement);
            }
        }
        contextListElement.add(contextElement);
    }
    element.add(contextListElement);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) Element(org.dom4j.Element) Point(org.eclipse.draw2d.geometry.Point) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

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