Example #1
0
  public void testGenerateFeed2() throws Exception {
    Map<String, String> contextPodcast = new HashMap<String, String>();
    contextPodcast.put("exo:feedType", "podcast");
    contextPodcast.put("repository", "repository");
    contextPodcast.put("srcWorkspace", COLLABORATION_WS);
    contextPodcast.put("actionName", "actionName");
    contextPodcast.put("exo:rssVersion", "rss_1.0");
    contextPodcast.put("exo:feedTitle", "Hello Feed");
    contextPodcast.put("exo:link", "Testing");
    contextPodcast.put("exo:summary", "Hello Summary");
    contextPodcast.put("exo:description", "Hello Description");
    contextPodcast.put("exo:storePath", "/Feeds");
    contextPodcast.put("exo:feedName", "podcastName");
    contextPodcast.put(
        "exo:queryPath", "SELECT * FROM exo:article where jcr:path LIKE '/Documents/%'");
    contextPodcast.put("exo:title", "Hello Title");
    contextPodcast.put("exo:url", "http://twitter.com");
    rssService.generateFeed(contextPodcast);

    session.getRootNode().addNode("Feeds");
    Node myFeeds = (Node) session.getItem("/Feeds");
    myFeeds.addNode("podcast");
    Node myPodcast = (Node) session.getItem("/Feeds/podcast");
    myPodcast.addNode("podcastName");
    Node myPodcastName = (Node) session.getItem("/Feeds/podcast/podcastName");
    assertEquals("Feeds", myFeeds.getName());
    assertEquals("podcast", myPodcast.getName());
    assertEquals("podcastName", myPodcastName.getName());
  }
  @Test
  public void testReOrderingOfChildNodesWithRemovedChild() throws Exception {
    // GIVEN
    ((MockNode) baseNode).setPrimaryNodeType(new MockNodeType(NodeTypes.Content.NAME, null, true));
    baseNode.addNode("child-a");
    baseNode.addNode("child-b");
    baseNode.addNode("child-c");
    JcrNodeAdapter item = new JcrNodeAdapter(baseNode);
    item.removeChild(new JcrNodeAdapter(baseNode.getNode("child-c")));
    item.addChild(new JcrNodeAdapter(baseNode.getNode("child-b")));
    item.addChild(new JcrNodeAdapter(baseNode.getNode("child-a")));

    // WHEN
    item.applyChanges();

    // THEN
    List<String> nodes =
        Lists.newArrayList(
            Iterators.transform(
                item.getJcrItem().getNodes(),
                new Function<Node, String>() {
                  @Nullable
                  @Override
                  public String apply(@Nullable Node node) {
                    return NodeUtil.getName(node);
                  }
                }));

    assertThat(nodes, contains("child-b", "child-a"));
  }
 private Node createEmptyCache(HtmlLibrary library, String root, Session session) {
   Node node = null;
   // this.lock.writeLock().lock();
   try {
     Node swap =
         JcrUtils.getOrCreateByPath(
             root,
             JcrResourceConstants.NT_SLING_FOLDER,
             JcrResourceConstants.NT_SLING_FOLDER,
             session,
             true);
     node = swap.addNode(getLibraryName(library), JcrConstants.NT_FILE);
     swap = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
     swap.setProperty(JcrConstants.JCR_LASTMODIFIED, 0L);
     swap.setProperty(JcrConstants.JCR_MIMETYPE, library.getType().contentType);
     swap.setProperty(
         JcrConstants.JCR_DATA,
         session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
     session.save();
     // this.lock.writeLock().unlock();
   } catch (RepositoryException re) {
     log.debug(re.getMessage());
   }
   return node;
 }
Example #4
0
  @Test
  @FixFor("MODE-1401")
  public void shouldAllowAddingUnderCheckedInNodeNewChildNodeWithOpvOfIgnore() throws Exception {
    registerNodeTypes(session, "cnd/versioning.cnd");

    // Set up parent node and check it in ...
    Node parent = session.getRootNode().addNode("versionableNode", "ver:versionable");
    parent.setProperty("versionProp", "v");
    parent.setProperty("copyProp", "c");
    parent.setProperty("ignoreProp", "i");
    session.save();
    versionManager.checkin(parent.getPath());

    // Try to add child with OPV of ignore ...
    Node child = parent.addNode("nonVersionedIgnoredChild", "ver:nonVersionableChild");
    child.setProperty("copyProp", "c");
    child.setProperty("ignoreProp", "i");
    session.save();

    // Try to update the properties on the child with OPV of 'ignore'
    child.setProperty("copyProp", "c2");
    child.setProperty("ignoreProp", "i2");
    session.save();

    // Try to add versionable child with OPV of ignore ...
    Node child2 = parent.addNode("versionedIgnoredChild", "ver:versionableChild");
    child2.setProperty("copyProp", "c");
    child2.setProperty("ignoreProp", "i");
    session.save();

    // Try to update the properties on the child with OPV of 'ignore'
    child2.setProperty("copyProp", "c2");
    child2.setProperty("ignoreProp", "i2");
    session.save();
  }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CreateNodeRequest)
   */
  @Override
  public void process(CreateNodeRequest request) {
    if (request == null) return;
    try {
      Workspace workspace = workspaceFor(request.inWorkspace());
      Node parent = workspace.node(request.under());
      String childName = workspace.stringFor(request.named());

      // Look for the primary type, if it was set on the request ...
      String primaryTypeName = null;
      for (Property property : request.properties()) {
        if (property.getName().equals(JcrLexicon.PRIMARY_TYPE)) {
          primaryTypeName = workspace.stringFor(property.getFirstValue());
          break;
        }
      }

      // Create the child node ...
      Node child = null;
      if (primaryTypeName != null) {
        child = parent.addNode(childName, primaryTypeName);
      } else {
        child = parent.addNode(childName);
      }
      assert child != null;

      // And set all of the properties on the new node ...
      workspace.setProperties(child, request);

      // Set up the actual results on the request ...
      request.setActualLocationOfNode(workspace.locationFor(child));
    } catch (Throwable e) {
      request.setError(e);
    }
  }
  @Override
  protected void internalStore(Mail mail) throws MessagingException, IOException {
    try {
      Session session = login();
      try {
        String name = Text.escapeIllegalJcrChars(mail.getName());
        final String xpath = "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)";

        QueryManager manager = session.getWorkspace().getQueryManager();
        @SuppressWarnings("deprecation")
        Query query = manager.createQuery(xpath, Query.XPATH);
        NodeIterator iterator = query.execute().getNodes();

        if (iterator.hasNext()) {
          while (iterator.hasNext()) {
            setMail(iterator.nextNode(), mail);
          }
        } else {
          Node parent = session.getRootNode().getNode(MAIL_PATH);
          Node node = parent.addNode(name, "james:mail");
          Node resource = node.addNode("jcr:content", "nt:resource");
          resource.setProperty("jcr:mimeType", "message/rfc822");
          setMail(node, mail);
        }
        session.save();
        logger.info("Mail " + mail.getName() + " stored in repository");
      } finally {
        session.logout();
      }
    } catch (IOException e) {
      throw new MessagingException("Unable to store message: " + mail.getName(), e);
    } catch (RepositoryException e) {
      throw new MessagingException("Unable to store message: " + mail.getName(), e);
    }
  }
