Beispiel #1
0
 /**
  * refine node for validation
  *
  * @param currentNode
  * @throws Exception
  */
 private static void refineNode(Node currentNode) throws Exception {
   if (currentNode instanceof NodeImpl && !((NodeImpl) currentNode).isValid()) {
     ExoContainer container = ExoContainerContext.getCurrentContainer();
     LinkManager linkManager =
         (LinkManager) container.getComponentInstanceOfType(LinkManager.class);
     if (linkManager.isLink(currentNode)) {
       try {
         currentNode = linkManager.getTarget(currentNode, false);
       } catch (RepositoryException ex) {
         currentNode = linkManager.getTarget(currentNode, true);
       }
     }
   }
 }
Beispiel #2
0
 /**
  * Test method TaxonomyService.init() Expect: Create system taxonomy tree in dms-system
  *
  * @see {@link # testInit()}
  */
 public void testInit() throws Exception {
   Node systemTreeDef = (Node) dmsSesssion.getItem(definitionPath + "/System");
   Node systemTreeStorage = (Node) dmsSesssion.getItem(storagePath + "/System");
   assertNotNull(systemTreeDef);
   assertNotNull(systemTreeStorage);
   assertEquals(systemTreeStorage, linkManage.getTarget(systemTreeDef, true));
 }
Beispiel #3
0
 /**
  * Test method TaxonomyService.addCategories() Input: add 2 categories in article node Output:
  * create 2 exo:taxonomyLink in each category
  *
  * @throws RepositoryException
  * @throws TaxonomyNodeAlreadyExistsException
  * @throws TaxonomyAlreadyExistsException
  */
 public void testAddCategories()
     throws RepositoryException, TaxonomyNodeAlreadyExistsException,
         TaxonomyAlreadyExistsException {
   session.getRootNode().addNode("MyDocuments");
   Node article = session.getRootNode().addNode("Article");
   session.save();
   taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Serie", "root");
   taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Serie", "A", "root");
   taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Serie", "B", "root");
   Node rootTree = (Node) session.getItem("/MyDocuments/Serie");
   taxonomyService.addTaxonomyTree(rootTree);
   taxonomyService.addCategories(article, "Serie", new String[] {"A", "B"}, true);
   Node link1 = (Node) session.getItem("/MyDocuments/Serie/A/Article");
   Node link2 = (Node) session.getItem("/MyDocuments/Serie/B/Article");
   assertTrue(link1.isNodeType("exo:taxonomyLink"));
   assertEquals(article, linkManage.getTarget(link1));
   assertTrue(link2.isNodeType("exo:taxonomyLink"));
   assertEquals(article, linkManage.getTarget(link2));
 }
Beispiel #4
0
 /**
  * Gets the node by category.
  *
  * @param parameters the parameters
  * @return the node by category
  * @throws Exception the exception
  */
 private Node getNodeByCategory(String parameters) throws Exception {
   try {
     if (taxonomyService == null) taxonomyService = WCMCoreUtils.getService(TaxonomyService.class);
     Node taxonomyTree = taxonomyService.getTaxonomyTree(parameters.split("/")[0]);
     Node symlink = taxonomyTree.getNode(parameters.substring(parameters.indexOf("/") + 1));
     return linkManager.getTarget(symlink);
   } catch (Exception e) {
     return null;
   }
 }
Beispiel #5
0
 /**
  * Test method TaxonomyService.getTaxonomyTree(String repository, String taxonomyName) Input:
  * Create taxonomy tree Music Expect: Node Music
  *
  * @throws RepositoryException
  * @throws TaxonomyNodeAlreadyExistsException
  * @throws TaxonomyAlreadyExistsException
  */
 public void testGetTaxonomyTree2()
     throws RepositoryException, TaxonomyNodeAlreadyExistsException,
         TaxonomyAlreadyExistsException {
   session.getRootNode().addNode("MyDocuments");
   session.save();
   taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Music", "root");
   Node musicTree = (Node) session.getItem("/MyDocuments/Music");
   taxonomyService.addTaxonomyTree(musicTree);
   assertTrue(dmsSesssion.itemExists(definitionPath + "/Music"));
   Node musicTreeDefinition = (Node) dmsSesssion.getItem(definitionPath + "/Music");
   assertEquals(musicTree, linkManage.getTarget(musicTreeDefinition, true));
 }
Beispiel #6
0
 public static Node getNodeSymLink(Node node) throws Exception {
   LinkManager linkManager = Util.getUIPortal().getApplicationComponent(LinkManager.class);
   Node realNode = null;
   if (linkManager.isLink(node)) {
     if (linkManager.isTargetReachable(node)) {
       realNode = linkManager.getTarget(node);
     }
   } else {
     realNode = node;
   }
   return realNode;
 }
