Search in sources :

Example 1 with RepositoryFileDaoFileExistsException

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();
}
Also used : RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) Node(javax.jcr.Node) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 2 with RepositoryFileDaoFileExistsException

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
    }
}
Also used : RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) Node(javax.jcr.Node) Matchers.anyString(org.mockito.Matchers.anyString) Property(javax.jcr.Property) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Aggregations

Node (javax.jcr.Node)2 RepositoryFileDaoFileExistsException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException)2 Property (javax.jcr.Property)1 RepositoryException (javax.jcr.RepositoryException)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)1