Search in sources :

Example 1 with TriggerException

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

the class CollectionConfigurationManager method checkCreateCollection.

/**
 * Check if the collection exists below the system collection. If not,
 * create it.
 *
 * @param broker eXist-db broker
 * @param txn according transaction
 * @param uri to the collection to create
 * @throws EXistException if something goes wrong
 */
private void checkCreateCollection(final DBBroker broker, final Txn txn, final XmldbURI uri) throws EXistException {
    try {
        Collection collection = broker.getCollection(uri);
        if (collection == null) {
            collection = broker.getOrCreateCollection(txn, uri);
            SanityCheck.THROW_ASSERT(collection != null);
            broker.saveCollection(txn, collection);
        }
    } catch (final TriggerException | PermissionDeniedException | IOException e) {
        throw new EXistException("Failed to initialize '" + uri + "' : " + e.getMessage());
    }
}
Also used : PermissionDeniedException(org.exist.security.PermissionDeniedException) IOException(java.io.IOException) EXistException(org.exist.EXistException) TriggerException(org.exist.collections.triggers.TriggerException)

Example 2 with TriggerException

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

the class CollectionConfiguration method configureTrigger.

private void configureTrigger(final ClassLoader cl, final Element triggerElement, final XmldbURI collectionConfigurationURI, final boolean testOnly) throws CollectionConfigurationException {
    // TODO : rely on schema-driven validation -pb
    final String classname = triggerElement.getAttributes().getNamedItem(CLASS_ATTRIBUTE).getNodeValue();
    try {
        final Class clazz = Class.forName(classname, true, cl);
        if (!Trigger.class.isAssignableFrom(clazz)) {
            throwOrLog("Trigger's class '" + classname + "' is not assignable from '" + Trigger.class + "'", testOnly);
            return;
        }
        final NodeList nlParameter = triggerElement.getElementsByTagNameNS(NAMESPACE, PARAMETER_ELEMENT);
        final Map<String, List<? extends Object>> parameters = ParametersExtractor.extract(nlParameter);
        boolean added = false;
        if (DocumentTrigger.class.isAssignableFrom(clazz)) {
            docTriggers.add(new DocumentTriggerProxy((Class<? extends DocumentTrigger>) clazz, parameters));
            added = true;
        }
        if (CollectionTrigger.class.isAssignableFrom(clazz)) {
            colTriggers.add(new CollectionTriggerProxy((Class<? extends CollectionTrigger>) clazz, parameters));
            added = true;
        }
        if (!added) {
            throw new TriggerException("Unknown Trigger class type: " + clazz.getName());
        }
    } catch (final ClassNotFoundException | TriggerException e) {
        if (testOnly) {
            throw new CollectionConfigurationException(e.getMessage(), e);
        } else {
            LOG.warn("Trigger class not found: {}", e.getMessage(), e);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) DocumentTriggerProxy(org.exist.collections.triggers.DocumentTriggerProxy) CollectionTrigger(org.exist.collections.triggers.CollectionTrigger) CollectionTriggerProxy(org.exist.collections.triggers.CollectionTriggerProxy) CollectionTrigger(org.exist.collections.triggers.CollectionTrigger) Trigger(org.exist.collections.triggers.Trigger) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) ConfigurationClass(org.exist.config.annotation.ConfigurationClass) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) TriggerException(org.exist.collections.triggers.TriggerException)

Example 3 with TriggerException

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

the class RestXqTrigger method after.

private void after(final DBBroker broker, final DocumentImpl document) throws TriggerException {
    final ExistXqueryRegistry xqueryRegistry = ExistXqueryRegistry.getInstance();
    if (xqueryRegistry.isXquery(document)) {
        try {
            final List<RestXqService> services = xqueryRegistry.findServices(broker, document);
            xqueryRegistry.registerServices(broker, services);
        } catch (final ExQueryException eqe) {
            throw new TriggerException(eqe.getMessage(), eqe);
        }
    }
}
Also used : RestXqService(org.exquery.restxq.RestXqService) ExQueryException(org.exquery.ExQueryException) TriggerException(org.exist.collections.triggers.TriggerException)

Example 4 with TriggerException

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

the class Deployment method scanDirectory.

