Search in sources :

Example 71 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class CopyFilesOperation method copyRenameMode.

private void copyRenameMode(RepositoryFile repoFile) {
    // First try to see if regular name is available
    String repoFileName = repoFile.getName();
    String copyText = "";
    String rootCopyText = "";
    String nameNoExtension = repoFileName;
    String extension = "";
    int indexOfDot = repoFileName.lastIndexOf('.');
    if (!(indexOfDot == -1)) {
        nameNoExtension = repoFileName.substring(0, indexOfDot);
        extension = repoFileName.substring(indexOfDot);
    }
    RepositoryFileDto testFile = // $NON-NLS-1$
    getRepoWs().getFile(path + FileUtils.PATH_SEPARATOR + nameNoExtension + extension);
    if (testFile != null) {
        // Second try COPY_PREFIX, If the name already ends with a COPY_PREFIX don't append twice
        if (!nameNoExtension.endsWith(Messages.getInstance().getString("FileResource.COPY_PREFIX"))) {
            // $NON-NLS-1$
            copyText = rootCopyText = Messages.getInstance().getString("FileResource.COPY_PREFIX");
            repoFileName = nameNoExtension + copyText + extension;
            testFile = getRepoWs().getFile(path + FileUtils.PATH_SEPARATOR + repoFileName);
        }
    }
    // Third try COPY_PREFIX + DUPLICATE_INDICATOR
    Integer nameCount = 1;
    while (testFile != null) {
        nameCount++;
        copyText = rootCopyText + Messages.getInstance().getString("FileResource.DUPLICATE_INDICATOR", nameCount);
        repoFileName = nameNoExtension + copyText + extension;
        testFile = getRepoWs().getFile(path + FileUtils.PATH_SEPARATOR + repoFileName);
    }
    IRepositoryFileData data = RepositoryFileHelper.getFileData(repoFile);
    RepositoryFileAcl acl = getRepository().getAcl(repoFile.getId());
    RepositoryFile duplicateFile = null;
    final RepositoryFile repositoryFile;
    if (repoFile.isFolder()) {
        // If the title is different than the source file, copy it separately
        if (!repoFile.getName().equals(repoFile.getTitle())) {
            duplicateFile = new RepositoryFile.Builder(repoFileName).title(RepositoryFile.DEFAULT_LOCALE, repoFile.getTitle() + copyText).hidden(repoFile.isHidden()).versioned(repoFile.isVersioned()).folder(true).build();
        } else {
            duplicateFile = new RepositoryFile.Builder(repoFileName).hidden(repoFile.isHidden()).folder(true).build();
        }
        repositoryFile = getRepository().createFolder(destDir.getId(), duplicateFile, acl, null);
        performFolderDeepCopy(repoFile, repositoryFile, DEFAULT_DEEPNESS);
    } else {
        // If the title is different than the source file, copy it separately
        if (!repoFile.getName().equals(repoFile.getTitle())) {
            duplicateFile = new RepositoryFile.Builder(repoFileName).title(RepositoryFile.DEFAULT_LOCALE, repoFile.getTitle() + copyText).hidden(repoFile.isHidden()).versioned(repoFile.isVersioned()).build();
        } else {
            duplicateFile = new RepositoryFile.Builder(repoFileName).hidden(repoFile.isHidden()).build();
        }
        repositoryFile = getRepository().createFile(destDir.getId(), duplicateFile, data, acl, null);
    }
    if (repositoryFile == null) {
        throw new UnifiedRepositoryAccessDeniedException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_CREATE", destDir.getId()));
    }
    getRepository().setFileMetadata(repositoryFile.getId(), getRepository().getFileMetadata(repoFile.getId()));
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 72 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class MondrianImportHandlerTest method testImportFile_DoNotApplyAclSettings.

@Test
public void testImportFile_DoNotApplyAclSettings() throws Exception {
    when(bundle.getProperty(eq(MondrianImportHandler.DOMAIN_ID))).thenReturn(MondrianImportHandler.DOMAIN_ID);
    when(bundle.isApplyAclSettings()).thenReturn(false);
    IAclAwareMondrianCatalogService aclImporter = mock(IAclAwareMondrianCatalogService.class);
    MondrianImportHandler handler = new MondrianImportHandler(mimeTypes, aclImporter);
    handler.importFile(bundle);
    ArgumentCaptor<RepositoryFileAcl> captor = ArgumentCaptor.forClass(RepositoryFileAcl.class);
    verify(aclImporter).addCatalog(any(InputStream.class), any(MondrianCatalog.class), anyBoolean(), captor.capture(), any(IPentahoSession.class));
    assertNull(captor.getValue());
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IAclAwareMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IAclAwareMondrianCatalogService) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 73 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandlerTest method testImportNewFileWithNoManifest.

@Test
public void testImportNewFileWithNoManifest() throws Exception {
    ImportTestBuilder importTesterBuilder = new ImportTestBuilder();
    importTesterBuilder.build().initialSetup().execute();
    RepositoryFile repositoryFile = mockRepository.getFile(PATH + "/" + TARGET_RESOURCE_NAME);
    assertNotNull(repositoryFile);
    RepositoryFileAcl acl = mockRepository.getAcl(repositoryFile.getId());
    assertHasDefaultPermissions(acl);
    assertHasDefaultOwner(acl);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 74 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandlerTest method testImportExistingFileWithManifestOwner.

@Test
public void testImportExistingFileWithManifestOwner() throws Exception {
    ImportTestBuilder importTesterBuilder = new ImportTestBuilder();
    importTesterBuilder.fileExists(true).hasManifest(true).overwriteFileIfExists(true).retainOwnership(false).applyAclSettings(true).overwriteAclSettings(false).build().initialSetup().execute();
    RepositoryFile repositoryFile = mockRepository.getFile(PATH + "/" + TARGET_RESOURCE_NAME);
    assertNotNull(repositoryFile);
    RepositoryFileAcl acl = mockRepository.getAcl(repositoryFile.getId());
    assertHasDefaultPermissions(acl);
    assertHasManifestOwner(acl);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 75 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandlerTest method createRepositoryFileAcl2.

private RepositoryFileAcl createRepositoryFileAcl2() {
    final RepositoryFileSid sid = new RepositoryFileSid(USER_NAME2);
    final boolean inheriting = false;
    final RepositoryFileAce ace1 = new RepositoryFileAce(sid, RepositoryFilePermission.READ, RepositoryFilePermission.WRITE, RepositoryFilePermission.DELETE);
    final RepositoryFileAce ace2 = new RepositoryFileAce(new RepositoryFileSid(USER_NAME), RepositoryFilePermission.READ, RepositoryFilePermission.WRITE, RepositoryFilePermission.DELETE);
    final List<RepositoryFileAce> aces = Arrays.asList(ace1, ace2);
    return new RepositoryFileAcl("", sid, inheriting, aces);
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)99 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)73 Test (org.junit.Test)50 ITenant (org.pentaho.platform.api.mt.ITenant)25 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)23 RepositoryFileAce (org.pentaho.platform.api.repository2.unified.RepositoryFileAce)15 Node (javax.jcr.Node)13 Matchers.anyString (org.mockito.Matchers.anyString)13 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)13 Serializable (java.io.Serializable)12 Session (javax.jcr.Session)12 JcrCallback (org.springframework.extensions.jcr.JcrCallback)12 ArrayList (java.util.ArrayList)11 RepositoryException (javax.jcr.RepositoryException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 IOException (java.io.IOException)9 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)9 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)8 InputStream (java.io.InputStream)7