@Test
  public void testChildren() throws RepositoryException {
    when(mockRes1.getPath()).thenReturn(RDF_PATH + "/res1");
    when(mockRes2.getPath()).thenReturn(RDF_PATH + "/res2");
    when(mockRes3.getPath()).thenReturn(RDF_PATH + "/res3");
    when(mockResourceNode.hasNodes()).thenReturn(true);
    final Stream<FedoraResource> first = of(mockRes1, mockRes2, mockRes3);
    final Stream<FedoraResource> second = of(mockRes1, mockRes2, mockRes3);
    when(mockResource.getChildren()).thenReturn(first).thenReturn(second);

    try (final ChildrenRdfContext context = new ChildrenRdfContext(mockResource, idTranslator)) {
      final Model results = context.collect(toModel());
      final Resource subject = idTranslator.reverse().convert(mockResource);

      final StmtIterator stmts =
          results.listStatements(subject, RdfLexicon.HAS_CHILD_COUNT, (RDFNode) null);

      assertTrue("There should have been a statement!", stmts.hasNext());
      final Statement stmt = stmts.nextStatement();
      assertTrue("Object should be a literal! " + stmt.getObject(), stmt.getObject().isLiteral());
      assertEquals(3, stmt.getInt());

      assertFalse("There should not have been a second statement!", stmts.hasNext());
    }
  }
