Search in sources :

Example 6 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method getConnVariables.

private static Set<String> getConnVariables(ConnectionItem connectionItem, Set<IConnParamName> paramSet) {
    if (connectionItem == null) {
        return null;
    }
    Set<String> varList = new HashSet<String>();
    Iterator<IConnParamName> paramIt = paramSet.iterator();
    while (paramIt.hasNext()) {
        Object param = paramIt.next();
        if (param instanceof EDBParamName) {
            varList.add(((EDBParamName) param).name());
        }
        if (param instanceof EFileParamName) {
            varList.add(((EFileParamName) param).name());
        }
        if (param instanceof EParamName) {
            varList.add(((EParamName) param).name());
        }
    }
    return varList;
}
Also used : EParamName(org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName) EDBParamName(org.talend.metadata.managment.ui.utils.DBConnectionContextUtils.EDBParamName) EFileParamName(org.talend.metadata.managment.ui.utils.FileConnectionContextUtils.EFileParamName) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashSet(java.util.HashSet)

Example 7 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method setJSONFilePropertiesForExistContextMode.

static void setJSONFilePropertiesForExistContextMode(JSONFileConnection jsonConn, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
    if (jsonConn == null) {
        return;
    }
    String jsonVariableName = null;
    for (IConnParamName param : paramSet) {
        if (param instanceof EParamName) {
            EParamName jsonParam = (EParamName) param;
            if (map != null && map.size() > 0) {
                for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : map.entrySet()) {
                    List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                    for (ConectionAdaptContextVariableModel model : modelList) {
                        if (model.getValue().equals(jsonParam.name())) {
                            jsonVariableName = model.getName();
                            break;
                        }
                    }
                }
            }
            if (jsonConn.isInputModel()) {
                switch(jsonParam) {
                    case FilePath:
                        jsonConn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                        break;
                    case Encoding:
                        jsonConn.setEncoding(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                        break;
                    case XPathQuery:
                        EList schema = jsonConn.getSchema();
                        if (schema != null) {
                            if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
                                JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
                                descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                            }
                        }
                    default:
                }
            } else {
                if (jsonParam.equals(EParamName.OutputFilePath)) {
                    jsonConn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) EParamName(org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName) EList(org.eclipse.emf.common.util.EList) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class GenericContextUtilTest method testExportAndRevertContextForComponentProperties.

@Test
public void testExportAndRevertContextForComponentProperties() {
    //$NON-NLS-1$
    String prefix = "testConn";
    GenericConnection connection = GenericMetadataFactory.eINSTANCE.createGenericConnection();
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    //$NON-NLS-1$
    props.userId.setValue("1");
    //$NON-NLS-1$
    TestNestedProperties nestedProps = (TestNestedProperties) props.getProperty("nestedProps");
    //$NON-NLS-1$
    nestedProps.userName.setValue("testUserName");
    //$NON-NLS-1$
    nestedProps.userPassword.setValue("testUserPassword");
    connection.setCompProperties(props.toSerialized());
    Set<IConnParamName> contextParams = new HashSet<>();
    //$NON-NLS-1$
    contextParams.add(createConnParamName("userId"));
    //$NON-NLS-1$
    contextParams.add(createConnParamName("nestedProps.userName"));
    //$NON-NLS-1$
    contextParams.add(createConnParamName("nestedProps.userPassword"));
    // Test export context
    GenericContextUtil.setPropertiesForContextMode(prefix, connection, contextParams);
    TestProperties deserProps = getPropertiesFromConnection(connection);
    //$NON-NLS-1$
    assertEquals("context.testConn_userId", deserProps.userId.getValue());
    //$NON-NLS-1$
    assertEquals("context.testConn_nestedProps_userName", deserProps.nestedProps.userName.getValue());
    //$NON-NLS-1$
    assertEquals("context.testConn_nestedProps_userPassword", deserProps.nestedProps.userPassword.getValue());
    assertEquals(deserProps.userId.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), true);
    assertEquals(deserProps.nestedProps.userName.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), true);
    assertEquals(deserProps.nestedProps.userPassword.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), true);
    // Test revert context
    ContextType contextType = TalendFileFactoryImpl.eINSTANCE.createContextType();
    //$NON-NLS-1$ //$NON-NLS-2$
    contextType.getContextParameter().add(createContextParameterType("testConn_userId", "1"));
    //$NON-NLS-1$ //$NON-NLS-2$
    contextType.getContextParameter().add(createContextParameterType("testConn_nestedProps_userName", "testUserName"));
    //$NON-NLS-1$ //$NON-NLS-2$
    contextType.getContextParameter().add(createContextParameterType("testConn_nestedProps_userPassword", "testUserPassword"));
    GenericContextUtil.revertPropertiesForContextMode(connection, contextType);
    deserProps = getPropertiesFromConnection(connection);
    //$NON-NLS-1$
    assertEquals("1", deserProps.userId.getValue());
    //$NON-NLS-1$
    assertEquals("testUserName", deserProps.nestedProps.userName.getValue());
    //$NON-NLS-1$
    assertEquals("testUserPassword", deserProps.nestedProps.userPassword.getValue());
    assertEquals(deserProps.userId.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), false);
    assertEquals(deserProps.nestedProps.userName.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), false);
    assertEquals(deserProps.nestedProps.userPassword.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), false);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)8 GenericConnParamName (org.talend.metadata.managment.ui.utils.GenericConnParamName)4 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ComponentProperties (org.talend.components.api.properties.ComponentProperties)3 ContextItem (org.talend.core.model.properties.ContextItem)3 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)3 Map (java.util.Map)2 EParamName (org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName)2 HashMap (java.util.HashMap)1 EList (org.eclipse.emf.common.util.EList)1 Test (org.junit.Test)1 JobContextManager (org.talend.core.model.context.JobContextManager)1 JavaType (org.talend.core.model.metadata.types.JavaType)1 IContextParameter (org.talend.core.model.process.IContextParameter)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)1