Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.PersistenceException


    throws PersistenceException {
        try {
            if ( session.itemExists(path) ) {
                session.getItem(path).remove();
            } else {
                throw new PersistenceException("Unable to delete resource at " + path + ". Resource does not exist.", null, path, null);
            }
        } catch (final RepositoryException e) {
            throw new PersistenceException("Unable to delete resource at " + path, e, path, null);
        }
    }
View Full Code Here


     */
    public void commit(final ResourceResolver resolver) throws PersistenceException {
        try {
            this.session.save();
        } catch (final RepositoryException e) {
            throw new PersistenceException("Unable to commit changes to session.", e);
        }
    }
View Full Code Here

                }
            }
            node.getSession().save();
            this.reset();
        } catch (final RepositoryException re) {
            throw new PersistenceException("Unable to persist changes.", re, getPath(), null);
        }
    }
View Full Code Here

        final String[] info = this.extractResourceInfo(path);
        if ( info != null && info.length == 2) {
            final boolean deleted = this.deletedResources.remove(path);
            final MongoDBResource oldResource = (MongoDBResource)this.getResource(resolver, path, info);
            if ( !deleted && oldResource != null ) {
                throw new PersistenceException("Resource already exists at " + path, null, path, null);
            }
            final DBObject dbObj = new BasicDBObject();
            dbObj.put(getPROP_PATH(), info[1]);
            if ( properties != null ) {
                for(Map.Entry<String, Object> entry : properties.entrySet()) {
                    final String key = propNameToKey(entry.getKey());
                    dbObj.put(key, entry.getValue());
                }
            }
            if ( deleted && oldResource != null ) {
                dbObj.put(PROP_ID, oldResource.getProperties().get(PROP_ID));
            }
            final MongoDBResource rsrc = new MongoDBResource(resolver, path, info[0], dbObj, this);
            this.changedResources.put(path, rsrc);

            return rsrc;
        }
        throw new PersistenceException("Illegal path - unable to create resource at " + path, null, path, null);
    }
View Full Code Here

                }
                return;
            }

        }
        throw new PersistenceException("Unable to delete resource at {}" + path, null, path, null);
    }
View Full Code Here

                        // create
                        col.save(changed.getProperties());
                        this.context.notifyUpdated(info);
                    }
                } else {
                    throw new PersistenceException("Unable to create collection " + changed.getCollection(), null, changed.getPath(), null);
                }
            }
        } finally {
            this.revert(resolver);
        }
View Full Code Here

                if (configuration != null) {
                    configuration.delete();
                }
            }
        } catch (IOException e) {
            throw new PersistenceException("Resources cannot be commited", e);
        }
    }
View Full Code Here

    public Resource create(ResourceResolver resolver, String path, Map<String, Object> properties) throws PersistenceException {
        SimplePathInfo pathInfo = extractPathInfo(path);

        if (pathInfo == null) {
            throw new PersistenceException("Invalid path: " + path, null);
        }

        if (!hasPermission(resolver, pathInfo.getResourcePath(), Session.ACTION_ADD_NODE)) {
            throw new PersistenceException("Not enough permissions");
        }

        String resourceName = pathInfo.getMainResourceName();

        boolean added = addToChangedResources(resourceName, properties, true);


        if (!added) {
            throw new PersistenceException("Resource already exists at " + path, null, resourceName, null);
        }

        return buildMainResource(resolver, pathInfo, properties);
    }
View Full Code Here

    public void delete(ResourceResolver resolver, String requestPath) throws PersistenceException {
        SimplePathInfo pathInfo = extractPathInfo(requestPath);

        if (pathInfo == null) {
            throw new PersistenceException("Invalid path: " + requestPath, null);
        }

        if (!hasPermission(resolver, pathInfo.getResourcePath(), Session.ACTION_REMOVE)) {
            throw new PersistenceException("Not enough permissions");
        }

        String resourceName = pathInfo.getMainResourceName();

        if (!deletedResources.contains(resourceName)) {
View Full Code Here

    private Resource createTenantResource(final ResourceResolver resolver, final String tenantId,
            final Map<String, Object> properties) throws PersistenceException {

        // check for duplicate first
        if (getTenantResource(resolver, tenantId) != null) {
            throw new PersistenceException("Tenant '" + tenantId + "' already exists");
        }

        Resource tenantRoot = resolver.getResource(tenantRootPath);

        if (tenantRoot == null) {
            Resource current = resolver.getResource("/");
            if (current == null) {
                throw new PersistenceException("Cannot get root Resource");
            }

            String[] segments = this.tenantRootPath.split("/");
            for (String segment : segments) {
                Resource child = current.getChild(segment);
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.PersistenceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.