Search in sources :

Example 6 with MetadataColumnExt

use of org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt in project tdi-studio-se by Talend.

the class FunctionManagerExtTest method testGetAvailableFunFromValue.

/**
     * 
     * DOC Administrator Comment method "testGetAvailableFunFromValue". test private method getAvailableFunFromValue(,,)
     * 
     * @throws Exception
     */
@Test
public void testGetAvailableFunFromValue() throws Exception {
    MetadataColumnExt baseConn = mock(MetadataColumnExt.class);
    when(baseConn.getTalendType()).thenReturn("id_String");
    AbstractFunctionParser parser = null;
    parser = new RoutineFunctionParser();
    parser.parse();
    List<TalendType> talendTypes = parser.getList();
    List<Function> funtions = new ArrayList<Function>();
    for (TalendType talendType : talendTypes) {
        if (talendType.getName().equals(baseConn.getTalendType())) {
            funtions.addAll(talendType.getFunctions());
        }
    }
    funtions.add(createCustomizeFunction());
    Method method = FunctionManagerExt.class.getDeclaredMethod("getAvailableFunFromValue", new Class[] { MetadataColumnExt.class, String.class, List.class });
    method.setAccessible(true);
    Function funtion = (Function) method.invoke(new FunctionManagerExt(), baseConn, value, funtions);
    Parameter parameter = null;
    for (Object stringParameter : funtion.getParameters()) {
        parameter = (Parameter) stringParameter;
    }
    assertEquals(value, parameter.getValue());
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt) Test(org.junit.Test)

Example 7 with MetadataColumnExt

use of org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt in project tdi-studio-se by Talend.

the class FunctionManagerExtTest method testGetOneColData.

@Test
public void testGetOneColData() {
    FunctionManagerExt functionManagerExt = new FunctionManagerExt();
    MetadataColumn newColumn = new MetadataColumn();
    //$NON-NLS-1$
    newColumn.setLabel("newColumn");
    newColumn.setTalendType(JavaTypesManager.STRING.getId());
    MetadataColumnExt columnExt = new MetadataColumnExt(newColumn);
    Function function = new Function();
    //$NON-NLS-1$
    function.setName("UPCASE");
    function.setDescription(PURE_PERL_DESC);
    //$NON-NLS-1$
    function.setClassName("StringHandling");
    StringParameter param = new StringParameter();
    //$NON-NLS-1$
    param.setName("string");
    //$NON-NLS-1$
    param.setValue("\"Hello\"");
    param.setType(JavaTypesManager.STRING.getId());
    //$NON-NLS-1$
    param.setComment("String");
    List<Parameter> params = new ArrayList<Parameter>();
    params.add(param);
    function.setParameters(params);
    columnExt.setFunction(function);
    // replace as false
    String value = functionManagerExt.getOneColData(columnExt);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(\"Hello\")");
    value = functionManagerExt.getOneColData(columnExt, false);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(\"Hello\")");
    value = functionManagerExt.getOneColData(columnExt, false, false);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(\"Hello\")");
    // replace as true
    value = functionManagerExt.getOneColData(columnExt, true);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(${0})");
    value = functionManagerExt.getOneColData(columnExt, false, true);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(${0})");
}
Also used : MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ArrayList(java.util.ArrayList) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt) Test(org.junit.Test)

Example 8 with MetadataColumnExt

use of org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt in project tdi-studio-se by Talend.

the class FunctionManagerExtTest method testGetFuntionFromColumn.

@Test
public void testGetFuntionFromColumn() {
    FunctionManagerExt functionManagerExt = new FunctionManagerExt();
    MetadataColumn newColumn = new MetadataColumn();
    //$NON-NLS-1$
    newColumn.setLabel("newColumn");
    newColumn.setTalendType(JavaTypesManager.STRING.getId());
    MetadataColumnExt columnExt = new MetadataColumnExt(newColumn);
    List<Function> funcs = functionManagerExt.getFunctionsByType(newColumn.getTalendType());
    if (funcs.size() > 0) {
        Function func = funcs.get(0);
        columnExt.setFunction(func);
        Function function = functionManagerExt.getFunctionFromColumn(columnExt);
        assertEquals(func.getName(), function.getName());
        assertEquals(func.getParameters().size(), function.getParameters().size());
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.MetadataColumn) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt) Test(org.junit.Test)

