use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException 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()));
}
Aggregations