Package org.apache.sling.api.resource

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


            final Map<String, Object> properties)
    throws PersistenceException {
        // check if the resource exists
        final Resource mountResource = this.getResource(resolver, path);
        if ( mountResource != null ) {
            throw new PersistenceException("Resource at " + path + " already exists.", null, path, null);
        }
        // creation of the root mount resource is not supported
        final String relativePath = getRelativePath(path);
        if ( relativePath == null || relativePath.length() == 0 ) {
            throw new PersistenceException("Resource at " + path + " can't be created.", null, path, null);
        }

        final ExtendedResourceHolder holder = this.getAllResources(resolver, path, relativePath);
        // we only support modifications if there is more than one location merged
        if ( holder.count < 2 ) {
            throw new PersistenceException("Modifying is only supported with at least two potentially merged resources.", null, path, null);
        }
        if ( holder.resources.size() == 0
             || (holder.resources.size() < holder.count && !holder.resources.get(holder.resources.size() - 1).getPath().equals(holder.highestResourcePath) )) {
            final String createPath = holder.highestResourcePath;
            final Resource parentResource = ResourceUtil.getOrCreateResource(resolver, ResourceUtil.getParent(createPath), (String)null, null, false);
View Full Code Here


    public void delete(final ResourceResolver resolver, final String path)
    throws PersistenceException {
        // deleting of the root mount resource is not supported
        final String relativePath = getRelativePath(path);
        if ( relativePath == null || relativePath.length() == 0 ) {
            throw new PersistenceException("Resource at " + path + " can't be created.", null, path, null);
        }

        // check if the resource exists
        final Resource mntResource = this.getResource(resolver, path);
        if ( mntResource == null ) {
            throw new PersistenceException("Resource at " + path + " does not exist", null, path, null);
        }
        final ExtendedResourceHolder holder = this.getAllResources(resolver, path, relativePath);
        // we only support modifications if there is more than one location merged
        if ( holder.count < 2 ) {
            throw new PersistenceException("Modifying is only supported with at least two potentially merged resources.", null, path, null);
        }

        if ( holder.resources.size() == 1 && holder.resources.get(0).getPath().equals(holder.highestResourcePath) ) {
            // delete the only resource which is the highest one
            resolver.delete(holder.resources.get(0));
View Full Code Here

            resources.remove(resource);
            Node node = resource.adaptTo(Node.class);
            try {
                node.remove();
            } catch (RepositoryException e) {
                throw new PersistenceException("RepositoryException: "+e, e);
            }
        } else {
            throw new UnsupportedOperationException("Not implemented");
        }
    }
View Full Code Here

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

        props.put(JCR_LASTMODIFIED, Calendar.getInstance());
        props.put(JCR_MIMETYPE, contentType);
        try {
             props.put(JCR_DATA, value.getInputStream());
        } catch (final IOException e) {
             throw new PersistenceException("Error while retrieving inputstream from parameter value.", e);
        }

        // get or create resource
        Resource result = parentResource.getChild(name);
        if ( result != null ) {
            final ModifiableValueMap vm = result.adaptTo(ModifiableValueMap.class);
            if ( vm == null ) {
                throw new PersistenceException("Resource at " + parentResource.getPath() + '/' + name + " is not modifiable.");
            }
            vm.putAll(props);
        } else {
            result = parentResource.getResourceResolver().create(parentResource, name, props);
        }
View Full Code Here

            inpStrmSet.add(lastChunkStream);
            mergeStrm = new SequenceInputStream(
                Collections.enumeration(inpStrmSet));
            IOUtils.copyLarge(mergeStrm, out);
        } catch (IOException e) {
            throw new PersistenceException("excepiton occured", e);
        } finally {
            IOUtils.closeQuietly(out);
            IOUtils.closeQuietly(mergeStrm);

        }
View Full Code Here

        }
        Node node = resource.adaptTo(Node.class);
        try {
            node.remove();
        } catch (RepositoryException e) {
            throw new PersistenceException("RepositoryException: "+e, e);
        }
    }
View Full Code Here

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

                        final String key = (String)ois.readObject();
                        final Object value = ois.readObject();
                        binaryProperties.put(key, value);
                    }
                } catch (final ClassNotFoundException cnfe) {
                    throw new PersistenceException("Class not found.", cnfe);
                } catch (final java.io.InvalidClassException ice) {
                    throw new PersistenceException("Invalid class.", ice);
                } catch (final IOException ioe) {
                    throw new PersistenceException("Unable to deserialize job properties.", ioe);
                } finally {
                    try {
                        ois.close();
                    } catch (final IOException ioe) {
                        throw new PersistenceException("Unable to deserialize job properties.", ioe);
                    }
                }
            }

            final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);

            properties.put(JobImpl.PROPERTY_BRIDGED_EVENT, true);
            final String topic = (String)properties.remove("slingevent:topic");
            properties.put(ResourceHelper.PROPERTY_JOB_TOPIC, topic);

            properties.remove(Job.PROPERTY_JOB_QUEUE_NAME);
            properties.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
            // and binary properties
            properties.putAll(binaryProperties);
            properties.remove("slingevent:properties");

            if ( !properties.containsKey(Job.PROPERTY_JOB_RETRIES) ) {
                properties.put(Job.PROPERTY_JOB_RETRIES, 10); // we put a dummy value here; this gets updated by the queue
            }
            if ( !properties.containsKey(Job.PROPERTY_JOB_RETRY_COUNT) ) {
                properties.put(Job.PROPERTY_JOB_RETRY_COUNT, 0);
            }

            final List<InstanceDescription> potentialTargets = caps.getPotentialTargets("/", null);
            String targetId = null;
            if ( potentialTargets != null && potentialTargets.size() > 0 ) {
                final QueueInfo info = configuration.getQueueConfigurationManager().getQueueInfo(topic);
                logger.debug("Found queue {} for {}", info.queueConfiguration, topic);
                targetId = caps.detectTarget(topic, vm, info);
                if ( targetId != null ) {
                    properties.put(Job.PROPERTY_JOB_QUEUE_NAME, info.queueName);
                    properties.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
                    properties.put(Job.PROPERTY_JOB_RETRIES, info.queueConfiguration.getMaxRetries());
                }
            }

            properties.put(Job.PROPERTY_JOB_CREATED_INSTANCE, "old:" + Environment.APPLICATION_ID);
            properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, ResourceHelper.RESOURCE_TYPE_JOB);

            final String jobId = configuration.getUniqueId(topic);
            properties.put(ResourceHelper.PROPERTY_JOB_ID, jobId);
            properties.remove(Job.PROPERTY_JOB_STARTED_TIME);

            final String newPath = configuration.getUniquePath(targetId, topic, jobId, vm);
            this.logger.debug("Moving 'old' job from {} to {}", jobResource.getPath(), newPath);

            ResourceHelper.getOrCreateResource(resolver, newPath, properties);
            resolver.delete(jobResource);
            resolver.commit();
        } catch (final InstantiationException ie) {
            throw new PersistenceException("Exception while reading reasource: " + ie.getMessage(), ie.getCause());
        }
    }
View Full Code Here

                    }

                } else {
                    final ValueMap vm = parent.adaptTo(ModifiableValueMap.class);
                    if ( vm == null ) {
                        throw new PersistenceException("Resource '" + parent.getPath() + "' is not modifiable.");
                    }
                    vm.remove(property.getName());
                }

                changes.add(Modification.onDeleted(property.getPath()));
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.