Beispiel #7
0
 private Node getTargetNode(Node showingNode) throws Exception {
   Node targetNode = null;
   if (linkManager.isLink(showingNode)) {
     try {
       targetNode = linkManager.getTarget(showingNode);
     } catch (ItemNotFoundException e) {
       targetNode = showingNode;
     }
   } else {
     targetNode = showingNode;
   }
   return targetNode;
 }
  private CategoryNode getCategoryNode(Node node, String parentPath) {

    CategoryNode categoryNode = null;
    try {
      if (node.isNodeType("exo:taxonomy")) {
        categoryNode = new CategoryNode(node.getName(), "", parentPath, getType(node));
      } else if (linkManager_.isLink(node)) {
        // In case document type, don't need parentId
        node = linkManager_.getTarget(node);
        categoryNode = new CategoryNode(node.getName(), "", "", getType(node));
      }
    } catch (ItemNotFoundException e) {
      LOG.error(e);
    } catch (RepositoryException e) {
      LOG.error(e);
    } catch (Exception e) {
      LOG.error(e);
    }
    return categoryNode;
  }
 private List<DocumentContent> getArticleNode(Node node, List<String> allDocumentType)
     throws Exception {
   List<DocumentContent> docs = new ArrayList<DocumentContent>();
   NodeIterator nodes = node.getNodes();
   Node docNode;
   List<Node> taxonomyTrees =
       taxonomyService_.getAllTaxonomyTrees(
           ((ManageableRepository) node.getSession().getRepository())
               .getConfiguration()
               .getName());
   while (nodes.hasNext()) {
     docNode = nodes.nextNode();
     if (linkManager_.isLink(docNode)) {
       docNode = linkManager_.getTarget(docNode);
       if (allDocumentType.contains(docNode.getPrimaryNodeType().getName())) {
         docs.add(getArticleContent(docNode, taxonomyTrees));
       }
     }
   }
   return docs;
 }
 @GET
 @Path("/articles/{repoName}/{docPath:.*}/")
 public Response getArticles(
     @PathParam("repoName") String repoName, @PathParam("docPath") String docPath) {
   DocumentContent docNode = null;
   ListResultNode listResultNode = new ListResultNode();
   if (docPath != null) {
     String taxonomyTree = docPath.split("/")[0];
     String path = docPath.substring(taxonomyTree.length());
     if (path.startsWith("/")) {
       path = path.substring(1);
     }
     try {
       if (documentTypes.isEmpty())
         documentTypes = templateService_.getAllDocumentNodeTypes(repoName);
       Node taxonomyNode = taxonomyService_.getTaxonomyTree(repoName, taxonomyTree);
       if (taxonomyNode == null)
         throw new PathNotFoundException("Can't find category " + taxonomyTree);
       if (!path.equals("")) {
         taxonomyNode = taxonomyNode.getNode(path);
       }
       if (linkManager_.isLink(taxonomyNode)) {
         List<Node> taxonomyTrees = taxonomyService_.getAllTaxonomyTrees(repoName);
         docNode = getArticleContent(linkManager_.getTarget(taxonomyNode), taxonomyTrees);
         return Response.ok(docNode, new MediaType("application", "json")).build();
       } else if (taxonomyNode.isNodeType("exo:taxonomy")) {
         listResultNode.setLstNode(getArticleNode(taxonomyNode, documentTypes));
         Collections.sort(listResultNode.getLstNode(), new NameComparator());
         return Response.ok(listResultNode, new MediaType("application", "json")).build();
       }
     } catch (PathNotFoundException exc) {
       LOG.error("Path Not found " + exc.getMessage(), exc);
       return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
     } catch (Exception e) {
       LOG.error(e);
       return Response.serverError().build();
     }
   }
   return Response.ok().build();
 }
Beispiel #11
0
 /**
  * GetRealNode
  *
  * @param strRepository
  * @param strWorkspace
  * @param strIdentifier
  * @param cacheVisibility the visibility of cache
  * @return the required node/ the target of a symlink node / null if node was in trash.
  * @throws RepositoryException
  */
 public static Node getRealNode(
     String strRepository,
     String strWorkspace,
     String strIdentifier,
     boolean isWCMBase,
     String cacheVisibility)
     throws RepositoryException {
   LinkManager linkManager = WCMCoreUtils.getService(LinkManager.class);
   Node selectedNode;
   if (isWCMBase) {
     selectedNode =
         getViewableNodeByComposer(
             strRepository,
             strWorkspace,
             strIdentifier,
             WCMComposer.BASE_VERSION,
             cacheVisibility);
   } else {
     selectedNode =
         getViewableNodeByComposer(
             strRepository, strWorkspace, strIdentifier, null, cacheVisibility);
   }
   if (selectedNode != null) {
     if (!org.exoplatform.ecm.webui.utils.Utils.isInTrash(selectedNode)) {
       if (linkManager.isLink(selectedNode)) {
         if (linkManager.isTargetReachable(selectedNode)) {
           selectedNode = linkManager.getTarget(selectedNode);
           if (!org.exoplatform.ecm.webui.utils.Utils.isInTrash(selectedNode)) {
             return selectedNode;
           }
         }
       } else {
         return selectedNode;
       }
     }
   }
   return null;
 }