Example #7
0
  @Test
  @FixFor("MODE-2147")
  public void shouldNotAllowVersionableMixinOnExternalNodes() throws Exception {
    federationManager.createProjection(
        "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed1");
    Node projectionRoot = session.getNode("/testRoot/fed1");
    try {
      projectionRoot.addMixin("mix:versionable");
      fail("Should not allow versionable mixin on external nodes");
    } catch (ConstraintViolationException e) {
      // expected
    }

    try {
      Node externalChild = projectionRoot.addNode("child");
      externalChild.addMixin("mix:versionable");
      session.save();
      fail("Should not allow versionable mixin on external nodes");
    } catch (ConstraintViolationException e) {
      // expected
    }

    Node externalChild = projectionRoot.addNode("child");
    assertThat(externalChild, is(notNullValue()));
    session.save();
    try {
      ((Node) session.getNode("/testRoot/child")).addMixin("mix:versionable");
      fail("Should not allow versionable mixin on external nodes");
    } catch (RepositoryException e) {
      // expected
    }
  }
Example #8
0
  @Test
  public void shouldUpdateExternalNodeChildren() throws Exception {
    federationManager.createProjection(
        "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    doc1Federated.addNode("federated1_1", null);
    session.save();

    String externalNodePath = "/testRoot/federated1/federated1_1";
    assertExternalNodeHasChildren(externalNodePath);

    Node externalNode = session.getNode(externalNodePath);
    externalNode.addNode("child1");
    externalNode.addNode("child2");
    session.save();

    assertExternalNodeHasChildren(externalNodePath, "child1", "child2");

    externalNode = session.getNode(externalNodePath);
    externalNode.getNode("child1").remove();
    externalNode.getNode("child2").remove();
    externalNode.addNode("child3");
    session.save();

    assertExternalNodeHasChildren(externalNodePath, "child3");
  }
Example #9
0
  @Test
  public void removingInternalNodeShouldNotRemoveExternalNodes() throws Exception {
    federationManager.createProjection(
        "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2");

    Node internalNode1 = testRoot.addNode("internalNode1");
    session.save();
    federationManager.createProjection(
        "/testRoot/internalNode1", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2");

    // remove the federated node directly
    assertNodeFound("/testRoot/internalNode1/federated2/federated3");
    internalNode1.remove();
    session.save();
    // check external nodes are still there
    assertNodeFound("/testRoot/federated2/federated3");

    testRoot.addNode("internalNode2").addNode("internalNode2_1");
    session.save();
    federationManager.createProjection(
        "/testRoot/internalNode2/internalNode2_1",
        SOURCE_NAME,
        MockConnector.DOC2_LOCATION,
        "federated2");
    // remove an ancestor of the federated node
    assertNodeFound("/testRoot/internalNode2/internalNode2_1/federated2/federated3");
    ((Node) session.getNode("/testRoot/internalNode2")).remove();
    session.save();

    // check external nodes are still there
    assertNodeFound("/testRoot/federated2/federated3");
  }
Example #10
0
  /**
   * test method getAllFavouriteNodesByUser. Input: /node0 /node1 /node2 /node3 /node3/node4. Tested
   * action: add favorite for 'root' to node0, node2, node4; add favorite for 'demo' to property of
   * node1,
   *
   * <p>expectedValue : 4 ( number of favorite nodes by 'root')
   *
   * @throws Exception
   */
  public void testGetAllFavouriteNodesByUser() throws Exception {
    Node rootNode = session.getRootNode();
    Node testNode = rootNode.addNode("testNode");
    session.save();

    Node node0 = testNode.addNode("node0");
    Node node1 = testNode.addNode("node1");
    Node node2 = testNode.addNode("node2");
    Node node3 = testNode.addNode("node3");
    Node node4 = node3.addNode("node4");

    favoriteService.addFavorite(node0, "root");
    favoriteService.addFavorite(node1, "demo");
    favoriteService.addFavorite(node2, "root");
    favoriteService.addFavorite(node3, "root");
    favoriteService.addFavorite(node4, "root");

    assertEquals(
        "testGetAllFavouriteNodesByUser failed!",
        4,
        favoriteService
            .getAllFavoriteNodesByUser(
                rootNode.getSession().getWorkspace().getName(), "repository", "root")
            .size());
    testNode.remove();
    session.save();
  }
  @Test
  @FixFor("MODE-2109 ")
  public void shouldOnlyAllowCloningInSomeCases() throws Exception {
    session.getWorkspace().createWorkspace("other");

    try {
      session.getRootNode().addNode("col1", "test:smallCollection");
      Node regular = session.getRootNode().addNode("regular");
      regular.addNode("regular1");
      session.save();

      // cloning a large collection is not allowed
      JcrWorkspace workspace = session.getWorkspace();
      try {
        workspace.clone(workspace.getName(), "/col1", "/regular", false);
        fail("Should not allow cloning");
      } catch (ConstraintViolationException e) {
        // expected
      }

      // clone a regular node into a large collection
      JcrSession otherSession = repository.login("other");
      Node col2 = otherSession.getRootNode().addNode("col2", "test:smallCollection");
      col2.addNode("child1");
      otherSession.save();

      otherSession.getWorkspace().clone(workspace.getName(), "/regular", "/col2/regular", false);
      NodeIterator nodes = otherSession.getNode("/col2").getNodes();
      assertEquals(2, nodes.getSize());
    } finally {
      session.getWorkspace().deleteWorkspace("other");
    }
  }
  @Test
  @FixFor("MODE-2109 ")
  public void shouldNotSupportSNS() throws Exception {
    Node col = session.getRootNode().addNode("smallCol", "test:smallCollection");
    col.addNode("child");

    try {
      col.addNode("child");
      fail("Unorderable collections should not support SNS");
    } catch (javax.jcr.ItemExistsException e) {
      // expected
    }
    session.refresh(false);
    col = session.getRootNode().addNode("smallCol", "test:smallCollection");
    col.addNode("child");
    session.save();
    col = session.getRootNode().getNode("smallCol");

    try {
      col.addNode("child");
      fail("Unorderable collections should not support SNS");
    } catch (javax.jcr.ItemExistsException e) {
      // expected
    }

    col.getNode("child").remove();
    Node child = col.addNode("child");
    child.setProperty("test", "test");
    session.save();

    NodeIterator nodes = session.getNode("/smallCol").getNodes();
    assertEquals(1, nodes.getSize());
    child = nodes.nextNode();
    assertEquals("test", child.getProperty("test").getString());
  }
Example #13
0
  @Test
  @FixFor("MODE-1401")
  public void shouldNotAllowAddingUnderCheckedInNodeNewChildNodeWithOpvOfSomethingOtherThanIgnore()
      throws Exception {
    registerNodeTypes(session, "cnd/versioning.cnd");

    // Set up parent node and check it in ...
    Node parent = session.getRootNode().addNode("versionableNode", "ver:versionable");
    parent.setProperty("versionProp", "v");
    parent.setProperty("copyProp", "c");
    parent.setProperty("ignoreProp", "i");
    session.save();
    versionManager.checkin(parent.getPath());

    // Try to add versionable child with OPV of not ignore ...
    try {
      parent.addNode("versionedChild", "ver:versionableChild");
      fail("should have failed");
    } catch (VersionException e) {
      // expected
    }

    // Try to add non-versionable child with OPV of not ignore ...
    try {
      parent.addNode("nonVersionedChild", "ver:nonVersionableChild");
      fail("should have failed");
    } catch (VersionException e) {
      // expected
    }
  }
  /**
   * Converts file to JCR binary content and stores to new node
   *
   * @param userNode note to which children node will be created with binary content * @param
   *     cvIStream CV file input stream
   * @param fileType type of file stored to node
   */
  public static void convertFileStreamToNode(
      Node userNode, InputStream cvIStream, AllowedFileType fileType) {
    if (userNode == null) {
      throw new IllegalArgumentException("User node is null");
    }
    if (cvIStream == null) {
      throw new IllegalArgumentException("CV file input stream is null");
    }
    if (fileType == null) {
      throw new IllegalArgumentException("File type is null");
    }

    try {
      Node cvNode = userNode.addNode(fileType.getNodeType().toString(), "nt:file");
      cvNode.addMixin(MIXIN_HASCONTENT.toString());
      Node content = cvNode.addNode("jcr:content", "nt:resource");
      content.setProperty(
          "jcr:data", userNode.getSession().getValueFactory().createBinary(cvIStream));
      content.setProperty("jcr:mimeType", fileType.getMimeType());
      cvNode.setProperty(
          PROP_CONTENT.toString(),
          Utils.extractText(content.getProperty("jcr:data").getBinary().getStream(), fileType));
    } catch (RepositoryException e) {
      logger.error(
          "Failed to convert " + fileType.toString() + " file to binary node. " + e.getMessage());
    }
  }
 private void initSettingHome() throws Exception {
   Node rootNode = session.getRootNode();
   if (rootNode.hasNode("settings") == false) {
     Node settingNode = rootNode.addNode("settings", "stg:settings");
     settingNode.addNode("user", "stg:subcontext");
     session.save();
   }
 }
 private void writePartAsFile(Session session, BodyPart part, String nodeName, Node parentNode)
     throws RepositoryException, MessagingException, IOException {
   Node fileNode = parentNode.addNode(nodeName, "nt:file");
   Node resourceNode = fileNode.addNode("jcr:content", "nt:resource");
   resourceNode.setProperty("jcr:mimeType", part.getContentType());
   resourceNode.setProperty(
       "jcr:data", session.getValueFactory().createValue(part.getInputStream()));
   resourceNode.setProperty("jcr:lastModified", Calendar.getInstance());
 }
Example #17
0
  @Override
  public void addFile(long companyId, long repositoryId, String fileName, InputStream is)
      throws PortalException, SystemException {

    Session session = null;

    try {
      session = JCRFactoryUtil.createSession();

      Workspace workspace = session.getWorkspace();

      VersionManager versionManager = workspace.getVersionManager();

      Node rootNode = getRootNode(session, companyId);

      Node repositoryNode = getFolderNode(rootNode, repositoryId);

      if (fileName.contains(StringPool.SLASH)) {
        String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH));

        fileName = fileName.substring(path.length() + 1);

        repositoryNode = getFolderNode(repositoryNode, path);
      }

      if (repositoryNode.hasNode(fileName)) {
        throw new DuplicateFileException(fileName);
      } else {
        Node fileNode = repositoryNode.addNode(fileName, JCRConstants.NT_FILE);

        Node contentNode = fileNode.addNode(JCRConstants.JCR_CONTENT, JCRConstants.NT_RESOURCE);

        contentNode.addMixin(JCRConstants.MIX_VERSIONABLE);
        contentNode.setProperty(JCRConstants.JCR_MIME_TYPE, "text/plain");

        ValueFactory valueFactory = session.getValueFactory();

        Binary binary = valueFactory.createBinary(is);

        contentNode.setProperty(JCRConstants.JCR_DATA, binary);

        contentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance());

        session.save();

        Version version = versionManager.checkin(contentNode.getPath());

        VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath());

        versionHistory.addVersionLabel(version.getName(), VERSION_DEFAULT, false);
      }
    } catch (RepositoryException re) {
      throw new SystemException(re);
    } finally {
      JCRFactoryUtil.closeSession(session);
    }
  }
