public void testRemoveMixLockableFromLockedNode() throws RepositoryException, NotExecutableException { try { lockedNode.removeMixin(mixLockable); lockedNode.save(); // the mixin got removed -> the lock should implicitely be released // as well in order not to have inconsistencies String msg = "Lock should have been released."; assertFalse(msg, lock.isLive()); assertFalse(msg, lockedNode.isLocked()); assertFalse(msg, lockMgr.isLocked(lockedNode.getPath())); assertFalse(msg, lockedNode.hasProperty(jcrLockOwner)); assertFalse(msg, lockedNode.hasProperty(jcrlockIsDeep)); } catch (ConstraintViolationException e) { // cannot remove the mixin -> ok // consequently the node must still be locked, the lock still live... String msg = "Lock must still be live."; assertTrue(msg, lock.isLive()); assertTrue(msg, lockedNode.isLocked()); assertTrue(msg, lockMgr.isLocked(lockedNode.getPath())); assertTrue(msg, lockedNode.hasProperty(jcrLockOwner)); assertTrue(msg, lockedNode.hasProperty(jcrlockIsDeep)); } finally { // ev. re-add the mixin in order to be able to unlock the node if (lockedNode.isLocked()) { ensureMixinType(lockedNode, mixLockable); lockedNode.save(); } } }
/** Test expiration of the lock */ public synchronized void testLockExpiration() throws RepositoryException, NotExecutableException { lockedNode.unlock(); long hint = 1; lock = lockMgr.lock(lockedNode.getPath(), isDeep(), isSessionScoped(), hint, null); // only test if timeout hint was respected. long remaining = lock.getSecondsRemaining(); if (remaining <= hint) { try { wait(remaining * 2000); // wait twice as long to be safe } catch (InterruptedException ignore) { } assertTrue( "A released lock must return a negative number of seconds", lock.getSecondsRemaining() < 0); String message = "If the timeout hint is respected the lock" + " must be automatically released."; assertFalse(message, lock.isLive()); assertFalse(message, lockedNode.isLocked()); assertFalse(message, lockMgr.isLocked(lockedNode.getPath())); assertFalse(message, lockedNode.hasProperty(Property.JCR_LOCK_IS_DEEP)); assertFalse(message, lockedNode.hasProperty(Property.JCR_LOCK_OWNER)); } else { throw new NotExecutableException("timeout hint was ignored."); } }
public void testIsLockedChild() throws RepositoryException { assertEquals( "Child node must be locked according to isDeep flag.", isDeep(), childNode.isLocked()); assertEquals( "Child node must be locked according to isDeep flag.", isDeep(), lockMgr.isLocked(childNode.getPath())); }
public void testIsLockedNewChild() throws RepositoryException { Node newChild = lockedNode.addNode(nodeName3, testNodeType); assertEquals( "New child node must be locked according to isDeep flag.", isDeep(), newChild.isLocked()); assertEquals( "New child node must be locked according to isDeep flag.", isDeep(), lockMgr.isLocked(newChild.getPath())); }
/** A locked node must also be locked if accessed by some other session. */ public void testLockVisibility() throws RepositoryException { Session otherSession = getHelper().getReadWriteSession(); try { Node ln = (Node) otherSession.getItem(lockedNode.getPath()); assertTrue("Locked node must also be locked for another session", ln.isLocked()); assertTrue("Locked node must also be locked for another session", ln.holdsLock()); assertTrue( "Locked node must also be locked for another session", getLockManager(otherSession).holdsLock(ln.getPath())); } finally { otherSession.logout(); } }
public void checkPermissonInfo(Node node) throws Exception { if (node.isLocked()) { String lockToken = LockUtil.getLockToken(node); if (lockToken != null) node.getSession().addLockToken(lockToken); if (!Utils.isLockTokenHolder(node)) { getChild(UIPermissionInfo.class) .getChild(UIGrid.class) .configure("usersOrGroups", UIPermissionInfo.PERMISSION_BEAN_FIELD, new String[] {}); getChild(UIPermissionForm.class).setRendered(false); } } else { if (!PermissionUtil.canChangePermission(node)) { getChild(UIPermissionInfo.class) .getChild(UIGrid.class) .configure("usersOrGroups", UIPermissionInfo.PERMISSION_BEAN_FIELD, new String[] {}); getChild(UIPermissionForm.class).setRendered(false); } } }
/** * Update link status. * * @param session the session * @param queryCommand the query command * @throws Exception the exception */ private void updateLinkStatus(Session session, String queryCommand) throws Exception { List<String> listBrokenLinks = new ArrayList<String>(); ValueFactory valueFactory = session.getValueFactory(); QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(queryCommand, Query.SQL); QueryResult results = query.execute(); NodeIterator iter = results.getNodes(); for (; iter.hasNext(); ) { Node webContent = iter.nextNode(); if (!webContent.isCheckedOut() || webContent.isLocked() || (webContent.isCheckedOut() && !webContent.getParent().isCheckedOut())) { continue; } Property links = webContent.getProperty("exo:links"); Value[] oldValues = links.getValues(); Value[] newValues = new Value[oldValues.length]; for (int iValues = 0; iValues < oldValues.length; iValues++) { String oldLink = oldValues[iValues].getString(); if (!oldLink.equals("")) { LinkBean linkBean = LinkBean.parse(oldLink); String oldUrl = linkBean.getUrl(); String oldStatus = getLinkStatus(oldUrl); String updatedLink = new LinkBean(oldUrl, oldStatus).toString(); if (LOG.isInfoEnabled()) { LOG.info(updatedLink); } newValues[iValues] = valueFactory.createValue(updatedLink); if (oldStatus.equals(LinkBean.STATUS_BROKEN)) { listBrokenLinks.add(oldUrl); } } } webContent.setProperty("exo:links", newValues); brokenLinksCache.put(webContent.getUUID(), listBrokenLinks); } session.save(); }
/** Test locks are released when session logs out */ public void testImplicitUnlock2() throws RepositoryException, NotExecutableException { Session other = getHelper().getReadWriteSession(); try { Node testNode = (Node) other.getItem(testRootNode.getPath()); Node lockedNode = testNode.addNode(nodeName1, testNodeType); other.save(); assertLockable(lockedNode); LockManager lMgr = getLockManager(other); Lock lock = lMgr.lock( lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner()); // access the locked noded added by another session testRootNode.refresh(false); Node n = (Node) superuser.getItem(lockedNode.getPath()); // remove lock implicit by logout lock-holding session other.logout(); // check if superuser session is properly informed about the unlock assertFalse(n.isLocked()); assertFalse(n.holdsLock()); try { n.getLock(); fail("Upon logout of the session a session-scoped lock must be gone."); } catch (LockException e) { // ok } } finally { if (other.isLive()) { other.logout(); } } }
/** {@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); } } // technically, the node can be deleted while it is locked; however, we want to avoid an // orphaned lock token; // delete // 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(); } }
/** * Test {@link LockManager#isLocked(String)} and {@link javax.jcr.Node#isLocked()}. * * @throws RepositoryException If an execption occurs. */ public void testNodeIsLocked() throws RepositoryException { assertTrue("Node must be locked after lock creation.", lockedNode.isLocked()); assertTrue("Node must be locked after lock creation.", lockMgr.isLocked(lockedNode.getPath())); }
public void tearDown(Context ctx) throws RepositoryException { Node node = (Node) ctx.get("node"); if (node.isLocked()) node.unlock(); }