/** * Get node from version store. */ protected Node getVersionedNode(Session session, String uuid) throws RepositoryException { try { return session.getNodeByIdentifier(uuid); } catch (ItemNotFoundException e) { // node is not versioned yet return null; } }
static Node getTokenNode(String token, Session session) throws RepositoryException { int pos = token.indexOf(DELIM); String id = (pos == -1) ? token : token.substring(0, pos); return session.getNodeByIdentifier(id); }
static Node getTokenNode(String token, Session session) throws RepositoryException { int pos = token.indexOf(DELIM); String id = (pos == -1) ? token : token.substring(0, pos); return session.getNodeByIdentifier(id); }
@Override public User exec(Session session) throws RepositoryException { Node priviledgedUserNode = session.getNodeByIdentifier(id); return newUserInstance(priviledgedUserNode); }
/** * Get a Node by identifier. */ public static Node getNodeByIdentifier(String workspace, String identifier) throws RepositoryException { if (workspace == null || identifier == null) { return null; } final Session jcrSession = MgnlContext.getJCRSession(workspace); return (jcrSession == null) ? null : jcrSession.getNodeByIdentifier(identifier); }
@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; } } );
@Override public synchronized Node getWrappedNode() { try { if (node == null || !node.getSession().isLive()) { Session session = getSessionForWrappedNode(this.workspace); node = session.getNodeByIdentifier(this.nodeIdentifier); } } catch (RepositoryException e) { throw new RuntimeException(e); } return node; }
public static Serializable getParentId( final Session session, final Serializable fileId ) throws RepositoryException { Node node = session.getNodeByIdentifier( fileId.toString() ); return node.getParent().getIdentifier(); }
public static Serializable getBaseVersionId( final Session session, final Serializable fileId ) throws RepositoryException { Node node = session.getNodeByIdentifier( fileId.toString() ); return session.getWorkspace().getVersionManager().getBaseVersion( node.getPath() ).getName(); }
/** * Creates link guessing best possible link format from current site and provided content. * * @param uuid UUID of content to create link to. * @param workspaceName Name of the repository where content is located. * @return Absolute link to the provided content. * @see info.magnolia.cms.i18n.AbstractI18nContentSupport */ public static String createLink(String workspaceName, String uuid) throws RepositoryException { Node node = MgnlContext.getJCRSession(workspaceName).getNodeByIdentifier(uuid); return createLink(node); }
protected String getResourceName(final String resourceId) { try { return MgnlContext.getJCRSession(getRepositoryName()).getNodeByIdentifier(resourceId).getName(); } catch (ItemNotFoundException e) { // referenced node doesn't exist return null; } catch (RepositoryException e) { log.error(e.getMessage(), e); } return null; }
/** * Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales. * * @param uuid UUID of content to create link to. * @param workspaceName Name of the repository where content is located. * @return Absolute link to the provided content. * @see info.magnolia.cms.i18n.AbstractI18nContentSupport */ public static String createAbsoluteLink(String workspaceName, String uuid) throws RepositoryException { Node jcrNode = MgnlContext.getJCRSession(workspaceName).getNodeByIdentifier(uuid); return createAbsoluteLink(jcrNode); }
private static void preventLostUpdate( final Session session, final PentahoJcrConstants pentahoJcrConstants, final RepositoryFile file ) throws RepositoryException { Node fileNode = session.getNodeByIdentifier( file.getId().toString() ); // guard against using a file retrieved from a more lenient session inside a more strict session Assert.notNull( fileNode ); if ( isVersioned( session, pentahoJcrConstants, fileNode ) ) { Assert.notNull( file.getVersionId(), "updating a versioned file requires a non-null version id" ); //$NON-NLS-1$ Assert.state( session.getWorkspace().getVersionManager().getBaseVersion( fileNode.getPath() ).getName().equals( file.getVersionId().toString() ), "update to this file has occurred since its last read" ); //$NON-NLS-1$ } }
public static RepositoryFile getFileAtVersion( final Session session, final PentahoJcrConstants pentahoJcrConstants, final IPathConversionHelper pathConversionHelper, final ILockHelper lockHelper, final Serializable fileId, final Serializable versionId ) throws RepositoryException { Node fileNode = session.getNodeByIdentifier( fileId.toString() ); Version version = session.getWorkspace().getVersionManager().getVersionHistory( fileNode.getPath() ).getVersion( versionId .toString() ); return nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, getNodeAtVersion( pentahoJcrConstants, version ) ); }
public static String getAbsolutePath( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node node ) throws RepositoryException { if ( node.isNodeType( pentahoJcrConstants.getNT_FROZENNODE() ) ) { return JcrStringHelper.pathDecode( session.getNodeByIdentifier( node.getProperty( pentahoJcrConstants .getJCR_FROZENUUID() ).getString() ).getPath() ); } return JcrStringHelper.pathDecode( node.getPath() ); }
public static RepositoryFileAcl createAcl( Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId, RepositoryFileAcl acl ) throws ItemNotFoundException, RepositoryException { Node node = session.getNodeByIdentifier( fileId.toString() ); String absPath = node.getPath(); AccessControlManager acMgr = session.getAccessControlManager(); AccessControlList acList = getAccessControlList( acMgr, absPath ); acMgr.setPolicy( absPath, acList ); return internalUpdateAcl( session, pentahoJcrConstants, fileId, acl ); }
private Node doImport(Node source) throws RepositoryException { try { this.importNode(getVersionSessionFor(source).getRootNode(), source); } catch (IOException ioe) { throw new RepositoryException("Failed to import node in magnolia version store : " + ioe.getMessage(), ioe); } Node root = getVersionSessionFor(source).getNodeByIdentifier(source.getIdentifier()); // save parent node since this node is newly created saveSessionWithoutPropertySessionWrapper(root.getSession()); return root; }
public Object doInJcr( final Session session ) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session ); Node node = session.getNodeByIdentifier( id.toString() ); if ( !node.getParent().isSame( session.getRootNode() ) ) { return toAcl( session, pentahoJcrConstants, node.getParent().getIdentifier() ); } else { return null; } } } );
@Test public void copyToNewVersionKeepTheLastModifiedBy() throws Exception { // GIVEN Node testNode = websiteSession.getRootNode().addNode("test", NodeTypes.Page.NAME); NodeTypes.LastModified.update(testNode, "testName", Calendar.getInstance()); testNode.getSession().save(); // WHEN copyUtil.copyToVersion(testNode, new RuleBasedNodePredicate(new Rule())); // THEN Node versionNode = versionSession.getNodeByIdentifier(testNode.getIdentifier()); assertEquals("testName", NodeTypes.LastModified.getLastModifiedBy(versionNode)); }
@Test public void copyToVersionWithNewStructure() throws Exception { // GIVEN Node testNode = websiteSession.getRootNode().addNode("test", NodeTypes.Page.NAME); // WHEN copyUtil.copyToVersion(testNode, new RuleBasedNodePredicate(new Rule())); // THEN Node versionNode = versionSession.getNodeByIdentifier(testNode.getIdentifier()); assertThat(versionNode.getParent().getPath(), matchesRegex("/\\w{2}/\\w{2}/\\w{2}")); assertThat(versionSession.getRootNode(), hasNode(CopyUtil.getSavePath(versionNode) + "/" + testNode.getIdentifier())); }