Search in sources :

Example 6 with JrxmlTempleteRepNode

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

the class LocalRepositoryObjectCRUD method moveFolderRepNode.

/**
 * move Folder Node.
 *
 * @param sourceNode
 * @param targetNode
 * @throws PersistenceException
 */
private void moveFolderRepNode(IRepositoryNode sourceNode, IRepositoryNode targetNode) throws PersistenceException {
    // MOD yyin 20130125 TDQ-5392
    IPath oldPath = null;
    List<String> jrxmlFileNames = null;
    List<JrxmlTempleteRepNode> jrxmlFileRepNodes = new ArrayList<JrxmlTempleteRepNode>();
    if (sourceNode instanceof JrxmlTempSubFolderNode) {
        // remeber the old path
        oldPath = RepositoryNodeHelper.getPath(sourceNode);
        // find all jrxml files in this folder
        jrxmlFileRepNodes = RepositoryNodeHelper.getJrxmlFileRepNodes(sourceNode, true);
        // remember the files name
        jrxmlFileNames = RepNodeUtils.getListOfJrxmlNameWithPath(oldPath, jrxmlFileRepNodes);
    }
    // ~
    moveFolder(sourceNode, targetNode);
    // ADD yyin 20130125 TDQ-5392
    if (sourceNode instanceof JrxmlTempSubFolderNode) {
        // use two array :old file names and new file names, to call the method.
        IPath newPath = RepositoryNodeHelper.getPath(targetNode);
        List<String> jrxmlFileNamesAfterMove = new ArrayList<String>();
        for (JrxmlTempleteRepNode jrxml : jrxmlFileRepNodes) {
            // check it there some sub folder under the source node
            IPath relativeTo = RepositoryNodeHelper.getPath(jrxml.getParent()).makeRelativeTo(oldPath);
            IPath tempPath = newPath.append(RepNodeUtils.getSeparator()).append(sourceNode.getLabel()).append(RepNodeUtils.getSeparator());
            if (relativeTo.segmentCount() > 0) {
                // if there are some sub folder under the source node
                tempPath = tempPath.append(relativeTo).append(RepNodeUtils.getSeparator());
            }
            jrxmlFileNamesAfterMove.add(tempPath.append(RepositoryNodeHelper.getFileNameOfTheNode(jrxml)).toOSString());
        }
        // update the depended reports
        RepNodeUtils.updateJrxmlRelatedReport(jrxmlFileNames, jrxmlFileNamesAfterMove);
    }
// ~
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode) JrxmlTempSubFolderNode(org.talend.dq.nodes.JrxmlTempSubFolderNode)

Example 7 with JrxmlTempleteRepNode

use of org.talend.dq.nodes.JrxmlTempleteRepNode 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 8 with JrxmlTempleteRepNode

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

the class RepNodeUtils method getListOfJrxmlNewNameWithPath.

/**
 * Used for replace only the renamed folder name, the path of the parent& the path of the sub folder should remain.
 *
 * @param oldPath: the path before rename
 * @param newPath: the new foler name
 * @param jrxmlFileRepNodes the related reports list with name
 * @return the full jrxml new names after folder renamed
 */
public static List<String> getListOfJrxmlNewNameWithPath(IPath oldPath, IPath newPath, List<JrxmlTempleteRepNode> jrxmlFileRepNodes) {
    List<String> jrxmlFileNames = new ArrayList<String>();
    for (JrxmlTempleteRepNode jrxml : jrxmlFileRepNodes) {
        // if the parent of the jrxml is not the current folder,
        IPath parentPath = RepositoryNodeHelper.getPath(jrxml.getParent());
        if (oldPath.equals(parentPath)) {
            jrxmlFileNames.add(newPath.append(separator).append(RepositoryNodeHelper.getFileNameOfTheNode(jrxml)).toOSString());
        } else {
            // change the old folder name in parent path to new path:
            // e.g. /tdq_libraries/JRXML Template/c01/(sub/) to -->/tdq_libraries/JRXML Template/c01_new/sub/
            // $NON-NLS-1$
            IPath replacedPath = new Path("");
            for (int i = 0; i < parentPath.segmentCount(); i++) {
                if (i < newPath.segmentCount() && !newPath.segment(i).equals(parentPath.segment(i))) {
                    replacedPath = replacedPath.append(newPath.segment(i)).append(separator);
                } else {
                    replacedPath = replacedPath.append(parentPath.segment(i)).append(separator);
                }
            }
            jrxmlFileNames.add(replacedPath.append(RepositoryNodeHelper.getFileNameOfTheNode(jrxml)).toOSString());
        }
    }
    return jrxmlFileNames;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode)

Example 9 with JrxmlTempleteRepNode

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

the class RepNodeUtils method getListOfJrxmlNameWithPath.

/**
 * get the full jrxml name with path before move/rename its parent folder.
 *
 * @param oldPath: the path before rename
 * @param jrxmlFileRepNodes the related reports list with name
 * @return the full jrxml new names with path
 */
