private JcrNodeModel getParent(JcrNodeModel model) { JcrNodeModel parentModel = model.getParentModel(); if (parentModel == null) { return new JcrNodeModel((Node) null); } try { // skip facetresult nodes in hierarchy Node parent = parentModel.getNode(); if (parent.isNodeType(HippoNodeType.NT_FACETRESULT)) { return new JcrNodeModel(parent.getParent()); } } catch (RepositoryException ex) { log.error(ex.getMessage()); } return parentModel; }
private JcrNodeModel getPhysicalNode(JcrNodeModel model) { Node node = model.getNode(); if (node != null) { try { if (node.isNodeType("nt:version")) { Node frozen = node.getNode("jcr:frozenNode"); String uuid = frozen.getProperty("jcr:frozenUuid").getString(); try { Node docNode = node.getSession().getNodeByUUID(uuid); if (docNode.getDepth() > 0) { Node parent = docNode.getParent(); if (parent.isNodeType(HippoNodeType.NT_HANDLE)) { return new JcrNodeModel(parent); } } return new JcrNodeModel(docNode); } catch (ItemNotFoundException infe) { // node doesn't exist anymore. If it's a document, the handle // should still be available though. if (frozen.hasProperty(HippoNodeType.HIPPO_PATHS)) { Value[] ancestors = frozen.getProperty(HippoNodeType.HIPPO_PATHS).getValues(); if (ancestors.length > 1) { uuid = ancestors[1].getString(); return new JcrNodeModel(node.getSession().getNodeByUUID(uuid)); } } throw infe; } } } catch (RepositoryException ex) { log.error(ex.getMessage()); } } return model; }
private boolean isFolder(JcrNodeModel nodeModel) { if (nodeModel.getNode() != null) { try { Node node = nodeModel.getNode(); if (node.isNodeType(HippoStdNodeType.NT_FOLDER) || node.isNodeType(HippoStdNodeType.NT_DIRECTORY) || node.isNodeType(HippoNodeType.NT_NAMESPACE) || node.isNodeType(HippoNodeType.NT_FACETBASESEARCH) || node.isNodeType("rep:root")) { return true; } } catch (RepositoryException ex) { log.error(ex.getMessage()); } return false; } return true; }
private JcrNodeModel findDocument(JcrNodeModel document) { if (document.getNode() == null) { return document; } else if (isFolder(document)) { folder = document; document = new JcrNodeModel((Node) null); } else { folder = getParent(document); while (!isFolder(folder)) { document = folder; folder = getParent(document); } } return document; }
public void detach() { IModel<Node> nodeModel = documentService.getModel(); if (nodeModel == null || nodeModel.getObject() == null) { nodeModel = folderService.getModel(); } if (nodeModel != null && nodeModel.getObject() != null) { path = new JcrItemModel(nodeModel.getObject()).getPath(); } else { path = null; } folderService.detach(); documentService.detach(); if (folder != null) { folder.detach(); } }