use of org.exist.collections.Collection in project exist by eXist-db.
the class ConstructedNodesRecoveryTest method testTempChildCollectionExists.
private void testTempChildCollectionExists(DBBroker broker, TransactionManager transact, String childCollectionName) throws PermissionDeniedException, IOException, TriggerException, TransactionException {
// create a transaction
try (final Txn transaction = transact.beginTransaction()) {
// get the temp child collection
Collection tempChildCollection = broker.getOrCreateCollection(transaction, XmldbURI.TEMP_COLLECTION_URI.append(childCollectionName));
assertNotNull(tempChildCollection);
broker.saveCollection(transaction, tempChildCollection);
transact.commit(transaction);
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class ForwardReferenceTest method setup.
@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool brokerPool = EXIST_EMBEDDED_SERVER.getBrokerPool();
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
try (final Collection testCollection = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI)) {
CONFIG_MODULE_URI = storeQuery(broker, transaction, CONFIG_MODULE, testCollection, CONFIG_MODULE_NAME);
assertEquals(TEST_COLLECTION_URI.append(CONFIG_MODULE_NAME), CONFIG_MODULE_URI);
PAGES_MODULE_URI = storeQuery(broker, transaction, PAGES_MODULE, testCollection, PAGES_MODULE_NAME);
assertEquals(TEST_COLLECTION_URI.append(PAGES_MODULE_NAME), PAGES_MODULE_URI);
TEST_PAGES_MODULE_URI = storeQuery(broker, transaction, TEST_PAGES_MODULE, testCollection, TEST_PAGES_MODULE_NAME);
assertEquals(TEST_COLLECTION_URI.append(TEST_PAGES_MODULE_NAME), TEST_PAGES_MODULE_URI);
}
transaction.commit();
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class ContentFunctionsTest method setup.
@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, TriggerException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
try (final Collection collection = broker.getOrCreateCollection(transaction, XmldbURI.create("/db/content-functions-test"))) {
try (final InputStream is = ContentFunctionsTest.class.getResourceAsStream("minimal.pdf")) {
assertNotNull(is);
collection.addBinaryResource(transaction, broker, XmldbURI.create("minimal.pdf"), is, "application/pdf", -1);
}
try (final InputStream is = ContentFunctionsTest.class.getResourceAsStream("test.xlsx")) {
assertNotNull(is);
collection.addBinaryResource(transaction, broker, XmldbURI.create("test.xlsx"), is, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", -1);
}
}
transaction.commit();
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class ValueSequenceTest method sortInDocumentOrder.
@Test
public void sortInDocumentOrder() throws EXistException, PermissionDeniedException, AuthenticationException {
final ValueSequence seq = new ValueSequence(true);
seq.keepUnOrdered(true);
// in-memory doc
final MemTreeBuilder memtree = new MemTreeBuilder();
memtree.startDocument();
memtree.startElement(new QName("m1", XMLConstants.NULL_NS_URI), null);
memtree.startElement(new QName("m2", XMLConstants.NULL_NS_URI), null);
memtree.characters("test data");
memtree.endElement();
memtree.endElement();
memtree.endDocument();
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final Subject admin = pool.getSecurityManager().authenticate("admin", "");
try (final DBBroker broker = pool.get(Optional.of(admin))) {
// persistent doc
final Collection sysCollection = broker.getCollection(SecurityManager.SECURITY_COLLECTION_URI);
final DocumentImpl doc = sysCollection.getDocument(broker, XmldbURI.create("config.xml"));
final NodeProxy docProxy = new NodeProxy(doc);
final NodeProxy nodeProxy = new NodeProxy(doc, ((NodeImpl) doc.getFirstChild()).getNodeId());
seq.add(memtree.getDocument());
seq.add(docProxy);
seq.add((org.exist.dom.memtree.NodeImpl) memtree.getDocument().getFirstChild());
seq.add(nodeProxy);
// call sort
seq.sortInDocumentOrder();
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class Sync method handleCollection.
private List<XmldbURI> handleCollection(final XmldbURI collectionPath, final String rootTargetAbsPath, final Path targetDirectory, final Date startDate, final boolean prune, final List<String> excludes, final MemTreeBuilder output) throws PermissionDeniedException, LockException {
try (final Collection collection = context.getBroker().openCollection(collectionPath, LockMode.READ_LOCK)) {
if (collection == null) {
reportError(output, "Collection not found: " + collectionPath);
return Collections.emptyList();
}
if (prune) {
pruneCollectionEntries(collection, rootTargetAbsPath, targetDirectory, excludes, output);
}
for (final Iterator<DocumentImpl> i = collection.iterator(context.getBroker()); i.hasNext(); ) {
final DocumentImpl doc = i.next();
final Path targetFile = targetDirectory.resolve(doc.getFileURI().toASCIIString());
saveFile(targetFile, doc, startDate, output);
}
final List<XmldbURI> subCollections = new ArrayList<>(collection.getChildCollectionCount(context.getBroker()));
for (final Iterator<XmldbURI> i = collection.collectionIterator(context.getBroker()); i.hasNext(); ) {
subCollections.add(i.next());
}
return subCollections;
}
}
Aggregations