Search in sources :

Example 1 with SourceFileRepNode

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

the class NewSourceFileActionProvider method fillContextMenu.

public void fillContextMenu(IMenuManager menu) {
    // MOD mzhao user readonly role on svn repository mode.
    if (!isShowMenu()) {
        return;
    }
    TreeSelection treeSelection = ((TreeSelection) this.getContext().getSelection());
    List<IFile> selectedFiles = new ArrayList<IFile>();
    if (treeSelection.size() == 1) {
        RepositoryNode node = (RepositoryNode) treeSelection.getFirstElement();
        if (node instanceof SourceFileSubFolderNode) {
            menu.add(new AddSqlFileAction(node));
            menu.add(new ImportSqlFileAction(node));
            menu.add(new RenameTdqFolderAction(node));
        } else if (node instanceof SourceFileFolderRepNode) {
            menu.add(new AddSqlFileAction(node));
            menu.add(new ImportSqlFileAction(node));
        } else if (node instanceof SourceFileRepNode) {
            // MOD klliu bug TDQ-4797 2012-02-29
            menu.add(new RenameSqlFileAction(node));
        }
        boolean isSelectFile = computeSelectedFiles(treeSelection, selectedFiles);
        if (isSelectFile && !selectedFiles.isEmpty()) {
            menu.add(new OpenSqlFileAction(selectedFiles));
        }
    }
}
Also used : RenameSqlFileAction(org.talend.dataprofiler.core.sql.RenameSqlFileAction) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) AddSqlFileAction(org.talend.dataprofiler.core.sql.AddSqlFileAction) SourceFileFolderRepNode(org.talend.dq.nodes.SourceFileFolderRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) RenameTdqFolderAction(org.talend.dataprofiler.core.ui.action.actions.RenameTdqFolderAction) SourceFileSubFolderNode(org.talend.dq.nodes.SourceFileSubFolderNode) ImportSqlFileAction(org.talend.dataprofiler.core.sql.ImportSqlFileAction) OpenSqlFileAction(org.talend.dataprofiler.core.sql.OpenSqlFileAction)

Example 2 with SourceFileRepNode

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

the class TOPRepositoryServiceTest method testSourceFileOpening2.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.service.TOPRepositoryService#sourceFileOpening(org.talend.repository.model.RepositoryNode)}
 * .
 */