Example 9 with MetadataColumnExt

use of org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt in project tdi-studio-se by Talend.

the class RowGeneratorComponent method sameMetadataFunctionsAs.

/*
     * add for bug TDI-26458 by fwang at 24 June,2013, need check update for functions.
     */
private boolean sameMetadataFunctionsAs(IMetadataTable metaTable) {
    List<IMetadataColumn> metaTables = metaTable.getListColumns();
    for (IMetadataColumn metaColum : metaTables) {
        if (!(metaColum instanceof MetadataColumnExt)) {
            break;
        }
        MetadataColumnExt metaColumExt = (MetadataColumnExt) metaColum;
        String functionValue = FunctionManagerExt.getOneColData(metaColumExt);
        for (Map<String, Object> map : getMapList()) {
            if (metaColumExt.getLabel().equals(map.get(COLUMN_NAME)) && !functionValue.equals(map.get(ARRAY))) {
                return false;
            }
        }
    }
    return true;
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)

Example 10 with MetadataColumnExt

use of org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt in project tdi-studio-se by Talend.

the class RowGeneratorComponentDocumentation method generateColumnInfo.

/**
     * Administrator Comment method "generateColumnInfo".
     * 
     * @param externalNodeElement
     */
private void generateColumnInfo(Element externalNodeElement) {
    for (IMetadataTable metadataTable : this.metadataListOut) {
        // rowGeneratorMain.getGeneratorUI().convert(metadataTable);
        for (IMetadataColumn tempColumn : metadataTable.getListColumns()) {
            MetadataColumnExt column = (MetadataColumnExt) tempColumn;
            //$NON-NLS-1$
            Element columnElement = externalNodeElement.addElement("column");
            //$NON-NLS-1$
            columnElement.addAttribute("name", HTMLDocUtils.checkString(column.getLabel()));
            //$NON-NLS-1$
            columnElement.addAttribute("key", String.valueOf(column.isKey()));
            String type = HTMLDocUtils.checkString(column.getTalendType());
            if (LanguageManager.getCurrentLanguage().equals(ECodeLanguage.JAVA)) {
                type = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
            }
            //$NON-NLS-1$
            columnElement.addAttribute("type", type);
            //$NON-NLS-1$
            columnElement.addAttribute("nullable", String.valueOf(column.isNullable()));
            String length;
            if ((column.getLength() == null) || (column.getLength() == 0)) {
                //$NON-NLS-1$
                length = "";
            } else {
                length = String.valueOf(column.getLength());
            }
            //$NON-NLS-1$
            columnElement.addAttribute("length", length);
            String precision;
            if ((column.getPrecision() == null) || (column.getPrecision() == 0)) {
                //$NON-NLS-1$
                precision = "";
            } else {
                precision = String.valueOf(column.getPrecision());
            }
            //$NON-NLS-1$
            columnElement.addAttribute("precision", precision);
            //$NON-NLS-1$
            columnElement.addAttribute("default", HTMLDocUtils.checkString(column.getDefault()));
            //$NON-NLS-1$
            columnElement.addAttribute("comment", HTMLDocUtils.checkString(column.getComment()));
            //$NON-NLS-1$
            String functionName = "";
            if (column.getFunction() != null) {
                functionName = column.getFunction().getName();
            }
            //$NON-NLS-1$
            columnElement.addAttribute("functions", HTMLDocUtils.checkString(functionName));
            //$NON-NLS-1$
            columnElement.addAttribute("parameters", HTMLDocUtils.checkString(column.getParameter()));
        // columnElement.addAttribute("preview",
        // HTMLDocUtils.checkString(column.getPreview()));
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Element(org.dom4j.Element) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)

Aggregations

MetadataColumnExt (org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)11 ArrayList (java.util.ArrayList)7 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)6 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)6 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 MetadataTable (org.talend.core.model.metadata.MetadataTable)2 Function (org.talend.designer.rowgenerator.data.Function)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 Element (org.dom4j.Element)1