Example #18
0
  @Test(expected = RepositoryException.class)
  public void shouldNotAllowWritesIfReadonly() throws Exception {
    federationManager.createProjection(
        "/testRoot", "mock-source-readonly", MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    Node externalNode1 = doc1Federated.addNode("federated1_1", null);
    externalNode1.addNode("federated1_1_1", null);

    session.save();
  }
  @Override
  public void createFile(Node parentNode, String fileName) throws RepositoryException {
    Node resourceNode = parentNode.addNode(fileName, newResourcePrimaryType);

    Node contentNode = resourceNode.addNode(CONTENT_NODE_NAME, newContentPrimaryType);
    contentNode.setProperty(DATA_PROP_NAME, "");
    contentNode.setProperty(MODIFIED_PROP_NAME, Calendar.getInstance());
    contentNode.setProperty(ENCODING_PROP_NAME, "UTF-8");
    contentNode.setProperty(MIME_TYPE_PROP_NAME, "text/plain");
  }
Example #20
0
  @FixFor("MODE-1624")
  @Test
  public void shouldAllowRemovingVersionFromVersionHistoryByRemovingVersionNode() throws Exception {
    print = false;

    Node outerNode = session.getRootNode().addNode("outerFolder");
    Node innerNode = outerNode.addNode("innerFolder");
    Node fileNode = innerNode.addNode("testFile.dat");
    fileNode.setProperty("jcr:mimeType", "text/plain");
    fileNode.setProperty("jcr:data", "Original content");
    session.save();

    fileNode.addMixin("mix:versionable");
    session.save();

    // Make several changes ...
    String path = fileNode.getPath();
    for (int i = 2; i != 7; ++i) {
      versionManager.checkout(path);
      fileNode.setProperty("jcr:data", "Original content " + i);
      session.save();
      versionManager.checkin(path);
    }

    // Get the version history ...
    VersionHistory history = versionManager.getVersionHistory(path);
    if (print) System.out.println("Before: \n" + history);
    assertThat(history, is(notNullValue()));
    assertThat(history.getAllLinearVersions().getSize(), is(6L));

    // Get the versions ...
    VersionIterator iter = history.getAllLinearVersions();
    Version v1 = iter.nextVersion();
    Version v2 = iter.nextVersion();
    Version v3 = iter.nextVersion();
    Version v4 = iter.nextVersion();
    Version v5 = iter.nextVersion();
    Version v6 = iter.nextVersion();
    assertThat(iter.hasNext(), is(false));
    assertThat(v1, is(notNullValue()));
    assertThat(v2, is(notNullValue()));
    assertThat(v3, is(notNullValue()));
    assertThat(v4, is(notNullValue()));
    assertThat(v5, is(notNullValue()));
    assertThat(v6, is(notNullValue()));

    // Remove the 3rd version (that is, i=3) ...
    // history.removeVersion(versionName);
    try {
      v3.remove();
      fail("Should not allow removing a protected node");
    } catch (ConstraintViolationException e) {
      // expected
    }
  }
Example #21
0
 /**
  * see https://issues.jboss.org/browse/MODE-1953
  *
  * @throws Exception
  */
 @Test
 public void testGetNodesMethod() throws Exception {
   Node jcrRootNode = ((Session) session).getRootNode();
   Node rootNode = jcrRootNode.addNode("mapSuperclassTest");
   Node newNode = rootNode.addNode("newNode");
   NodeIterator nodeIterator = rootNode.getNodes("myMap");
   assertFalse(nodeIterator.hasNext());
   session.save();
   nodeIterator = rootNode.getNodes("myMap");
   assertFalse(nodeIterator.hasNext());
 }
Example #22
0
 private Node addDocument(Node folder, String name) throws RepositoryException {
   Node handle = folder.addNode(name, HippoNodeType.NT_HANDLE);
   handle.addMixin(HippoNodeType.NT_HARDHANDLE);
   Node document = handle.addNode(name, "hippo:testdocument");
   document.addMixin(JcrConstants.MIX_VERSIONABLE);
   document.addMixin("hippostd:publishable");
   document.setProperty("hippostd:state", "published");
   Node html = document.addNode("html", "hippostd:html");
   html.setProperty("hippostd:content", "<html><body>Lorem</body></html>");
   return handle;
 }
  private void updateViewerPresets(Resource configResource, S7Config s7Config)
      throws RepositoryException {

    // Get the presets from S7 and store them on the node
    //
    List<Scene7Asset> assets =
        scene7Service.searchAssets(
            s7Config.getBasePath(),
            Boolean.TRUE,
            Boolean.TRUE,
            new String[] {"ViewerPreset"},
            null,
            new String[] {
              "assetArray/items/assetHandle",
              "assetArray/items/type",
              "assetArray/items/name",
              "assetArray/items/viewerPresetInfo"
            },
            null,
            s7Config);

    if (assets.size() > 0) {
      String path = configResource.getPath() + "/" + Scene7PresetsService.REL_PATH_VIEWER_PRESETS;

      Node node = prepNode(configResource.getResourceResolver(), path);
      int i = 0;
      for (Scene7Asset asset : assets) {
        String name = asset.getName();
        String type = asset.getViewerPresetType();

        Node presetNode = node.addNode("preset" + i);
        presetNode.setProperty("name", name);
        presetNode.setProperty("type", (type != null ? type : ""));
        presetNode.setProperty("config", s7Config.getBasePath() + name);

        Map<String, String> viewerPresetConfigurationSettings =
            asset.getViewerPresetConfigurationSettings();
        if (viewerPresetConfigurationSettings != null
            && !viewerPresetConfigurationSettings.isEmpty()) {
          presetNode = presetNode.addNode("settings");
          for (Entry<String, String> entry : viewerPresetConfigurationSettings.entrySet()) {
            String settingName = entry.getKey();
            String value = entry.getValue();
            if (settingName != null && value != null) {
              presetNode.setProperty(settingName, value);
            }
          }
        }
        i++;
      }
    }
  }
Example #24
0
  @Test
  @FixFor("MODE-1401")
  public void shouldAllowRemovingFromCheckedInNodeExistingChildNodeWithOpvOfIgnore()
      throws Exception {
    registerNodeTypes(session, "cnd/versioning.cnd");

    // Set up parent node and check it in ...
    Node parent = session.getRootNode().addNode("versionableNode", "ver:versionable");
    parent.setProperty("versionProp", "v");
    parent.setProperty("copyProp", "c");
    parent.setProperty("ignoreProp", "i");

    Node child1 = parent.addNode("nonVersionedIgnoredChild", "ver:nonVersionableChild");
    child1.setProperty("copyProp", "c");
    child1.setProperty("ignoreProp", "i");

    Node child2 = parent.addNode("versionedIgnoredChild", "ver:versionableChild");
    child2.setProperty("copyProp", "c");
    child2.setProperty("ignoreProp", "i");

    session.save();
    versionManager.checkin(parent.getPath());

    // Should be able to change the properties on the ignored children
    child1.setProperty("copyProp", "c2");
    child1.setProperty("ignoreProp", "i2");
    child2.setProperty("copyProp", "c2");
    child2.setProperty("ignoreProp", "i2");
    session.save();

    // Try to remove the two child nodes that have an OPV of 'ignore' ...
    child1.remove();
    child2.remove();
    session.save();

    // Should be able to change the ignored properties on the checked-in parent ...
    parent.setProperty("ignoreProp", "i");

    // Should not be able to set any non-ignored properties on the checked in parent ...
    try {
      parent.setProperty("copyProp", "c2");
      fail("not allowed");
    } catch (VersionException e) {
      // expected
    }
    try {
      parent.setProperty("versionProp", "v2");
      fail("not allowed");
    } catch (VersionException e) {
      // expected
    }
  }
 /**
  * Creates a nt:file node, under the root node, at the given path and with the jcr:data property
  * pointing at the filepath.
  *
  * @param nodeRelativePath the path under the root node, where the nt:file will be created.
  * @param filePath a path relative to {@link Class#getResourceAsStream(String)} where a file is
  *     expected at runtime
  * @return the new node
  * @throws RepositoryException if anything fails
  */
 protected Node createNodeWithContentFromFile(String nodeRelativePath, String filePath)
     throws RepositoryException {
   Node parent = rootNode;
   for (String pathSegment : nodeRelativePath.split("/")) {
     parent = parent.addNode(pathSegment);
   }
   Node content = parent.addNode(JcrConstants.JCR_CONTENT);
   content.setProperty(
       JcrConstants.JCR_DATA,
       ((javax.jcr.Session) session).getValueFactory().createBinary(resourceStream(filePath)));
   session.save();
   return parent;
 }
Example #26
0
 @Test
 public void shouldReturnEmptyIterator() throws RepositoryException {
   Node jcrRootNode = session.getRootNode();
   Node rootNode = jcrRootNode.addNode("mapSuperclassTest");
   // session.save();
   Node newNode = rootNode.addNode("newNode");
   assertNotNull(newNode);
   NodeIterator nodeIterator = rootNode.getNodes("myMap");
   assertFalse(nodeIterator.hasNext());
   session.save();
   nodeIterator = rootNode.getNodes("myMap");
   assertFalse(nodeIterator.hasNext());
 }
  @Test
  @FixFor("MODE-2109 ")
  public void shouldSupportTransientNodeOperations() throws Exception {
    Set<String> allChildrenPaths = new HashSet<>();
    Node col = session.getRootNode().addNode("smallCol", "test:smallCollection");
    allChildrenPaths.add(col.addNode("child1").getPath());
    session.save();
    // add a transient node and iterate
    col = session.getNode("/smallCol");
    allChildrenPaths.add(col.addNode("child2").getPath());
    NodeIterator nodeIterator = col.getNodes();
    assertEquals(allChildrenPaths.size(), nodeIterator.getSize());
    Set<String> iterableChildren = new HashSet<>();
    while (nodeIterator.hasNext()) {
      iterableChildren.add(nodeIterator.nextNode().getPath());
    }
    assertEquals("Incorrect iteration result", allChildrenPaths, iterableChildren);
    assertEquals(allChildrenPaths.size(), col.getNodes("child*").getSize());
    assertEquals(2, col.getNodes("child1|child2").getSize());
    assertEquals(0, col.getNodes("child_1|child_2").getSize());

    session.save();

    // remove a node and iterate before saving
    AbstractJcrNode child1 = session.getNode("/smallCol/child1");
    String child1Path = child1.getPath();

    child1.remove();
    allChildrenPaths.remove(child1Path);
    nodeIterator = session.getNode("/smallCol").getNodes();
    assertEquals(allChildrenPaths.size(), nodeIterator.getSize());
    iterableChildren = new HashSet<>();
    while (nodeIterator.hasNext()) {
      iterableChildren.add(nodeIterator.nextNode().getPath());
    }
    assertEquals("Incorrect iteration result", allChildrenPaths, iterableChildren);
    assertEquals(allChildrenPaths.size(), col.getNodes("child*").getSize());

    // discard the changes
    session.refresh(false);
    allChildrenPaths.add(child1Path);
    // reiterate
    nodeIterator = session.getNode("/smallCol").getNodes();
    assertEquals(allChildrenPaths.size(), nodeIterator.getSize());
    iterableChildren = new HashSet<>();
    while (nodeIterator.hasNext()) {
      iterableChildren.add(nodeIterator.nextNode().getPath());
    }
    assertEquals("Incorrect iteration result", allChildrenPaths, iterableChildren);
    assertEquals(allChildrenPaths.size(), col.getNodes("child*").getSize());
  }
Example #28
0
  public void testJCR1438_Simple() throws Exception {
    Node testRoot = root.addNode("testRoot");
    root.save();

    Node l1Node = testRoot.addNode("l1");
    l1Node.addMixin("mix:versionable");
    Node folder = l1Node.addNode("folder", "nt:folder");
    root.save();

    l1Node.checkin();
    l1Node.checkout();
    root.save();

    Node testImage = folder.addNode("test_image", "nt:file");
    testImage.addMixin("mix:versionable");

    Node contentTestImage = testImage.addNode("jcr:content", "nt:resource");
    contentTestImage.setProperty("jcr:data", "content_test_image_data");
    contentTestImage.setProperty("jcr:encoding", "UTF-8");
    contentTestImage.setProperty("jcr:lastModified", Calendar.getInstance());
    contentTestImage.setProperty("jcr:mimeType", "text/jpeg");
    root.save();

    Version tImageV1 = testImage.checkin();
    testImage.checkout();
    testImage.save();

    Version v2 = l1Node.checkin();
    l1Node.checkout();
    root.save();

    Node rTestImage = testRoot.getNode("l1").getNode("folder").getNode("test_image");
    assertNotNull(rTestImage);
    Node rTestImageContent = rTestImage.getNode("jcr:content");
    assertNotNull(rTestImageContent);
    assertNotNull(rTestImageContent.getProperty("jcr:data"));
    assertEquals("content_test_image_data", rTestImageContent.getProperty("jcr:data").getString());

    /*testImage.remove();
    root.save();*/

    l1Node.restore("2", true);

    rTestImage = testRoot.getNode("l1").getNode("folder").getNode("test_image");
    assertNotNull(rTestImage);
    rTestImageContent = rTestImage.getNode("jcr:content");
    assertNotNull(rTestImageContent);
    assertNotNull(rTestImageContent.getProperty("jcr:data"));
    assertEquals("content_test_image_data", rTestImageContent.getProperty("jcr:data").getString());
  }
  public void beforeSuite() throws Exception {
    session = loginWriter();
    root = session.getRootNode().addNode("testroot", "nt:unstructured");
    for (int i = 0; i < NODE_COUNT; i++) {
      Node node = root.addNode("node" + i, "nt:unstructured");
      for (int j = 0; j < NODE_COUNT; j++) {
        node.addNode("node" + j, "nt:unstructured");
      }
      session.save();
    }

    for (int i = 0; i < READER_COUNT; i++) {
      addBackgroundJob(new Reader());
    }
  }
Example #30
0
  /**
   * Test get active java script_03.
   *
   * <p>When node input is exo:webcontent and have some child node but does not content mixin type.
   */
  public void testGetActiveJavaScript_03() {
    try {
      Node webContent = documentNode.addNode(WEB_CONTENT_NODE_NAME, "exo:webContent");

      webContent.setProperty("exo:title", WEB_CONTENT_NODE_NAME);
      webContent.addNode("jsFolder", "exo:jsFolder");
      session.save();

      String jsData = javascriptService.getActiveJavaScript(webContent);

      assertEquals("", jsData);
    } catch (Exception e) {
      fail();
    }
  }