DefaultDeleteHelper implements IDeleteHelper { public List<RepositoryFile> getDeletedFiles( final Session session, final PentahoJcrConstants pentahoJcrConstants, final String origParentFolderPath, final String filter ) throws RepositoryException { Node trashNode = getOrCreateTrashInternalFolderNode( session, pentahoJcrConstants ); QueryObjectModelFactory fac = session.getWorkspace().getQueryManager().getQOMFactory(); final String selectorName = "selector"; final Selector selector = fac.selector( "nt:base", selectorName ); Constraint origParentFolderPathConstraint = fac.comparison( fac.propertyValue( selectorName, pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ), QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, fac.literal( session.getValueFactory().createValue( origParentFolderPath ) ) ); Constraint origNameConstraint = null; if ( StringUtils.hasLength( filter ) ) { String convertedFilter = filter.replace( '*', '%' ); origNameConstraint = fac.comparison( fac.propertyValue( selectorName, pentahoJcrConstants.getPHO_ORIGNAME() ), QueryObjectModelConstants.JCR_OPERATOR_LIKE, fac.literal( session.getValueFactory().createValue( convertedFilter ) ) ); } Constraint descendantNodeConstraint = fac.descendantNode( selectorName, trashNode.getPath() ); Constraint allConstraints = fac.and( descendantNodeConstraint, origParentFolderPathConstraint ); if ( StringUtils.hasLength( filter ) ) { allConstraints = fac.and( allConstraints, origNameConstraint ); } Query query = fac.createQuery( selector, allConstraints, null, null ); QueryResult result = session.getWorkspace().getQueryManager().createQuery( query.getStatement(), Query.JCR_JQOM ).execute(); NodeIterator nodeIter = result.getNodes(); List<RepositoryFile> deletedFiles = new ArrayList<RepositoryFile>(); String user = PentahoSessionHolder.getSession().getName(); while ( nodeIter.hasNext() ) { Node trashFileIdNode = nodeIter.nextNode(); if ( trashFileIdNode.hasNodes() ) { deletedFiles.add( nodeToDeletedFile( session, pentahoJcrConstants, trashFileIdNode.getNodes().nextNode(), user ) ); } else { throw new RuntimeException( Messages.getInstance().getString( "DefaultDeleteHelper.ERROR_0002_NOT_CLEAN" ) ); } } Set<RepositoryFile> mergedDeletedFiles = new HashSet<RepositoryFile>(); mergedDeletedFiles.addAll( deletedFiles ); mergedDeletedFiles.addAll( legacyGetDeletedFiles( session, pentahoJcrConstants, pathConversionHelper .relToAbs( origParentFolderPath ), filter ) ); List<RepositoryFile> mergedList = new ArrayList<RepositoryFile>( mergedDeletedFiles ); Collections.sort( mergedList ); return mergedList; } DefaultDeleteHelper( final ILockHelper lockHelper, final IPathConversionHelper pathConversionHelper ); void deleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                          final Serializable fileId ); List<RepositoryFile> getDeletedFiles( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                                               final String origParentFolderPath, final String filter ); List<RepositoryFile> getDeletedFiles( final Session session, final PentahoJcrConstants pentahoJcrConstants ); List<RepositoryFile> getAllDeletedFiles( final Session session,
      final PentahoJcrConstants pentahoJcrConstants ); void permanentlyDeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                                     final Serializable fileId ); void undeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                            final Serializable fileId ); String getOriginalParentFolderPath( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                                             final Serializable fileId ); static final String JCR_ROOT_VERSION; }
@Test public void testGetDeletedFiles() throws Exception { final String path1 = "path1"; final Calendar date1 = Calendar.getInstance(); final Node deletedNode1 = createDeletedNode( path1, date1 ); final String path2 = "path2"; final Calendar date2 = Calendar.getInstance(); final Node deletedNode2 = createDeletedNode( path2, date2 ); final NodeIterator nodeIterator = mock( NodeIterator.class ); when( nodeIterator.hasNext() ).thenReturn( true, true, false ); when( nodeIterator.nextNode() ).thenReturn( deletedNode1, deletedNode2 ); final Node nodeTrash = mock( Node.class ); when( nodeTrash.getNodes() ).thenReturn( nodeIterator ); final Node nodeUserFolder = mock( Node.class ); when( nodeUserFolder.hasNode( anyString() ) ).thenReturn( true ); when( nodeUserFolder.getNode( anyString() ) ).thenReturn( nodeTrash ); when( session.getItem( anyString() ) ).thenReturn( nodeUserFolder ); final List<RepositoryFile> deletedFiles = defaultDeleteHelper.getDeletedFiles( session, pentahoJcrConstants ); assertNotNull( deletedFiles ); assertEquals( 2, deletedFiles.size() ); assertEquals( path1, deletedFiles.get( 0 ).getOriginalParentFolderPath() ); assertEquals( path2, deletedFiles.get( 1 ).getOriginalParentFolderPath() ); assertEquals( date1.getTime(), deletedFiles.get( 0 ).getDeletedDate() ); assertEquals( date2.getTime(), deletedFiles.get( 1 ).getDeletedDate() ); }