Skip to content

Commit

Permalink
Ignore child resources of parsys without assigned resource type (retu…
Browse files Browse the repository at this point in the history
…rning nt:unstructured as resource type).
  • Loading branch information
stefanseifert committed Feb 13, 2024
1 parent eb85cd1 commit d8b232b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<action type="update" dev="sseifert">
Switch to AEM 6.5.17 as minimum version.
</action>
<action type="fix" dev="sseifert">
Ignore child resources of parsys without assigned resource type (returning nt:unstructured as resource type).
</action>
</release>

<release version="1.7.2" date="2023-12-18">
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/wcm/wcm/parsys/controller/Parsys.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static io.wcm.wcm.parsys.ParsysNameConstants.PN_PARSYS_PARAGRAPH_VALIDATE;
import static io.wcm.wcm.parsys.ParsysNameConstants.PN_PARSYS_WRAPPER_CSS;
import static io.wcm.wcm.parsys.ParsysNameConstants.PN_PARSYS_WRAPPER_ELEMENT;
import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -157,6 +158,9 @@ private void activate() {
parsysParentResource = currentResource;
}
for (Resource childResource : parsysParentResource.getChildren()) {
if (!acceptResource(childResource)) {
continue;
}
Item item = createResourceItem(childResource);
if (wcmMode != WCMMode.DISABLED || item.isValid()) {
items.add(item);
Expand All @@ -167,6 +171,11 @@ private void activate() {
}
}

private static boolean acceptResource(Resource resource) {
// skip resources without assigned resource type
return !StringUtils.equals(resource.getResourceType(), NT_UNSTRUCTURED);
}

private static boolean getDecoration(String[] paragraphNoDecorationWcmMode, WCMMode wcmMode) {
if (paragraphNoDecorationWcmMode != null && paragraphNoDecorationWcmMode.length > 0) {
for (String wcmModeItem : paragraphNoDecorationWcmMode) {
Expand Down Expand Up @@ -364,6 +373,9 @@ public boolean isWrapperElement() {
private <T> Map<String, T> getChildModels(@NotNull Class<T> modelClass) {
Map<String, T> models = new LinkedHashMap<>();
for (Resource child : slingModelFilter.filterChildResources(currentResource.getChildren())) {
if (!acceptResource(child)) {
continue;
}
T model = modelFactory.getModelFromWrappedRequest(request, child, modelClass);
if (model != null) {
models.put(child.getName(), model);
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/io/wcm/wcm/parsys/controller/ParsysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public Iterable<Resource> answer(InvocationOnMock invocation) throws Throwable {
par2Resource = context.create().resource(parsysResource.getPath() + "/par2",
"sling:resourceType", COMPONENT_PATH_2,
"valid", false);
// this should be always ignored as it does not contain a resource type
context.create().resource(parsysResource.getPath() + "/ignore1",
"valid", true);

context.currentResource(parsysResource);
}
Expand Down Expand Up @@ -315,7 +318,8 @@ void testNewAreaResourceTypeFromSuperComponent() {
void testOtherParentParsysResource() {
context.create().resource("/apps/" + RESOURCE_TYPE_SAMPLE);
parsysResource = context.create().resource(page.getContentResource().getPath() + "/parsysOther");
par1Resource = context.create().resource(parsysResource.getPath() + "/par1");
par1Resource = context.create().resource(parsysResource.getPath() + "/par1",
"sling:resourceType", RESOURCE_TYPE_SAMPLE);

context.request().setAttribute(RA_PARSYS_PARENT_RESOURCE, parsysResource);

Expand Down

0 comments on commit d8b232b

Please sign in to comment.