private Node getOrCreateUserNode(Session session, String userName) throws RepositoryException { String userNodePath = WORKSPACE_PATH + userName; return JcrUtils.getOrCreateByPath(userNodePath, USER_NODE_TYPE, session); }
public Node getBucketNode() throws RepositoryException { final String[] pathArray = getPathArray(); Node targetNode = cacheRoot; for(String path : pathArray){ Node childNode = JcrUtils.getOrCreateByPath(targetNode, path,false,OAK_UNSTRUCTURED, OAK_UNSTRUCTURED,false); if(!childNode.hasProperty(PN_ISBUCKETNODE)){ childNode.setProperty(PN_ISBUCKETNODE, true); } targetNode = childNode; } return targetNode; }
private Node getOrCreateMessageNode(Session session, String userName, Message message) throws RepositoryException { String messageNodePath = WORKSPACE_PATH + userName + "/" + message.getId(); return JcrUtils.getOrCreateByPath(messageNodePath, false, USER_NODE_TYPE, MESSAGE_NODE_TYPE, session, false); }
/** * Save the headers into a headers node under the cache entry node. * @throws RepositoryException */ private void populateHeaders() throws RepositoryException { final Node headers = JcrUtils.getOrCreateByPath(entryNode, JCRHttpCacheStoreConstants.PATH_HEADERS, false, OAK_UNSTRUCTURED, OAK_UNSTRUCTURED, false); for(Iterator<Map.Entry<String, List<String>>> entryIterator = cacheContent.getHeaders().entrySet().iterator(); entryIterator.hasNext();){ Map.Entry<String, List<String>> entry = entryIterator.next(); final String key = entry.getKey(); final List<String> values = entry.getValue(); headers.setProperty(key, values.toArray(new String[values.size()])); } }
@Override protected void createSourceContent(Session session) throws RepositoryException { JcrUtils.getOrCreateByPath("/left/child1/grandchild1", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/left/child1/grandchild2", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/left/child1/grandchild3", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/left/child2/grandchild1", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/left/child2/grandchild2", "nt:unstructured", session); session.save(); }
protected void createSourceContent2(Session session) throws RepositoryException { JcrUtils.getOrCreateByPath("/left/child2/grandchild3", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/left/child2/grandchild2", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/left/child3", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/right/child1/grandchild1", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/right/child1/grandchild2", "nt:unstructured", session); session.save(); }
@Override protected void createSourceContent(Session session) throws RepositoryException { registerCustomPrivileges(session); JcrUtils.getOrCreateByPath("/content/child1/grandchild1", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/content/child1/grandchild2", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/content/child1/grandchild3", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/content/child2/grandchild1", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/content/child2/grandchild2", "nt:unstructured", session); session.save(); }
/** * Save the inputstream to a binary property under the cache entry node. * @throws RepositoryException */ private void populateBinaryContent() throws RepositoryException { final Node contents = JcrUtils.getOrCreateByPath(entryNode, JCRHttpCacheStoreConstants.PATH_CONTENTS, false, JcrConstants.NT_FILE, JcrConstants.NT_FILE, false); final Node jcrContent = JcrUtils.getOrCreateByPath(contents, JcrConstants.JCR_CONTENT, false, JcrConstants.NT_RESOURCE, JcrConstants.NT_RESOURCE, false); //save input stream to node final Binary binary = session.getValueFactory().createBinary(cacheContent.getInputDataStream()); jcrContent.setProperty(JcrConstants.JCR_DATA, binary); jcrContent.setProperty(JcrConstants.JCR_MIMETYPE, cacheContent.getContentType()); }
protected void modifySourceContent(Session session) throws RepositoryException { JcrUtils.getOrCreateByPath("/content/child2/grandchild3", "nt:unstructured", session); JcrUtils.getOrCreateByPath("/content/child3", "nt:unstructured", session); final Node child1 = JcrUtils.getOrCreateByPath("/content/child1", "nt:unstructured", session); child1.remove(); session.save(); }
private void configureBundling() throws ParseException, RepositoryException, IOException { CndImporter.registerNodeTypes(new StringReader(TEST_NODE_TYPE), s); Node bundlor = JcrUtils.getOrCreateByPath(BundlingConfigHandler.CONFIG_PATH, "oak:Unstructured", s); Node asset = bundlor.addNode("oak:Asset"); asset.setProperty(PROP_PATTERN, new String[]{ "jcr:content", "jcr:content/metadata", "jcr:content/renditions" }); s.save(); }
protected void addTestContent(RepositoryFixture fixture, String basePath, String propName, int count) throws IOException, RepositoryException { Session session = fixture.getAdminSession(); for (int i = 0; i < count; i++) { getOrCreateByPath(basePath+i, "oak:Unstructured", session).setProperty(propName, "bar"); } session.save(); session.logout(); }
public void setUp() throws Exception { super.setUp(); Node node = JcrUtils.getOrCreateByPath(PATH_EXISTING_NODE, "nt:unstructured", superuser); node.setProperty(NAME_EXISTING_PROPERTY, "value"); superuser.save(); }
public void addFailure(String payloadPath, String trackPath, Calendar failedAt) throws RepositoryException { Node failure = JcrUtils.getOrCreateByPath(resource.getChild(Workspace.NN_FAILURES).adaptTo(Node.class), Workspace.NN_FAILURE, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false); JcrUtil.setProperty(failure, Failure.PN_PAYLOAD_PATH, payloadPath); if (StringUtils.isNotBlank(trackPath)) { JcrUtil.setProperty(failure, Failure.PN_PATH, Payload.dereference(trackPath)); } if (failedAt != null) { JcrUtil.setProperty(failure, Failure.PN_FAILED_AT, failedAt); } }
public void addFailure(String payloadPath, String trackPath, Calendar failedAt) throws RepositoryException { Node failure = JcrUtils.getOrCreateByPath(resource.getChild(Workspace.NN_FAILURES).adaptTo(Node.class), Workspace.NN_FAILURE, true, Workspace.NT_UNORDERED, Workspace.NT_UNORDERED, false); JcrUtil.setProperty(failure, Failure.PN_PAYLOAD_PATH, payloadPath); if (StringUtils.isNotBlank(trackPath)) { JcrUtil.setProperty(failure, Failure.PN_PATH, Payload.dereference(trackPath)); } if (failedAt != null) { JcrUtil.setProperty(failure, Failure.PN_FAILED_AT, failedAt); } }
@Test public void insecureFacets() throws Exception { Node facetConfig = getOrCreateByPath(indexNode.getPath() + "/" + FACETS, "nt:unstructured", session); facetConfig.setProperty(PROP_SECURE_FACETS, PROP_SECURE_FACETS_VALUE_INSECURE); indexNode.setProperty(PROP_REFRESH_DEFN, true); session.save(); createLargeDataset(); assertEquals(actualLabelCount, getFacets()); }
@Test public void secureFacets_withAdminSession() throws Exception { Node facetConfig = getOrCreateByPath(indexNode.getPath() + "/" + FACETS, "nt:unstructured", session); facetConfig.setProperty(PROP_SECURE_FACETS, PROP_SECURE_FACETS_VALUE_INSECURE); indexNode.setProperty(PROP_REFRESH_DEFN, true); session.save(); createLargeDataset(); qe = session.getWorkspace().getQueryManager(); assertEquals(actualLabelCount, getFacets()); }
@Test public void createVersionedNode() throws Exception{ Node asset = JcrUtils.getOrCreateByPath("/bundlingtest/foo.png", "oak:Unstructured", "oak:Asset", s, false); asset.addMixin(JcrConstants.MIX_VERSIONABLE); Node content = asset.addNode("jcr:content", "oak:Unstructured"); content.addNode("metadata", "oak:Unstructured"); s.save(); VersionManager vm = s.getWorkspace().getVersionManager(); String assetPath = asset.getPath(); vm.checkin(assetPath); String versionedPath = vm.getBaseVersion(assetPath).getNode("jcr:frozenNode").getPath(); //Both normal node and versioned nodes should be bundled assertNull(getNodeDocument(concat(assetPath, "jcr:content"))); assertNull(getNodeDocument(concat(versionedPath, "jcr:content"))); }
@Test public void indexExternalChange() throws Exception{ Node a = JcrUtils.getOrCreateByPath("/b", "oak:Unstructured", s1); a.setProperty("foo", "x"); s1.save(); assertThat(queryResult(s1, "foo", "x"), containsInAnyOrder("/a", "/b")); //on C2 /b would not be part of index assertThat(queryResult(s2, "foo", "x"), containsInAnyOrder("/a")); asDS(ns1).runBackgroundOperations(); asDS(ns2).runBackgroundOperations(); //Now the external change should be picked up and reflect in query result assertThat(queryResult(s2, "foo", "x"), containsInAnyOrder("/a", "/b")); }
@Override protected void prepareTestData(Session s) throws RepositoryException { nswb1.register(JournalPropertyService.class, new LuceneJournalPropertyService(1000), null); nswb2.register(JournalPropertyService.class, new LuceneJournalPropertyService(1000), null); IndexDefinitionBuilder idx = new IndexDefinitionBuilder(); idx.indexRule("nt:base").property("foo").propertyIndex(); idx.async("async", "sync"); Node idxNode = JcrUtils.getOrCreateByPath("/oak:index/fooIndex", "oak:QueryIndexDefinition", s); idx.build(idxNode); Node a = JcrUtils.getOrCreateByPath("/a", "oak:Unstructured", s); a.setProperty("foo", "x"); s.save(); runAsyncIndex(w1); }
private void createIndex() throws RepositoryException { IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder(); idxBuilder.noAsync().evaluatePathRestrictions() .indexRule("nt:base") .property("cons") .propertyIndex() .property("foo") .getBuilderTree().setProperty(PROP_FACETS, true); indexNode = getOrCreateByPath("/oak:index", "nt:unstructured", session) .addNode("index", INDEX_DEFINITIONS_NODE_TYPE); idxBuilder.build(indexNode); session.save(); }