Search in sources :

Example 1 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-kettle by pentaho.

the class PurRepositoryTestingUtils method setAclManagementCallback.

/**
 * Create a {@linkplain JcrCallback} for setting up ACL management in test repository
 *
 * @return acl management callback
 */
static JcrCallback setAclManagementCallback() {
    return new JcrCallback() {

        @Override
        public Object doInJcr(Session session) throws IOException, RepositoryException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            Workspace workspace = session.getWorkspace();
            PrivilegeManager privilegeManager = ((JackrabbitWorkspace) workspace).getPrivilegeManager();
            try {
                privilegeManager.getPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE());
            } catch (AccessControlException ace) {
                privilegeManager.registerPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE(), false, new String[0]);
            }
            session.save();
            return null;
        }
    };
}
Also used : PentahoJcrConstants(org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants) PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 2 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class DefaultDeleteHelperTest method testVersionHistoryDeleted.

@Test
public void testVersionHistoryDeleted() throws Exception {
    String fileID = "testFileID";
    final Node nodeToRemove = mock(Node.class);
    when(nodeToRemove.getPath()).thenReturn("nodePath");
    when(nodeToRemove.isNodeType(pentahoJcrConstants.getNT_FROZENNODE())).thenReturn(true);
    when(nodeToRemove.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())).thenReturn(true);
    NodeType nt = mock(NodeType.class);
    when(nt.getName()).thenReturn(NameConstants.MIX_VERSIONABLE.getLocalName());
    when(nodeToRemove.getPrimaryNodeType()).thenReturn(nt);
    when(nodeToRemove.getMixinNodeTypes()).thenReturn(new NodeType[] {});
    Property prop1 = mock(Property.class);
    String pho_nt_pentahofile = pentahoJcrConstants.getPHO_NT_PENTAHOFILE();
    when(prop1.toString()).thenReturn(pho_nt_pentahofile);
    when(prop1.getString()).thenReturn(pho_nt_pentahofile);
    when(nodeToRemove.getProperty(pentahoJcrConstants.getJCR_FROZENPRIMARYTYPE())).thenReturn(prop1);
    final PropertyIterator referencesPropertyIterator = mock(PropertyIterator.class);
    when(referencesPropertyIterator.hasNext()).thenReturn(false);
    when(nodeToRemove.getReferences()).thenReturn(referencesPropertyIterator);
    when(session.getNodeByIdentifier(fileID)).thenReturn(nodeToRemove);
    when(session.getNamespacePrefix(anyString())).thenReturn("prefix:");
    Workspace workspace = mock(Workspace.class);
    when(session.getWorkspace()).thenReturn(workspace);
    VersionManager versionManager = mock(VersionManager.class);
    when(workspace.getVersionManager()).thenReturn(versionManager);
    VersionHistory history = mock(VersionHistory.class);
    when(versionManager.getVersionHistory("nodePath")).thenReturn(history);
    VersionIterator versions = mock(VersionIterator.class);
    when(history.getAllVersions()).thenReturn(versions);
    when(versions.hasNext()).thenReturn(true, false);
    Version version = mock(Version.class);
    when(versions.next()).thenReturn(version);
    String value = "Omega Man";
    when(version.getName()).thenReturn(value);
    try {
        defaultDeleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileID);
        verify(versionManager).getVersionHistory(nodeToRemove.getPath());
        verify(nodeToRemove).remove();
        verify(history).removeVersion(value);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) PropertyIterator(javax.jcr.PropertyIterator) VersionIterator(javax.jcr.version.VersionIterator) Matchers.anyString(org.mockito.Matchers.anyString) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 3 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class DefaultDeleteHelperTest method testDeleteFile.

@Test
public void testDeleteFile() throws Exception {
    String fileID = "testFileID";
    final Node nodeDeletedFile = mock(Node.class);
    final Node nodeTrash = mock(Node.class);
    when(nodeTrash.hasNode(anyString())).thenReturn(true);
    when(nodeTrash.getNode(anyString())).thenReturn(nodeDeletedFile);
    final Node nodeUserFolder = mock(Node.class);
    when(nodeUserFolder.hasNode(anyString())).thenReturn(true);
    when(nodeUserFolder.getNode(anyString())).thenReturn(nodeTrash);
    final Node nodeDeletedParent = mock(Node.class);
    when(nodeDeletedParent.getPath()).thenReturn("parentPath");
    final Node nodeToRemove = mock(Node.class);
    when(nodeToRemove.getPath()).thenReturn("nodePath");
    when(nodeToRemove.getParent()).thenReturn(nodeDeletedParent);
    when(session.getNodeByIdentifier(fileID)).thenReturn(nodeToRemove);
    when(session.getItem(anyString())).thenReturn(nodeUserFolder);
    try {
        defaultDeleteHelper.deleteFile(session, pentahoJcrConstants, fileID);
        verify(nodeDeletedFile).setProperty(eq(pentahoJcrConstants.getPHO_DELETEDDATE()), any(Calendar.class));
        verify(nodeDeletedFile).setProperty(eq(pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH()), anyString());
        verify(nodeDeletedFile).setProperty(eq(pentahoJcrConstants.getPHO_ORIGNAME()), anyString());
        verify(session).move(eq(nodeToRemove.getPath()), anyString());
    } catch (Exception e) {
        fail();
    }
}
Also used : Node(javax.jcr.Node) Calendar(java.util.Calendar) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Example 4 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class DefaultDeleteHelperTest method testVersionHistoryDeletedWithParent.

