Search in sources :

Example 81 with ContextType

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;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) BasicEList(org.eclipse.emf.common.util.BasicEList) IContextManager(org.talend.core.model.process.IContextManager)

Example 82 with ContextType

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));
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) TdReport(org.talend.dataquality.reports.TdReport) ArrayList(java.util.ArrayList) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) Test(org.junit.Test)

Example 83 with ContextType

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()]);
}
Also used : IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) BasicEList(org.eclipse.emf.common.util.BasicEList) ContextParameterProposal(org.talend.core.ui.proposal.ContextParameterProposal) ArrayList(java.util.ArrayList) JobContextManager(org.talend.core.model.context.JobContextManager) IContextManager(org.talend.core.model.process.IContextManager) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 84 with ContextType

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
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JobContextManager(org.talend.core.model.context.JobContextManager) Property(org.talend.core.model.properties.Property) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 85 with ContextType

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;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)108 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)27 ArrayList (java.util.ArrayList)26 ContextItem (org.talend.core.model.properties.ContextItem)21 PersistenceException (org.talend.commons.exception.PersistenceException)17 File (java.io.File)16 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)15 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)13 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 List (java.util.List)10 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)8 Map (java.util.Map)8 EList (org.eclipse.emf.common.util.EList)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 Property (org.talend.core.model.properties.Property)6 HashSet (java.util.HashSet)5