use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testRemoveRolesFromUser.
@Test
public void testRemoveRolesFromUser() {
String user = "testUser1";
String roles = "testRole1";
userRoleResource = spy(userRoleResource);
IPentahoSession session = mock(IPentahoSession.class);
doReturn(user).when(session).getName();
doReturn(session).when(userRoleResource).getSession();
doNothing().when(userRoleResource).updateRolesForCurrentSession();
Response response = userRoleResource.removeRolesFromUser(user, roles);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class JcrRepositoryDumpToFile method execute.
public void execute() {
if (filename != null) {
// $NON-NLS-1$
final String ZIP_EXTENSION = ".zip";
// let the user know this is a zip
if (!filename.endsWith(ZIP_EXTENSION)) {
filename = filename + ZIP_EXTENSION;
}
// $NON-NLS-1$
logger.debug(String.format("dumping repository to file \"%s\"", filename));
ZipOutputStream tmpOut = null;
try {
tmpOut = new ZipOutputStream(new BufferedOutputStream(FileUtils.openOutputStream(new File(filename))));
} catch (IOException e) {
IOUtils.closeQuietly(tmpOut);
throw new RuntimeException(e);
}
final ZipOutputStream out = tmpOut;
// stash existing session
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
// run as repo super user
PentahoSessionHolder.setSession(createRepositoryAdminPentahoSession(repositoryAdminUsername));
try {
txnTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(final TransactionStatus status) {
jcrTemplate.execute(new JcrCallback() {
public Object doInJcr(final Session session) throws RepositoryException, IOException {
switch(mode) {
case SYS:
{
final boolean SKIP_BINARY = false;
final boolean NO_RECURSE = false;
// $NON-NLS-1$
out.putNextEntry(new ZipEntry("repository.xml"));
// $NON-NLS-1$
session.exportSystemView("/", out, SKIP_BINARY, NO_RECURSE);
return null;
}
case DOC:
{
final boolean SKIP_BINARY = false;
final boolean NO_RECURSE = false;
// $NON-NLS-1$
out.putNextEntry(new ZipEntry("repository.xml"));
// $NON-NLS-1$
session.exportDocumentView("/", out, SKIP_BINARY, NO_RECURSE);
return null;
}
default:
{
// $NON-NLS-1$
out.putNextEntry(new ZipEntry("repository.txt"));
session.getRootNode().accept(new DumpToFileTraversingItemVisitor(out));
return null;
}
}
}
});
}
});
} finally {
// restore original session
PentahoSessionHolder.setSession(origPentahoSession);
IOUtils.closeQuietly(out);
}
// $NON-NLS-1$
logger.debug(String.format("dumped repository to file \"%s\"", filename));
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class DefaultDeleteHelper method getOrCreateTrashInternalFolderNode.
/**
* Creates and/or returns an internal folder called {@code .trash} located just below the user's home folder.
*/
private Node getOrCreateTrashInternalFolderNode(final Session session, final PentahoJcrConstants pentahoJcrConstants) throws RepositoryException {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
Tenant tenant = new Tenant(tenantId, true);
String userName = pentahoSession.getName();
Node userHomeFolderNode = (Node) session.getItem(ServerRepositoryPaths.getUserHomeFolderPath(tenant, JcrStringHelper.fileNameEncode(userName)));
if (userHomeFolderNode.hasNode(FOLDER_NAME_TRASH)) {
return userHomeFolderNode.getNode(FOLDER_NAME_TRASH);
} else {
return userHomeFolderNode.addNode(FOLDER_NAME_TRASH, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER());
}
}
use of org.pentaho.platform.api.engine.IPentahoSession 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.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class DumpToFilePentahoSystemListener method startup.
// ~ Instance fields
// =================================================================================================
// ~ Constructors
// ====================================================================================================
// ~ Methods
// =========================================================================================================
@Override
public boolean startup(IPentahoSession pentahoSession) {
Mode tmpMode = null;
if (!StringUtils.hasText(fileName)) {
fileName = System.getProperty(PROP_DUMP_TO_FILE);
tmpMode = Mode.CUSTOM;
if (fileName == null) {
fileName = System.getProperty(PROP_DUMP_TO_FILE_SYSTEM_VIEW);
tmpMode = Mode.SYS;
}
if (fileName == null) {
fileName = System.getProperty(PROP_DUMP_TO_FILE_DOCUMENT_VIEW);
tmpMode = Mode.DOC;
}
} else {
tmpMode = Mode.CUSTOM;
}
final Mode mode = tmpMode;
if (fileName != null) {
// $NON-NLS-1$
final JcrTemplate jcrTemplate = PentahoSystem.get(JcrTemplate.class, "jcrTemplate", pentahoSession);
TransactionTemplate txnTemplate = // $NON-NLS-1$
PentahoSystem.get(TransactionTemplate.class, "jcrTransactionTemplate", pentahoSession);
// $NON-NLS-1$
String repositoryAdminUsername = PentahoSystem.get(String.class, "repositoryAdminUsername", pentahoSession);
// $NON-NLS-1$
final String ZIP_EXTENSION = ".zip";
// let the user know this is a zip
if (!fileName.endsWith(ZIP_EXTENSION)) {
fileName = fileName + ZIP_EXTENSION;
}
// $NON-NLS-1$
logger.debug(String.format("dumping repository to file \"%s\"", fileName));
ZipOutputStream tmpOut = null;
try {
tmpOut = new ZipOutputStream(new BufferedOutputStream(FileUtils.openOutputStream(new File(fileName))));
} catch (IOException e) {
IOUtils.closeQuietly(tmpOut);
throw new RuntimeException(e);
}
final ZipOutputStream out = tmpOut;
// stash existing session
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
// run as repo super user
PentahoSessionHolder.setSession(createRepositoryAdminPentahoSession(repositoryAdminUsername));
try {
txnTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(final TransactionStatus status) {
jcrTemplate.execute(new JcrCallback() {
public Object doInJcr(final Session session) throws RepositoryException, IOException {
switch(mode) {
case SYS:
{
final boolean SKIP_BINARY = false;
final boolean NO_RECURSE = false;
// $NON-NLS-1$
out.putNextEntry(new ZipEntry("repository.xml"));
// $NON-NLS-1$
session.exportSystemView("/", out, SKIP_BINARY, NO_RECURSE);
return null;
}
case DOC:
{
final boolean SKIP_BINARY = false;
final boolean NO_RECURSE = false;
// $NON-NLS-1$
out.putNextEntry(new ZipEntry("repository.xml"));
// $NON-NLS-1$
session.exportDocumentView("/", out, SKIP_BINARY, NO_RECURSE);
return null;
}
default:
{
// $NON-NLS-1$
out.putNextEntry(new ZipEntry("repository.txt"));
session.getRootNode().accept(new DumpToFileTraversingItemVisitor(out));
return null;
}
}
}
});
}
});
} finally {
// restore original session
PentahoSessionHolder.setSession(origPentahoSession);
IOUtils.closeQuietly(out);
}
// $NON-NLS-1$
logger.debug(String.format("dumped repository to file \"%s\"", fileName));
}
return true;
}
Aggregations