Search in sources :

Example 56 with RepositoryFile

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

the class ExportManifestEntity method getRepositoryFileAcl.

/**
 * Helper method for importing. Returns a FileRepositoryAcl object for the the ExportManifestEntity. Will return null
 * if there is no EntityAcl present.
 *
 * @return RepositoryFile
 */
public RepositoryFileAcl getRepositoryFileAcl() throws ExportManifestFormatException {
    RepositoryFileAcl repositoryFileAcl;
    EntityAcl entityAcl = getEntityAcl();
    if (entityAcl == null) {
        return null;
    }
    ArrayList<RepositoryFileAce> repositoryFileAces = new ArrayList<RepositoryFileAce>();
    RepositoryFileSid rfs;
    for (EntityAcl.Aces ace : entityAcl.getAces()) {
        rfs = getSid(ace.getRecipient(), ace.getRecipientType());
        HashSet<RepositoryFilePermission> permissionSet = new HashSet<RepositoryFilePermission>();
        for (String permission : ace.getPermissions()) {
            permissionSet.add(getPermission(permission));
        }
        RepositoryFileAce repositoryFileAce = new RepositoryFileAce(rfs, EnumSet.copyOf(permissionSet));
        repositoryFileAces.add(repositoryFileAce);
    }
    repositoryFileAcl = new RepositoryFileAcl("", getSid(entityAcl.getOwner(), entityAcl.getOwnerType()), entityAcl.isEntriesInheriting(), repositoryFileAces);
    return repositoryFileAcl;
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) ArrayList(java.util.ArrayList) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) EntityAcl(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.EntityAcl) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) HashSet(java.util.HashSet)

Example 57 with RepositoryFile

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

the class RepositoryFileImportFileHandler method checkAndCreatePath.

/**
 * Check path for existance. If path does not exist create folders as necessary to satisfy the path. When done return
 * the Id of the path received.
 *
 * @param repositoryPath
 * @return
 */
