Search in sources :

Example 26 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class LocalXMLResourceDOMTest method cleanup.

@AfterClass
public static void cleanup() throws XMLDBException {
    final CollectionManagementService cms = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    cms.removeCollection(TestConstants.TEST_COLLECTION_URI.getRawCollectionPath());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) AfterClass(org.junit.AfterClass)

Example 27 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class LocalXMLResourceDOMTest method setup.

@BeforeClass
public static void setup() throws XMLDBException {
    final CollectionManagementService cms = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    final Collection coll = cms.createCollection(TestConstants.TEST_COLLECTION_URI.lastSegment().toString());
    final XMLResource r = (XMLResource) coll.createResource(TEST_RESOURCE_NAME, XMLResource.RESOURCE_TYPE);
    r.setContent("<properties><property key=\"type\">Table</property><test/></properties><!-- comment -->");
    coll.storeResource(r);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) XMLResource(org.xmldb.api.modules.XMLResource) BeforeClass(org.junit.BeforeClass)

Example 28 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class CollectionConfigurationTest method collectionConfigurationService10.

/**
 * Remove config document
 */
@Test
public void collectionConfigurationService10() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    CollectionManagementService cms = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    Collection sub2 = cms.createCollection(COLLECTION_SUB2.toString());
    UserManagementService ums = (UserManagementService) sub2.getService("UserManagementService", "1.0");
    ums.chmod("rwxr-xr-x");
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(CONFIG1);
    // ... then index document
    XMLResource doc = (XMLResource) sub2.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    sub2.storeResource(doc);
    XPathQueryService service = (XPathQueryService) sub2.getService("XPathQueryService", "1.0");
    // 3 numeric values
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, result.getSize());
    // remove config document thus dropping the configuration
    Collection confCol = DatabaseManager.getCollection("xmldb:exist://" + CONF_COLL_URI.toString(), ADMIN_DB_USER, ADMIN_DB_PWD);
    Resource confDoc = confCol.getResource(DEFAULT_COLLECTION_CONFIG_FILE);
    assertNotNull(confDoc);
    confCol.removeResource(confDoc);
    // cms = (CollectionManagementService) confCol.getService("CollectionManagementService", "1.0");
    // cms.removeCollection(".");
    idxConf.reindexCollection();
    // index should be empty since configuration was removed
    result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals(0, result.getSize());
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals(0, result.getSize());
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(0, result.getSize());
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(0, result.getSize());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 29 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class CollectionConfigurationTest method setUp.

@Before
public void setUp() throws Exception {
    final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    final Collection testCollection = service.createCollection(TEST_COLLECTION);
    UserManagementService ums = (UserManagementService) testCollection.getService("UserManagementService", "1.0");
    // change ownership to guest
    final Account guest = ums.getAccount(GUEST_DB_USER);
    ums.chown(guest, guest.getPrimaryGroup());
    ums.chmod("rwxr-xr-x");
    final Collection testConfCollection = service.createCollection(CONF_COLL_URI.toString());
    ums = (UserManagementService) testConfCollection.getService("UserManagementService", "1.0");
    // change ownership to guest
    ums.chown(guest, guest.getPrimaryGroup());
    ums.chmod("rwxr-xr-x");
// configColl = cms.createCollection(CONF_COLL_URI.toString());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) Collection(org.xmldb.api.base.Collection)

Example 30 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class CollectionConfigurationTest method collectionConfigurationService7.

/**
 * Check if configurations are properly passed down the collection hierarchy.
 */
@Test
public void collectionConfigurationService7() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    CollectionManagementService cms = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    Collection sub2 = cms.createCollection(COLLECTION_SUB2.toString());
    UserManagementService ums = (UserManagementService) sub2.getService("UserManagementService", "1.0");
    ums.chmod("rwxr-xr-x");
    // Configure collection automatically
    // sub2 should inherit its index configuration from the top collection
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(CONFIG1);
    // ... then index document
    XMLResource doc = (XMLResource) sub2.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    sub2.storeResource(doc);
    XPathQueryService service = (XPathQueryService) sub2.getService("XPathQueryService", "1.0");
    // 3 numeric values
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, result.getSize());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Aggregations

CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)148 Collection (org.xmldb.api.base.Collection)84 XMLResource (org.xmldb.api.modules.XMLResource)33 Resource (org.xmldb.api.base.Resource)25 Before (org.junit.Before)23 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)21 After (org.junit.After)21 Test (org.junit.Test)19 UserManagementService (org.exist.xmldb.UserManagementService)14 ResourceSet (org.xmldb.api.base.ResourceSet)14 BinaryResource (org.xmldb.api.modules.BinaryResource)13 XPathQueryService (org.xmldb.api.modules.XPathQueryService)9 Account (org.exist.security.Account)7 IndexQueryService (org.exist.xmldb.IndexQueryService)6 AfterClass (org.junit.AfterClass)6 Database (org.xmldb.api.base.Database)6 XMLDBException (org.xmldb.api.base.XMLDBException)6 Path (java.nio.file.Path)5 BeforeClass (org.junit.BeforeClass)5 InputStream (java.io.InputStream)4