use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.
the class DefaultDeleteHelper method permanentlyDeleteFile.
/**
* {@inheritDoc}
*/
public void permanentlyDeleteFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
Assert.notNull(fileId);
Node fileNode = session.getNodeByIdentifier(fileId.toString());
// guard against using a file retrieved from a more lenient session inside a more strict session
Assert.notNull(fileNode);
// see if anything is referencing this node; if yes, then we cannot delete it as a
// ReferentialIntegrityException
// will result
Set<RepositoryFile> referrers = new HashSet<RepositoryFile>();
PropertyIterator refIter = fileNode.getReferences();
if (refIter.hasNext()) {
while (refIter.hasNext()) {
// for each referrer property, march up the tree until we find the file node to which the property belongs
RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty());
if (referrer != null) {
referrers.add(referrer);
}
}
if (!referrers.isEmpty()) {
RepositoryFile referee = JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode);
throw new RepositoryFileDaoReferentialIntegrityException(referee, referrers);
}
}
// it first
if (fileNode.isLocked()) {
Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath());
// don't need lock token anymore
lockHelper.removeLockToken(session, pentahoJcrConstants, lock);
}
// if this file was non-permanently deleted, delete its containing folder too
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
String trashFolder = ServerRepositoryPaths.getUserHomeFolderPath(new Tenant(tenantId, true), PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + FOLDER_NAME_TRASH;
Node parent = fileNode.getParent();
purgeHistory(fileNode, session, pentahoJcrConstants);
if (fileNode.getPath().startsWith(trashFolder)) {
// Remove the file and then the wrapper foler
fileNode.remove();
parent.remove();
} else {
fileNode.remove();
}
}
use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.
the class JcrTenantUtils method getTenantedUser.
public static String getTenantedUser(String username) {
if (username != null && !username.equals(getRepositoryAdminUserName()) && getUserNameUtils() != null) {
ITenant tenant = getUserNameUtils().getTenant(username);
if (tenant == null || tenant.getId() == null) {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
if (tenantId == null) {
tenantId = getDefaultTenantPath();
}
tenant = new Tenant(tenantId, true);
return getUserNameUtils().getPrincipleId(tenant, username);
} else {
return username;
}
} else {
return username;
}
}
use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.
the class JcrTenantUtils method getTenantedRole.
public static String getTenantedRole(String principal) {
if (principal != null && !principal.equals("administrators") && getRoleNameUtils() != null) {
ITenant tenant = getRoleNameUtils().getTenant(principal);
if (tenant == null || tenant.getId() == null) {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
if (tenantId == null) {
tenantId = getDefaultTenantPath();
}
tenant = new Tenant(tenantId, true);
return getRoleNameUtils().getPrincipleId(tenant, principal);
} else {
return principal;
}
} else {
return principal;
}
}
use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.
the class AbstractRepositoryTenantManager method getChildTenants.
public List<ITenant> getChildTenants(Session session, final ITenant parentTenant, final boolean includeDisabledTenants) throws RepositoryException {
List<ITenant> children = new ArrayList<ITenant>();
List<RepositoryFile> allChildren = JcrRepositoryFileUtils.getChildren(session, new PentahoJcrConstants(session), pathConversionHelper, null, getTenantRootFolder(session, parentTenant).getId(), null);
for (RepositoryFile repoFile : allChildren) {
Map<String, Serializable> metadata = JcrRepositoryFileUtils.getFileMetadata(session, repoFile.getId());
if (metadata.containsKey(ITenantManager.TENANT_ROOT) && (Boolean) metadata.get(ITenantManager.TENANT_ROOT)) {
Tenant tenant = new Tenant(repoFile.getPath(), isTenantEnabled(session, repoFile.getId()));
if (includeDisabledTenants || tenant.isEnabled()) {
children.add(new Tenant(pathConversionHelper.relToAbs(repoFile.getPath()), isTenantEnabled(session, repoFile.getId())));
}
}
}
return children;
}
use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.
the class RepositoryTenantManager method createTenantFolder.
private RepositoryFile createTenantFolder(final ITenant parentTenant, final String tenantName, final String tenantCreatorId) {
return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException {
Tenant tenant = null;
RepositoryFile parentFolder = null;
if (parentTenant == null) {
tenant = new Tenant("/" + tenantName, true);
} else {
tenant = new Tenant(parentTenant.getRootFolderAbsolutePath() + "/" + tenantName, true);
String folderPath = parentTenant.getRootFolderAbsolutePath();
parentFolder = repositoryFileDao.getFileByAbsolutePath(folderPath);
}
RepositoryFileAcl acl = new RepositoryFileAcl.Builder(tenantCreatorId).entriesInheriting(false).build();
RepositoryFile systemTenantFolder = repositoryFileDao.createFolder(parentFolder != null ? parentFolder.getId() : null, new RepositoryFile.Builder(tenant.getName()).folder(true).build(), acl, "");
repositoryFileDao.getFileByAbsolutePath(tenant.getId());
Map<String, Serializable> fileMeta = repositoryFileDao.getFileMetadata(systemTenantFolder.getId());
fileMeta.put(ITenantManager.TENANT_ROOT, true);
fileMeta.put(ITenantManager.TENANT_ENABLED, true);
JcrRepositoryFileUtils.setFileMetadata(session, systemTenantFolder.getId(), fileMeta);
createRuntimeRolesFolderNode(session, new PentahoJcrConstants(session), tenant);
return systemTenantFolder;
}
});
}
Aggregations