@Override
 public void handleEvent(Event event) {
   if (!Framework.isDevModeSet()) {
     log.info("Do not flush the directory caches: dev mode is not set");
     return;
   }
   if (!ReloadEventNames.RELOAD_EVENT_ID.equals(event.getId())) {
     return;
   }
   try {
     RepositoryManager rm = Framework.getService(RepositoryManager.class);
     // Transaction management
     final boolean txStarted =
         !TransactionHelper.isTransactionActive() && TransactionHelper.startTransaction();
     boolean txSucceed = false;
     try {
       new UnrestrictedSessionRunner(rm.getDefaultRepositoryName()) {
         @Override
         public void run() {
           DocumentRoutingService service =
               Framework.getLocalService(DocumentRoutingService.class);
           service.importAllRouteModels(session);
         }
       }.runUnrestricted();
       txSucceed = true;
     } finally {
       if (txStarted) {
         if (!txSucceed) {
           TransactionHelper.setTransactionRollbackOnly();
           log.warn("Rollbacking import of route models");
         }
         TransactionHelper.commitOrRollbackTransaction();
       }
     }
   } catch (NuxeoException e) {
     log.error("Error while reloading the route models", e);
   }
 }
Пример #2
0
  @Override
  protected void doHandleStatelessRequest(Request req, Response res) {
    String repo = (String) req.getAttributes().get("repo");
    String docid = (String) req.getAttributes().get("docid");

    DOMDocumentFactory domFactory = new DOMDocumentFactory();

    DOMDocument result = (DOMDocument) domFactory.createDocument();

    if (repo == null || repo.equals("*")) {
      try {
        Element serversNode = result.createElement("avalaibleServers");
        result.setRootElement((org.dom4j.Element) serversNode);

        RepositoryManager repositoryManager = Framework.getLocalService(RepositoryManager.class);
        for (String repositoryName : repositoryManager.getRepositoryNames()) {
          Element server = result.createElement("server");
          server.setAttribute("title", repositoryName);
          server.setAttribute("url", getRelURL(repositoryName, "*"));
          serversNode.appendChild(server);
        }
        res.setEntity(result.asXML(), MediaType.TEXT_XML);
        res.getEntity().setCharacterSet(CharacterSet.UTF_8);
        return;
      } catch (DOMException e) {
        handleError(result, res, e);
        return;
      }
    } else {
      DocumentModel dm;

      boolean init = initRepository(res, repo);
      boolean isRoot = false;
      try {
        if (init) {
          if (docid == null || docid.equals("*")) {
            dm = session.getRootDocument();
            isRoot = true;
          } else {
            dm = session.getDocument(new IdRef(docid));
          }
        } else {
          handleError(res, "Unable to init repository");
          return;
        }
      } catch (NuxeoException e) {
        handleError(res, e);
        return;
      }

      Element current = result.createElement("document");
      try {
        current.setAttribute("title", dm.getTitle());
      } catch (DOMException | NuxeoException e) {
        handleError(res, e);
      }
      current.setAttribute("type", dm.getType());
      current.setAttribute("id", dm.getId());
      current.setAttribute("name", dm.getName());
      if (isRoot) {
        current.setAttribute("url", getRelURL(repo, ""));
      } else {
        current.setAttribute("url", getRelURL(repo, dm.getRef().toString()));
      }
      result.setRootElement((org.dom4j.Element) current);

      if (dm.isFolder()) {
        // Element childrenElem = result.createElement("children");
        // root.appendChild(childrenElem);

        DocumentModelList children;
        try {
          children = session.getChildren(dm.getRef());
        } catch (NuxeoException e) {
          handleError(result, res, e);
          return;
        }

        for (DocumentModel child : children) {
          Element el = result.createElement("document");
          try {
            el.setAttribute("title", child.getTitle());
          } catch (DOMException e) {
            handleError(res, e);
          } catch (NuxeoException e) {
            handleError(res, e);
          }
          el.setAttribute("type", child.getType());
          el.setAttribute("id", child.getId());
          el.setAttribute("name", child.getName());
          el.setAttribute("url", getRelURL(repo, child.getRef().toString()));
          current.appendChild(el);
        }
      }

      res.setEntity(result.asXML(), MediaType.TEXT_XML);
      res.getEntity().setCharacterSet(CharacterSet.UTF_8);
    }
  }
Пример #3
0
 protected CoreSession getRestrictedSession(String userName) {
   RepositoryManager rm = Framework.getLocalService(RepositoryManager.class);
   Map<String, Serializable> ctx = new HashMap<>();
   ctx.put("principal", new UserPrincipal(userName, null, false, false));
   return CoreInstance.openCoreSession(rm.getDefaultRepositoryName(), ctx);
 }
 private String getRepository() {
   RepositoryManager mgr = Framework.getLocalService(RepositoryManager.class);
   return mgr.getDefaultRepositoryName();
 }