use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class RepositoryFileImportFileHandler method getParentId.
/**
* Returns the Id of the parent folder of the file path provided
*
* @param repositoryPath
* @return
*/
protected Serializable getParentId(final String repositoryPath) {
Assert.notNull(repositoryPath);
final String parentPath = RepositoryFilenameUtils.getFullPathNoEndSeparator(repositoryPath);
final RepositoryFile parentFile = repository.getFile(parentPath);
if (parentFile == null) {
return null;
}
Serializable parentFileId = parentFile.getId();
Assert.notNull(parentFileId);
return parentFileId;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class DefaultDeleteHelperTest method testGetDeletedFiles1.
@Test
public void testGetDeletedFiles1() 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);
// 2 nodes in trash
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(nodeUserFolder.getIdentifier()).thenReturn("nodeUserFolderID");
final Selector selector = mock(Selector.class);
final Value value = mock(Value.class);
final ValueFactory valueFactory = mock(ValueFactory.class);
when(valueFactory.createValue(anyString())).thenReturn(value);
final QueryObjectModel queryObjectModel = mock(QueryObjectModel.class);
final QueryObjectModelFactory qomFactory = mock(QueryObjectModelFactory.class);
when(qomFactory.createQuery(Matchers.<Source>any(), Matchers.<Constraint>any(), Matchers.<Ordering[]>any(), Matchers.<Column[]>any())).thenReturn(queryObjectModel);
when(qomFactory.selector(anyString(), anyString())).thenReturn(selector);
final QueryResult queryResult = mock(QueryResult.class);
when(queryResult.getNodes()).thenReturn(nodeIterator);
final Query query = mock(Query.class);
when(query.execute()).thenReturn(queryResult);
final QueryManager queryManager = mock(QueryManager.class);
when(queryManager.getQOMFactory()).thenReturn(qomFactory);
when(queryManager.createQuery(anyString(), anyString())).thenReturn(query);
final Workspace workspace = mock(Workspace.class);
when(workspace.getQueryManager()).thenReturn(queryManager);
when(session.getItem(anyString())).thenReturn(nodeUserFolder);
when(session.getValueFactory()).thenReturn(valueFactory);
when(session.getWorkspace()).thenReturn(workspace);
when(session.itemExists(anyString())).thenReturn(true);
final String someFilter = "someFilter";
final List<RepositoryFile> deletedFiles = defaultDeleteHelper.getDeletedFiles(session, pentahoJcrConstants, path1, someFilter);
assertNotNull(deletedFiles);
assertEquals(2, deletedFiles.size());
for (RepositoryFile file : deletedFiles) {
if (file.getOriginalParentFolderPath().equals(path1)) {
assertEquals(file.getDeletedDate(), date1.getTime());
} else if (file.getOriginalParentFolderPath().equals(path2)) {
assertEquals(file.getDeletedDate(), date2.getTime());
} else {
fail("Deleted file doesn't have correct path");
}
}
verify(valueFactory).createValue(someFilter);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class DefaultDeleteHelperTest method testGetAllDeletedFiles.
@Test
public void testGetAllDeletedFiles() 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 Node nodeTrash = mock(Node.class);
when(nodeTrash.getNodes()).thenAnswer(invoc -> {
final NodeIterator nodeIterator = mock(NodeIterator.class);
// 2 nodes in trash
when(nodeIterator.hasNext()).thenReturn(true, true, false);
when(nodeIterator.nextNode()).thenReturn(deletedNode1, deletedNode2);
return nodeIterator;
});
final Node nodeOtherFolder = mock(Node.class);
when(nodeOtherFolder.hasNode(anyString())).thenReturn(true);
when(nodeOtherFolder.getNode(anyString())).thenReturn(nodeTrash);
final String pathUsr = "pathUser";
final Calendar dateUsr = Calendar.getInstance();
final Node deletedNodeUsr = createDeletedNode(pathUsr, dateUsr);
final Node nodeTrashUsr = mock(Node.class);
when(nodeTrashUsr.getNodes()).thenAnswer(invoc -> {
NodeIterator nodeIteratorUsr = mock(NodeIterator.class);
when(nodeIteratorUsr.hasNext()).thenReturn(true, false);
when(nodeIteratorUsr.nextNode()).thenReturn(deletedNodeUsr);
return nodeIteratorUsr;
});
final Node nodeUserFolder = mock(Node.class);
when(nodeUserFolder.hasNode(anyString())).thenReturn(true);
when(nodeUserFolder.getNode(anyString())).thenReturn(nodeTrashUsr);
final boolean[] admin = { false };
defaultDeleteHelper = new DefaultDeleteHelper(lockHelper, pathConversionHelper) {
@Override
protected boolean isAdmin() {
return admin[0];
}
@Override
protected List<String> getUserList() {
return Arrays.asList("test", "other");
}
};
when(session.getItem(endsWith("/other"))).thenReturn(nodeOtherFolder);
when(session.getItem(endsWith("/test"))).thenReturn(nodeUserFolder);
// regular user
final List<RepositoryFile> deletedFiles = defaultDeleteHelper.getAllDeletedFiles(session, pentahoJcrConstants);
assertNotNull(deletedFiles);
assertEquals(1, deletedFiles.size());
assertEquals(pathUsr, deletedFiles.get(0).getOriginalParentFolderPath());
// as admin
admin[0] = true;
final List<RepositoryFile> deletedFilesAdmin = defaultDeleteHelper.getAllDeletedFiles(session, pentahoJcrConstants);
assertNotNull(deletedFilesAdmin);
assertEquals(3, deletedFilesAdmin.size());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class DefaultDeleteHelperTest method testGetDeletedFiles.
@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);
// 2 nodes in trash
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());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class InheritDefaultAclHandlerTest method setUp.
@Before
public void setUp() {
StandaloneSession pentahoSession = new StandaloneSession("test", "test");
PentahoSessionHolder.setSession(pentahoSession);
repositoryFile = mock(RepositoryFile.class);
inheritDefaultAclHandler = new InheritDefaultAclHandler();
}
Aggregations