public void process()

in core/src/main/java/org/apache/sling/cms/core/internal/operations/TouchLastModifiedPostOperation.java [54:93]


    public void process(SlingHttpServletRequest request, final List<Modification> changes) throws Exception {

        // get the source of creates, modifies and reorders
        List<String> paths = changes.stream()
                .filter(m -> (m.getType() == ModificationType.CREATE || m.getType() == ModificationType.MODIFY
                        || m.getType() == ModificationType.ORDER))
                .map(Modification::getSource).collect(Collectors.toList());

        // get the destination for copies and moves
        paths.addAll(changes.stream()
                .filter(m -> (m.getType() == ModificationType.COPY || m.getType() == ModificationType.MOVE))
                .map(Modification::getDestination).collect(Collectors.toList()));
        log.debug("Found {} applicable paths", paths.size());
        
        // filter down to only distinct publishable resources
        Set<String> parentPaths = new HashSet<>();
        List<Resource> resources = paths.stream().map(p -> request.getResourceResolver().getResource(p))
                .map(CMSUtils::findPublishableParent).filter(p -> {
                    if (p == null || parentPaths.contains(p.getPath())) {
                        return false;
                    } else {
                        parentPaths.add(p.getPath());
                        return true;
                    }
                }).collect(Collectors.toList());
        log.debug("Filtered to {} publishable resources", resources.size());
        
        resources.forEach(r -> {
            Optional<ModifiableValueMap> op = Optional.ofNullable(r.getChild(JcrConstants.JCR_CONTENT))
                    .map(c -> c.adaptTo(ModifiableValueMap.class));
            op.ifPresent(mvm -> {
                log.debug("Updating last modified date on parent of {}", request.getResource());
                mvm.put(CMSConstants.PN_LAST_MODIFIED_BY, request.getResourceResolver().getUserID());
                mvm.put(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
            });
            if (!op.isPresent()) {
                log.warn("Unable to get modifiable value map for {}", request.getResource());
            }
        });
    }