Search in sources :

Example 1 with IndexQueryService

use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.

the class AbstractTestUpdate method setUp.

@Before
public void setUp() throws Exception {
    final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    testCollection = service.createCollection("test");
    final IndexQueryService idx = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idx.configureCollection(XCONF);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) IndexQueryService(org.exist.xmldb.IndexQueryService) Before(org.junit.Before)

Example 2 with IndexQueryService

use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.

the class TriggerConfigTest method updateTriggers.

@Test
public void updateTriggers() {
    try {
        Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
        IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
        iqs.configureCollection(EMPTY_COLLECTION_CONFIG);
        Collection configCol = DatabaseManager.getCollection(BASE_URI + "/db/system/config" + testCollection, "admin", "");
        Resource resource = configCol.createResource(DEFAULT_COLLECTION_CONFIG_FILE, "XMLResource");
        resource.setContent(COLLECTION_CONFIG);
        configCol.storeResource(resource);
        resource = root.createResource("data.xml", "XMLResource");
        resource.setContent(DOCUMENT_CONTENT);
        root.storeResource(resource);
        XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet result = qs.query("if (doc-available('" + testCollection + "/messages.xml')) then doc('" + testCollection + "/messages.xml')/events/event[@id = 'STORE-DOCUMENT']/string(@collection) else ()");
        assertEquals(1, result.getSize());
        assertEquals(testCollection, result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService)

Example 3 with IndexQueryService

use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.

the class TriggerConfigTest method storeDocument.

@Test
public void storeDocument() {
    try {
        Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
        IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
        iqs.configureCollection(COLLECTION_CONFIG);
        Resource resource = root.createResource("data.xml", "XMLResource");
        resource.setContent(DOCUMENT_CONTENT);
        root.storeResource(resource);
        XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet result = qs.queryResource("messages.xml", "string(//event[last()]/@collection)");
        assertEquals(1, result.getSize());
        assertEquals(testCollection, result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService)

Example 4 with IndexQueryService

use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.

the class TriggerConfigTest method removeDocument.

@Test
public void removeDocument() {
    try {
        Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
        IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
        iqs.configureCollection(COLLECTION_CONFIG);
        Resource resource = root.createResource("data.xml", "XMLResource");
        resource.setContent(DOCUMENT_CONTENT);
        root.storeResource(resource);
        root.removeResource(resource);
        XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet result = qs.queryResource("messages.xml", "string(//event[last()]/@collection)");
        assertEquals(1, result.getSize());
        assertEquals(testCollection, result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService)

Example 5 with IndexQueryService

use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.

the class XQueryTriggerTest method documentBinaryCreate.

/**
 * test a trigger fired by creating a new Binary Document
 */
@Test
public void documentBinaryCreate() throws XMLDBException {
    // configure the Collection with the trigger under test
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    // this will fire the trigger
    final Resource res = testCollection.createResource(BINARY_DOCUMENT_NAME, "BinaryResource");
    final byte[] content = Base64.decodeBase64(BINARY_DOCUMENT_CONTENT);
    res.setContent(content);
    testCollection.storeResource(res);
    // remove the trigger for the Collection under test
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    // TODO : understand why it is necessary !
    service.setProperty(OutputKeys.INDENT, "no");
    ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(EVENTS);
    assertEquals(2, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger1'][@type = 'finish'][collection = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "'][uri = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "/" + BINARY_DOCUMENT_NAME + "'][event = 'CREATE-DOCUMENT']/document");
// assertEquals(1, result.getSize());
// assertEquals("<document>" + BINARY_DOCUMENT_CONTENT + "</document>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

IndexQueryService (org.exist.xmldb.IndexQueryService)25 Collection (org.xmldb.api.base.Collection)9 ResourceSet (org.xmldb.api.base.ResourceSet)9 XMLResource (org.xmldb.api.modules.XMLResource)9 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)6 XPathQueryService (org.xmldb.api.modules.XPathQueryService)6 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)5 EXistResource (org.exist.xmldb.EXistResource)4 Resource (org.xmldb.api.base.Resource)4 BinaryResource (org.xmldb.api.modules.BinaryResource)4 XQueryService (org.xmldb.api.modules.XQueryService)4 InputStream (java.io.InputStream)3 XmldbURI (org.exist.xmldb.XmldbURI)3 Before (org.junit.Before)3 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)2 URISyntaxException (java.net.URISyntaxException)1 UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)1 Account (org.exist.security.Account)1 UserAider (org.exist.security.internal.aider.UserAider)1 StartException (org.exist.start.StartException)1