use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method setFileMetadata.
@Override
public void setFileMetadata(final Serializable fileId, final Map<String, Serializable> metadataMap) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
JcrRepositoryFileUtils.setFileMetadata(session, fileId, metadataMap);
return null;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalGetFileById.
private RepositoryFile internalGetFileById(final Serializable fileId, final boolean loadMaps, final IPentahoLocale locale) {
Assert.notNull(fileId);
return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Node fileNode;
try {
fileNode = session.getNodeByIdentifier(fileId.toString());
} catch (ItemNotFoundException e) {
logger.info("Couldn't find file by id: " + fileId);
fileNode = null;
}
RepositoryFile file = fileNode != null ? JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode, loadMaps, locale) : null;
if (file != null) {
RepositoryFileAcl acl = aclDao.getAcl(file.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.READ, acl, PentahoSessionHolder.getSession())) {
return null;
}
}
return file;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method getData.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> T getData(final Serializable fileId, final Serializable versionId, final Class<T> contentClass) {
Assert.notNull(fileId);
return (T) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
IRepositoryFileData data = JcrRepositoryFileUtils.getContent(session, pentahoJcrConstants, fileId, versionId, findTransformerForRead(JcrRepositoryFileUtils.getFileContentType(session, pentahoJcrConstants, fileId, versionId), contentClass));
if (fileId != null) {
RepositoryFile file = internalGetFileById(fileId, false, null);
if (file != null) {
RepositoryFileAcl acl = aclDao.getAcl(fileId);
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.READ, acl, PentahoSessionHolder.getSession())) {
return null;
}
}
}
return data;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalCreateFile.
private RepositoryFile internalCreateFile(final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData content, final RepositoryFileAcl acl, final String versionMessage) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
/*
* PPP-3049: Changed the Assert.notNull(content) to code that creates a file with a single blank when the assert
* WOULD have been triggered.
*/
Assert.notNull(file);
Assert.isTrue(!file.isFolder());
// Get repository file info and acl info of parent
if (parentFolderId != null) {
RepositoryFile parentRepositoryFile = getFileById(parentFolderId);
if (parentRepositoryFile != null) {
RepositoryFileAcl parentAcl = aclDao.getAcl(parentRepositoryFile.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(parentRepositoryFile, RepositoryFilePermission.WRITE, parentAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
}
// Assert.notNull(content);
DataNode emptyDataNode = new DataNode(file.getName());
// $NON-NLS-1$ //$NON-NLS-2$
emptyDataNode.setProperty(" ", "content");
final IRepositoryFileData emptyContent = new NodeRepositoryFileData(emptyDataNode);
return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);
Node fileNode = JcrRepositoryFileUtils.createFileNode(session, pentahoJcrConstants, parentFolderId, file, content == null ? emptyContent : content, findTransformerForWrite(content == null ? emptyContent.getClass() : content.getClass()));
// create a tmp file with correct path for default acl creation purposes.
String path = JcrRepositoryFileUtils.getAbsolutePath(session, pentahoJcrConstants, fileNode);
RepositoryFile tmpFile = new RepositoryFile.Builder(file).path(path).build();
// we must create the acl during checkout
aclDao.createAcl(fileNode.getIdentifier(), acl == null ? defaultAclHandler.createDefaultAcl(tmpFile) : acl);
session.save();
if (file.isVersioned()) {
JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, fileNode, versionMessage, file.getCreatedDate(), false);
}
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, Messages.getInstance().getString("JcrRepositoryFileDao.USER_0002_VER_COMMENT_ADD_FILE", file.getName(), // $NON-NLS-1$ //$NON-NLS-2$
(parentFolderId == null ? "root" : parentFolderId.toString())));
return JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode);
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method getTree.
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public RepositoryFileTree getTree(final String relPath, final int depth, final String filter, final boolean showHidden) {
Assert.hasText(relPath);
final RepositoryRequest repositoryRequest = new RepositoryRequest(relPath, showHidden, depth, filter);
return (RepositoryFileTree) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
String absPath = pathConversionHelper.relToAbs(relPath);
return JcrRepositoryFileUtils.getTree(session, pentahoJcrConstants, pathConversionHelper, lockHelper, absPath, repositoryRequest, accessVoterManager);
}
});
}
Aggregations