Refine search
/** * Tests if the primary node type is properly stored in jcr:primaryType */ public void testPrimaryType() throws Exception { // get default workspace test root node using superuser session Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath()); Node testNode = defaultRootNode.addNode(nodeName1, testNodeType); assertEquals("The primary node type is not properly stored in jcr:primaryType",testNodeType,testNode.getProperty(jcrPrimaryType).getString()); }
/** * Test if Item.isNew() returns false after a NodeItem is added and * the node is saved (persistent). * * @see javax.jcr.Item#isNew() */ public void testPersistentNodeItemIsNew () throws RepositoryException { Node testNode = testRootNode.addNode(nodeName1, testNodeType); testRootNode.getSession().save(); Item testNodeItem = superuser.getItem(testNode.getPath()); // check testNodeItem is new after save assertFalse("Item.isNew() must return false after a new NodeItem is added and the parent Node is saved", testNodeItem.isNew()); }
private List<RestItem> updateMultipleNodes( HttpServletRequest request, Session session, TreeMap<String, JSONObject> nodesByPath ) throws RepositoryException, JSONException { List<RestItem> result = new ArrayList<RestItem>(); for (String nodePath : nodesByPath.keySet()) { Item item = session.getItem(nodePath); item = updateItem(item, nodesByPath.get(nodePath)); result.add(createRestItem(request, 0, session, item)); } session.save(); return result; }
public void testMoveNode() throws Exception { Node n = (Node) readOnlySession.getItem(testNodePath); String destPath = testRootNode.getPath() + "/" + nodeName2; try { readOnlySession.move(n.getPath(), destPath); readOnlySession.save(); fail("A read only session must not be allowed to move a node"); } catch (AccessDeniedException e) { // expected log.debug(e.getMessage()); } }
public void testWorkspaceMoveNode() throws Exception { Node n = (Node) readOnlySession.getItem(testNodePath); String destPath = testRootNode.getPath() + "/" + nodeName2; try { readOnlySession.getWorkspace().move(n.getPath(), destPath); fail("A read only session must not be allowed to move a node"); } catch (AccessDeniedException e) { // expected log.debug(e.getMessage()); } }
@Override protected synchronized void setAttribute(String workspaceId, String attributeKey, String attributeValue) throws RepositoryException { if (!availableWorkspaceNames.contains(workspaceId)) { throw new IllegalStateException("Trying to set attribute of workspace " + workspaceId + " that doesn't exist or was removed."); } Session session = getSession(workspaceId); Node node = (Node) session.getItem(NODE_PATH); Node properties; if (!node.hasNode(PROPERTIES_NODE)) { properties = node.addNode(PROPERTIES_NODE, "nt:unstructured"); } else { properties = node.getNode(PROPERTIES_NODE); } properties.setProperty(attributeKey, attributeValue); node.getSession().save(); setCachedAttribute(workspaceId, attributeKey, attributeValue); }
public boolean execute(Context context) throws Exception { Session session = ((JCRAppContext)context).getSession(); Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey)); String relPath = (String)context.get(pathKey); if (context.containsKey(nodeTypeKey)) context.put(resultKey, parentNode.addNode(relPath, (String)context.get(nodeTypeKey))); else context.put(resultKey, parentNode.addNode(relPath)); return true; }
/** * Creates a new node using {@link Node#addNode(String, String)}, saves using * {@link javax.jcr.Session#save()}. Uses a second session to verify if the * node has been safed. */ public void testAddNodeSessionSave() throws RepositoryException { // get default workspace test root node using superuser session Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath()); // add node Node testNode = defaultRootNode.addNode(nodeName1, testNodeType); // save new node superuser.save(); // use a different session to verify if the node is there Session session = getHelper().getReadOnlySession(); try { session.getItem(testNode.getPath()); } finally { session.logout(); } }
/** * Tests if jcr:primaryType is protected */ public void testPrimaryTypeProtected() throws Exception { // get default workspace test root node using superuser session Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath()); Node testNode = defaultRootNode.addNode(nodeName1, testNodeType); try { testNode.setProperty(jcrPrimaryType,ntBase); fail("Manually setting jcr:primaryType should throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { // ok } }
public void testShallowHoldForOtherSession() throws RepositoryException, NotExecutableException { retentionMgr.addHold(testNodePath, getHoldName(), false); superuser.save(); // check for other session assertNoEffect((Node) otherS.getItem(childN.getPath()), nodeName3, propertyName2); assertEffect((Node) otherS.getItem(testNodePath), childN.getName(), childP.getName(), nodeName3, propertyName2); }
public void testCopyNode() throws Exception { Node n = (Node) readOnlySession.getItem(testNodePath); String destPath = testRootNode.getPath() + "/" + nodeName2; try { readOnlySession.getWorkspace().copy(n.getPath(), destPath); fail("A read only session must not be allowed to copy a node"); } catch (AccessDeniedException e) { // expected log.debug(e.getMessage()); } } }
public Node createAuthzFolderNode( final Session session, final PentahoJcrConstants pentahoJcrConstants, final ITenant tenant ) throws RepositoryException { Node tenantRootFolderNode = null; try { tenantRootFolderNode = (Node) session.getItem( ServerRepositoryPaths.getTenantRootFolderPath( tenant ) ); } catch ( PathNotFoundException e ) { Assert.state( false, Messages.getInstance().getString( "JcrRoleAuthorizationPolicyRoleBindingDao.ERROR_0002_REPO_NOT_INITIALIZED" ) ); //$NON-NLS-1$ } Node authzFolderNode = tenantRootFolderNode.addNode( FOLDER_NAME_AUTHZ, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER() ); session.save(); return authzFolderNode; }
public void testIsSameProperty() throws RepositoryException { Node n = testRootNode.addNode(nodeName1, testNodeType); Property p = n.setProperty(propertyName1, "anyvalue"); testRootNode.save(); // access same property through different session Session otherSession = getHelper().getReadOnlySession(); try { Property otherProperty = (Property) otherSession.getItem(p.getPath()); assertTrue(p.isSame(otherProperty)); } finally { otherSession.logout(); } }
/** * Creates a new node using {@link Node#addNode(String)} , saves using * {@link javax.jcr.Session#save()}. Uses a second session to verify if the * node has been saved. */ public void testAddNodeSessionSave() throws RepositoryException { // get default workspace test root node using superuser session Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath()); // add a node Node testNode = defaultRootNode.addNode(nodeName1, testNodeType); // save new nodes superuser.save(); // use a different session to verify if the node is there Session session = getHelper().getReadOnlySession(); try { testNode = (Node) session.getItem(testNode.getPath()); } finally { session.logout(); } }
/** * Adds a new node using {@link javax.jcr.Node#addNode(String)} with an * index for the new name. * <p>This should throw an {@link RepositoryException}. */ public void testAddNodeRepositoryExceptionRelPathIndex() throws RepositoryException { // get default workspace test root node using superuser session Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath()); try { // use invalid relPath defaultRootNode.addNode(nodeName1 + "[1]", testNodeType); fail("Creating a node with index as postfix for new name should throw RepositoryException"); } catch (RepositoryException e) { // ok, works as expected } }
public void testRemoveLockedChild() throws RepositoryException { Session otherSession = getHelper().getReadWriteSession(); try { Node child = (Node) otherSession.getItem(childNode.getPath()); child.remove(); otherSession.save(); fail("A node below a deeply locked node cannot be removed by another Session."); } catch (LockException e) { // success } finally { otherSession.logout(); } } }
public void testTransientShallowHoldForOtherSession() throws RepositoryException, NotExecutableException { retentionMgr.addHold(testNodePath, getHoldName(), false); assertNoEffect((Node) otherS.getItem(testNodePath), nodeName3, propertyName2); assertNoEffect((Node) otherS.getItem(childN.getPath()), nodeName3, propertyName2); assertNoEffect((Property) otherS.getItem(childP.getPath())); }
protected Node getOrCreateLockTokensNode( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Lock lock ) throws RepositoryException { String absPath = ServerRepositoryPaths.getUserHomeFolderPath( userNameUtils.getTenant( getLockOwner( session, pentahoJcrConstants, lock ) ), userNameUtils.getPrincipleName( getLockOwner( session, pentahoJcrConstants, lock ) ) ); Node userHomeFolderNode = (Node) session.getItem( absPath ); if ( userHomeFolderNode.hasNode( FOLDER_NAME_LOCK_TOKENS ) ) { return userHomeFolderNode.getNode( FOLDER_NAME_LOCK_TOKENS ); } else { Node lockTokensNode = userHomeFolderNode.addNode( FOLDER_NAME_LOCK_TOKENS, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER() ); session.save(); return lockTokensNode; } }