use of org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException in project pentaho-platform by pentaho.
the class DefaultDeleteHelper method undeleteFile.
/**
* {@inheritDoc}
*/
public void undeleteFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
Node fileToUndeleteNode = session.getNodeByIdentifier(fileId.toString());
String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath();
String origParentFolderPath = getOriginalParentFolderPath(session, pentahoJcrConstants, fileToUndeleteNode, false);
String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName();
if (session.itemExists(absDestPath)) {
RepositoryFile file = JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem(absDestPath));
throw new RepositoryFileDaoFileExistsException(file);
}
session.move(fileToUndeleteNode.getPath(), absDestPath);
session.getItem(trashFileIdNodePath).remove();
}
use of org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException in project pentaho-platform by pentaho.
the class DefaultDeleteHelperTest method testUndeleteFile.
@Test
public void testUndeleteFile() throws Exception {
String fileID = "testFileID";
final Property origParentFolderPathProperty = mock(Property.class);
when(origParentFolderPathProperty.getString()).thenReturn("origParentFolderPath");
final Node nodeDeletedParent = mock(Node.class);
when(nodeDeletedParent.getPath()).thenReturn("parentPath");
when(nodeDeletedParent.hasProperty(pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH())).thenReturn(true);
when(nodeDeletedParent.getProperty(pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH())).thenReturn(origParentFolderPathProperty);
final Node nodeToRemove = mock(Node.class);
when(nodeToRemove.getPath()).thenReturn("nodePath");
when(nodeToRemove.getParent()).thenReturn(nodeDeletedParent);
when(session.getItem(anyString())).thenReturn(nodeDeletedParent);
when(session.getNodeByIdentifier(fileID)).thenReturn(nodeToRemove);
try {
defaultDeleteHelper.undeleteFile(session, pentahoJcrConstants, fileID);
verify(session).move(eq(nodeToRemove.getPath()), anyString());
verify(nodeDeletedParent).remove();
} catch (Exception e) {
e.printStackTrace();
fail();
}
// must fail if there is something at the original path
when(session.itemExists(anyString())).thenReturn(true);
try {
defaultDeleteHelper.undeleteFile(session, pentahoJcrConstants, fileID);
} catch (RepositoryFileDaoFileExistsException e1) {
// it's ok
}
}
Aggregations