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()));
}
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());
}
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);
}
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);
}
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);
}
Aggregations