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;
}
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));
}
}
}
}
}
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);
}
Aggregations