Search in sources :

Example 1 with ConnectionRepNode

use of org.talend.dq.nodes.ConnectionRepNode in project tdq-studio-se by Talend.

the class SwitchContextProvider method shouldShowSwitchMenu.

/**
 * DOC msjian Comment method "shouldShowReloadMenu".
 *
 * @param node
 * @return
 */
@SuppressWarnings("unchecked")
private boolean shouldShowSwitchMenu(RepositoryNode node) {
    ENodeType type = node.getType();
    // MOD msjian 2012-2-13 TDQ-4559: make it support file/mdm connection
    if ((ENodeType.REPOSITORY_ELEMENT.equals(type) || ENodeType.TDQ_REPOSITORY_ELEMENT.equals(type)) && node instanceof ConnectionRepNode) {
        // MOD qiongli 2011-10-10
        String contextId = null;
        Item item = node.getObject().getProperty().getItem();
        if (item instanceof ConnectionItem) {
            Connection connection = ((ConnectionItem) item).getConnection();
            if (connection != null) {
                contextId = connection.getContextId();
            }
        }
        // This menu will be available only when a context is not null and has more than one group.
        if (contextId != null && !PluginConstant.EMPTY_STRING.equals(contextId.trim())) {
            ContextItem objContextItem = ContextUtils.getContextItemById2(contextId);
            EList<Context> contexts = objContextItem.getContext();
            if (contexts != null && contexts.size() > 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : Context(org.talend.core.context.Context) Item(org.talend.core.model.properties.Item) ContextItem(org.talend.core.model.properties.ContextItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ContextItem(org.talend.core.model.properties.ContextItem) ConnectionRepNode(org.talend.dq.nodes.ConnectionRepNode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType)

Example 2 with ConnectionRepNode

use of org.talend.dq.nodes.ConnectionRepNode in project tdq-studio-se by Talend.

the class RepNodeUtilsTest method testIsValidSelectionForMatchAnalysis.

/**
 * Test: 1) when the selected node is: connection, catalog,schema, folder, will not be valid; 2) when the selected
 * nodes are: multiple table/views, multiple columns from different table/view, will not be valid; 3) when the
 * selected node is: one single table/view/file table,will be valid; 4) when the selected nodes are: multiple
 * columns from one same table/view, will be valid.
 */
@Test
public void testIsValidSelectionForMatchAnalysis() {
    // 1) when the selected node is: connection, catalog,schema, folder, will not be valid;
    List<IRepositoryNode> nodes = new ArrayList<IRepositoryNode>();
    ConnectionRepNode cNode = mock(ConnectionRepNode.class);
    nodes.add(cNode);
    Assert.assertFalse(RepNodeUtils.isValidSelectionFromSameTable(nodes));
    DBConnectionRepNode dbNode = mock(DBConnectionRepNode.class);
    nodes.clear();
    nodes.add(dbNode);
    Assert.assertFalse(RepNodeUtils.isValidSelectionFromSameTable(nodes));
    DBConnectionFolderRepNode dbfNode = mock(DBConnectionFolderRepNode.class);
    nodes.clear();
    nodes.add(dbfNode);
    Assert.assertFalse(RepNodeUtils.isValidSelectionFromSameTable(nodes));
    DQDBFolderRepositoryNode folderNode = mock(DQDBFolderRepositoryNode.class);
    nodes.clear();
    nodes.add(folderNode);
    Assert.assertFalse(RepNodeUtils.isValidSelectionFromSameTable(nodes));
    DBCatalogRepNode catalogNode = mock(DBCatalogRepNode.class);
    nodes.clear();
    nodes.add(catalogNode);
    Assert.assertFalse(RepNodeUtils.isValidSelectionFromSameTable(nodes));
    DBSchemaRepNode schemaNode = mock(DBSchemaRepNode.class);
    nodes.clear();
    nodes.add(schemaNode);
    Assert.assertFalse(RepNodeUtils.isValidSelectionFromSameTable(nodes));
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) ConnectionRepNode(org.talend.dq.nodes.ConnectionRepNode) DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) DBSchemaRepNode(org.talend.dq.nodes.DBSchemaRepNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) DBCatalogRepNode(org.talend.dq.nodes.DBCatalogRepNode) ArrayList(java.util.ArrayList) DQDBFolderRepositoryNode(org.talend.dq.nodes.DQDBFolderRepositoryNode) DBConnectionFolderRepNode(org.talend.dq.nodes.DBConnectionFolderRepNode) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ConnectionRepNode

use of org.talend.dq.nodes.ConnectionRepNode in project tdq-studio-se by Talend.

the class ConnectionEditor method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    if (masterPage.isDirty()) {
        masterPage.doSave(monitor);
        setPartName(masterPage.getIntactElemenetName());
        // MOD qiongli 2012-11-29 avoid item is proxy(get item form IRepositoryViewObject).
        ConnectionRepNode connectionRepNode = ((ConnectionInfoPage) getMasterPage()).getCurrentRepNode();
        if (connectionRepNode != null && connectionRepNode instanceof DBConnectionRepNode) {
            IRepositoryViewObject object = connectionRepNode.getObject();
            if (object != null) {
                ConnectionItem item = (ConnectionItem) object.getProperty().getItem();
                String name = ((DatabaseConnectionItem) item).getConnection().getName();
                CWMPlugin.getDefault().updateConnetionAliasByName(item.getConnection(), masterPage.getOldDataproviderName());
                masterPage.setOldDataproviderName(name);
            }
        }
        // refresh the analysis editor
        if (masterPage.isNameTextUpdate()) {
            WorkbenchUtils.nodifyDependedAnalysis((ConnectionItem) connectionRepNode.getObject().getProperty().getItem());
            // WorkbenchUtils.refreshCurrentAnalysisEditor();
            masterPage.setModify(false);
            // TDQ-11312
            if (this.getEditorInput() instanceof FileEditorInput) {
                this.setInput(masterPage.getEditorInput());
            }
        }
    }
    setEditorObject(((ConnectionInfoPage) getMasterPage()).getCurrentRepNode());
    super.doSave(monitor);
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) ConnectionRepNode(org.talend.dq.nodes.ConnectionRepNode) DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 4 with ConnectionRepNode

use of org.talend.dq.nodes.ConnectionRepNode in project tdq-studio-se by Talend.

the class LocalRepositoryObjectCRUD method moveRepositoryNodes.

/**
 * move RepositoryNodes to the target RepositoryNode.
 *
 * @param repositoryNodes
 * @param targetNode
 * @throws PersistenceException
 */
private void moveRepositoryNodes(IRepositoryNode[] repositoryNodes, IRepositoryNode targetNode) throws PersistenceException {
    if (repositoryNodes != null) {
        for (IRepositoryNode sourceNode : repositoryNodes) {
            if (sourceNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                if (sourceNode instanceof AnalysisRepNode || sourceNode instanceof ConnectionRepNode) {
                    moveAnaConNode(sourceNode, targetNode);
                } else if (sourceNode instanceof ReportRepNode) {
                    moveReportRepNode(sourceNode, targetNode);
                } else {
                    IPath makeRelativeTo = getMakeRelativeTo(sourceNode);
                    IPath removeLastSegments = makeRelativeTo.removeLastSegments(1);
                    if (sourceNode instanceof SysIndicatorDefinitionRepNode) {
                        // SystemIndicatorDefinition can't be moved
                        if (!((SysIndicatorDefinitionRepNode) sourceNode).isSystemIndicator()) {
                            moveOthersNode(sourceNode, targetNode, removeLastSegments);
                        }
                    } else if (sourceNode instanceof PatternRepNode) {
                        moveOthersNode(sourceNode, targetNode, removeLastSegments);
                    } else if (sourceNode instanceof JrxmlTempleteRepNode) {
                        moveJrxmlFileRepNode(sourceNode, targetNode, makeRelativeTo);
                    } else if (sourceNode instanceof SourceFileRepNode || sourceNode instanceof RuleRepNode) {
                        moveOthersNode(sourceNode, targetNode, makeRelativeTo);
                    } else {
                        moveOthersNode(sourceNode, targetNode, removeLastSegments);
                    }
                }
            } else if (sourceNode.getType() == ENodeType.SIMPLE_FOLDER) {
                moveFolderRepNode(sourceNode, targetNode);
            }
            // refresh the dq repository tree view
            CorePlugin.getDefault().refreshDQView(targetNode.getParent());
            // MOD qiongli 2012-4-23,only refresh the parent of source node at here.
            CorePlugin.getDefault().refreshDQView(sourceNode.getParent());
        }
    }
}
Also used : ReportAnalysisRepNode(org.talend.dq.nodes.ReportAnalysisRepNode) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) ConnectionRepNode(org.talend.dq.nodes.ConnectionRepNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) ReportRepNode(org.talend.dq.nodes.ReportRepNode) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) RuleRepNode(org.talend.dq.nodes.RuleRepNode) PatternRepNode(org.talend.dq.nodes.PatternRepNode)

Example 5 with ConnectionRepNode

use of org.talend.dq.nodes.ConnectionRepNode in project tdq-studio-se by Talend.

the class SwitchContextAction method run.

/*
     * MOD yyin 20120917 TDQ-5362, do NOT reload DB when switching context.
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    // MOD msjian 2012-2-13 TDQ-4559: make it support file connection
    if (selectedObject instanceof ConnectionRepNode) {
        ConnectionRepNode conRepNode = (ConnectionRepNode) selectedObject;
        Item item = conRepNode.getObject().getProperty().getItem();
        if (item instanceof ConnectionItem) {
            ConnectionItem connItem = (ConnectionItem) item;
            // Added yyin 20120925 TDQ-5668, check this connection's editor is open or not, if open, close.
            CorePlugin.getDefault().closeEditorIfOpened(connItem);
            // ~
            String chooseContext = chooseContext(connItem.getConnection());
            boolean isUpdated = SwitchContextGroupNameImpl.getInstance().updateContextGroup(connItem, chooseContext);
            if (isUpdated) {
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    log.debug(DefaultMessagesImpl.getString("SwitchContextAction.saveMessage", chooseContext, "successful"));
                }
                // ADD msjian TDQ-8834 2014-4-10: after switch the context, update the sql explore alias
                // information.
                CWMPlugin.getDefault().updateConnetionAliasByName(connItem.getConnection(), connItem.getProperty().getLabel());
                // TDQ-8834~
                CorePlugin.getDefault().refreshDQView(selectedObject);
            } else {
                // $NON-NLS-1$
                MessageDialog.openWarning(// $NON-NLS-1$
                CorePlugin.getDefault().getWorkbench().getDisplay().getActiveShell(), // $NON-NLS-1$
                "", // $NON-NLS-1$
                DefaultMessagesImpl.getString("SwitchContextAction.nullParameterError"));
                // $NON-NLS-1$ //$NON-NLS-2$
                log.error(DefaultMessagesImpl.getString("SwitchContextAction.saveMessage", chooseContext, "failed"));
            }
        }
    }
// TDQ-4559~
}
Also used : Item(org.talend.core.model.properties.Item) ContextItem(org.talend.core.model.properties.ContextItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ConnectionRepNode(org.talend.dq.nodes.ConnectionRepNode) ConnectionItem(org.talend.core.model.properties.ConnectionItem)

Aggregations

ConnectionRepNode (org.talend.dq.nodes.ConnectionRepNode)5 ConnectionItem (org.talend.core.model.properties.ConnectionItem)3 ContextItem (org.talend.core.model.properties.ContextItem)2 Item (org.talend.core.model.properties.Item)2 DBConnectionRepNode (org.talend.dq.nodes.DBConnectionRepNode)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 ArrayList (java.util.ArrayList)1 IPath (org.eclipse.core.runtime.IPath)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Context (org.talend.core.context.Context)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 AnalysisRepNode (org.talend.dq.nodes.AnalysisRepNode)1 DBCatalogRepNode (org.talend.dq.nodes.DBCatalogRepNode)1 DBConnectionFolderRepNode (org.talend.dq.nodes.DBConnectionFolderRepNode)1 DBSchemaRepNode (org.talend.dq.nodes.DBSchemaRepNode)1 DQDBFolderRepositoryNode (org.talend.dq.nodes.DQDBFolderRepositoryNode)1