use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdq-studio-se by Talend.
the class ContextHelper method getUrlWithoutContext.
/**
* translate the context variable in the string to the value according to the specific context group name.
*
* @param context
* @param contextGroupName
* @param contextString the stirng contains context variable, example:
* jdbc:mysql://context.TdqContext_Host:context.TdqContext_Port/context.TdqContext_DbName?characterEncoding=UTF8
* @return
*/
public static String getUrlWithoutContext(List<ContextType> context, String contextGroupName, String contextString) {
// key is the context script code(start with context.), value is the context value
Map<String, String> contextValues = new HashMap<String, String>();
for (ContextType contextType : context) {
if (contextType.getName().equals(contextGroupName)) {
for (Object obj : contextType.getContextParameter()) {
ContextParameterType cpt = (ContextParameterType) obj;
contextValues.put(ContextParameterUtils.getNewScriptCode(cpt.getName(), LANGUAGE), cpt.getRawValue());
}
break;
}
}
return getUrlWithoutContext(contextString, contextValues);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdq-studio-se by Talend.
the class ContextHelperTest method testGetOutputFolderFromReports.
/**
* Test method for {@link org.talend.dq.helper.ContextHelper#getOutputFolderFromReports(java.util.List)}.
*/
@Test
public void testGetOutputFolderFromReports() {
// $NON-NLS-1$
String empty = "";
// $NON-NLS-1$
String blank = " ";
// $NON-NLS-1$
String defaultStr = "default";
// $NON-NLS-1$
String var1 = "context.outputFolder";
// $NON-NLS-1$
String var1a = "outputFolder";
// $NON-NLS-1$
String var2 = "context.of2";
// $NON-NLS-1$
String var2a = "of2";
// $NON-NLS-1$
String folder1 = "/home/user/talend/a";
// $NON-NLS-1$
String folder2 = "/home/user/talend/b";
Assert.assertNull(ContextHelper.getOutputFolderFromReports(null));
Assert.assertNull(ContextHelper.getOutputFolderFromReports(new ArrayList<TdReport>()));
List<TdReport> reports = new ArrayList<TdReport>();
TdReport tdReport = ReportsFactory.eINSTANCE.createTdReport();
tdReport.setDefaultContext(defaultStr);
TaggedValue tv = CoreFactory.eINSTANCE.createTaggedValue();
tv.setTag(TaggedValueHelper.OUTPUT_FOLDER_TAG);
tv.setValue(empty);
tdReport.getTaggedValue().add(tv);
reports.add(tdReport);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
tv.setValue(blank);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
tv.setValue(folder1);
Assert.assertEquals(folder1, ContextHelper.getOutputFolderFromReports(reports));
tv.setValue(var1);
Assert.assertEquals(var1, ContextHelper.getOutputFolderFromReports(reports));
TdReport tdReport2 = ReportsFactory.eINSTANCE.createTdReport();
tdReport2.setDefaultContext(defaultStr);
TaggedValue tv2 = CoreFactory.eINSTANCE.createTaggedValue();
tv2.setTag(TaggedValueHelper.OUTPUT_FOLDER_TAG);
tv2.setValue(empty);
tdReport2.getTaggedValue().add(tv2);
reports.add(tdReport2);
ContextType ct = TalendFileFactory.eINSTANCE.createContextType();
ct.setName(defaultStr);
ContextParameterType cpt = TalendFileFactory.eINSTANCE.createContextParameterType();
cpt.setName(var1a);
cpt.setValue(folder1);
ct.getContextParameter().add(cpt);
tdReport.getContext().add(ct);
ContextType ct2 = TalendFileFactory.eINSTANCE.createContextType();
ct2.setName(defaultStr);
ContextParameterType cpt2 = TalendFileFactory.eINSTANCE.createContextParameterType();
cpt2.setName(var2a);
cpt2.setValue(folder2);
ct2.getContextParameter().add(cpt2);
tdReport2.getContext().add(ct2);
// both context, different output folder
tv.setValue(var1);
tv2.setValue(var2);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
// both context, same output folder
cpt2.setValue(folder1);
ct2.getContextParameter().clear();
ct2.getContextParameter().add(cpt2);
tdReport2.getContext().clear();
tdReport2.getContext().add(ct2);
String temp = ContextHelper.getOutputFolderFromReports(reports);
Assert.assertTrue(var1.equals(temp) || var2.equals(temp));
// both real folder, different output folder
tv.setValue(folder1);
tdReport.getTaggedValue().clear();
tdReport.getTaggedValue().add(tv);
tv2.setValue(folder2);
tdReport2.getTaggedValue().clear();
tdReport2.getTaggedValue().add(tv2);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
// both real folder, same output folder
tv2.setValue(folder1);
tdReport2.getTaggedValue().clear();
tdReport2.getTaggedValue().add(tv2);
Assert.assertEquals(folder1, ContextHelper.getOutputFolderFromReports(reports));
// context and real folder, different output folder
tv2.setValue(var2);
tdReport2.getTaggedValue().clear();
tdReport2.getTaggedValue().add(tv2);
cpt2.setValue(folder2);
ct2.getContextParameter().clear();
ct2.getContextParameter().add(cpt2);
tdReport2.getContext().clear();
tdReport2.getContext().add(ct2);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
// context and real folder, same output folder
cpt2.setValue(folder1);
ct2.getContextParameter().clear();
ct2.getContextParameter().add(cpt2);
tdReport2.getContext().clear();
tdReport2.getContext().add(ct2);
Assert.assertEquals(folder1, ContextHelper.getOutputFolderFromReports(reports));
// one report's output folder is empty(mean default location)
tv2.setValue(empty);
tdReport2.getTaggedValue().clear();
tdReport2.getTaggedValue().add(tv2);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
// one report's output folder is blank(mean default location)
tv2.setValue(blank);
tdReport2.getTaggedValue().clear();
tdReport2.getTaggedValue().add(tv2);
Assert.assertNull(ContextHelper.getOutputFolderFromReports(reports));
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method createContextItem.
public void createContextItem(String name) throws PersistenceException {
// ContextType--default
ContextType createContextDefault = TalendFileFactory.eINSTANCE.createContextType();
createContextDefault.setName(ContextTpeyNameOld);
ContextParameterType createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
createContextParameterTypeForDefault.setName(paramNameCatalog);
createContextParameterTypeForDefault.setValue(catalogOld);
createContextDefault.getContextParameter().add(createContextParameterTypeForDefault);
createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
createContextParameterTypeForDefault.setName(paramNameSchema);
createContextParameterTypeForDefault.setValue(schemaOld);
createContextDefault.getContextParameter().add(createContextParameterTypeForDefault);
// ~ContextType--default
// ContextType--test
ContextType createContextTest = TalendFileFactory.eINSTANCE.createContextType();
createContextTest.setName(ContextTpeyNameNew);
createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
createContextParameterTypeForDefault.setName(paramNameCatalog);
createContextParameterTypeForDefault.setValue(catalogNew);
createContextTest.getContextParameter().add(createContextParameterTypeForDefault);
createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
createContextParameterTypeForDefault.setName(paramNameSchema);
createContextParameterTypeForDefault.setValue(schemaNew);
createContextTest.getContextParameter().add(createContextParameterTypeForDefault);
// ~ContextType--test
// ConntextItem
ContextItem contextItem = PropertiesFactory.eINSTANCE.createContextItem();
Property contextProperty = PropertiesFactory.eINSTANCE.createProperty();
contextProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
contextProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
contextProperty.setStatusCode("");
contextProperty.setLabel(name);
contextItem.setProperty(contextProperty);
JobContextManager contextManager = new JobContextManager();
String nextId = factory.getNextId();
contextProperty.setId(nextId);
contextProperty.setLabel(contextProperty.getDisplayName());
contextManager.saveToEmf(contextItem.getContext());
contextItem.setDefaultContext(contextManager.getDefaultContext().getName());
contextItem.getContext().clear();
contextItem.getContext().add(createContextDefault);
contextItem.getContext().add(createContextTest);
factory.create(contextItem, Path.EMPTY);
// ContextItem
// connection
createConnectionItem(connectionName, null, false);
Connection connection = createDatabaseConnectionItem.getConnection();
connection.setContextId(contextProperty.getId());
createCatalog(catalogOld);
// ~connection data
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tbd-studio-se by Talend.
the class NoSQLConnectionContextManagerTest method setUp.
@Before
public void setUp() throws Exception {
noSqlConnection = NosqlFactory.eINSTANCE.createNoSQLConnection();
String jsonStr = "[{\"REPLICA_HOST\":\"context.Mongo1_ReplicaHost_1\",\"REPLICA_PORT\":\"context.Mongo1_ReplicaPort_1\"}]";
noSqlConnection.getAttributes().put(IMongoDBAttributes.REPLICA_SET, jsonStr);
Set<String> attributes = new HashSet<String>();
attributes.add(IMongoDBAttributes.DATABASE);
attributes.add(IMongoDBAttributes.REPLICA_SET);
manager = new NoSQLConnectionContextManager(noSqlConnection, attributes);
contextType = TalendFileFactory.eINSTANCE.createContextType();
ContextParameterType hostParam = TalendFileFactory.eINSTANCE.createContextParameterType();
ContextParameterType portParam = TalendFileFactory.eINSTANCE.createContextParameterType();
hostParam.setName("Mongo1_ReplicaHost_1");
hostParam.setValue("localhost");
portParam.setName("Mongo1_ReplicaPort_1");
portParam.setValue("12701");
contextType.getContextParameter().add(hostParam);
contextType.getContextParameter().add(portParam);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tbd-studio-se by Talend.
the class ClusterTestUtil method createContextType.
public static ContextType createContextType(String contextGroupName, String... paramNames) {
ContextType context = TalendFileFactory.eINSTANCE.createContextType();
context.setName(contextGroupName);
if (paramNames != null) {
for (String paramName : paramNames) {
ContextParameterType param = TalendFileFactory.eINSTANCE.createContextParameterType();
param.setName(paramName);
// $NON-NLS-1$
param.setType("id_String");
context.getContextParameter().add(param);
}
}
return context;
}
Aggregations