@Test
public void testSourceFileOpening2() {
    // test for SourceFileSubFolderNode
    SourceFileSubFolderNode folderNodeMock = mock(SourceFileSubFolderNode.class);
    SourceFileRepNode nodeMock = mock(SourceFileRepNode.class);
    List<IRepositoryNode> nodeList = new ArrayList<IRepositoryNode>();
    nodeList.add(nodeMock);
    when(folderNodeMock.getChildren()).thenReturn(nodeList);
    boolean ok = Boolean.TRUE;
    // $NON-NLS-1$
    String msg = "msg";
    ReturnCode rc = new ReturnCode(msg, ok);
    // $NON-NLS-1$
    stub(method(WorkspaceResourceHelper.class, "checkSourceFileNodeOpening", SourceFileRepNode.class)).toReturn(rc);
    TOPRepositoryService service = new TOPRepositoryService();
    assertTrue(service.sourceFileOpening(folderNodeMock));
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) SourceFileSubFolderNode(org.talend.dq.nodes.SourceFileSubFolderNode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with SourceFileRepNode

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

the class UnitTestBuildHelper method createRealSourceFileNode.

public static SourceFileRepNode createRealSourceFileNode(String name, RepositoryNode parentNode, IPath createPath, Boolean isDelete) {
    SourceFileRepNode fileRepNode = null;
    TDQSourceFileItem sourceFileItem = PropertiesFactoryImpl.eINSTANCE.createTDQSourceFileItem();
    org.talend.core.model.properties.Property fileProperty = PropertiesFactory.eINSTANCE.createProperty();
    fileProperty.setId(EcoreUtil.generateUUID());
    fileProperty.setItem(sourceFileItem);
    fileProperty.setLabel(name);
    sourceFileItem.setProperty(fileProperty);
    sourceFileItem.setFilename(name);
    sourceFileItem.setName(name);
    ByteArray byteArray = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createByteArray();
    byteArray.setInnerContent(PluginConstant.EMPTY_STRING.getBytes());
    sourceFileItem.setContent(byteArray);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(isDelete);
    sourceFileItem.setState(itemState);
    try {
        ProxyRepositoryFactory.getInstance().create(sourceFileItem, createPath, false);
        IRepositoryViewObject fileViewObject = new RepositoryViewObject(fileProperty);
        fileRepNode = new SourceFileRepNode(fileViewObject, parentNode, ENodeType.REPOSITORY_ELEMENT, null);
        fileRepNode.setProperties(EProperties.CONTENT_TYPE, ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT);
        fileRepNode.setProperties(EProperties.LABEL, ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT);
        fileViewObject.setRepositoryNode(fileRepNode);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    return fileRepNode;
}
Also used : TDQSourceFileItem(org.talend.dataquality.properties.TDQSourceFileItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ByteArray(org.talend.core.model.properties.ByteArray) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) Property(org.talend.core.model.properties.Property) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 4 with SourceFileRepNode

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

the class WorkspaceResourceHelperTest method testCheckSourceFileNodeOpening.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.helper.WorkspaceResourceHelper#checkSourceFileNodeOpening(org.talend.dq.nodes.SourceFileRepNode)}
 * .
 */
@Test
public void testCheckSourceFileNodeOpening() {
    SourceFileRepNode fileNodeMock = mock(SourceFileRepNode.class);
    // $NON-NLS-1$
    String nodeLabel = "nodeLabel";
    when(fileNodeMock.getLabel()).thenReturn(nodeLabel);
    // $NON-NLS-1$
    stub(method(WorkspaceResourceHelper.class, "sourceFileHasBeenOpened", SourceFileRepNode.class)).toReturn(Boolean.TRUE);
    ReturnCode rc = WorkspaceResourceHelper.checkSourceFileNodeOpening(fileNodeMock);
    assertTrue(rc.isOk());
    assertTrue(rc.getMessage().startsWith(nodeLabel));
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with SourceFileRepNode

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

the class RepositoryNodeHelper method recursiveFindFile.

/**
 * DOC msjian Comment method "recursiveFindFile".
 *
 * @param file
 * @return
 */
public static DQRepositoryNode recursiveFindFile(IFile file) {
    if (file == null) {
        return null;
    }
    String fileName = file.getName();
    List<?> fileRepNodes = null;
    if (fileName.toLowerCase().endsWith(PluginConstant.JRXML_STRING)) {
        fileRepNodes = getJrxmlFileRepNodes(getLibrariesFolderNode(EResourceConstant.JRXML_TEMPLATE), true);
    } else if (fileName.toLowerCase().endsWith(PluginConstant.SQL_STRING)) {
        fileRepNodes = getSourceFileRepNodes(getLibrariesFolderNode(EResourceConstant.SOURCE_FILES), true);
    }
    if (fileRepNodes != null) {
        for (int i = 0; i < fileRepNodes.size(); i++) {
            DQRepositoryNode childNode = (DQRepositoryNode) fileRepNodes.get(i);
            String childNodeFileName = PluginConstant.EMPTY_STRING;
            if (childNode instanceof JrxmlTempleteRepNode) {
                childNodeFileName = childNode.getObject().getProperty().eResource().getURI().lastSegment().replaceAll(PluginConstant.PROPERTIES_STRING, PluginConstant.JRXML_STRING);
            } else if (childNode instanceof SourceFileRepNode) {
                childNodeFileName = childNode.getObject().getProperty().eResource().getURI().lastSegment().replaceAll(PluginConstant.PROPERTIES_STRING, PluginConstant.SQL_STRING);
            }
            if (fileName.equals(childNodeFileName)) {
                return childNode;
            }
        }
    }
    return null;
}
Also used : DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode)

Aggregations

SourceFileRepNode (org.talend.dq.nodes.SourceFileRepNode)15 IRepositoryNode (org.talend.repository.model.IRepositoryNode)7 JrxmlTempleteRepNode (org.talend.dq.nodes.JrxmlTempleteRepNode)6 SourceFileSubFolderNode (org.talend.dq.nodes.SourceFileSubFolderNode)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ReturnCode (org.talend.utils.sugars.ReturnCode)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 AnalysisRepNode (org.talend.dq.nodes.AnalysisRepNode)4 RepositoryNode (org.talend.repository.model.RepositoryNode)4 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 ExchangeComponentRepNode (org.talend.dataprofiler.core.ui.exchange.ExchangeComponentRepNode)3 DBCatalogRepNode (org.talend.dq.nodes.DBCatalogRepNode)3 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)3 DBConnectionRepNode (org.talend.dq.nodes.DBConnectionRepNode)3 DBSchemaRepNode (org.talend.dq.nodes.DBSchemaRepNode)3 DBTableRepNode (org.talend.dq.nodes.DBTableRepNode)3 DBViewRepNode (org.talend.dq.nodes.DBViewRepNode)3