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