private Serializable checkAndCreatePath(String repositoryPath, String manifestKey) throws PlatformImportException {
    if (getParentId(repositoryPath) == null) {
        String parentPath = RepositoryFilenameUtils.getFullPathNoEndSeparator(repositoryPath);
        String parentManifestKey = RepositoryFilenameUtils.getFullPathNoEndSeparator(manifestKey);
        if (!getImportSession().getFoldersCreatedImplicitly().contains(parentPath)) {
            RepositoryFile parentFile = repository.getFile(parentPath);
            if (parentFile == null) {
                checkAndCreatePath(parentPath, parentManifestKey);
                try {
                    parentFile = createFolderJustInTime(parentPath, parentManifestKey);
                } catch (Exception e) {
                    throw new PlatformImportException(messages.getString("DefaultImportHandler.ERROR_0010_JUST_IN_TIME_FOLDER_CREATION", repositoryPath));
                }
            }
            Serializable parentFileId = parentFile.getId();
            Assert.notNull(parentFileId);
        }
    }
    return getParentId(repositoryPath);
}
Also used : Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) ExportManifestFormatException(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifestFormatException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Example 58 with RepositoryFile

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

the class RepositoryFileImportFileHandler method createFolderJustInTime.

public RepositoryFile createFolderJustInTime(String folderPath, String manifestKey) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    // The file doesn't exist and it is a folder. Create folder.
    getLogger().trace("Creating implied folder [" + folderPath + "]");
    final Serializable parentId = getParentId(folderPath);
    Assert.notNull(parentId);
    boolean isHidden;
    if (getImportSession().isFileHidden(manifestKey) == null) {
        isHidden = false;
    } else {
        isHidden = getImportSession().isFileHidden(manifestKey);
    }
    RepositoryFile.Builder builder = new RepositoryFile.Builder(RepositoryFilenameUtils.getName(folderPath)).path(RepositoryFilenameUtils.getPath(folderPath)).folder(true).hidden(isHidden);
    RepositoryFile repoFile = builder.build();
    RepositoryFileAcl repoAcl = getImportSession().processAclForFile(manifestKey);
    if (repoAcl != null) {
        repoFile = repository.createFolder(parentId, repoFile, repoAcl, null);
        RepositoryFileAcl repositoryFileAcl = null;
        try {
            repositoryFileAcl = getImportSession().getManifest().getExportManifestEntity(manifestKey).getRepositoryFileAcl();
        } catch (NullPointerException e) {
        // If npe then manifest entry is not defined which is likely so just ignore
        } catch (ExportManifestFormatException e) {
        // Same goes here
        }
        updateAcl(true, repoFile, repositoryFileAcl);
    } else {
        repoFile = repository.createFolder(parentId, repoFile, null);
    }
    getImportSession().getFoldersCreatedImplicitly().add(folderPath);
    return repoFile;
}
Also used : Serializable(java.io.Serializable) ExportManifestFormatException(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifestFormatException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 59 with RepositoryFile

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

the class RepositoryFileImportFileHandler method updateAcl.

/**
 * Create a formal <code>RepositoryFileAcl</code> object for import.
 *
 * @param newFile
 *          Whether the file is being newly created or was pre-existing
 * @param repositoryFileAcl
 *          The effect Acl as defined in the manifest)
 * @param repositoryFile
 *          The <code>RepositoryFile</code> of the target file
 */
private void updateAcl(boolean newFile, RepositoryFile repositoryFile, RepositoryFileAcl repositoryFileAcl) {
    getLogger().debug("File " + (newFile ? "is new" : "already exists"));
    if (repositoryFileAcl != null && (getImportSession().isApplyAclSettings() || !getImportSession().isRetainOwnership())) {
        RepositoryFileAcl manifestAcl = repositoryFileAcl;
        RepositoryFileAcl originalAcl = repository.getAcl(repositoryFile.getId());
        // Determine who will own this file
        RepositoryFileSid newOwner;
        if (getImportSession().isRetainOwnership()) {
            if (newFile) {
                getLogger().debug("Getting Owner from Session");
                newOwner = getDefaultAcl(repositoryFile).getOwner();
            } else {
                getLogger().debug("Getting Owner from existing file");
                newOwner = originalAcl.getOwner();
            }
        } else {
            getLogger().debug("Getting Owner from Manifest");
            newOwner = manifestAcl.getOwner();
        }
        // Determine the Aces we will use for this file
        // The ACL we will use the permissions from
        RepositoryFileAcl useAclForPermissions;
        if (getImportSession().isApplyAclSettings() && (getImportSession().isOverwriteAclSettings() || newFile)) {
            getLogger().debug("Getting permissions from Manifest");
            useAclForPermissions = manifestAcl;
        } else {
            if (newFile) {
                getLogger().debug("Getting permissions from Default settings");
                useAclForPermissions = getDefaultAcl(repositoryFile);
            } else {
                getLogger().debug("Getting permissions from existing file");
                useAclForPermissions = originalAcl;
            }
        }
        // Make the new Acl if it has changed from the orignal
        if (!newOwner.equals(originalAcl.getOwner()) || !useAclForPermissions.equals(originalAcl)) {
            RepositoryFileAcl updatedAcl = new RepositoryFileAcl(repositoryFile.getId(), newOwner, useAclForPermissions.isEntriesInheriting(), useAclForPermissions.getAces());
            repository.updateAcl(updatedAcl);
        }
    }
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 60 with RepositoryFile

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

the class RepositoryFileImportFileHandler method createFile.

/**
 * Creates a new file in the repository
 *
 * @param bundle
 * @param data
 */
protected RepositoryFile createFile(final RepositoryFileImportBundle bundle, final String repositoryPath, final IRepositoryFileData data) throws PlatformImportException {
    if (solutionHelper.isInApprovedExtensionList(repositoryPath)) {
        final RepositoryFile file = new RepositoryFile.Builder(bundle.getName()).hidden(isHiddenBundle(bundle)).schedulable(bundle.isSchedulable()).title(RepositoryFile.DEFAULT_LOCALE, getTitle(bundle.getTitle() != null ? bundle.getTitle() : bundle.getName())).versioned(true).build();
        final Serializable parentId = checkAndCreatePath(repositoryPath, getImportSession().getCurrentManifestKey());
        final RepositoryFileAcl acl = bundle.getAcl();
        if (null == acl) {
            return repository.createFile(parentId, file, data, bundle.getComment());
        } else {
            return repository.createFile(parentId, file, data, acl, bundle.getComment());
        }
    } else {
        getLogger().trace("The file [" + repositoryPath + "] is not in the list of approved file extension that can be stored in the repository.");
        return null;
    }
}
Also used : Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32