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());
}
}
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);
}
}
}
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);
}
}
}
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;
}
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);
}
Aggregations