Package org.modeshape.jcr.api

Examples of org.modeshape.jcr.api.JcrTools


    }

    @Test
    @FixFor( "MODE-1978" )
    public void shouldAllowRemovingArtifactWithNoExistingTrash() throws Exception {
        JcrTools tools = new JcrTools();
        // print = true;

        // Register the node types ...
        registerNodeTypes("cnd/sramp.cnd");

        UUID uuid = UUID.randomUUID();
        Node artifacts = tools.findOrCreateNode(session, "/sramp/artifacts", "nt:folder");
        session.save();

        Node artifact = artifacts.addNode(uuid.toString(), "sramp:nonDocumentArtifactType");
        printMessage("Added artifact node: " + artifact);
        artifact.addMixin("sramp:xsdDocument");
        artifact.setProperty("sramp:uuid", uuid.toString());
        Node artifactChild = artifact.addNode("child", "sramp:derivedArtifactPrimaryType");
        printMessage("Added child node: " + artifactChild);
        artifactChild.addMixin("sramp:elementDeclaration");
        artifactChild.setProperty("sramp:uuid", UUID.randomUUID().toString());
        session.save();

        // Now "remove" it by removing the doc type mixins, adding the "deleted" mixin, and moving it to a different area ...
        artifact.addMixin("sramp:deletedArtifact");
        artifact.removeMixin("sramp:xsdDocument");
        artifactChild.addMixin("sramp:deletedArtifact");
        artifactChild.removeMixin("sramp:elementDeclaration");

        String srcPath = artifact.getPath();
        String trashPath = srcPath.replace("sramp", "sramp-trash");
        String parentSrcPath = artifacts.getPath();
        String parentTrashPath = parentSrcPath.replace("sramp", "sramp-trash");

        Node artifactTrash = tools.findOrCreateNode(session, parentTrashPath, "nt:folder");
        print(artifactTrash);

        session.move(srcPath, trashPath);
        session.save();
    }
View Full Code Here


                AbstractJcrNode parentOfOutput = null;
                try {
                    parentOfOutput = outputSession.getNode(work.getOutputPath());
                } catch (PathNotFoundException e) {
                    LOGGER.trace("Creating missing output path for {0}", logMsg);
                    JcrTools tools = new JcrTools();
                    parentOfOutput = (AbstractJcrNode)tools.findOrCreateNode(outputSession, work.getOutputPath());
                }

                // Now determine the name of top node in the output, using the last segment of the selected path ...
                String outputNodeName = computeOutputNodeName(selectedNode);
View Full Code Here

    }

    @Test
    @FixFor("MODE-1573")
    public void shouldPerformRoundTripOnDocumentViewWithBinaryContent() throws Exception {
        JcrTools tools = new JcrTools();

        File binaryFile = new File("src/test/resources/io/binary.pdf");
        assert (binaryFile.exists() && binaryFile.isFile());

        File outputFile = File.createTempFile("modeshape_import_export_" + System.currentTimeMillis(), "_test");
        outputFile.deleteOnExit();
        tools.uploadFile(session, "file", binaryFile);
        session.save();
        session.exportDocumentView("/file", new FileOutputStream(outputFile), false, false);
        assertTrue(outputFile.length() > 0);

        session.getRootNode().getNode("file").remove();
View Full Code Here

        sessC.importXML("/", brixWorkspace, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
        sessC.save();

        // re-import
        if (print) {
            new JcrTools().printSubgraph(sessA.getNode(root));
        }
        sessA.getItem(root).remove();
        sessA.save();

        brixWorkspace = resourceStream("io/brixWorkspace.xml");
View Full Code Here

    private Projection[] projections;
    private JcrTools tools;

    @Before
    public void before() throws Exception {
        tools = new JcrTools();
        readOnlyProjection = new Projection("readonly-files", "target/federation/files-read");
        readOnlyProjectionWithExclusion = new Projection("readonly-files-with-exclusion",
                                                         "target/federation/files-read-exclusion");
        readOnlyProjectionWithInclusion = new Projection("readonly-files-with-inclusion",
                                                         "target/federation/files-read-inclusion");
View Full Code Here

            System.exit(-1);
            return;
        }

        Session session = null;
        JcrTools tools = new JcrTools();
        try {
            // Get the repository
            repository = engine.getRepository(repositoryName);

            // Create a session ...
            session = repository.login("default");

            // Create the '/files' node that is an 'nt:folder' ...
            Node root = session.getRootNode();
            Node filesNode = root.addNode("files", "nt:folder");
            assert filesNode != null;

            // Update a couple of files ...
            tools.uploadFile(session, "/files/caution.png", getFile("caution.png"));
            tools.uploadFile(session, "/files/sample1.mp3", getFile("sample1.mp3"));
            tools.uploadFile(session, "/files/fixedWidthFile.txt", getFile("fixedWidthFile.txt"));
            tools.uploadFile(session, "/files/JcrRepository.class", getFile("JcrRepository.clazz"));

            // Save the session ...
            session.save();

            // Now look for the output. Note that sequencing may take a bit, so we'll cheat by just trying
            // to find the node until we can find it, waiting a maximum amount of time before failing.
            // The proper way is to either use events or not to expect the sequencers have finished.
            Node png = findNodeAndWait(session, "/images/caution.png", 10, TimeUnit.SECONDS);
            if (print) tools.printSubgraph(png);

            Node sampleMp3 = findNodeAndWait(session, "/audio/sample1.mp3", 10, TimeUnit.SECONDS);
            if (print) tools.printSubgraph(sampleMp3);

            Node javaClass = findNodeAndWait(session, "/java/JcrRepository.class", 10, TimeUnit.SECONDS);
            if (print) tools.printSubgraph(javaClass);

            Node textFile = findNodeAndWait(session, "/text/fixedWidthFile.txt", 10, TimeUnit.SECONDS);
            if (print) tools.printSubgraph(textFile);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null) session.logout();
View Full Code Here

        assertTrue(subFolder.exists());
        assertTrue(subFolder.isDirectory());

        //now add a file
        ByteArrayInputStream bis = new ByteArrayInputStream("test string".getBytes());
        new JcrTools().uploadFile(session, "/root/sub_folder/file", bis);
        session.save();
        File file = new File(subFolder, "file");
        assertTrue(file.exists());
        assertTrue(file.isFile());
        assertEquals("test string", IoUtil.read(file));
View Full Code Here

            assertThat(testFile.getPath() + " should be a file", testFile.isFile(), is(true));
            assertThat(testFile.getPath() + " should be readable", testFile.canRead(), is(true));
            testFileSizesInBytes.put(testFile.getName(), testFile.length());
        }

        final JcrTools tools = new JcrTools();

        startRunStop(new RepositoryOperation() {
            @Override
            public Void call() throws Exception {
                Session session = repository.login();

                // Add some content ...
                session.getRootNode().addNode("testNode");
                for (File testFile : testFiles) {
                    String name = testFile.getName();
                    Node fileNode = tools.uploadFile(session, "/testNode/" + name, testFile);
                    Binary binary = fileNode.getNode("jcr:content").getProperty("jcr:data").getBinary();
                    assertThat(binary.getSize(), is(testFileSizesInBytes.get(name)));
                }

                session.save();
View Full Code Here

    public void beforeEach() throws Exception {
        super.beforeEach();
        if (startRepositoryAutomatically()) {
            startRepository();
        }
        tools = new JcrTools();
    }
View Full Code Here

        }
    }

    protected void printSubgraph( Node node ) throws RepositoryException {
        if (print) {
            JcrTools tools = new JcrTools();
            tools.printSubgraph(node);
        }
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.api.JcrTools

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.