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);
}
// ~
}
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());
}
}
}
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;
}
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;
}
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);
}
Aggregations