/** * Delete the resource at the given path. * This change is kept in the transient space of this provider * until {@link #commit(ResolveContext)} is called. * <p> * This method is only called if the provider supports this and indicates * it by setting the {@link #PROPERTY_MODIFIABLE} to the value {@code true}. * * @param ctx The {@link ResolveContext}. * @param resource The resource to delete. * * @throws PersistenceException If anything fails */ public void delete(final @NotNull ResolveContext<T> ctx, final @NotNull Resource resource) throws PersistenceException { throw new PersistenceException("delete is not supported."); }
private JobResult runReplicated(ResourceResolver resolver, String searchPath) { JobResult result = JobResult.FAILED; final Script script = scriptFinder.find(searchPath, resolver); if (script == null) { LOG.warn("Replicated script cannot be found by script manager: {}", searchPath); } else if (ExecutionMode.ON_DEMAND.equals(script.getExecutionMode()) && script.isPublishRun()) { try { process(script, resolver); result = JobResult.OK; } catch (PersistenceException e) { LOG.error(e.getMessage(), e); } } return result; }
private static ConfigurationPersistenceException convertPersistenceException(String message, PersistenceException ex) { if (StringUtils.equals(ex.getCause().getClass().getName(), "javax.jcr.AccessDeniedException")) { // detect if commit failed due to read-only access to repository return new ConfigurationPersistenceAccessDeniedException("No write access: " + message, ex); } return new ConfigurationPersistenceException(message, ex); }
/** * Create a new persistence exception. * @param msg Exception message. * @param cause Exception cause. * @param resourcePath The optional resource path * @param propertyName The optional property name */ public PersistenceException(final String msg, final Throwable cause, final String resourcePath, final String propertyName) { super(msg); initCause(cause); this.resourcePath = resourcePath; this.propertyName = propertyName; }
/** * Create a new resource at the given path. * The new resource is put into the transient space of this provider * until {@link #commit(ResolveContext)} is called. * <p> * A resource provider must value {@link org.apache.sling.api.resource.ResourceResolver#PROPERTY_RESOURCE_TYPE} * to set the resource type of a resource. * <p> * This method is only called if the provider supports this and indicates * it by setting the {@link #PROPERTY_MODIFIABLE} to the value {@code true}. * * @param ctx The {@link ResolveContext}. * @param path The resource path. * @param properties Optional properties * @return The new resource. * * @throws PersistenceException If anything fails */ public @NotNull Resource create(final @NotNull ResolveContext<T> ctx, final String path, final Map<String, Object> properties) throws PersistenceException { throw new PersistenceException("create is not supported."); }
private JobResult runReplicated(ResourceResolver resolver, String searchPath) { JobResult result = JobResult.FAILED; final Script script = scriptFinder.find(searchPath, resolver); if (script == null) { LOG.warn("Replicated script cannot be found by script manager: {}", searchPath); } else if (ExecutionMode.ON_DEMAND.equals(script.getExecutionMode()) && script.isPublishRun()) { try { process(script, resolver); result = JobResult.OK; } catch (PersistenceException e) { LOG.error(e.getMessage(), e); } } return result; }
public void setTypedProperty(final Object n, final String name, final String[] values, final int type, final boolean multiValued) throws PersistenceException { if ( n != null && supportImpl != null ) { ((JCRSupportImpl)supportImpl).setTypedProperty(n, name, values, type, multiValued); } else { throw new PersistenceException("Property should be stored through JCR but JCR support is not available"); } }
ResourceHelper.getOrCreateBasePath(resolver, this.getUnassignedJobsPath()); } catch ( final PersistenceException pe ) { logger.error("Unable to create default paths: " + pe.getMessage(), pe); throw new RuntimeException(pe); } finally {
public void setPrimaryNodeType(final Object node, final String type) throws PersistenceException { if ( node != null && supportImpl != null ) { ((JCRSupportImpl)supportImpl).setPrimaryNodeType(node, type); } else { throw new PersistenceException("Node type should be set but JCR support is not available"); } }
ServletUtils.writeMessage(response, "error", String.format("Script '%s' cannot be processed because of" + " repository error: %s", scriptPath, e.getMessage())); } catch (ExecutionException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
public void setTypedProperty(final Object n, final String name, final String[] values, final int type, final boolean multiValued) throws PersistenceException { try { if (multiValued) { ((Node)n).setProperty(name, values, type); } else if (values.length >= 1) { ((Node)n).setProperty(name, values[0], type); } } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re); } }
ServletUtils.writeMessage(response, "error", String.format("Script '%s' cannot be processed because of" + " repository error: %s", scriptPath, e.getMessage())); } catch (ExecutionException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@Override public void commit(final @Nonnull ResolveContext<JcrProviderState> ctx) throws PersistenceException { try { ctx.getProviderState().getSession().save(); } catch (final RepositoryException e) { throw new PersistenceException("Unable to commit changes to session.", e); } }
@Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final ResourceResolver resolver = request.getResourceResolver(); final String searchPath = request.getParameter("scriptPath"); final Script script = scriptFinder.find(searchPath, resolver); if (script == null) { ServletUtils.writeMessage(response, "error", "Script not found: " + searchPath); return; } final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script); try { final String executionMode = request.getParameter("executionMode"); if (executionMode != null) { modifiableScript.setExecutionMode(ExecutionMode.valueOf(executionMode.toUpperCase())); } final String executionEnabled = request.getParameter("executionEnabled"); if (executionEnabled != null) { modifiableScript.setExecutionEnabled(BooleanUtils.toBoolean(executionEnabled)); } ServletUtils.writeMessage(response, "success", "Script configuration updated"); } catch (PersistenceException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); ServletUtils .writeMessage(response, "error", "Cannot update script configuration: " + e.getMessage()); } } }
public Integer getPropertyType(final Object node, final String name) throws PersistenceException { try { if ( ((Node)node).hasProperty(name) ) { return ((Node)node).getProperty(name).getType(); } } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re); } return null; }
@Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final ResourceResolver resolver = request.getResourceResolver(); final String searchPath = request.getParameter("scriptPath"); final Script script = scriptFinder.find(searchPath, resolver); if (script == null) { ServletUtils.writeMessage(response, "error", "Script not found: " + searchPath); return; } final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script); try { final String executionMode = request.getParameter("executionMode"); if (executionMode != null) { modifiableScript.setExecutionMode(ExecutionMode.valueOf(executionMode.toUpperCase())); } final String executionEnabled = request.getParameter("executionEnabled"); if (executionEnabled != null) { modifiableScript.setExecutionEnabled(BooleanUtils.toBoolean(executionEnabled)); } ServletUtils.writeMessage(response, "success", "Script configuration updated"); } catch (PersistenceException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); ServletUtils .writeMessage(response, "error", "Cannot update script configuration: " + e.getMessage()); } } }
/** * Create a unique asset name based on the current time and a up-to-1000 counter. * * @param assetManager assetManager object * @param destPath the folder the asset will be moved into * @param assetName the asset name * @return a unique asset path to the asset * @throws PersistenceException */ private String createUniqueAssetPath(AssetManager assetManager, String destPath, String assetName) throws PersistenceException { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); final String now = sdf.format(new Date()); String destAssetPath = destPath + "/" + assetName; int count = 0; while (assetManager.assetExists(destAssetPath)) { if (count > 1000) { throw new PersistenceException("Unable to generate a unique name after 1000 attempts. Something must be wrong!"); } if (count == 0) { destAssetPath = destPath + "/" + now + "_" + assetName; } else { destAssetPath = destPath + "/" + now + "_" + count + "_" + assetName; } count++; } return destAssetPath; }
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)) { deletedResources.add(resourceName); changedResources.remove(resourceName); } }
public void delete(ResourceResolver resolver, String path) throws PersistenceException { if (ROOT_PATH.equals(path) || !adapter.validPath(path)) { throw new PersistenceException("Unable to delete resource at {}" + path, null, path, null); } Pattern pathsToDeletePattern = PathUtil.getSameOrDescendantPathPattern(path); // remove all existing path and probably descendant paths from list of deleted paths Iterator<String> deletedResourcesIterator = deletedResources.iterator(); while (deletedResourcesIterator.hasNext()) { String deletedPath = deletedResourcesIterator.next(); if (pathsToDeletePattern.matcher(deletedPath).matches()) { deletedResourcesIterator.remove(); } } // remove all changed descendant items from changeset Iterator<Map.Entry<String, NoSqlData>> changeResourcesIterator = changedResources.entrySet().iterator(); while (changeResourcesIterator.hasNext()) { Map.Entry<String, NoSqlData> entry = changeResourcesIterator.next(); if (pathsToDeletePattern.matcher(entry.getKey()).matches()) { changeResourcesIterator.remove(); } } // add path to delete deletedResources.add(path); }
public void setPrimaryNodeType(final Object node, final String type) throws PersistenceException { try { ((Node)node).setPrimaryType(type); } catch ( final RepositoryException re) { throw new PersistenceException(re.getMessage(), re); } }