use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl 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.RepositoryFileAcl 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.RepositoryFileAcl 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;
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class InheritDefaultAclHandlerTest method testCreateDefaultAcl.
@Test
public void testCreateDefaultAcl() {
RepositoryFileAcl repositoryFileAcl = inheritDefaultAclHandler.createDefaultAcl(repositoryFile);
assertTrue(repositoryFileAcl.isEntriesInheriting());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class MockUnifiedRepository method createFolder.
@Override
public RepositoryFile createFolder(final Serializable parentFolderId, final RepositoryFile file, final RepositoryFileAcl acl, final String versionMessage) {
Validate.isTrue(file.isFolder());
Validate.isTrue(!file.isVersioned());
if (!hasAccess(parentFolderId, EnumSet.of(WRITE))) {
throw new AccessDeniedException("access denied");
}
FileRecord parentFolder = idManager.getFileById(parentFolderId);
RepositoryFile fileFromRepo = new RepositoryFile.Builder(file).path(parentFolder.getPath() + (parentFolder.getPath().endsWith(RepositoryFile.SEPARATOR) ? "" : RepositoryFile.SEPARATOR) + file.getName()).title(findTitle(file)).description(findDesc(file)).build();
RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder(acl).build();
FileRecord fileRecord = new FileRecord(fileFromRepo, null, aclFromRepo, new HashMap<String, Serializable>());
idManager.register(fileRecord);
parentFolder.addChild(fileRecord);
return fileRecord.getFile();
}
Aggregations