@Test public void testDropTargetWithSkuSelection() throws Exception { Map<String, Object> map = new HashMap<>(); map.put("./multiDropTarget->@items", "/var/commerce/products/a"); map.put("./selectionId", "sku"); map.put("./multiple", Boolean.FALSE); map.put("./@CopyFrom", "/does/not/matter"); List<Modification> modifications = new ArrayList<>(); modifications.add(Modification.onCopied("/does/not/matter", "/content/postprocessor/jcr:content/noExistingMultiValue")); MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver()); request.setResource(context.resourceResolver().resolve("/content/postprocessor/jcr:content/noExistingComposite")); request.setParameterMap(map); MultiFieldDropTargetPostProcessor dropTargetPostProcessor = new MultiFieldDropTargetPostProcessor(); dropTargetPostProcessor.process(request, modifications); assertThat(modifications).hasSize(2); Resource resource = request.getResource(); assertThat(resource.getValueMap()).hasSize(1); Resource dropTargetResource = resource.getResourceResolver().getResource("/content/postprocessor/jcr:content/noExistingMultiValue"); ValueMap targetValueMap = dropTargetResource.getValueMap(); assertThat(targetValueMap.get("items", String.class)).isEqualTo("a"); }
@Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } } }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }  }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }  @Override void process(SlingHttpServletRequest request, List<Modification> modifications); }
MultiFieldDropTargetPostProcessor implements SlingPostProcessor { @Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }  @Override void process(SlingHttpServletRequest request, List<Modification> modifications);  }