Exemple #1
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;
 }
Exemple #2
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;
 }
Exemple #3
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);
       }
     }
   }
 }
Exemple #4
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));
 }
Exemple #5
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));
 }
Exemple #6
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;
   }
 }
  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;
  }
Exemple #8
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));
 }
 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();
 }
Exemple #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;
 }
Exemple #12
0
 private void updateSymlinkByQuery(
     String workspace, String statement, SessionProvider sessionProvider) {
   try {
     ManageableRepository manageableRepository = repositoryService.getCurrentRepository();
     Session session = sessionProvider.getSession(workspace, manageableRepository);
     QueryManager manager = session.getWorkspace().getQueryManager();
     NodeIterator iter = manager.createQuery(statement, Query.SQL).execute().getNodes();
     while (iter.hasNext()) {
       try {
         Node currentNode = iter.nextNode();
         linkManager.updateSymlink(currentNode);
       } catch (Exception ex) {
         if (LOG.isErrorEnabled()) {
           LOG.error("Can not update symlink data", ex);
         }
       }
     }
   } catch (RepositoryException e) {
     if (LOG.isErrorEnabled()) {
       LOG.error("Can not update symlinks data", e);
     }
   }
 }
Exemple #13
0
  public void execute(JobExecutionContext context) throws JobExecutionException {
    Session session = null;
    try {
      if (LOG.isInfoEnabled()) {
        LOG.info("Start Execute ImportXMLJob");
      }
      if (stagingStorage == null) {

        JobDataMap jdatamap = context.getJobDetail().getJobDataMap();
        stagingStorage = jdatamap.getString("stagingStorage");
        temporaryStorge = jdatamap.getString("temporaryStorge");
        if (LOG.isDebugEnabled()) {
          LOG.debug("Init parameters first time :");
        }
      }
      SessionProvider sessionProvider = SessionProvider.createSystemProvider();
      String containerName = WCMCoreUtils.getContainerNameFromJobContext(context);
      RepositoryService repositoryService_ =
          WCMCoreUtils.getService(RepositoryService.class, containerName);
      ManageableRepository manageableRepository = repositoryService_.getCurrentRepository();
      PublicationService publicationService =
          WCMCoreUtils.getService(PublicationService.class, containerName);
      PublicationPlugin publicationPlugin =
          publicationService
              .getPublicationPlugins()
              .get(AuthoringPublicationConstant.LIFECYCLE_NAME);
      XMLInputFactory factory = XMLInputFactory.newInstance();

      File stagingFolder = new File(stagingStorage);
      File tempfolder = new File(temporaryStorge);

      File[] files = null;
      File xmlFile = null;
      XMLStreamReader reader = null;
      InputStream xmlInputStream = null;
      int eventType;
      List<LinkObject> listLink = new ArrayList<LinkObject>();
      LinkObject linkObj = new LinkObject();
      boolean hasNewContent = false;
      if (stagingFolder.exists()) {
        files = stagingFolder.listFiles();
        if (files != null) {
          hasNewContent = true;
          for (int i = 0; i < files.length; i++) {
            xmlFile = files[i];
            if (xmlFile.isFile()) {
              MimeTypeResolver resolver = new MimeTypeResolver();
              String fileName = xmlFile.getName();
              String hashCode = fileName.split("-")[0];
              String mimeType = resolver.getMimeType(xmlFile.getName());
              if ("text/xml".equals(mimeType)) {
                xmlInputStream = new FileInputStream(xmlFile);
                reader = factory.createXMLStreamReader(xmlInputStream);
                while (reader.hasNext()) {
                  eventType = reader.next();
                  if (eventType == XMLEvent.START_ELEMENT && "data".equals(reader.getLocalName())) {
                    String data = reader.getElementText();

                    if (!tempfolder.exists()) tempfolder.mkdirs();
                    long time = System.currentTimeMillis();
                    File file =
                        new File(
                            temporaryStorge
                                + File.separator
                                + "-"
                                + hashCode
                                + "-"
                                + time
                                + ".xml.tmp");
                    InputStream inputStream = new ByteArrayInputStream(data.getBytes());
                    OutputStream out = new FileOutputStream(file);
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = inputStream.read(buf)) > 0) out.write(buf, 0, len);
                    out.close();
                    inputStream.close();
                  }
                  try {
                    if (eventType == XMLEvent.START_ELEMENT
                        && "published-content".equals(reader.getLocalName())) {
                      linkObj.setSourcePath(reader.getAttributeValue(0)); // --Attribute
                      // number
                      // 0 =
                      // targetPath
                    }
                    if (eventType == XMLEvent.START_ELEMENT
                        && "type".equals(reader.getLocalName())) {
                      linkObj.setLinkType(reader.getElementText());
                    }
                    if (eventType == XMLEvent.START_ELEMENT
                        && "title".equals(reader.getLocalName())) {
                      linkObj.setLinkTitle(reader.getElementText());
                    }
                    if (eventType == XMLEvent.START_ELEMENT
                        && "targetPath".equals(reader.getLocalName())) {
                      linkObj.setLinkTargetPath(reader.getElementText());
                      listLink.add(linkObj);
                    }

                    if (eventType == XMLEvent.START_ELEMENT
                        && "unpublished-content".equals(reader.getLocalName())) {

                      String contentTargetPath = reader.getAttributeValue(0);
                      String[] strContentPath = contentTargetPath.split(":");
                      StringBuffer sbContPath = new StringBuffer();
                      boolean flag = true;
                      for (int index = 2; index < strContentPath.length; index++) {
                        if (flag) {
                          sbContPath.append(strContentPath[index]);
                          flag = false;
                        } else {
                          sbContPath.append(":").append(strContentPath[index]);
                        }
                      }
                      sessionProvider = SessionProvider.createSystemProvider();

                      manageableRepository = repositoryService_.getCurrentRepository();
                      String workspace = strContentPath[1];
                      session = sessionProvider.getSession(workspace, manageableRepository);
                      String contentPath = sbContPath.toString();
                      if (session.itemExists(contentPath)) {
                        Node currentContent = (Node) session.getItem(contentPath);
                        HashMap<String, String> variables = new HashMap<String, String>();
                        variables.put("nodePath", contentTargetPath);
                        variables.put("workspaceName", workspace);
                        if (currentContent.hasProperty(
                                StageAndVersionPublicationConstant.PUBLICATION_LIFECYCLE_NAME)
                            && AuthoringPublicationConstant.LIFECYCLE_NAME.equals(
                                currentContent
                                    .getProperty(
                                        StageAndVersionPublicationConstant
                                            .PUBLICATION_LIFECYCLE_NAME)
                                    .getString())
                            && PublicationDefaultStates.PUBLISHED.equals(
                                currentContent
                                    .getProperty(StageAndVersionPublicationConstant.CURRENT_STATE)
                                    .getString())) {

                          publicationPlugin.changeState(
                              currentContent, PublicationDefaultStates.UNPUBLISHED, variables);
                          if (LOG.isInfoEnabled()) {
                            LOG.info(
                                "Change the status of the node "
                                    + currentContent.getPath()
                                    + " from "
                                    + PublicationDefaultStates.PUBLISHED
                                    + " to "
                                    + PublicationDefaultStates.UNPUBLISHED);
                          }
                        }
                      } else {
                        if (LOG.isWarnEnabled()) {
                          LOG.warn("The node " + contentPath + " does not exist");
                        }
                      }
                    }

                  } catch (Exception ie) {
                    if (LOG.isWarnEnabled()) {
                      LOG.warn("Error in ImportContentsJob: " + ie.getMessage());
                    }
                  }
                }
                reader.close();
                xmlInputStream.close();
                xmlFile.delete();
              }
            }
          }
        }
      }
      files = tempfolder.listFiles();
      if (files != null) {
        for (int i = 0; i < files.length; i++) {
          xmlFile = files[i];
          InputStream inputStream = new FileInputStream(xmlFile);
          reader = factory.createXMLStreamReader(inputStream);
          String workspace = null;
          String nodePath = new String();

          while (reader.hasNext()) {
            eventType = reader.next();
            if (eventType == XMLEvent.START_ELEMENT) {
              if (reader.getLocalName().equals("property")) {
                String value = reader.getAttributeValue(0);
                if (MIX_TARGET_PATH.equals(value)) {
                  eventType = reader.next();
                  if (eventType == XMLEvent.START_ELEMENT) {
                    reader.next();
                    nodePath = reader.getText();
                  }
                } else if (MIX_TARGET_WORKSPACE.equals(value)) {
                  eventType = reader.next();
                  if (eventType == XMLEvent.START_ELEMENT) {
                    reader.next();
                    workspace = reader.getText();
                  }
                }
              }
            }
          }
          reader.close();
          inputStream.close();
          session = sessionProvider.getSession(workspace, manageableRepository);
          if (session.itemExists(nodePath)) session.getItem(nodePath).remove();
          session.save();

          String path = nodePath.substring(0, nodePath.lastIndexOf(JCR_File_SEPARATOR));
          if (!session.itemExists(path)) {
            String[] pathTab = path.split(JCR_File_SEPARATOR);
            Node node_ = session.getRootNode();
            StringBuffer path_ = new StringBuffer(JCR_File_SEPARATOR);
            for (int j = 1; j < pathTab.length; j++) {
              path_ = path_.append(pathTab[j] + JCR_File_SEPARATOR);
              if (!session.itemExists(path_.toString())) {
                node_.addNode(pathTab[j], "nt:unstructured");
              }
              node_ = (Node) session.getItem(path_.toString());
            }
          }

          session.importXML(path, new FileInputStream(xmlFile), 0);
          session.save();
          xmlFile.delete();

          if (hasNewContent) {
            for (LinkObject obj : listLink) {
              String[] linkTarget = obj.getLinkTargetPath().split(":");
              StringBuffer itemPath = new StringBuffer();
              boolean flag = true;
              for (int index = 2; index < linkTarget.length; index++) {
                if (flag) {
                  itemPath.append(linkTarget[index]);
                  flag = false;
                } else {
                  itemPath.append(":");
                  itemPath.append(linkTarget[index]);
                }
              }
              String[] linkSource = obj.getSourcePath().split(":");
              session = sessionProvider.getSession(linkTarget[1], manageableRepository);
              Node parentNode = (Node) session.getItem(itemPath.toString());

              StringBuffer sourcePath = new StringBuffer();
              boolean flagSource = true;
              for (int index = 2; index < linkSource.length; index++) {
                if (flagSource) {
                  sourcePath.append(linkSource[index]);
                  flagSource = false;
                } else {
                  sourcePath.append(":");
                  sourcePath.append(linkSource[index]);
                }
              }

              if (parentNode.hasNode(obj.getLinkTitle())) {
                Node existedNode = (Node) session.getItem(itemPath + "/" + obj.getLinkTitle());
                existedNode.remove();
              }
              session = sessionProvider.getSession(linkSource[1], manageableRepository);
              Node targetNode = (Node) session.getItem(sourcePath.toString());
              LinkManager linkManager = WCMCoreUtils.getService(LinkManager.class, containerName);
              linkManager.createLink(parentNode, obj.getLinkType(), targetNode, obj.getLinkTitle());
            }
          }
        }
      }
      if (LOG.isInfoEnabled()) {
        LOG.info("End Execute ImportXMLJob");
      }
    } catch (RepositoryException ex) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Repository 'repository ' not found.");
      }
    } catch (Exception ex) {
      if (LOG.isErrorEnabled()) {
        LOG.error("Error when importing Contents : " + ex.getMessage(), ex);
      }
    } finally {
      if (session != null) session.logout();
    }
  }
Exemple #14
0
 public static boolean isSymLink(Node node) throws RepositoryException {
   LinkManager linkManager = Util.getUIPortal().getApplicationComponent(LinkManager.class);
   return linkManager.isLink(node);
 }
 public boolean accept(Map<String, Object> context) throws Exception {
   if (context == null) return true;
   LinkManager linkManager = WCMCoreUtils.getService(LinkManager.class);
   Node currentNode = (Node) context.get(Node.class.getName());
   return linkManager.isLink(currentNode) || !Utils.isTrashHomeNode(currentNode);
 }