Search in sources :

Example 31 with Txn

use of org.exist.storage.txn.Txn in project exist by eXist-db.

the class TransformTest method cleanupResources.

@AfterClass
public static void cleanupResources() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        deleteCollection(broker, transaction, TEST_IDS_COLLECTION);
        deleteCollection(broker, transaction, TEST_DOCUMENT_XSLT_COLLECTION);
        deleteCollection(broker, transaction, TEST_SIMPLE_XML_COLLECTION);
        deleteCollection(broker, transaction, TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION);
        deleteCollection(broker, transaction, TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION);
        deleteCollection(broker, transaction, TEST_TWO_NODES_COLLECTION);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 32 with Txn

use of org.exist.storage.txn.Txn in project exist by eXist-db.

the class TransformTest method storeResources.

@BeforeClass
public static void storeResources() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        createCollection(broker, transaction, TEST_IDS_COLLECTION, Tuple(LIST_OPS_XSLT_NAME, LIST_OPS_XSLT), Tuple(INPUT_LIST_XML_NAME, INPUT_XML), Tuple(DICTIONARY_XML_NAME, DICTIONARY_XML));
        createCollection(broker, transaction, TEST_DOCUMENT_XSLT_COLLECTION, Tuple(DOCUMENT_XSLT_NAME, DOCUMENT_XSLT));
        createCollection(broker, transaction, TEST_SIMPLE_XML_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_COLLECTION)));
        createCollection(broker, transaction, TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML_WITH_COMMENT), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION)));
        createCollection(broker, transaction, TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML_WITH_TWO_COMMENTS), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION)));
        createCollection(broker, transaction, TEST_TWO_NODES_COLLECTION, Tuple(TWO_NODES_XML_NAME, TWO_NODES_XML), Tuple(COUNT_DESCENDANTS_TWO_NODES_XSLT_NAME, COUNT_DESCENDANTS_TWO_NODES_XSLT));
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 33 with Txn

use of org.exist.storage.txn.Txn in project exist by eXist-db.

the class GroupMembershipFunctionRemoveGroupMemberTest method setup.

@Before
public void setup() throws EXistException, PermissionDeniedException, XPathException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    // create user with personal group as primary group
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = createUser(broker, sm, USER1_NAME, USER1_PWD);
        final Group otherGroup1 = createGroup(broker, sm, OTHER_GROUP1_NAME);
        addUserToGroup(sm, user1, otherGroup1);
        addUserAsGroupManager(USER1_NAME, OTHER_GROUP1_NAME);
        final Group otherGroup2 = createGroup(broker, sm, OTHER_GROUP2_NAME);
        addUserToGroup(sm, user1, otherGroup2);
        addUserAsGroupManager(USER1_NAME, OTHER_GROUP2_NAME);
        transaction.commit();
    }
    // check that the user is as we expect
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = sm.getAccount(USER1_NAME);
        assertEquals(USER1_NAME, user1.getPrimaryGroup());
        final String[] user1Groups = user1.getGroups();
        assertArrayEquals(new String[] { USER1_NAME, OTHER_GROUP1_NAME, OTHER_GROUP2_NAME }, user1Groups);
        for (final String user1Group : user1Groups) {
            assertNotNull(sm.getGroup(user1Group));
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) Before(org.junit.Before)

Example 34 with Txn

use of org.exist.storage.txn.Txn in project exist by eXist-db.

the class PermissionsFunctionChmodTest method cleanupDb.

@AfterClass
public static void cleanupDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        removeUser(sm, USER2_NAME);
        removeUser(sm, USER1_NAME);
        removeCollection(broker, transaction, TestConstants.TEST_COLLECTION_URI);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 35 with Txn

use of org.exist.storage.txn.Txn in project exist by eXist-db.

the class SendEmailIT method sendEmailJavaMail.

@Test
public void sendEmailJavaMail() throws EXistException, XPathException, PermissionDeniedException, IOException, MessagingException {
    final String from = "sender@place1.com";
    final String to = "recipient@place2.com";
    final String subject = "some email subject";
    final String messageText = UUIDGenerator.getUUIDversion4();
    final String query = "import module namespace mail = \"http://exist-db.org/xquery/mail\";\n" + "let $session := mail:get-mail-session(\n" + "    <properties>\n" + "        <property name=\"mail.transport.protocol\" value=\"smtp\"/>\n" + "        <property name=\"mail.smtp.port\" value=\"" + smtpPort + "\"/>\n" + "        <property name=\"mail.smtp.host\" value=\"127.0.0.1\"/>\n" + "    </properties>\n" + ")\n" + "return\n" + "    mail:send-email(\n" + "        $session,\n" + "        <mail><from>" + from + "</from><to>" + to + "</to><subject>" + subject + "</subject><message><text>" + messageText + "</text></message></mail>\n" + "    )";
    // send the email from XQuery via SMTP
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Source source = new StringSource(query);
    try (final DBBroker broker = pool.getBroker();
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        // execute query
        final Boolean sendResult = withCompiledQuery(broker, source, compiledXQuery -> {
            executeQuery(broker, compiledXQuery);
            return true;
        });
        transaction.commit();
        assertTrue(sendResult.booleanValue());
    }
    // check the SMTP server received the email
    final MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
    assertEquals(1, receivedMessages.length);
    final MimeMessage receivedMessage = receivedMessages[0];
    // final Address sender = receivedMessage.getSender();
    // assertEquals(from, sender.toString());
    final Address[] recipients = receivedMessage.getRecipients(Message.RecipientType.TO);
    assertEquals(1, recipients.length);
    assertEquals(to, recipients[0].toString());
    assertEquals(subject, receivedMessage.getSubject());
    assertEquals(messageText, GreenMailUtil.getBody(receivedMessage));
}
Also used : DBBroker(org.exist.storage.DBBroker) Address(jakarta.mail.Address) MimeMessage(jakarta.mail.internet.MimeMessage) StringSource(org.exist.source.StringSource) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) Test(org.junit.Test)

Aggregations

Txn (org.exist.storage.txn.Txn)358 DBBroker (org.exist.storage.DBBroker)215 BrokerPool (org.exist.storage.BrokerPool)179 Collection (org.exist.collections.Collection)162 TransactionManager (org.exist.storage.txn.TransactionManager)129 Sequence (org.exist.xquery.value.Sequence)84 StringInputSource (org.exist.util.StringInputSource)83 Test (org.junit.Test)80 XmldbURI (org.exist.xmldb.XmldbURI)55 EXistException (org.exist.EXistException)50 PermissionDeniedException (org.exist.security.PermissionDeniedException)38 Source (org.exist.source.Source)37 StringSource (org.exist.source.StringSource)37 DocumentImpl (org.exist.dom.persistent.DocumentImpl)35 InputSource (org.xml.sax.InputSource)33 XQuery (org.exist.xquery.XQuery)32 IOException (java.io.IOException)31 LockedDocument (org.exist.dom.persistent.LockedDocument)28 InputStream (java.io.InputStream)27 Path (java.nio.file.Path)24