@GET @Path("/all/{repoName}") public Response getCategory(@PathParam("repoName") String repoName) { List<CategoryNode> listCategoryNode = new ArrayList<CategoryNode>(); if (repoName == null || repoName.trim().isEmpty()) { return Response.status(HTTPStatus.NOT_FOUND) .entity(new RepositoryException("Can't find repository")) .build(); } // Get all category try { if (documentTypes.isEmpty()) documentTypes = templateService_.getAllDocumentNodeTypes(repoName); List<Node> categoryNodes = taxonomyService_.getAllTaxonomyTrees(repoName); for (Node rootCategoryNode : categoryNodes) { getTaxnomyNodeRescursive(rootCategoryNode, rootCategoryNode, listCategoryNode); } } catch (Exception e) { LOG.error(e); return Response.serverError().build(); } ListResultNode listResultNode = new ListResultNode(); listResultNode.setLstNode(listCategoryNode); return Response.ok(listResultNode, new MediaType("application", "json")).build(); }
@GET @Path("/all/{repoName}/{catePath:.*}/") public Response getCategory( @PathParam("repoName") String repoName, @PathParam("catePath") String catePath) { List<CategoryNode> listCategoryNode = new ArrayList<CategoryNode>(); if (catePath != null && !catePath.trim().isEmpty()) { String taxonomyTree = catePath.split("/")[0]; String path = catePath.substring(taxonomyTree.length()); if (path.startsWith("/")) { path = path.substring(1); } try { Node taxonomyTreeNode = taxonomyService_.getTaxonomyTree(repoName, taxonomyTree); if (taxonomyTreeNode == null) throw new PathNotFoundException("Can't find category " + taxonomyTree); Node category; NodeIterator iterNode; if (path.equals("")) { iterNode = taxonomyTreeNode.getNodes(); } else { iterNode = taxonomyTreeNode.getNode(path).getNodes(); } CategoryNode categoryNode; while (iterNode.hasNext()) { category = iterNode.nextNode(); categoryNode = getCategoryNode(category, makePath(category, taxonomyTreeNode)); if (categoryNode != null) listCategoryNode.add(categoryNode); } } 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(); } } ListResultNode listResultNode = new ListResultNode(); Collections.sort(listCategoryNode, new NameComparator()); listResultNode.setLstNode(listCategoryNode); return Response.ok(listResultNode, new MediaType("application", "json")).build(); }
@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(); }