use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method restoreFileAtVersion.
/**
* {@inheritDoc}
*/
@Override
public void restoreFileAtVersion(final Serializable fileId, final Serializable versionId, final String versionMessage) {
if (isKioskEnabled()) {
throw new RuntimeException(// $NON-NLS-1$
Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
Assert.notNull(versionId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
Node fileNode = session.getNodeByIdentifier(fileId.toString());
session.getWorkspace().getVersionManager().restore(fileNode.getPath(), versionId.toString(), true);
return null;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method deleteFileAtVersion.
/**
* {@inheritDoc}
*/
@Override
public void deleteFileAtVersion(final Serializable fileId, final Serializable versionId) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
Assert.notNull(versionId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
RepositoryFile fileToBeDeleted = getFileById(fileId);
// Get repository file info and acl info of parent
if (fileToBeDeleted != null) {
RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl(fileToBeDeleted.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
Node fileToDeleteNode = session.getNodeByIdentifier(fileId.toString());
session.getWorkspace().getVersionManager().getVersionHistory(fileToDeleteNode.getPath()).removeVersion(versionId.toString());
session.save();
return null;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method getReferrers.
@Override
@SuppressWarnings("unchecked")
public List<RepositoryFile> getReferrers(final Serializable fileId) {
if (fileId == null) {
return new ArrayList<RepositoryFile>();
}
return (List<RepositoryFile>) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
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);
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);
}
}
}
session.save();
return Arrays.asList(referrers.toArray());
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method canUnlockFile.
/**
* {@inheritDoc}
*/
@Override
public boolean canUnlockFile(final Serializable fileId) {
return (Boolean) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Node fileNode = session.getNodeByIdentifier(fileId.toString());
Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath());
return lockHelper.canUnlock(session, pentahoJcrConstants, lock);
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method deleteLocalePropertiesForFile.
@Override
public void deleteLocalePropertiesForFile(final RepositoryFile repositoryFile, final String locale) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(repositoryFile);
Assert.notNull(locale);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
String versionMessage = Messages.getInstance().getString("JcrRepositoryFileDao.LOCALE_0002_DELETE_PROPERTIES", repositoryFile.getId());
lockHelper.addLockTokenToSessionIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
JcrRepositoryFileUtils.deleteFileLocaleProperties(session, repositoryFile.getId(), locale);
session.save();
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, repositoryFile.getId(), versionMessage);
lockHelper.removeLockTokenFromSessionIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
return null;
}
});
}
Aggregations