public static List<String> getListOfJrxmlNameWithPath(IPath path, List<JrxmlTempleteRepNode> jrxmlFileRepNodes) {
    List<String> jrxmlFileNames = new ArrayList<String>();
    for (JrxmlTempleteRepNode jrxml : jrxmlFileRepNodes) {
        // if the parent of the jrxml is not the current folder,
        IPath parentPath = RepositoryNodeHelper.getPath(jrxml.getParent());
        IPath makeRelativeTo = null;
        if (path.equals(parentPath)) {
            makeRelativeTo = path.append(separator).append(RepositoryNodeHelper.getFileNameOfTheNode(jrxml));
        } else {
            makeRelativeTo = parentPath.append(separator).append(RepositoryNodeHelper.getFileNameOfTheNode(jrxml));
        }
        jrxmlFileNames.add(makeRelativeTo.toOSString());
    }
    return jrxmlFileNames;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode)

Example 10 with JrxmlTempleteRepNode

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

the class RepositoryNodeHelperTest method testGetIFile.

/**
 * Test method for
 * {@link org.talend.dq.helper.RepositoryNodeHelper#getIFile(org.talend.repository.model.IRepositoryNode)}.
 */
@Test
public void testGetIFile() {
    // test non-ModelElement node, such as Jrxml File and Source File
    JrxmlTempleteRepNode jrxmlNodeMock = mock(JrxmlTempleteRepNode.class);
    // Jrxml File and Source File don't have ModelElement
    ModelElement meNull = null;
    // $NON-NLS-1$
    stub(method(RepositoryNodeHelper.class, "getModelElementFromRepositoryNode", JrxmlTempleteRepNode.class)).toReturn(meNull);
    PowerMockito.mockStatic(ResourcesPlugin.class);
    IWorkspace workspaceMock = mock(IWorkspace.class);
    when(ResourcesPlugin.getWorkspace()).thenReturn(workspaceMock);
    IWorkspaceRoot workspaceRootMock = mock(IWorkspaceRoot.class);
    when(workspaceMock.getRoot()).thenReturn(workspaceRootMock);
    IRepositoryViewObject repoViewObjMock = mock(IRepositoryViewObject.class);
    when(jrxmlNodeMock.getObject()).thenReturn(repoViewObjMock);
    Property propertyMock = mock(Property.class);
    when(repoViewObjMock.getProperty()).thenReturn(propertyMock);
    Item itemMock = mock(Item.class);
    when(propertyMock.getItem()).thenReturn(itemMock);
    Resource resourceMock = mock(Resource.class);
    when(itemMock.eResource()).thenReturn(resourceMock);
    // $NON-NLS-1$
    String propPathStr = "/Talend/Talend_All_trunk/runtime/TDQEE_runtime_50/PP/TDQ_Libraries/JRXML Template/column/b01_column_basic_0.1.properties";
    URI uriReal = URI.createFileURI(propPathStr);
    when(resourceMock.getURI()).thenReturn(uriReal);
    IFile fileMock = mock(IFile.class);
    when(workspaceRootMock.getFile((Path) any())).thenReturn(fileMock);
    IFile iFile = RepositoryNodeHelper.getIFile(jrxmlNodeMock);
    assertEquals(fileMock, iFile);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Resource(org.eclipse.emf.ecore.resource.Resource) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode) Property(org.talend.core.model.properties.Property) URI(org.eclipse.emf.common.util.URI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

JrxmlTempleteRepNode (org.talend.dq.nodes.JrxmlTempleteRepNode)11 SourceFileRepNode (org.talend.dq.nodes.SourceFileRepNode)6 ArrayList (java.util.ArrayList)5 IRepositoryNode (org.talend.repository.model.IRepositoryNode)5 IPath (org.eclipse.core.runtime.IPath)4 JrxmlTempSubFolderNode (org.talend.dq.nodes.JrxmlTempSubFolderNode)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 AnalysisRepNode (org.talend.dq.nodes.AnalysisRepNode)3 PatternRepNode (org.talend.dq.nodes.PatternRepNode)3 ReportAnalysisRepNode (org.talend.dq.nodes.ReportAnalysisRepNode)3 ReportRepNode (org.talend.dq.nodes.ReportRepNode)3 RuleRepNode (org.talend.dq.nodes.RuleRepNode)3 SysIndicatorDefinitionRepNode (org.talend.dq.nodes.SysIndicatorDefinitionRepNode)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 ExchangeCategoryRepNode (org.talend.dataprofiler.core.ui.exchange.ExchangeCategoryRepNode)2 ExchangeComponentRepNode (org.talend.dataprofiler.core.ui.exchange.ExchangeComponentRepNode)2 DBCatalogRepNode (org.talend.dq.nodes.DBCatalogRepNode)2 DBColumnFolderRepNode (org.talend.dq.nodes.DBColumnFolderRepNode)2 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)2 DBConnectionFolderRepNode (org.talend.dq.nodes.DBConnectionFolderRepNode)2