@SuppressWarnings("unchecked") protected void removeRSSItem(String itemId, Node node, String description) throws Exception { RSS data = new RSS(node); SyndFeed feed = data.read(); List<SyndEntry> entries = feed.getEntries(); Node removeNode = getNodeById(itemId); if (removeNode.isNodeType("exo:topic")) { List<Node> listRemovePosts = getListRemove(removeNode, "exo:post"); removeItem(entries, listRemovePosts); } else if (removeNode.isNodeType("exo:forum")) { List<Node> listRemoveForum = getListRemove(removeNode, "exo:topic"); for (Node n : listRemoveForum) { List<Node> listRemovePosts = getListRemove(n, "exo:post"); removeItem(entries, listRemovePosts); } removeItem(entries, listRemoveForum); } feed.setEntries(entries); String title = new PropertyReader(node).string("exo:name", "Root"); feed.setTitle(title); feed.setDescription(description); data.saveFeed(feed, FORUM_RSS_TYPE); }
@Override public ResultNode createData(Node node, Row row) { try { PortalRequestContext portalRequestContext = Util.getPortalRequestContext(); PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); PortletRequest portletRequest = portletRequestContext.getRequest(); StringBuffer baseURI = new StringBuffer(); baseURI .append(portletRequest.getScheme()) .append("://") .append(portletRequest.getServerName()); if (portletRequest.getServerPort() != 80) { baseURI.append(":").append(String.format("%s", portletRequest.getServerPort())); } baseURI.append(portalRequestContext.getPortalContextPath()); if (node.isNodeType("mop:pagelink")) { node = node.getParent(); } if (node.isNodeType("gtn:language")) { node = node.getParent().getParent(); } String userNaviUri = baseURI.toString() + "/" + PageDataCreator.getUserNavigationURI(node).toString(); if (userNavigationUriList.contains(userNaviUri)) { return null; } userNavigationUriList.add(userNaviUri); return new ResultNode(node, row, userNaviUri); } catch (Exception e) { return null; } }
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; }
@Override public Node filterNodeToDisplay(Node node) { try { if (!node.isNodeType("mop:navigation") && !node.isNodeType("mop:pagelink") && !node.isNodeType("gtn:language")) { return null; } else { return node; } } catch (RepositoryException e) { return null; } }
/** * Performs check out of the specified node. * * @param node the node to perform the check out * @see VersionManager#checkout(String) for details */ public void checkout(Node node) throws UnsupportedRepositoryOperationException, LockException, RepositoryException { while (!node.isCheckedOut()) { if (!node.isNodeType("mix:versionable") && !node.isNodeType("mix:simpleVersionable")) { node = node.getParent(); } else { String absPath = node.getPath(); VersionManager versionManager = getWorkspace().getVersionManager(); if (!versionManager.isCheckedOut(absPath)) { versionManager.checkout(absPath); } return; } } }
public void testSave() throws Exception { UserStateModel userModel = new UserStateModel( session.getUserID(), new Date().getTime(), UserStateService.DEFAULT_STATUS); userStateService.save(userModel); SessionProvider sessionProvider = SessionProvider.createSystemProvider(); try { Node userNodeApp = nodeHierarchyCreator.getUserApplicationNode(sessionProvider, session.getUserID()); assertTrue(userNodeApp.hasNode(VIDEOCALLS_BASE_PATH)); Node videoCallNode = userNodeApp.getNode(VIDEOCALLS_BASE_PATH); assertTrue(videoCallNode.isNodeType(USER_STATATUS_NODETYPE)); assertTrue(videoCallNode.hasProperty(USER_ID_PROP)); assertEquals(userModel.getUserId(), videoCallNode.getProperty(USER_ID_PROP).getString()); assertTrue(videoCallNode.hasProperty(LAST_ACTIVITY_PROP)); assertEquals( userModel.getLastActivity(), videoCallNode.getProperty(LAST_ACTIVITY_PROP).getLong()); assertTrue(videoCallNode.hasProperty(STATUS_PROP)); assertEquals(userModel.getStatus(), videoCallNode.getProperty(STATUS_PROP).getString()); } finally { sessionProvider.close(); } }
/** {@inheritDoc} */ public void watchDocument(Node documentNode, String userName, int notifyType) throws Exception { Session session = documentNode.getSession(); Value newWatcher = session.getValueFactory().createValue(userName); if (!documentNode.isNodeType(EXO_WATCHABLE_MIXIN)) { documentNode.addMixin(EXO_WATCHABLE_MIXIN); if (notifyType == NOTIFICATION_BY_EMAIL) { documentNode.setProperty(EMAIL_WATCHERS_PROP, new Value[] {newWatcher}); documentNode.save(); session.save(); EmailNotifyListener listener = new EmailNotifyListener(documentNode); observeNode(documentNode, listener); } session.save(); } else { List<Value> watcherList = new ArrayList<Value>(); if (notifyType == NOTIFICATION_BY_EMAIL) { if (documentNode.hasProperty(EMAIL_WATCHERS_PROP)) { for (Value watcher : documentNode.getProperty(EMAIL_WATCHERS_PROP).getValues()) { watcherList.add(watcher); } watcherList.add(newWatcher); } documentNode.setProperty( EMAIL_WATCHERS_PROP, watcherList.toArray(new Value[watcherList.size()])); documentNode.save(); } session.save(); } }
private String getHandleUuid(final String documentPath) { if (documentPath == null) { return null; } final int idx = documentPath.lastIndexOf("/"); if (idx > 0) { final String handlePath = documentPath.substring(0, idx); try { final Node node = session.getNode(handlePath); if (node.isNodeType(HippoNodeType.NT_HANDLE)) { return node.getIdentifier(); } } catch (PathNotFoundException e) { log.debug( "Document handle '{}' was removed before we could log workflow event", handlePath); } catch (RepositoryException e) { log.error( "Failed to determine uuid of document handle at " + handlePath + " while logging workflow event", e); } } return null; }
public static String getRealNodePath(Node node) throws Exception { if (node.isNodeType("nt:frozenNode")) { Node realNode = getRealNode(node); return Text.escape(realNode.getPath(), '%', true) + "?version=" + node.getParent().getName(); } return Text.escape(node.getPath(), '%', true); }
/** * Returns the number of children that have to be displayed in the tree. * * <p>If there are more than <code>numChildrenToCheck</code> children (including the ones that * will not be displayed) <code>numChildrenToCheck + 1</code> is returned to indicate that there * could be more children. * * @param res parent resource * @param numChildrenToCheck The max number of children to check * @return list of child resources */ private int countChildren(Resource res, int numChildrenToCheck) { int count = 0; int totalCount = 0; Iterator<Resource> iter = resolver.listChildren(res); while (iter.hasNext() && totalCount <= numChildrenToCheck) { Resource child = iter.next(); if (shouldAddChild(child)) { // skip hidden (incl. "jcr:content") and non hierarchical nodes // see IsSiteAdminPredicate for the detailed conditions try { Node n = child.adaptTo(Node.class); if (!n.isNodeType(DamConstants.NT_DAM_ASSET)) { count++; } totalCount++; } catch (RepositoryException re) { // Ignored } } } if (totalCount == numChildrenToCheck + 1) { // avoid auto expand return totalCount; } return count; }
/** * @param node the node to check * @return true if {@code node}'s primary type is one of the types in {@link * #contentPrimaryTypes}; may not be null * @throws RepositoryException if an error occurs checking the node's primary type */ private boolean isContent(Node node) throws RepositoryException { for (String nodeType : contentPrimaryTypes) { if (node.isNodeType(nodeType)) return true; } return false; }
private void purgeHistory(Node fileNode, Session session, PentahoJcrConstants pentahoJcrConstants) throws RepositoryException { // Delete all previous versions of this node VersionManager versionManager = session.getWorkspace().getVersionManager(); if (JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, fileNode)) { // go down to children NodeIterator nodes = fileNode.getNodes(); while (nodes.hasNext()) { Node next = (Node) nodes.next(); purgeHistory(next, session, pentahoJcrConstants); } } else if (JcrRepositoryFileUtils.isPentahoFile(pentahoJcrConstants, fileNode) && fileNode.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())) { VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath()); VersionIterator allVersions = versionHistory.getAllVersions(); while (allVersions.hasNext()) { Version next = (Version) allVersions.next(); String name = next.getName(); // Root version cannot be deleted, the remove below will take care of that. if (!JCR_ROOT_VERSION.equals(name)) { versionHistory.removeVersion(name); } } } }
private boolean isNodeFile(Node node) { try { return node.isNodeType("nt:file"); } catch (RepositoryException e) { throw new RuntimeException(e); } }
/** * Test method TaxonomyService.addTaxonomyNode() Input: Add one taxonomy node below MyDocument * Expect: One node with primary node type = exo:taxonomy in path MyDocument/ * * @throws TaxonomyNodeAlreadyExistsException * @throws RepositoryException */ public void testAddTaxonomyNode1() throws TaxonomyNodeAlreadyExistsException, RepositoryException { session.getRootNode().addNode("MyDocuments"); session.save(); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Sport", "root"); Node taxonomyNode = (Node) session.getItem("/MyDocuments/Sport"); assertTrue(taxonomyNode.isNodeType("exo:taxonomy")); }
/** * Get the real node from frozen node, symlink node return True if the node is viewable, otherwise * will return False * * @param node: The node to check */ public static Node getRealNode(Node node) throws Exception { // TODO: Need to add to check symlink node if (node.isNodeType("nt:frozenNode")) { String uuid = node.getProperty("jcr:frozenUuid").getString(); return node.getSession().getNodeByUUID(uuid); } return node; }
/** * @param node the node to check * @return true if {@code node}'s primary type is one of the types in {@link #filePrimaryTypes}; * may not be null * @throws RepositoryException if an error occurs checking the node's primary type */ @Override public boolean isFile(Node node) throws RepositoryException { for (String nodeType : filePrimaryTypes) { if (node.isNodeType(nodeType)) return true; } return false; }
private String getType(Node node) throws Exception { if (node.isNodeType("exo:taxonomy")) { return "category"; } else if (documentTypes.contains(node.getPrimaryNodeType().getName())) { return "article"; } return ""; }
@Override public boolean isVersioned() { try { return node.isNodeType("mix:versionable"); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
/** * initializes fields * * @throws Exception */ public void initParams() throws Exception { // get current node // name field if (currentNode.hasProperty("exo:title")) { nameValue_ = currentNode.getProperty("exo:title").getValue().getString(); } if (currentNode.hasNode("jcr:content")) { Node content = currentNode.getNode("jcr:content"); if (content.hasProperty("dc:title")) { try { nameValue_ = content.getProperty("dc:title").getValues()[0].getString(); } catch (Exception e) { nameValue_ = null; } } } if (nameValue_ == null) nameValue_ = currentNode.getName(); boolean hasNavigableMixinType = currentNode.isNodeType("exo:navigable"); if (hasNavigableMixinType) { isVisible = true; if (currentNode.getParent().isNodeType("exo:navigable")) { if (currentNode.hasProperty("exo:index")) { index_ = currentNode.getProperty("exo:index").getLong(); } renderIndexField = true; } if (currentNode.hasProperty("exo:navigationNode")) { navigationNode_ = currentNode.getProperty("exo:navigationNode").getString(); } if (currentNode.hasProperty("exo:clickable")) { if (currentNode.getProperty("exo:clickable").getBoolean()) { isClickable = true; } else isClickable = false; } if (currentNode.hasProperty("exo:page")) { listTargetPage_ = currentNode.getProperty("exo:page").getString(); } if (currentNode.hasProperty("exo:pageParamId")) { listShowClvBy_ = currentNode.getProperty("exo:pageParamId").getString(); } if (currentNode.hasProperty("exo:childrenPage")) { detailTargetPage_ = currentNode.getProperty("exo:childrenPage").getString(); } if (currentNode.hasProperty("exo:childrenPageParamId")) { detailShowClvBy_ = currentNode.getProperty("exo:childrenPageParamId").getString(); } } }
@SuppressWarnings("unchecked") protected void populateCurrentPage(int page) throws Exception { if (iter_ == null) { iter_ = setQuery(isQuery_, value_); setAvailablePage((int) iter_.getSize()); if (page == 0) currentPage_ = 0; // nasty trick for getAll() else checkAndSetPage(page); page = currentPage_; } Node currentNode; long pageSize = 0; if (page > 0) { long position = 0; pageSize = getPageSize(); if (page == 1) position = 0; else { position = (page - 1) * pageSize; iter_.skip(position); } } else { pageSize = iter_.getSize(); } currentListPage_ = new ArrayList<Object>(); for (int i = 0; i < pageSize; i++) { if (iter_.hasNext()) { currentNode = iter_.nextNode(); if (currentNode.isNodeType("exo:post")) { currentListPage_.add(getPost(currentNode)); } else if (currentNode.isNodeType(Utils.TYPE_TOPIC)) { currentListPage_.add(getTopic(currentNode)); } else if (currentNode.isNodeType(Utils.USER_PROFILES_TYPE)) { currentListPage_.add(getUserProfile(currentNode)); } else if (currentNode.isNodeType("exo:privateMessage")) { currentListPage_.add(getPrivateMessage(currentNode)); } } else { break; } } iter_ = null; if (sessionManager.getCurrentSession() != null && sessionManager.getCurrentSession().isLive()) { sessionManager.closeSession(); } }
public VoidReturn execute(Session session) throws Exception { Node node; node = (Node) getCurrentSession().getItem(path); String linkItem = getPageLink() + "?portal:componentId=forum&portal:type=action&portal:isSecure=false&uicomponent=UIBreadcumbs&" + "op=ChangePath&objectId="; if (node.isNodeType("exo:post")) { linkItem = node.getProperty("exo:link").getString(); linkItem = linkItem.substring(0, linkItem.indexOf("objectId=") + 9); postUpdated(path, linkItem, updated); } else if (node.isNodeType("exo:topic")) { topicUpdated(path, linkItem, updated); } else if (node.isNodeType("exo:forum")) { forumUpdated(path, linkItem, updated); } return VoidReturn.VALUE; }
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; }
@Override protected boolean isApplicableDocumentType(Node node) throws RepositoryException { for (String nodeType : REQUIRED_NODE_TYPES) { if (node.isNodeType(nodeType)) { return true; } } return false; }
public Set<Node> getReferrers(Node document) throws RepositoryException { Set<Node> referrers = new TreeSet<Node>( new Comparator<Node>() { public int compare(Node node1, Node node2) { try { return node1.getIdentifier().compareTo(node2.getIdentifier()); } catch (UnsupportedRepositoryOperationException ex) { // cannot happen return 0; } catch (RepositoryException ex) { return 0; } } }); if (!document.isNodeType(HippoNodeType.NT_DOCUMENT)) { return null; } document = ((HippoNode) document).getCanonicalNode(); Node handle = document.getParent(); if (!handle.isNodeType(HippoNodeType.NT_HANDLE) || !handle.isNodeType(HippoNodeType.NT_HARDHANDLE)) { return null; } String uuid = handle.getIdentifier(); QueryManager queryManager = document.getSession().getWorkspace().getQueryManager(); String statement = "//*[@hippo:docbase='" + uuid + "']"; Query query = queryManager.createQuery(statement, Query.XPATH); QueryResult result = query.execute(); for (NodeIterator iter = result.getNodes(); iter.hasNext(); ) { Node node = iter.nextNode(); while (node != null && !node.isNodeType(HippoNodeType.NT_DOCUMENT)) { node = (node.getDepth() > 0 ? node.getParent() : null); } if (node != null) { if (node.isNodeType("hippostd:publishable") && node.hasProperty("hippostd:state") && node.getProperty("hippostd:state").getString().equals("published")) { referrers.add(node); } } } return referrers; }
public static Map<String, String> populateActivityData( Node node, String activityOwnerId, String activityMsgBundleKey, boolean isSystemComment, String systemComment) throws Exception { /** The date formatter. */ DateFormat dateFormatter = null; dateFormatter = new SimpleDateFormat(ISO8601.SIMPLE_DATETIME_FORMAT); // get activity data String repository = ((ManageableRepository) node.getSession().getRepository()).getConfiguration().getName(); String workspace = node.getSession().getWorkspace().getName(); String illustrationImg = Utils.getIllustrativeImage(node); String strDateCreated = ""; if (node.hasProperty(NodetypeConstant.EXO_DATE_CREATED)) { Calendar dateCreated = node.getProperty(NodetypeConstant.EXO_DATE_CREATED).getDate(); strDateCreated = dateFormatter.format(dateCreated.getTime()); } String strLastModified = ""; if (node.hasNode(NodetypeConstant.JCR_CONTENT)) { Node contentNode = node.getNode(NodetypeConstant.JCR_CONTENT); if (contentNode.hasProperty(NodetypeConstant.JCR_LAST_MODIFIED)) { Calendar lastModified = contentNode.getProperty(NodetypeConstant.JCR_LAST_MODIFIED).getDate(); strLastModified = dateFormatter.format(lastModified.getTime()); } } activityOwnerId = activityOwnerId != null ? activityOwnerId : ""; // populate data to map object Map<String, String> activityParams = new HashMap<String, String>(); activityParams.put(ContentUIActivity.CONTENT_NAME, node.getName()); activityParams.put(ContentUIActivity.AUTHOR, activityOwnerId); activityParams.put(ContentUIActivity.DATE_CREATED, strDateCreated); activityParams.put(ContentUIActivity.LAST_MODIFIED, strLastModified); activityParams.put(ContentUIActivity.CONTENT_LINK, getContentLink(node)); activityParams.put( ContentUIActivity.ID, node.isNodeType(NodetypeConstant.MIX_REFERENCEABLE) ? node.getUUID() : ""); activityParams.put(ContentUIActivity.REPOSITORY, repository); activityParams.put(ContentUIActivity.WORKSPACE, workspace); activityParams.put(ContentUIActivity.MESSAGE, activityMsgBundleKey); activityParams.put(ContentUIActivity.MIME_TYPE, getMimeType(node)); activityParams.put(ContentUIActivity.IMAGE_PATH, illustrationImg); activityParams.put(ContentUIActivity.IMAGE_PATH, illustrationImg); if (isSystemComment) { activityParams.put(ContentUIActivity.IS_SYSTEM_COMMENT, String.valueOf(isSystemComment)); activityParams.put(ContentUIActivity.SYSTEM_COMMENT, systemComment); } return activityParams; }
protected Node getNodeToCheckState(Node node) throws Exception { Node displayNode = node; if (displayNode.isNodeType("nt:resource")) { displayNode = node.getParent(); } // return exo:webContent when exo:htmlFile found if (displayNode.isNodeType("exo:htmlFile")) { Node parent = displayNode.getParent(); if (parent.isNodeType("exo:webContent")) return parent; return displayNode; } // String[] contentTypes = queryCriteria.getContentTypes(); if (contentTypes != null && contentTypes.length > 0) { String primaryNodeType = displayNode.getPrimaryNodeType().getName(); if (!ArrayUtils.contains(contentTypes, primaryNodeType)) return null; } return displayNode; }
protected RepositoryFile getReferrerFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Property referrerProperty) throws RepositoryException { Node currentNode = referrerProperty.getParent(); while (!currentNode.isNodeType(pentahoJcrConstants.getPHO_NT_PENTAHOHIERARCHYNODE())) { currentNode = currentNode.getParent(); } // if folder, then referrer is a lock token record (under the user's home folder) which will be // cleaned up by // lockHelper; ignore it if (currentNode.isNodeType(pentahoJcrConstants.getPHO_NT_PENTAHOFOLDER())) { return null; } else { return JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, currentNode); } }
/** * check if the given child should be added to the list of children to display * * @param child Resource to test * @return if the child should be added */ private boolean shouldAddChild(Resource child) { try { Node childNode = child.adaptTo(Node.class); return DPSUtil.getDPSResourceType(childNode) != null || childNode.isNodeType(JcrConstants.NT_FOLDER); } catch (RepositoryException ex) { log.error("Child could not be queried", ex); } return false; }
/** * 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)); }
/** * A repository implementation may make its workspace root nodes mix:referenceable. If so, then * the root node of all workspaces must be referenceable, and all must have the same UUID. */ public void testReferenceableRootNode() throws RepositoryException, NotExecutableException { // compare UUID of default workspace and a second workspace Node rootNode = session.getRootNode(); if (rootNode.isNodeType(mixReferenceable)) { // check if root node in second workspace is referenceable too Node rootNodeW2 = sessionW2.getRootNode(); if (!rootNodeW2.isNodeType(mixReferenceable)) { fail("Root node in second workspace is not referenceable."); } // check if all root nodes have the same UUID assertEquals( "Referenceable root nodes of different workspaces must have same UUID.", rootNode.getUUID(), rootNodeW2.getUUID()); } else { throw new NotExecutableException("Root node is not referenceable"); } }