Refine search
/** * Returns the primary package root. If the root does not exist yet and {@code autoCreate} is {@code true} it will * be created. * * @param autoCreate if {@code true} the roots are created if missing. * @return the the package root or {@code null} * @throws RepositoryException if an error occurs. */ @Nullable public Node getPrimaryPackageRoot(boolean autoCreate) throws RepositoryException { if (packRoots[0] == null) { if (session.nodeExists(packRootPaths[0])) { packRoots[0] = session.getNode(packRootPaths[0]); } else if (autoCreate) { if (session.hasPendingChanges()) { throw new RepositoryException("Unwilling to create package root folder while session has transient changes."); } packRoots[0] = JcrUtils.getOrCreateByPath(packRootPaths[0], NodeType.NT_FOLDER, NodeType.NT_FOLDER, session, true); } } return packRoots[0]; }
/** * Returns the default repository of the current environment. * Implemented by calling {@link #getRepository(Map)} with a * <code>null</code> parameter map. * * @see RepositoryFactory#getRepository(Map) * @return default repository * @throws RepositoryException if a default repository is not available * or can not be accessed */ public static Repository getRepository() throws RepositoryException { return getRepository((Map<String, String>) null); }
public static void uploadStream(Resource resource, InputStream stream) throws RepositoryException { Node parent = resource.adaptTo(Node.class); Node file = JcrUtils.getOrAddNode(parent, "bin", NodeType.NT_FILE); Node content = JcrUtils.getOrAddNode(file, Node.JCR_CONTENT, NodeType.NT_RESOURCE); Binary binary = parent.getSession().getValueFactory().createBinary(stream); content.setProperty(Property.JCR_DATA, binary); JcrUtils.getOrAddNode(parent, "refs", NodeType.NT_UNSTRUCTURED); }
private Collection<String> getNodeNames( String path, String nodeType ) throws MetadataResolutionException { List<String> names = new ArrayList<>(); try { Node root = getJcrSession().getRootNode(); Node nodeAtPath = root.getNode( path ); for ( Node node : JcrUtils.getChildNodes( nodeAtPath ) ) { if ( node.isNodeType( nodeType ) ) { names.add( node.getName() ); } } } catch ( PathNotFoundException e ) { // ignore repo not found for now } catch ( RepositoryException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } return names; }
if (node.hasNode("multiReference")) { node.getNode("multiReference").remove(); if (node.hasNode("resReference")) { Node multiReference = node.addNode("multiReference"); ValueFactory factory = node.getSession().getValueFactory(); multiReference.setProperty("ref", new Value[] { factory.createValue(resource), JcrUtils.putFile( node, "testFile", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes(StandardCharsets.UTF_8)));
if (node != null) { try (FileInputStream stream = new FileInputStream(file)) { if (node.isNodeType(JcrConstants.NT_FILE)) { targetParent = node.getParent(); targetName = node.getName(); Calendar nodeLastMod = JcrUtils.getLastModified(node); if (!nodeLastMod.before(fileLastMod)) { log.info("File '{}' does not have a newer timestamp than '{}'. Skipping import.", if (targetParent.hasNode(targetName)) { Node targetNode = targetParent.getNode(targetName); Calendar nodeLastMod = JcrUtils.getLastModified(targetNode); if (!nodeLastMod.before(fileLastMod)) { log.info("File '{}' does not have a newer timestamp than '{}'. Skipping import.", JcrUtils.putFile(targetParent, targetName, mimeType, stream); node.getSession().save(); } catch (RepositoryException e) { throw new ImportException("Unable to import from file '" + dataSource + "' to '"
String filePath; try { Node parent = testRootNode.addNode("parent"); Node n = JcrUtils.putFile(parent, "file", "text/plain", new ByteArrayInputStream("data".getBytes())); parentPath = parent.getPath(); filePath = n.getPath(); superuser.save(); } catch (RepositoryException e) { throw new NotExecutableException(); Node n1 = s.getNode(filePath); Node n2 = n1.getNode("jcr:content"); n2.setProperty("jcr:data", new java.io.ByteArrayInputStream("data2".getBytes())); s.move(parentPath, destPath); s.save(); } else {
@Override protected void setUp() throws Exception { super.setUp(); for (Node c : JcrUtils.getChildNodes(testRootNode)) { testRootNode.getSession().removeItem(c.getPath()); } testRootNode.getSession().save(); }
/** * Returns the last modified date of the given file node. The value is * read from the jcr:lastModified property of this node or alternatively * from a jcr:content child node. * * @since Apache Jackrabbit 2.3 * @param node file node * @return last modified date, or <code>null</code> if not available * @throws RepositoryException if the last modified date can not be accessed */ public static Calendar getLastModified(Node node) throws RepositoryException { if (node.hasProperty(Property.JCR_LAST_MODIFIED)) { return node.getProperty(Property.JCR_LAST_MODIFIED).getDate(); } else if (node.hasNode(Node.JCR_CONTENT)) { return getLastModified(node.getNode(Node.JCR_CONTENT)); } else { return null; } }
public void testNtFile() throws RepositoryException, IOException { while (testRootNode.hasNode(nodeName1)) { testRootNode.getNode(nodeName1).remove(); } String content = "The quick brown fox jumps over the lazy dog."; Node file = JcrUtils.putFile(testRootNode, nodeName1, "text/plain", new ByteArrayInputStream(content.getBytes("UTF-8"))); testRootNode.getSession().save(); String xpath = testPath + "/*[jcr:contains(jcr:content, 'lazy')]"; executeXPathQuery(xpath, new Node[] { file }); }
@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()); }
@Override public Collection<String> getArtifactVersions( String repositoryId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException { Set<String> versions = new LinkedHashSet<String>(); try { Node root = getJcrSession().getRootNode(); Node node = root.getNode( getProjectVersionPath( repositoryId, namespace, projectId, projectVersion ) ); for ( Node n : JcrUtils.getChildNodes( node ) ) { versions.add( n.getProperty( "version" ).getString() ); } } catch ( PathNotFoundException e ) { // ignore repo not found for now } catch ( RepositoryException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } return versions; }
QueryManager queryManager = session.getWorkspace().getQueryManager(); for ( Row row : JcrUtils.getRows( queryResult ) ) if ( n.hasNode( MavenArtifactFacet.FACET_ID ) ) Node facetNode = n.getNode( MavenArtifactFacet.FACET_ID ); type = facetNode.getProperty( "type" ).getString(); throw new MetadataRepositoryException( e.getMessage(), e );
@Override public void run() { try { parent.getSession().refresh(false); Node file = JcrUtils.putFile( parent, "file-" + counter++, "application/octet-stream", new TestInputStream(FILE_SIZE * 1024)); parent.getSession().save(); addPath(file.getPath()); } catch (Exception e) { e.printStackTrace(); } }
@SuppressWarnings("deprecation") @Test public void nodeTypeConstraint() throws Exception { Session session = getAdminSession(); Node root = session.getRootNode(); Node folder1 = root.addNode("folder1", "nt:folder"); Node folder2 = root.addNode("folder2", "nt:folder"); JcrUtils.putFile(folder1, "file", "text/plain", new ByteArrayInputStream("foo bar".getBytes("UTF-8"))); folder2.addNode("folder3", "nt:folder"); session.save(); QueryManager qm = session.getWorkspace().getQueryManager(); Query q = qm.createQuery("//element(*, nt:folder)", Query.XPATH); Set<String> paths = new HashSet<String>(); for (RowIterator it = q.execute().getRows(); it.hasNext();) { paths.add(it.nextRow().getPath()); } assertEquals(new HashSet<String>(Arrays.asList("/folder1", "/folder2", "/folder2/folder3")), paths); }
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(); }
@Override public Object call() throws Exception { try { Node testRoot = session.getNode(p); createChildren(testRoot, 100); for (Node m : JcrUtils.getChildNodes(testRoot)) { createChildren(m, 100 / WRITER_COUNT); for (Node n : JcrUtils.getChildNodes(m)) { createChildren(n, 5); } } session.save(); } finally { session.logout(); } return null; }
private void basicCrudTest(Repository repository) throws RepositoryException { Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); Node rootNode = session.getRootNode(); Node child = JcrUtils.getOrAddNode(rootNode, "child", "oak:Unstructured"); child.setProperty("foo3", "bar3"); session.logout(); System.out.println("Basic test passed"); }
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(); }