@Test
public void testVersionHistoryDeletedWithParent() throws Exception {
    String fileID = "testFileID";
    final Node nodeToRemove = mock(Node.class);
    when(nodeToRemove.getPath()).thenReturn("nodePath");
    when(nodeToRemove.isNodeType(pentahoJcrConstants.getNT_FROZENNODE())).thenReturn(true);
    NodeType nt = mock(NodeType.class);
    when(nt.getName()).thenReturn(NameConstants.MIX_VERSIONABLE.getLocalName());
    when(nodeToRemove.getPrimaryNodeType()).thenReturn(nt);
    when(nodeToRemove.getMixinNodeTypes()).thenReturn(new NodeType[] {});
    when(nodeToRemove.isNodeType(pentahoJcrConstants.getNT_FROZENNODE())).thenReturn(true);
    when(nodeToRemove.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())).thenReturn(true);
    Property prop1 = mock(Property.class);
    String pho_nt_pentahofile = pentahoJcrConstants.getPHO_NT_PENTAHOFILE();
    when(prop1.toString()).thenReturn(pho_nt_pentahofile);
    when(prop1.getString()).thenReturn(pho_nt_pentahofile);
    when(nodeToRemove.getProperty(pentahoJcrConstants.getJCR_FROZENPRIMARYTYPE())).thenReturn(prop1);
    final PropertyIterator referencesPropertyIterator = mock(PropertyIterator.class);
    when(referencesPropertyIterator.hasNext()).thenReturn(false);
    when(nodeToRemove.getReferences()).thenReturn(referencesPropertyIterator);
    when(session.getNodeByIdentifier(fileID)).thenReturn(nodeToRemove);
    when(session.getNamespacePrefix(anyString())).thenReturn("prefix:");
    Workspace workspace = mock(Workspace.class);
    when(session.getWorkspace()).thenReturn(workspace);
    VersionManager versionManager = mock(VersionManager.class);
    when(workspace.getVersionManager()).thenReturn(versionManager);
    VersionHistory history = mock(VersionHistory.class);
    when(versionManager.getVersionHistory("nodePath")).thenReturn(history);
    VersionIterator versions = mock(VersionIterator.class);
    when(history.getAllVersions()).thenReturn(versions);
    when(versions.hasNext()).thenReturn(true, false);
    Version version = mock(Version.class);
    when(versions.next()).thenReturn(version);
    String value = "Omega Man";
    when(version.getName()).thenReturn(value);
    String parentID = "parent";
    final Node parent = mock(Node.class);
    when(session.getNodeByIdentifier(parentID)).thenReturn(parent);
    when(parent.getPath()).thenReturn("parentNodePath");
    when(parent.isNodeType(pentahoJcrConstants.getNT_FROZENNODE())).thenReturn(true);
    Property prop = mock(Property.class);
    String pho_nt_pentahofolder = pentahoJcrConstants.getPHO_NT_PENTAHOFOLDER();
    when(prop.toString()).thenReturn(pho_nt_pentahofolder);
    when(prop.getString()).thenReturn(pho_nt_pentahofolder);
    when(parent.getProperty(pentahoJcrConstants.getJCR_FROZENPRIMARYTYPE())).thenReturn(prop);
    when(parent.getReferences()).thenReturn(referencesPropertyIterator);
    NodeIterator nodeIterator = mock(NodeIterator.class);
    when(nodeIterator.hasNext()).thenReturn(true, false);
    when(nodeIterator.next()).thenReturn(nodeToRemove);
    when(parent.getNodes()).thenReturn(nodeIterator);
    try {
        defaultDeleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, parentID);
        verify(versionManager).getVersionHistory(nodeToRemove.getPath());
        verify(parent).remove();
        verify(history).removeVersion(value);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) PropertyIterator(javax.jcr.PropertyIterator) VersionIterator(javax.jcr.version.VersionIterator) Matchers.anyString(org.mockito.Matchers.anyString) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 5 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class DefaultDeleteHelperTest method testPermanentlyDeleteFile.

