use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdq-studio-se by Talend.
the class AbstractMetadataFormPage method getContexts.
/**
* get the context list from the report editor.
*
* @return
*/
protected List<ContextType> getContexts() {
EList<ContextType> el = new BasicEList<ContextType>();
IContextManager contextManager = currentEditor.getContextManager();
contextManager.saveToEmf(el);
return el;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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.ContextType in project tdq-studio-se by Talend.
the class TdqProposalProvider method getProposals.
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
if (this.getSupportContextEditor() != null && this.getSupportContextEditor().getContextManager() != null) {
IContextManager contextManager = this.getSupportContextEditor().getContextManager();
String defaultContextName = contextManager.getDefaultContext().getName();
EList<ContextType> contexts = new BasicEList<ContextType>();
contextManager.saveToEmf(contexts);
List<IContextParameter> ctxParams = new JobContextManager(contexts, defaultContextName).getDefaultContext().getContextParameterList();
for (IContextParameter ctxParam : ctxParams) {
proposals.add(new ContextParameterProposal(ctxParam));
}
}
return proposals.toArray(new IContentProposal[proposals.size()]);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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.ContextType in project tbd-studio-se by Talend.
the class CassandraMetadataHandler method getKeySpace.
private Object getKeySpace(NoSQLConnection connection, String ksName) throws NoSQLServerException {
ContextType contextType = null;
if (StringUtils.isEmpty(ksName)) {
return null;
}
if (connection.isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
}
if (contextType != null) {
ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
}
// if ksName has quote,then case sensitive
boolean hasQuote = (ksName.charAt(0) == '"') && (ksName.charAt(ksName.length() - 1) == '"');
try {
initCluster(connection);
List<Object> keySpaces = getKeySpaces(connection);
for (Object keySpace : keySpaces) {
// $NON-NLS-1$
String tmpKsName = (String) NoSQLReflection.invokeMethod(keySpace, "getName");
if (hasQuote) {
ksName = TalendQuoteUtils.removeQuotesIfExist(ksName);
if (ksName.equals(tmpKsName)) {
return keySpace;
}
// case in-sensitive by default for kaName
} else if (ksName.equalsIgnoreCase(tmpKsName)) {
return keySpace;
}
}
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return null;
}
Aggregations