Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore child resources of parsys without assigned resource type (returning nt:unstructured as resource type) #2

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" issue="2">
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
Loading