Search in sources :

Example 1 with ExcelSchemaBean

use of org.talend.core.repository.model.preview.ExcelSchemaBean in project tdi-studio-se by Talend.

the class ShadowProcess method buildProcess.

private IProcess buildProcess() {
    IProcess ps = null;
    if (description.getEncoding() != null) {
        currentProcessEncoding = TalendTextUtils.removeQuotes(description.getEncoding());
    }
    FileOutputDelimitedNode outNode = new FileOutputDelimitedNode(TalendTextUtils.addQuotes("" + PathUtils.getPortablePath(outPath.toOSString())), //$NON-NLS-1$ 
    description.getEncoding());
    switch(type) {
        case FILE_DELIMITED:
        case FILE_CSV:
            FileInputDelimitedNode inDelimitedNode = new FileInputDelimitedNode(inPath, description.getRowSeparator(), description.getFieldSeparator(), description.getLimitRows(), description.getHeaderRow(), description.getFooterRow(), description.getEscapeCharacter(), description.getTextEnclosure(), description.getRemoveEmptyRowsToSkip(), description.isSplitRecord(), description.getEncoding(), type);
            ps = new FileinToDelimitedProcess<FileInputDelimitedNode>(inDelimitedNode, outNode);
            break;
        case FILE_POSITIONAL:
            FileInputPositionalNode inPositionalNode = new FileInputPositionalNode(inPath, description.getRowSeparator(), description.getPattern(), description.getHeaderRow(), description.getFooterRow(), description.getLimitRows(), description.getRemoveEmptyRowsToSkip(), description.getEncoding());
            outNode.setColumnNumber(inPositionalNode.getColumnNumber());
            ps = new FileinToDelimitedProcess<FileInputPositionalNode>(inPositionalNode, outNode);
            break;
        case FILE_REGEXP:
            FileInputRegExpNode inRegExpNode = new FileInputRegExpNode(inPath, description.getRowSeparator(), description.getPattern(), description.getLimitRows(), description.getHeaderRow(), description.getFooterRow(), description.getRemoveEmptyRowsToSkip(), description.getEncoding());
            ps = new FileinToDelimitedProcess<FileInputRegExpNode>(inRegExpNode, outNode);
            break;
        case FILE_XML:
            List<Map<String, String>> newmappings = new ArrayList<Map<String, String>>();
            List<Map<String, String>> oldmappings = description.getMapping();
            for (int i = 0; i < oldmappings.size(); i++) {
                Map<String, String> map = oldmappings.get(i);
                //$NON-NLS-1$ //$NON-NLS-2$
                map.put("SCHEMA_COLUMN", "row" + i);
                newmappings.add(map);
            }
            FileInputXmlNode inXmlNode = new FileInputXmlNode(inPath, description.getLoopQuery(), description.getMapping(), description.getLoopLimit(), description.getEncoding());
            ps = new FileinToDelimitedProcess<FileInputXmlNode>(inXmlNode, outNode);
            break;
        case FILE_EXCEL:
            // hywang add for excel 2007
            String versionCheck = "false";
            String afterRemoveQuotesPath = TalendTextUtils.removeQuotes(inPath);
            if (afterRemoveQuotesPath.toLowerCase().endsWith(".xlsx")) {
                versionCheck = "true";
            }
            FileInputExcelNode excelNode = null;
            ExcelSchemaBean excelBean = description.getExcelSchemaBean();
            excelNode = new FileInputExcelNode(inPath, description.getSchema(), //$NON-NLS-1$
            description.getEncoding() == null ? TalendTextUtils.addQuotes("ISO-8859-1") : description.getEncoding(), Integer.toString(description.getLimitRows()), Integer.toString(description.getHeaderRow()), Integer.toString(description.getFooterRow()), Boolean.toString(description.getRemoveEmptyRowsToSkip()), excelBean, versionCheck);
            outNode.setMetadataList(excelNode.getMetadataList());
            ps = new FileinToDelimitedProcess<FileInputExcelNode>(excelNode, outNode);
            break;
        case FILE_LDIF:
            outNode = new FileOutputDelimitedForLDIF(TalendTextUtils.addQuotes(//$NON-NLS-1$
            "" + PathUtils.getPortablePath(outPath.toOSString())), description.getEncoding());
            FileInputLdifNode inLdifNode = new FileInputLdifNode(inPath, description.getSchema(), description.getEncoding());
            outNode.setMetadataList(inLdifNode.getMetadataList());
            ps = new FileinToDelimitedProcess<FileInputLdifNode>(inLdifNode, outNode);
            break;
        case LDAP_SCHEMA:
            // outNode = new FileOutputDelimitedForLDIF(TalendTextUtils.addQuotes(""
            // + PathUtils.getPortablePath(outPath.toOSString())), description.getEncoding());
            LDAPSchemaInputNode inLDAPSchemaNode = new LDAPSchemaInputNode(TalendTextUtils.addQuotes(//$NON-NLS-1$
            "" + PathUtils.getPortablePath(outPath.toOSString())), description.getSchema(), description.getEncoding(), description.getLdapSchemaBean());
            List<IMetadataTable> metadataList = inLDAPSchemaNode.getMetadataList();
            for (IMetadataTable metadataTable : metadataList) {
                // for bug15450
                List<IMetadataColumn> listColumns = metadataTable.getListColumns();
                for (IMetadataColumn metadataColumn : listColumns) {
                    String label = metadataColumn.getLabel();
                    boolean validColumnName = MetadataToolHelper.isValidColumnName(label);
                    if (!validColumnName) {
                        metadataColumn.setLabel(label.replaceAll("[^a-zA-Z0-9_]", "_"));
                    }
                }
            }
            outNode.setMetadataList(metadataList);
            ps = new FileinToDelimitedProcess<LDAPSchemaInputNode>(inLDAPSchemaNode, outNode);
            break;
        case WSDL_SCHEMA:
            // outNode = new FileOutputDelimitedForLDIF(TalendTextUtils.addQuotes(""
            // + PathUtils.getPortablePath(outPath.toOSString())), description.getEncoding());
            WSDLSchemaInputNode inWSDLSchemaNode = new WSDLSchemaInputNode(TalendTextUtils.addQuotes(//$NON-NLS-1$
            "" + PathUtils.getPortablePath(outPath.toOSString())), description.getEncoding(), description.getSchema(), description.getWsdlSchemaBean(), description.getWsdlSchemaBean().getParameters());
            outNode.setMetadataList(inWSDLSchemaNode.getMetadataList());
            ps = new FileinToDelimitedProcess<WSDLSchemaInputNode>(inWSDLSchemaNode, outNode);
            break;
        case SALESFORCE_SCHEMA:
            SalesforceSchemaInputNode inSalesforceNode = new SalesforceSchemaInputNode(description.getSchema(), description.getSalesforceSchemaBean());
            outNode.setMetadataList(inSalesforceNode.getMetadataList());
            SalesforceSchemaBean salesforceSchemaBean = description.getSalesforceSchemaBean();
            boolean uesHttp = salesforceSchemaBean.isUesHttp();
            salesforceSchemaBean.isUseProxy();
            if (uesHttp) {
                String proxyHost = salesforceSchemaBean.getProxyHost();
                String proxyPort = salesforceSchemaBean.getProxyPort();
                String userName = salesforceSchemaBean.getProxyUsername();
                String password = salesforceSchemaBean.getProxyPassword();
                final Prejob prejob = new Prejob("");
                final SetProxy setProxy = new SetProxy("HTTP_PROXY", proxyHost, proxyPort, userName, password, proxyHost + "|" + proxyPort);
                ps = new FileinToDelimitedProcess<SalesforceSchemaInputNode>(inSalesforceNode, outNode, prejob, setProxy);
            } else {
                ps = new FileinToDelimitedProcess<SalesforceSchemaInputNode>(inSalesforceNode, outNode);
            }
            break;
        default:
            break;
    }
    return ps;
}
Also used : ArrayList(java.util.ArrayList) ExcelSchemaBean(org.talend.core.repository.model.preview.ExcelSchemaBean) SalesforceSchemaBean(org.talend.core.repository.model.preview.SalesforceSchemaBean) IProcess(org.talend.core.model.process.IProcess) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IProcess (org.talend.core.model.process.IProcess)1 ExcelSchemaBean (org.talend.core.repository.model.preview.ExcelSchemaBean)1 SalesforceSchemaBean (org.talend.core.repository.model.preview.SalesforceSchemaBean)1