/** * Wraps the {@code Resource} obtained by calling {@code create} on the wrapped resource resolver. * * @param parent The parent resource * @param name The name of the child resource - this is a plain name, not a path! * @param properties Optional properties for the resource * @return a wrapped resource obtained through the wrapped resource resolver */ @NotNull @Override public Resource create(@NotNull Resource parent, @NotNull String name, Map<String, Object> properties) throws PersistenceException { return ResourceResolverResourceWrapper.wrap(this, wrapped.create(parent, name, properties)); }
private Resource createMessageResource(ResourceResolver resolver) throws PersistenceException { final Resource parent = ResourceUtil.getOrCreateResource(resolver, SERIALIZED_ACTIONS, Collections.singletonMap("jcr:primaryType", (Object) "sling:OrderedFolder"), null, false); return resolver.create(parent, UUID.randomUUID().toString(), Collections.singletonMap("jcr:primaryType", (Object) "nt:unstructured")); }
public void createMissingNode(String path, ResourceResolver rr, Map<String, CompositeVariant> row) throws PersistenceException { String parentPath = StringUtils.substringBeforeLast(path, "/"); Resource parent = ResourceUtil.getOrCreateResource(rr, parentPath, defaultNodeType, defaultNodeType, true); String nodeName = StringUtils.substringAfterLast(path, "/"); if (!row.containsKey(JCR_PRIMARY_TYPE)) { row.put("JCR_TYPE", new CompositeVariant(defaultNodeType)); } Map<String, Object> nodeProps = new HashMap(row); rr.refresh(); rr.create(parent, nodeName, nodeProps); }
private Resource createHistoryComponent(Page historyPage) throws PersistenceException { ResourceResolver resourceResolver = historyPage.getContentResource().getResourceResolver(); Map<String, Object> props = ImmutableMap.<String, Object> builder()// .put(ResourceResolver.PROPERTY_RESOURCE_TYPE, HISTORY_COMPONENT_RESOURCE_TYPE) // .build(); return resourceResolver.create(historyPage.getContentResource(), HISTORY_COMPONENT, props); } }, null);
private Resource createHistoryComponent(Page historyPage) throws PersistenceException { ResourceResolver resourceResolver = historyPage.getContentResource().getResourceResolver(); Map<String, Object> props = ImmutableMap.<String, Object> builder()// .put(ResourceResolver.PROPERTY_RESOURCE_TYPE, HISTORY_COMPONENT_RESOURCE_TYPE) // .build(); return resourceResolver.create(historyPage.getContentResource(), HISTORY_COMPONENT, props); } }, null);
protected Resource getOrCreateStatusTrackingResource(ResourceResolver resourceResolver, Class<?> scriptClass) { String scriptClassName = scriptClass.getName(); Resource resource = resourceResolver.getResource(SCRIPT_STATUS_JCR_FOLDER + "/" + scriptClassName); if (resource == null) { Resource folder = resourceResolver.getResource(SCRIPT_STATUS_JCR_FOLDER); try { resource = resourceResolver.create(folder, scriptClassName, Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED)); } catch (PersistenceException re) { logger.error("On-deploy script cannot be run because the system could not find or create the script status node: {}/{}", SCRIPT_STATUS_JCR_FOLDER, scriptClassName); throw new OnDeployEarlyTerminationException(re); } } return resource; }
private void create(@NotNull final String path, @NotNull final Map<String, Object> properties) throws PersistenceException { final String parentPath = ResourceUtil.getParent(path); final String name = ResourceUtil.getName(path); final Resource parent = this.resolver.getResource(parentPath); this.resolver.create(parent, name, properties); }
private void createSequenceItemResource(Asset asset, ProcessArgs processArgs, ResourceResolver resourceResolver, Resource parentResource, AtomicInteger count, ValueMap properties) { try { resourceResolver.create(parentResource, String.valueOf(count.incrementAndGet()), new ImmutableMap.Builder<String, Object>() .put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED) .put("xmpNodeType", "xmpStruct") .put(processArgs.getNameProperty(), properties.get(PN_SMART_TAG_NAME, String.class)) .put(processArgs.getConfidenceProperty(), properties.get(PN_SMART_TAG_CONFIDENCE, Double.class)) .build()); } catch (PersistenceException e) { log.error("Unable to sync Smart Tag [ {} ] to XMP Metadata structure for asset [ {} ]", properties.get("name", String.class), asset.getPath(), e); } }
private Resource createWithChanges(final Resource parent, final String name, final String typeHint, final List<Modification> changes) throws PersistenceException { Map<String, Object> properties = null; if ( typeHint != null ) { // sling resource type not allowed for nt:file nor nt:resource if ( !jcrSupport.isNode(parent) || (!JcrConstants.NT_FILE.equals(typeHint) && !JcrConstants.NT_RESOURCE.equals(typeHint)) ) { properties = Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)typeHint); } else { properties = Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, (Object)typeHint); } } final Resource result = parent.getResourceResolver().create(parent, name, properties); changes.add(Modification.onCreated(result.getPath())); return result; }
@Before public void setup() throws Exception { resolver = resourceResolverFactory.getAdministrativeResourceResolver(null); assertNotNull("Expecting non-null ResourceResolver", resolver); final Resource root = resolver.getResource("/"); assertNotNull("Expecting non-null root Resource", root); final String path = getClass().getSimpleName() + "_" + System.currentTimeMillis(); testRoot = resolver.create(root, path, null); }
private Resource createResourceHierarchy(String path) { String parentPath = ResourceUtil.getParent(path); if (parentPath == null) { return null; } Resource parentResource = resourceResolver.getResource(parentPath); if (parentResource == null) { parentResource = createResourceHierarchy(parentPath); } Map<String, Object> props = new HashMap<>(); props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED); try { return resourceResolver.create(parentResource, ResourceUtil.getName(path), props); } catch (PersistenceException ex) { throw new RuntimeException(ex); } }
private Resource copy(ResourceResolver resolver, String sourcePath, Resource destParent) throws PersistenceException { Resource source = resolver.getResource(sourcePath); Map<String, Object> properties = Maps.newHashMap(source.getValueMap()); properties.remove(JcrConstants.JCR_UUID); Resource dest = resolver.create(destParent, source.getName(), properties); if (source.getChild(JcrConstants.JCR_CONTENT) != null) { copy(resolver, sourcePath + "/" + JcrConstants.JCR_CONTENT, dest); } return dest; }
private Resource copy(ResourceResolver resolver, String sourcePath, Resource destParent) throws PersistenceException { Resource source = resolver.getResource(sourcePath); Map<String, Object> properties = Maps.newHashMap(source.getValueMap()); properties.remove(JcrConstants.JCR_UUID); Resource dest = resolver.create(destParent, source.getName(), properties); if (source.getChild(JcrConstants.JCR_CONTENT) != null) { copy(resolver, sourcePath + "/" + JcrConstants.JCR_CONTENT, dest); } return dest; }
private static Resource createResource(Resource root, String relPath) throws PersistenceException { ResourceResolver resourceResolver = root.getResourceResolver(); String path = root.getPath() + "/" + relPath; final String parentPath = ResourceUtil.getParent(path); final String name = ResourceUtil.getName(path); Resource parent = ResourceUtil.getOrCreateResource(resourceResolver, parentPath, RESOURCE_FOLDER, RESOURCE_FOLDER, false); Map<String, Object> props = Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) RESOURCE_FOLDER); return resourceResolver.create(parent, name, props); }
protected void createOrUpdateChildren(String childName, Object fieldValue, Resource parent, SerializerContext ctx, ResourceResolver resolver) throws PersistenceException { Resource child = parent.getChild(childName); if (child == null) { child = resolver.create(parent, childName, ctx.getInitialProperties()); } else { removeExistingChildren(child); } createChildren(childName, fieldValue, ctx, child); }
private Resource createActionResource(ResourceResolver resolver, String actionType, String relPath) throws PersistenceException { final String path = createPath(relPath, config.getActionRoot(), config.getRandomPathPattern()); final Resource page = ResourceUtil.getOrCreateResource(resolver, path, Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, (Object) "cq:Page"), null, false); final Map<String, Object> contentMap = new LinkedHashMap<String, Object>(); contentMap.put(JcrConstants.JCR_PRIMARYTYPE, "cq:PageContent"); contentMap.put("cq:distribute", false); final Resource content = resolver.create(page, JcrConstants.JCR_CONTENT, contentMap); resolver.commit(); final ModifiableValueMap map = content.adaptTo(ModifiableValueMap.class); map.put(NameConstants.PN_PAGE_LAST_MOD, Calendar.getInstance()); map.put(NameConstants.PN_PAGE_LAST_MOD_BY, resolver.getUserID()); map.put("cq:distribute", true); return content; }
/** * Copy the source as a child resource to the parent */ private Resource copy(final Resource source, final Resource dest) throws PersistenceException { final ValueMap vm = source.getValueMap(); final Resource result = source.getResourceResolver().create(dest, source.getName(), vm); for(final Resource c : source.getChildren()) { copy(c, result); } return result; } }
/** * Move the source as a child resource to the parent */ private void move(final Resource source, final Resource dest) throws PersistenceException { // first copy final ValueMap vm = source.getValueMap(); final Resource result = source.getResourceResolver().create(dest, source.getName(), vm); for(final Resource c : source.getChildren()) { move(c, result); } // then delete source.getResourceResolver().delete(source); } }
private void createMissingTargetFolders(ResourceResolver rr, Resource source) throws RepositoryException, PersistenceException, MovingException { if (!resourceExists(rr, getDestinationPath())) { Actions.setCurrentItem(getSourcePath() + "->" + getDestinationPath()); String targetParentPath = StringUtils.substringBeforeLast(getDestinationPath(), "/"); String targetName = StringUtils.substringAfterLast(getDestinationPath(), "/"); if (getParent() == null) { if (!resourceExists(rr, getDestinationPath())) { createFolderNode(targetParentPath, rr); } } else { waitUntilResourceFound(rr, targetParentPath); } Resource destParent = rr.getResource(targetParentPath); Logger.getLogger(MovingFolder.class.getName()).log(Level.INFO, "Creating target for {0}", getSourcePath()); rr.create(destParent, targetName, getClonedProperties(source)); rr.commit(); rr.refresh(); } }
private void moveOrClonePage(ResourceResolver rr, PageManager manager, String contentPath, String destinationParent, ResourceResolver res) throws WCMException, PersistenceException { Resource source = rr.getResource(getSourcePath()); if (resourceExists(res, contentPath)) { manager.move(source, getDestinationPath(), getPreviousSibling(), true, true, listToStringArray(getAllReferences()), listToStringArray(getPublishedReferences())); } else if (!resourceExists(res, getDestinationPath())) { Resource parent = res.getResource(destinationParent); res.create(parent, source.getName(), getClonedProperties(source)); } res.commit(); res.refresh(); }