Search in sources :

Example 61 with RepositoryFile

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;
}
Also used : Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 62 with RepositoryFile

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);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Calendar(java.util.Calendar) Node(javax.jcr.Node) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Matchers.anyString(org.mockito.Matchers.anyString) ValueFactory(javax.jcr.ValueFactory) QueryResult(javax.jcr.query.QueryResult) Column(javax.jcr.query.qom.Column) Value(javax.jcr.Value) Ordering(javax.jcr.query.qom.Ordering) QueryManager(javax.jcr.query.QueryManager) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) Selector(javax.jcr.query.qom.Selector) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 63 with RepositoryFile

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());
}
Also used : NodeIterator(javax.jcr.NodeIterator) Calendar(java.util.Calendar) Node(javax.jcr.Node) List(java.util.List) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 64 with RepositoryFile

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());
}
Also used : NodeIterator(javax.jcr.NodeIterator) Calendar(java.util.Calendar) Node(javax.jcr.Node) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 65 with RepositoryFile

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();
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Before(org.junit.Before)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32