@Test
public void testPermanentlyDeleteFile() throws Exception {
    String fileID = "testFileID";
    final Node nodeDeletedFile = mock(Node.class);
    final Node nodeTrash = mock(Node.class);
    when(nodeTrash.hasNode(anyString())).thenReturn(true);
    when(nodeTrash.getNode(anyString())).thenReturn(nodeDeletedFile);
    final Node nodeUserFolder = mock(Node.class);
    when(nodeUserFolder.hasNode(anyString())).thenReturn(true);
    when(nodeUserFolder.getNode(anyString())).thenReturn(nodeTrash);
    final Node nodeDeletedParent = mock(Node.class);
    when(nodeDeletedParent.getPath()).thenReturn("parentPath");
    final PropertyIterator referencesPropertyIterator = mock(PropertyIterator.class);
    when(referencesPropertyIterator.hasNext()).thenReturn(false);
    final Node nodeToRemove = mock(Node.class);
    when(nodeToRemove.getPath()).thenReturn("nodePath");
    when(nodeToRemove.getParent()).thenReturn(nodeDeletedParent);
    when(nodeToRemove.getReferences()).thenReturn(referencesPropertyIterator);
    when(nodeToRemove.isLocked()).thenReturn(false);
    when(session.getNodeByIdentifier(fileID)).thenReturn(nodeToRemove);
    when(session.getItem(anyString())).thenReturn(nodeUserFolder);
    Workspace workspace = mock(Workspace.class);
    VersionManager versionManager = mock(VersionManager.class);
    when(workspace.getVersionManager()).thenReturn(versionManager);
    when(session.getWorkspace()).thenReturn(workspace);
    try {
        defaultDeleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileID);
        verify(nodeToRemove).remove();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // test locked file
    when(nodeToRemove.isLocked()).thenReturn(true);
    final Lock lock = mock(Lock.class);
    final LockManager lockManager = mock(LockManager.class);
    when(lockManager.getLock(eq(nodeToRemove.getPath()))).thenReturn(lock);
    when(workspace.getLockManager()).thenReturn(lockManager);
    when(session.getWorkspace()).thenReturn(workspace);
    try {
        defaultDeleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileID);
        verify(lockHelper).removeLockToken(eq(session), eq(pentahoJcrConstants), eq(lock));
        verify(nodeToRemove, times(2)).remove();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // if remove from trash folder, folder containing the file need to be removed
    final String trashPath = ServerRepositoryPaths.getUserHomeFolderPath(new Tenant(null, true), PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + ".trash";
    when(nodeToRemove.getPath()).thenReturn(trashPath);
    try {
        defaultDeleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileID);
        verify(nodeToRemove, times(3)).remove();
        verify(nodeDeletedParent).remove();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // test if there are references to this file
    final Node referenceNode = mock(Node.class);
    when(referenceNode.isNodeType(eq(pentahoJcrConstants.getPHO_NT_PENTAHOHIERARCHYNODE()))).thenReturn(true);
    when(referenceNode.isNodeType(eq(pentahoJcrConstants.getPHO_NT_PENTAHOFOLDER()))).thenReturn(false);
    final Property property = mock(Property.class);
    when(property.getParent()).thenReturn(referenceNode);
    when(referencesPropertyIterator.hasNext()).thenReturn(true, true, false);
    when(referencesPropertyIterator.nextProperty()).thenReturn(property);
    try {
        defaultDeleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileID);
    } catch (RepositoryFileDaoReferentialIntegrityException e1) {
    // it's ok
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) Tenant(org.pentaho.platform.core.mt.Tenant) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Matchers.anyString(org.mockito.Matchers.anyString) VersionManager(javax.jcr.version.VersionManager) Property(javax.jcr.Property) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace) Lock(javax.jcr.lock.Lock) Test(org.junit.Test)

Aggregations

Node (javax.jcr.Node)15 RepositoryException (javax.jcr.RepositoryException)9 PentahoJcrConstants (org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants)9 RepositoryFileDaoFileExistsException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException)7 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 Property (javax.jcr.Property)5 Workspace (javax.jcr.Workspace)5 Serializable (java.io.Serializable)4 NodeIterator (javax.jcr.NodeIterator)4 PropertyIterator (javax.jcr.PropertyIterator)4 Session (javax.jcr.Session)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 ITenant (org.pentaho.platform.api.mt.ITenant)4 Tenant (org.pentaho.platform.core.mt.Tenant)4 JcrCallback (org.springframework.extensions.jcr.JcrCallback)4 Lock (javax.jcr.lock.Lock)3