private List<String> scanDirectory(final DBBroker broker, final Txn transaction, final Path directory, final XmldbURI target, final InMemoryNodeSet resources, final boolean inRootDir, final boolean isResourcesDir, final Optional<RequestedPerms> requestedPerms, final List<String> errors) {
    Collection collection = null;
    try {
        collection = broker.getOrCreateCollection(transaction, target);
        setPermissions(broker, requestedPerms, true, null, collection.getPermissionsNoLock());
        broker.saveCollection(transaction, collection);
    } catch (final PermissionDeniedException | TriggerException | IOException e) {
        LOG.warn(e);
        errors.add(e.getMessage());
    }
    final boolean isResources = isResourcesDir || isResourceDir(target, resources);
    // the root dir is not allowed to be a resources directory
    if (!inRootDir && isResources) {
        try {
            storeBinaryResources(broker, transaction, directory, collection, requestedPerms, errors);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    } else {
        storeFiles(broker, transaction, directory, collection, inRootDir, requestedPerms, errors);
    }
    // scan sub directories
    try (final Stream<Path> subDirs = Files.find(directory, 1, (path, attrs) -> (!path.equals(directory)) && attrs.isDirectory())) {
        subDirs.forEach(path -> scanDirectory(broker, transaction, path, target.append(FileUtils.fileName(path)), resources, false, isResources, requestedPerms, errors));
    } catch (final IOException ioe) {
        LOG.warn("Unable to scan sub-directories", ioe);
    }
    return errors;
}
Also used : Path(java.nio.file.Path) Collection(org.exist.collections.Collection) PermissionDeniedException(org.exist.security.PermissionDeniedException) IOException(java.io.IOException) TriggerException(org.exist.collections.triggers.TriggerException) PermissionDeniedException(org.exist.security.PermissionDeniedException) EXistException(org.exist.EXistException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) TriggerException(org.exist.collections.triggers.TriggerException)

Example 5 with TriggerException

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

the class LocalCollectionManagementService method createCollection.

@Override
public Collection createCollection(final XmldbURI name, final Date created) throws XMLDBException {
    final XmldbURI collName = resolve(name);
    withDb((broker, transaction) -> {
        try {
            final org.exist.collections.Collection coll = broker.getOrCreateCollection(transaction, collName, Optional.ofNullable(created).map(c -> new Tuple2<>(null, c.getTime())));
            try (final ManagedCollectionLock collectionLock = broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(collName)) {
                broker.saveCollection(transaction, coll);
            }
            return null;
        } catch (final LockException | TriggerException e) {
            throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
        }
    });
    return new LocalCollection(user, brokerPool, collection, collName);
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockedDocument(org.exist.dom.persistent.LockedDocument) BrokerPool(org.exist.storage.BrokerPool) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ManagedCollectionLock(org.exist.storage.lock.ManagedCollectionLock) PreserveType(org.exist.storage.DBBroker.PreserveType) LockException(org.exist.util.LockException) Subject(org.exist.security.Subject) Optional(java.util.Optional) DocumentImpl(org.exist.dom.persistent.DocumentImpl) EXistException(org.exist.EXistException) TriggerException(org.exist.collections.triggers.TriggerException) ErrorCodes(org.xmldb.api.base.ErrorCodes) Lock(org.exist.storage.lock.Lock) Nullable(javax.annotation.Nullable) Collection(org.xmldb.api.base.Collection) LockException(org.exist.util.LockException) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) XMLDBException(org.xmldb.api.base.XMLDBException) TriggerException(org.exist.collections.triggers.TriggerException) ManagedCollectionLock(org.exist.storage.lock.ManagedCollectionLock)

Aggregations

TriggerException (org.exist.collections.triggers.TriggerException)25 EXistException (org.exist.EXistException)18 PermissionDeniedException (org.exist.security.PermissionDeniedException)18 Txn (org.exist.storage.txn.Txn)13 XmldbURI (org.exist.xmldb.XmldbURI)11 IOException (java.io.IOException)10 Collection (org.exist.collections.Collection)10 LockException (org.exist.util.LockException)10 DocumentImpl (org.exist.dom.persistent.DocumentImpl)9 DBBroker (org.exist.storage.DBBroker)7 TransactionManager (org.exist.storage.txn.TransactionManager)6 Sequence (org.exist.xquery.value.Sequence)6 LockedDocument (org.exist.dom.persistent.LockedDocument)5 NotificationService (org.exist.storage.NotificationService)5 StringValue (org.exist.xquery.value.StringValue)5 ValueSequence (org.exist.xquery.value.ValueSequence)5 StoredNode (org.exist.dom.persistent.StoredNode)4 XPathException (org.exist.xquery.XPathException)4 URISyntaxException (java.net.URISyntaxException)3 Path (java.nio.file.Path)3