Search in sources :

Example 76 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class CopyCollectionTest method copyCol.

private void copyCol(final Subject execAsUser, final DBBroker.PreserveType preserve, final XmldbURI srcColName, final XmldbURI destColName) throws EXistException, PermissionDeniedException, LockException, IOException, TriggerException {
    final XmldbURI src = TEST_COLLECTION_URI.append(srcColName);
    final XmldbURI dest = TEST_COLLECTION_URI.append(destColName);
    final BrokerPool pool = existWebServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(execAsUser));
        final Txn transaction = pool.getTransactionManager().beginTransaction();
        final Collection srcCol = broker.openCollection(src, LockMode.READ_LOCK);
        final Collection destCol = broker.openCollection(dest.removeLastSegment(), LockMode.WRITE_LOCK)) {
        broker.copyCollection(transaction, srcCol, destCol, dest.lastSegment(), preserve);
        transaction.commit();
    }
    // basic shallow check that copy of the collection is the same as the original
    try (final DBBroker broker = pool.get(Optional.of(execAsUser));
        final Collection original = broker.openCollection(src, LockMode.READ_LOCK);
        final Collection copy = broker.openCollection(dest, LockMode.READ_LOCK)) {
        assertEquals(original.getDocumentCount(broker), copy.getDocumentCount(broker));
        assertEquals(original.getChildCollectionCount(broker), copy.getChildCollectionCount(broker));
    }
}
Also used : Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) XmldbURI(org.exist.xmldb.XmldbURI)

Example 77 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class MoveCollectionRecoveryTest method store.

private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final String sample;
        try (final InputStream is = SAMPLES.getBiblioSample()) {
            assertNotNull(is);
            sample = InputStreamUtil.readString(is, UTF_8);
        }
        broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test);
        final Collection dest = broker.getOrCreateCollection(transaction, TestConstants.DESTINATION_COLLECTION_URI);
        assertNotNull(dest);
        broker.saveCollection(transaction, dest);
        broker.moveCollection(transaction, test, dest, XmldbURI.create("test3"));
        transact.commit(transaction);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) InputStream(java.io.InputStream) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 78 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class MoveCollectionRecoveryTest method moveToSelfSubCollection.

@Test(expected = PermissionDeniedException.class)
public void moveToSelfSubCollection() throws EXistException, IOException, PermissionDeniedException, TriggerException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection src = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(src);
        broker.saveCollection(transaction, src);
        final Collection dst = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
        assertNotNull(dst);
        broker.saveCollection(transaction, dst);
        broker.moveCollection(transaction, src, dst, src.getURI().lastSegment());
        fail("expect PermissionDeniedException: Cannot move collection '/db/test' to it child collection '/db/test/test2'");
        transact.commit(transaction);
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) Test(org.junit.Test)

Example 79 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class MoveOverwriteCollectionTest method moveAndOverwriteCollection.

/**
 * This test ensures that when moving an Collection over the top of an existing Collection,
 * the overwritten resource is completely removed from the database;
 * i.e. its nodes are no longer present in the structural index
 */
@Test
public void moveAndOverwriteCollection() throws Exception {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Tuple3<Collection, Collection, Collection> collections = store(broker);
        try {
            final DefaultDocumentSet docs = new DefaultDocumentSet();
            docs.add(collections._1.getDocument(broker, doc1Name));
            docs.add(collections._2.getDocument(broker, doc2Name));
            docs.add(collections._3.getDocument(broker, doc3Name));
            moveToRoot(broker, collections._3);
            final Collection col = broker.getCollection(TEST_COLLECTION_URI);
            docs.add(col.getDocument(broker, doc3Name));
            checkIndex(broker, docs);
        } finally {
            collections._3.close();
            collections._2.close();
            collections._1.close();
        }
    }
}
Also used : Collection(org.exist.collections.Collection) Test(org.junit.Test)

Example 80 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class MarshallerTest method startDB.

@BeforeClass
public static void startDB() throws EXistException, DatabaseConfigurationException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection root = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        broker.saveCollection(transaction, root);
        broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(TEST_DOC), MimeType.XML_TYPE, root);
        transact.commit(transaction);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) BeforeClass(org.junit.BeforeClass)

Aggregations

Collection (org.exist.collections.Collection)297 Txn (org.exist.storage.txn.Txn)160 XmldbURI (org.exist.xmldb.XmldbURI)99 DBBroker (org.exist.storage.DBBroker)89 TransactionManager (org.exist.storage.txn.TransactionManager)86 BrokerPool (org.exist.storage.BrokerPool)69 StringInputSource (org.exist.util.StringInputSource)57 Test (org.junit.Test)57 EXistException (org.exist.EXistException)43 PermissionDeniedException (org.exist.security.PermissionDeniedException)43 DocumentImpl (org.exist.dom.persistent.DocumentImpl)42 IOException (java.io.IOException)33 LockedDocument (org.exist.dom.persistent.LockedDocument)31 SAXException (org.xml.sax.SAXException)26 InputStream (java.io.InputStream)19 Path (java.nio.file.Path)19 Permission (org.exist.security.Permission)19 LockException (org.exist.util.LockException)16 TriggerException (org.exist.collections.triggers.TriggerException)15 BinaryDocument (org.exist.dom.persistent.BinaryDocument)15