Search in sources :

Example 6 with UnifiedRepositoryAccessDeniedException

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

Aggregations

UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 IOException (java.io.IOException)2 Test (org.junit.Test)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IllegalSelectorException (java.nio.channels.IllegalSelectorException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)1 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)1