Java Code Examples for javax.jcr.query.QueryResult#getNodes()
The following examples show how to use
javax.jcr.query.QueryResult#getNodes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlogServiceImpl.java From publick-sling-blog with Apache License 2.0 | 7 votes |
/** * Get blog posts with pagination * * @param offset The starting point of blog posts to return. * @param limit The number of blog posts to return. * @return The blog posts. */ public NodeIterator getPosts(Long offset, Long limit) { NodeIterator nodes = null; if (session != null) { try { QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(BLOG_QUERY, Query.JCR_SQL2); if (offset != null) { query.setOffset(offset); } if (limit != null) { query.setLimit(limit); } QueryResult result = query.execute(); nodes = result.getNodes(); } catch (RepositoryException e) { LOGGER.error("Could not search repository", e); } } return nodes; }
Example 2
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 6 votes |
private Entity[] getEntities(QueryResult queryResult) { try { NodeIterator nodes = queryResult.getNodes(); List<Entity> entities = new ArrayList<Entity>(); while (nodes.hasNext()) { Entity entity = getEntity(nodes.nextNode()); if (entity != null) { entities.add(entity); } } return entities.toArray(new Entity[entities.size()]); } catch (RepositoryException e) { throw convertJcrAccessException(e); } }
Example 3
Source File: StorageUpdate10.java From nextreports-server with Apache License 2.0 | 6 votes |
private void modifyDashboardState() throws RepositoryException { LOG.info("Modify dashboard state - add columnCount property"); String path = StorageConstants.DASHBOARDS_ROOT; String className = "ro.nextreports.server.domain.DashboardState"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@className='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " dashboard state nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.setProperty("columnCount", 2); } getTemplate().save(); }
Example 4
Source File: StorageUpdate12.java From nextreports-server with Apache License 2.0 | 6 votes |
private void addRuntimeNameProperty() throws RepositoryException { String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + "//*[@className='ro.nextreports.server.domain.Report']" + "//*[fn:name()='parametersValues']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("RuntimeHistory : Found " + nodes.getSize() + " parameterValues nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); NodeIterator childrenIt = node.getNodes(); while (childrenIt.hasNext()) { Node child = childrenIt.nextNode(); child.setProperty("runtimeName", child.getName()); } } getTemplate().save(); }
Example 5
Source File: StorageUpdate15.java From nextreports-server with Apache License 2.0 | 6 votes |
private void updateTemplateNodes() throws RepositoryException { // add shortcutType node to all report templates nodes String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + "//*[@className='ro.nextreports.server.domain.Report']/templates"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Add shortcutType node to all report templates nodes : Found " + nodes.getSize() + " report nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); NodeIterator templatesForReport = node.getNodes(); while (templatesForReport.hasNext()) { Node template = templatesForReport.nextNode(); Node shortcutTypeNode = template.addNode("shortcutType"); shortcutTypeNode.setProperty("type", 0); shortcutTypeNode.setProperty("timeType", 0); shortcutTypeNode.setProperty("timeUnits", 0); } } getTemplate().save(); }
Example 6
Source File: StorageUpdate6.java From nextreports-server with Apache License 2.0 | 6 votes |
private void addAnalystUserProfile() throws RepositoryException { LOG.info("User profile analyst"); String path = StorageConstants.USERS_ROOT ; String className = "ro.nextreports.server.domain.User"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@className='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.setProperty("profile", "analyst"); } getTemplate().save(); }
Example 7
Source File: StorageUpdate8.java From nextreports-server with Apache License 2.0 | 6 votes |
private void updateInternalSettings() throws RepositoryException { // find all internalSettings nodes from DASHBOARDS and change chartId property in entityId String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.DASHBOARDS_ROOT) + "//*[fn:name()='internalSettings']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " internalSettings nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); try { Property prop = node.getProperty("chartId"); node.setProperty("entityId", prop.getValue()); prop.remove(); } catch (PathNotFoundException ex) { // if property not found we have nothing to do } } }
Example 8
Source File: StorageUpdate3.java From nextreports-server with Apache License 2.0 | 6 votes |
private void renameChartWidgetClassName() throws RepositoryException { LOG.info("Rename chart widget class name"); String path = StorageConstants.DASHBOARDS_ROOT; String className = "ro.nextreports.server.web.chart.ChartWidget"; String newClassName = "ro.nextreports.server.web.dashboard.chart.ChartWidget"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@widgetClassName='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.setProperty("widgetClassName", newClassName); } getTemplate().save(); }
Example 9
Source File: StorageUpdate20.java From nextreports-server with Apache License 2.0 | 5 votes |
private void renamePackage(String path, String propertyName) throws RepositoryException { String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@" + propertyName + "]"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " entity nodes with property '" + propertyName + "'"); while (nodes.hasNext()) { renamePackage(nodes.nextNode(), propertyName); } }
Example 10
Source File: StorageUpdate11.java From nextreports-server with Apache License 2.0 | 5 votes |
private void convertReports() throws RepositoryException { String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + "//*[@className='ro.nextreports.server.domain.Report' and @type='Next']" + "//*[fn:name()='jcr:content' and @jcr:mimeType='text/xml']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Converter 5.1 : Found " + nodes.getSize() + " report nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); Node reportNode = node.getParent().getParent().getParent().getParent(); String reportName = reportNode.getName(); String reportPath = reportNode.getPath(); LOG.info(" * Start convert '" + reportPath + "'"); Property prop = node.getProperty("jcr:data"); String xml = null; try { xml = new Converter_5_2().convertFromInputStream(prop.getBinary().getStream(), true); if (xml != null) { ValueFactory valueFactory = node.getSession().getValueFactory(); Binary binaryValue = valueFactory.createBinary(new ByteArrayInputStream(xml.getBytes("UTF-8"))); node.setProperty ("jcr:data", binaryValue); LOG.info("\t -> OK"); } else { LOG.error("\t -> FAILED : null xml"); } } catch (Throwable t) { LOG.error("\t-> FAILED : " + t.getMessage(), t); } } }
Example 11
Source File: CatalogDataResourceProviderManagerImpl.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
/** * Find all existing virtual catalog data roots using all query defined in service configuration. * * @param resolver Resource resolver * @return all virtual catalog roots */ @SuppressWarnings("unchecked") private List<Resource> findDataRoots(ResourceResolver resolver) { List<Resource> allResources = new ArrayList<>(); for (String queryString : this.findAllQueries) { if (!StringUtils.contains(queryString, "|")) { throw new IllegalArgumentException("Query string does not contain query syntax seperated by '|': " + queryString); } String queryLanguage = StringUtils.substringBefore(queryString, "|"); String query = StringUtils.substringAfter(queryString, "|"); // data roots are JCR nodes, so we prefer JCR query because the resource resolver appears to be unreliable // when we are in the middle of registering/unregistering resource providers try { Session session = resolver.adaptTo(Session.class); Workspace workspace = session.getWorkspace(); QueryManager qm = workspace.getQueryManager(); Query jcrQuery = qm.createQuery(query, queryLanguage); QueryResult result = jcrQuery.execute(); NodeIterator nodes = result.getNodes(); while (nodes.hasNext()) { Node node = nodes.nextNode(); Resource resource = resolver.getResource(node.getPath()); if (resource != null) { allResources.add(resource); } } } catch (RepositoryException x) { log.error("Error finding data roots", x); } } dataRoots = allResources; return allResources; }
Example 12
Source File: StorageUpdater.java From nextreports-server with Apache License 2.0 | 5 votes |
private void resetFirstUsageDates() throws Exception { LOG.info("Reset firstUsage.date for all users"); String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.USERS_ROOT) + "//*[@className='ro.nextreports.server.domain.UserPreferences']"; QueryResult queryResult = jcrTemplate.query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " user preferences nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); Node pNode = node.getNode("preferences"); try { Property property = pNode.getProperty("firstUsage.date"); if (property.getValue() != null) { LOG.info(" removed firstUsage.date = " + property.getString() + " for user " + node.getParent().getName()); String s = null; pNode.setProperty("firstUsage.date", s); } } catch (PathNotFoundException ex) { // nothing to do } } jcrTemplate.save(); }
Example 13
Source File: StorageUpdate7.java From nextreports-server with Apache License 2.0 | 5 votes |
private void addDestinations() throws RepositoryException { LOG.info("Add destinations to scheduler jobs"); String path = StorageConstants.SCHEDULER_ROOT ; String className = "ro.nextreports.server.domain.SchedulerJob"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@className='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " scheduler job nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); if (node.hasNode("mail")) { LOG.info("Found 'mail' node for '" + node.getName() + "'"); Node mailNode = node.getNode("mail"); LOG.info("Create '" + StorageConstants.DESTINATIONS + "' node for '" + node.getName() + "'"); Node destinationsNode = node.addNode(StorageConstants.DESTINATIONS); className = SmtpDestination.class.getName(); LOG.info("Change 'className' property for 'mail' node to '" + className + "'"); mailNode.setProperty("className", className); LOG.info("Move '" + mailNode.getName() + "' to '" + destinationsNode.getName() + "/mail"); getTemplate().move(mailNode.getPath(), destinationsNode.getPath() + "/mail"); } } getTemplate().save(); }
Example 14
Source File: StorageUpdate18.java From nextreports-server with Apache License 2.0 | 5 votes |
private void onUpdate() throws RepositoryException { String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.DATASOURCES_ROOT) + "//*[@className='ro.nextreports.server.domain.DataSource']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " data sources nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); Node propertiesNode = node.addNode(StorageConstants.PROPERTIES); } getTemplate().save(); }
Example 15
Source File: StorageUpdate13.java From nextreports-server with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void createNodeTemplates() throws RepositoryException { Session session = SessionFactoryUtils.getSession(getTemplate().getSessionFactory(), false); Workspace workspace = session.getWorkspace(); NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager(); // nodeTypeManager.unregisterNodeType(StorageConstants.NEXT_REPORT_MIXIN); NodeTypeTemplate nodeTypeTemplate = nodeTypeManager.createNodeTypeTemplate(); nodeTypeTemplate.setName(StorageConstants.NEXT_REPORT_MIXIN); nodeTypeTemplate.setMixin(true); nodeTypeTemplate.setOrderableChildNodes(false); nodeTypeTemplate.setPrimaryItemName("nt:unstructured"); nodeTypeTemplate.setDeclaredSuperTypeNames(new String[] { "mix:referenceable", "mix:versionable" }); NodeDefinitionTemplate nodeDefinitionTemplate = nodeTypeManager.createNodeDefinitionTemplate(); nodeDefinitionTemplate.setName("runHistory"); nodeDefinitionTemplate.setDefaultPrimaryTypeName("nt:unstructured"); nodeDefinitionTemplate.setRequiredPrimaryTypeNames(new String[] { "nt:unstructured" }); nodeDefinitionTemplate.setAutoCreated(true); nodeDefinitionTemplate.setMandatory(false); nodeDefinitionTemplate.setOnParentVersion(OnParentVersionAction.IGNORE); nodeDefinitionTemplate.setProtected(false); nodeDefinitionTemplate.setSameNameSiblings(false); nodeTypeTemplate.getNodeDefinitionTemplates().add(nodeDefinitionTemplate); NodeDefinitionTemplate nodeDefinitionTemplate2 = nodeTypeManager.createNodeDefinitionTemplate(); nodeDefinitionTemplate2.setName("templates"); nodeDefinitionTemplate2.setDefaultPrimaryTypeName("nt:unstructured"); nodeDefinitionTemplate2.setRequiredPrimaryTypeNames(new String[] { "nt:unstructured" }); nodeDefinitionTemplate2.setAutoCreated(true); nodeDefinitionTemplate2.setMandatory(false); nodeDefinitionTemplate2.setOnParentVersion(OnParentVersionAction.IGNORE); nodeDefinitionTemplate2.setProtected(false); nodeDefinitionTemplate2.setSameNameSiblings(false); nodeTypeTemplate.getNodeDefinitionTemplates().add(nodeDefinitionTemplate2); LOG.info("Registering node type mixin '" + StorageConstants.NEXT_REPORT_MIXIN + "'"); nodeTypeManager.registerNodeType(nodeTypeTemplate, true); // add templates node to all existing reports String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + "//*[@className='ro.nextreports.server.domain.Report']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Create templates nodes : Found " + nodes.getSize() + " report nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.addNode("templates"); } getTemplate().save(); }
Example 16
Source File: StorageUpdate.java From nextreports-server with Apache License 2.0 | 4 votes |
protected NodeIterator getNodesByClassName(String className) throws Exception { String statement = "/jcr:root" + StorageConstants.NEXT_SERVER_ROOT + "//*[@className='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); return queryResult.getNodes(); }
Example 17
Source File: StorageUpdate16.java From nextreports-server with Apache License 2.0 | 4 votes |
private void changeDemoSettings() throws RepositoryException { // change demo database path (depends on installation selection) String path = StorageConstants.DATASOURCES_ROOT ; String statement = "/jcr:root" + ISO9075.encodePath(path) + "/demo/Demo"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " Demo data source"); if (nodes.hasNext()) { Node node = nodes.nextNode(); String oldUrl = node.getProperty("url").getString(); int index = oldUrl.indexOf(";"); String prefix = "jdbc:derby:"; String urlPath = oldUrl.substring(prefix.length(), index); String newUrlPath = System.getProperty("nextserver.home") + "/demo/data"; node.setProperty("url", prefix + newUrlPath + oldUrl.substring(index)); LOG.info("Change Demo old url '" + oldUrl + "' with new url '" + newUrlPath + "'"); } // change properties from installer (base url, reports home, http port) in demo data JCR (see StorageUpdate9) String settingsPath = StorageConstants.SETTINGS_ROOT ; String settingsStatement = "/jcr:root" + ISO9075.encodePath(settingsPath); QueryResult settingsQueryResult = getTemplate().query(settingsStatement); NodeIterator settingsNodes = settingsQueryResult.getNodes(); if (settingsNodes.hasNext()) { Node settingsNode = settingsNodes.nextNode(); String baseUrl = NextServerConfiguration.get().getConfiguration().getString("nextserver.baseUrl", "http://localhost:8081"); settingsNode.setProperty(StorageConstants.BASE_URL, baseUrl); LOG.info("Set Base Url : " + baseUrl); String home; // reports.home property can be found only in property file till version 4.2 if (NextServerConfiguration.get().getConfiguration().containsKey("reports.home")) { home = NextServerConfiguration.get().getConfiguration().getString("reports.home", "./reports"); } else { // if not found we use installer property home = NextServerConfiguration.get().getConfiguration().getString("nextserver.home", ".") + "/reports"; } settingsNode.setProperty(StorageConstants.REPORTS_HOME, home); LOG.info("Set Reports Home : " + home); // http port modified in installer boolean httpModified = !baseUrl.contains("8081"); String reportsUrl; if (httpModified) { reportsUrl = baseUrl + "/reports"; } else { reportsUrl = NextServerConfiguration.get().getConfiguration().getString("reports.url", "http://localhost:8081/reports"); } settingsNode.setProperty(StorageConstants.REPORTS_URL, reportsUrl); LOG.info("Set Reports Url : " + reportsUrl); } getTemplate().save(); }