Example #2
0
    /**
     * Recursive method to make all children visible or not
     *
     * @param node
     * @param visible
     */
    private void propagateVisibility(Node node, boolean visible) throws RepositoryException {
      if (node.hasNodes()) {
        // loop over child nodes...
        NodeIterator itChildNodes = node.getNodes();
        while (itChildNodes.hasNext()) {
          Node childNode = itChildNodes.nextNode();

          boolean hasNavigableMixinType = childNode.isNodeType("exo:navigable");
          if (visible) {
            boolean folderType =
                childNode.isNodeType("nt:folder") || childNode.isNodeType("exo:taxonomy");
            boolean navigableType =
                folderType
                    || childNode.isNodeType("exo:webContent")
                    || childNode.isNodeType("exo:product")
                    || childNode.isNodeType("exo:taxonomyLink");

            if (!hasNavigableMixinType && navigableType) {
              if (childNode.canAddMixin("exo:navigable")) {
                childNode.addMixin("exo:navigable");
              } else {
                // uiApp.addMessage(new
                // ApplicationMessage("UISingleExternalMetadataForm.msg.can-not-add",	null));
                // event.getRequestContext().addUIComponentToUpdateByAjax(uiApp.getUIPopupMessages());
                return;
              }

              childNode.setProperty("exo:navigationNode", "");
              childNode.setProperty("exo:index", 1000);
              childNode.setProperty("exo:clickable", true);
              childNode.setProperty("exo:page", "");
              childNode.setProperty("exo:pageParamId", "");
              childNode.setProperty("exo:childrenPage", "");
              childNode.setProperty("exo:childrenPageParamId", "");

              childNode.save();

              if (folderType) {
                propagateVisibility(childNode, visible);
              }
            }
          } else {
            if (hasNavigableMixinType) {
              childNode.removeMixin("exo:navigable");
              childNode.save();
            }

            propagateVisibility(childNode, visible);
          }
        }
      }
    }
 @Test
 public void testNoRoot() throws Exception {
   build(content, session);
   session.save();
   session.refresh(false);
   Node mirror = traverse(session, "/test/notallowed");
   assertNotNull(mirror);
   assertFalse(mirror.hasNodes());
   NodeIterator iter = mirror.getNodes();
   while (iter.hasNext()) {
     fail("no child nodes allowed");
   }
 }
  @Test
  public void testNoChildren() throws RepositoryException {
    when(mockResourceNode.hasNodes()).thenReturn(false);

    try (final ChildrenRdfContext childrenRdfContext =
        new ChildrenRdfContext(mockResource, idTranslator)) {
      final Model results = childrenRdfContext.collect(toModel());
      final Resource subject = idTranslator.reverse().convert(mockResource);

      final StmtIterator stmts =
          results.listStatements(subject, RdfLexicon.HAS_CHILD_COUNT, (RDFNode) null);

      assertTrue("There should have been a statement!", stmts.hasNext());
      final Statement stmt = stmts.nextStatement();
      assertTrue("Object should be a literal! " + stmt.getObject(), stmt.getObject().isLiteral());
      assertEquals(0, stmt.getInt());

      assertFalse("There should not have been a second statement!", stmts.hasNext());
    }
  }
  /** {@inheritDoc} */
  public List<RepositoryFile> getDeletedFiles(
      final Session session,
      final PentahoJcrConstants pentahoJcrConstants,
      final String origParentFolderPath,
      final String filter)
      throws RepositoryException {
    Node trashNode = getOrCreateTrashInternalFolderNode(session, pentahoJcrConstants);

    // query Trash Structure 2
    QueryObjectModelFactory fac = session.getWorkspace().getQueryManager().getQOMFactory();
    final String selectorName = "selector"; // $NON-NLS-1$

    // selector
    final Selector selector = fac.selector("nt:base", selectorName); // $NON-NLS-1$
    // constraint1
    Constraint origParentFolderPathConstraint =
        fac.comparison(
            fac.propertyValue(selectorName, pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH()),
            QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
            fac.literal(session.getValueFactory().createValue(origParentFolderPath)));
    // constraint2
    Constraint origNameConstraint = null;
    if (StringUtils.hasLength(filter)) {
      String convertedFilter = filter.replace('*', '%');
      origNameConstraint =
          fac.comparison(
              fac.propertyValue(selectorName, pentahoJcrConstants.getPHO_ORIGNAME()),
              QueryObjectModelConstants.JCR_OPERATOR_LIKE,
              fac.literal(session.getValueFactory().createValue(convertedFilter)));
    }
    // constraint3
    Constraint descendantNodeConstraint = fac.descendantNode(selectorName, trashNode.getPath());
    // AND together constraints
    Constraint allConstraints = fac.and(descendantNodeConstraint, origParentFolderPathConstraint);
    if (StringUtils.hasLength(filter)) {
      allConstraints = fac.and(allConstraints, origNameConstraint);
    }
    Query query = fac.createQuery(selector, allConstraints, null, null);
    QueryResult result =
        session
            .getWorkspace()
            .getQueryManager()
            .createQuery(query.getStatement(), Query.JCR_JQOM)
            .execute();

    NodeIterator nodeIter = result.getNodes();
    List<RepositoryFile> deletedFiles = new ArrayList<RepositoryFile>();

    while (nodeIter.hasNext()) {
      Node trashFileIdNode = nodeIter.nextNode();
      if (trashFileIdNode.hasNodes()) {
        // since the nodes returned by the query are the trash file ID nodes, need to
        // getNodes().nextNode() to get
        // first
        // (and only) child
        deletedFiles.add(
            nodeToDeletedFile(session, pentahoJcrConstants, trashFileIdNode.getNodes().nextNode()));
      } else {
        throw new RuntimeException(
            Messages.getInstance()
                .getString("DefaultDeleteHelper.ERROR_0002_NOT_CLEAN")); // $NON-NLS-1$
      }
    }

    // now we need to handle legacy trash since legacy trashed files don't have origParentFolderPath
    // property

    Set<RepositoryFile> mergedDeletedFiles = new HashSet<RepositoryFile>();
    mergedDeletedFiles.addAll(deletedFiles);
    mergedDeletedFiles.addAll(
        legacyGetDeletedFiles(
            session,
            pentahoJcrConstants,
            pathConversionHelper.relToAbs(origParentFolderPath),
            filter));

    List<RepositoryFile> mergedList = new ArrayList<RepositoryFile>(mergedDeletedFiles);
    Collections.sort(mergedList);
    return mergedList;
  }
  private void migrateRightList(
      Document doc,
      Node trainingAndEventsRightNode,
      Session session,
      String locale,
      Map<String, String> urlMap)
      throws RepositoryException {
    Elements listElements = doc.select("div.n13-pilot");

    // Check for the follow us
    Elements followUs =
        !doc.select("div.fw-cisco-assistant").isEmpty()
            ? doc.select("div.fw-cisco-assistant").select("div.s14-pilot")
            : null;
    if (followUs != null && !followUs.isEmpty()) {
      sb.append(Constants.FOLLOWUS_NODE_NOT_FOUND);
    } else {
      log.debug("Follow us does not exists");
    }
    // end of check for follow us

    // Check for image
    Element listEle = listElements.first();
    if (listEle != null) {
      Elements imgElements = listEle.getElementsByTag("img");
      if (imgElements != null && imgElements.size() > 0) {
        int count = 0;
        for (Element imgElement : imgElements) {
          count = count + 1;
        }
        sb.append("<li>" + "" + count + " extra images found in the right List</li>");
      }
      Element sibling = listEle.nextElementSibling();
      if (sibling != null) {
        Elements image = sibling.getElementsByTag("img");
        if (!image.isEmpty()) {
          sb.append(Constants.EXTRA_IMG_FOUND_IN_RIGHT_PANEL);
        }
      }
    }
    // end of check for image
    if (listElements.size() > 0) {
      int count = 0;
      for (Element listElement : listElements) {
        if (listElement.parent().hasClass("gd-right")) {
          count = count + 1;
        }
      }
      NodeIterator listNodeIterator =
          trainingAndEventsRightNode.hasNodes()
              ? trainingAndEventsRightNode.getNodes("list*")
              : null;
      Elements ulEle = null;
      if (listNodeIterator != null) {
        int nodeSize = (int) listNodeIterator.getSize();
        log.debug("node Size" + nodeSize + "ele Size" + count);
        if (count == nodeSize) {
          Node listNode = null;
          for (Element ele : listElements) {
            listNode = (Node) listNodeIterator.next();
            setListElements(ele, listNode, session, locale, urlMap);
          }
        } else if (nodeSize < count) {
          Node listNode;
          for (Element ele : listElements) {
            ulEle = ele.getElementsByTag("ul");
            if (listNodeIterator.hasNext()) {
              if (!ulEle.isEmpty()) {
                listNode = (Node) listNodeIterator.next();
                setListElements(ele, listNode, session, locale, urlMap);
              }
            }
          }
          sb.append(
              Constants.MISMATCH_IN_LIST_NODES + count + Constants.LIST_NODES_COUNT + nodeSize);
        } else if (nodeSize > count) {
          Node listNode;
          for (Element ele : listElements) {
            listNode = (Node) listNodeIterator.next();
            setListElements(ele, listNode, session, locale, urlMap);
          }
          sb.append(
              Constants.MISMATCH_IN_LIST_NODES + count + Constants.LIST_NODES_COUNT + nodeSize);
        }
      } else {
        sb.append(Constants.LIST_NODE_NOT_FOUND);
      }
    } else {
      sb.append("<li>List component not found in web url</li>");
    }
  }