Skip to content

Commit

Permalink
Merge pull request #508 from exadel-inc/release-2.5.0
Browse files Browse the repository at this point in the history
[Tech] Merged release-2.5.0 branch to master
  • Loading branch information
smiakchilo authored Feb 7, 2024
2 parents 32248aa + 93bec7f commit cf63b40
Show file tree
Hide file tree
Showing 37 changed files with 524 additions and 26 deletions.
2 changes: 1 addition & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit</artifactId>
<version>2.4.1</version>
<version>2.5.0</version>
</parent>

<artifactId>etoolbox-authoring-kit-all</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit</artifactId>
<version>2.4.1</version>
<version>2.5.0</version>
</parent>

<artifactId>etoolbox-authoring-kit-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exadel.aem.toolkit.api.annotations.policies;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.exadel.aem.toolkit.api.annotations.meta.ValueRestriction;
import com.exadel.aem.toolkit.api.annotations.meta.ValueRestrictions;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MaxChildren {
/**
* Specifies the maximum number of children allowed for container component
* @return Long value, 0 or greater
*/
@ValueRestriction(ValueRestrictions.NON_NEGATIVE)
long value();

/**
* Used to specify target node for max children limit. The limitation applies to the current annotated component
* if set to {@link PolicyTarget#CURRENT}. Otherwise, the limitation is applied to a container nested within the current
* component. E.g. if the current component is an inheritor of parsys, setting {@code targetContainer} to {@link
* PolicyTarget#CURRENT} means that the limitation affects which components can be added to the current
* one. But if the current component contains a parsys inside you need to skip {@code targetContainer} or set it to
* {@link PolicyTarget#CHILD} so that the limitation applies to the parsys.
* @return {@link PolicyTarget} value
*/
PolicyTarget targetContainer() default PolicyTarget.CHILD;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.exadel.aem.toolkit.api.annotations.policies;

/**
* Defines possible values of {@link AllowedChildren#targetContainer()} property
* Defines possible values of {@link AllowedChildren#targetContainer()} and {@link MaxChildren#targetContainer()} properties
*/
public enum PolicyTarget {
CHILD,
Expand Down
6 changes: 3 additions & 3 deletions docs/content/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ seoTitle: Installation - Exadel Authoring Kit
<dependency>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit-core</artifactId>
<version>2.4.1</version> <!-- Prefer the latest stable version whenever possible -->
<version>2.5.0</version> <!-- Prefer the latest stable version whenever possible -->
<scope>provided</scope> <!-- Do not use compile or runtime scope!-->
</dependency>
```
Expand All @@ -21,7 +21,7 @@ seoTitle: Installation - Exadel Authoring Kit
<plugin>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit-plugin</artifactId>
<version>2.4.1</version>
<version>2.5.0</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -79,7 +79,7 @@ You need to do two steps.
<dependency>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit-all</artifactId>
<version>2.4.1</version>
<version>2.5.0</version>
<type>content-package</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions docs/website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion it.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit</artifactId>
<version>2.4.1</version>
<version>2.5.0</version>
</parent>

<artifactId>etoolbox-authoring-kit-it.tests</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit</artifactId>
<version>2.4.1</version>
<version>2.5.0</version>
</parent>

<artifactId>etoolbox-authoring-kit-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.exadel.aem.toolkit.plugin.handlers.common.CqDialogHandler;
import com.exadel.aem.toolkit.plugin.handlers.common.CqEditConfigHandler;
import com.exadel.aem.toolkit.plugin.handlers.common.CqHtmlTagHandler;
import com.exadel.aem.toolkit.plugin.handlers.common.MaxChildrenHandler;
import com.exadel.aem.toolkit.plugin.handlers.common.PropertyMappingHandler;
import com.exadel.aem.toolkit.plugin.handlers.dependson.DependsOnHandler;
import com.exadel.aem.toolkit.plugin.handlers.editconfig.DropTargetsHandler;
Expand All @@ -54,12 +55,17 @@ public class Handlers {
private static final BiConsumer<Source, Target> CASUAL_ANNOTATIONS_HANDLER = new CasualAnnotationsHandler();
private static final BiConsumer<Source, Target> PROPERTY_MAPPING_HANDLER = new PropertyMappingHandler();
private static final BiConsumer<Source, Target> ALLOWED_CHILDREN_HANDLER = new AllowedChildrenHandler();
private static final BiConsumer<Source, Target> MAX_CHILDREN_HANDLER = new MaxChildrenHandler();

// UI-specific handlers
private static final BiConsumer<Source, Target> CHILD_EDIT_CONFIG_HANDLER = new CqChildEditConfigHandler().andThen(ALLOWED_CHILDREN_HANDLER);
private static final BiConsumer<Source, Target> CHILD_EDIT_CONFIG_HANDLER = new CqChildEditConfigHandler()
.andThen(ALLOWED_CHILDREN_HANDLER)
.andThen(MAX_CHILDREN_HANDLER);
private static final BiConsumer<Source, Target> COMPONENT_HANDLER = new ComponentHandler();
private static final BiConsumer<Source, Target> DIALOG_HANDLER = new CqDialogHandler();
private static final BiConsumer<Source, Target> EDIT_CONFIG_HANDLER = new CqEditConfigHandler().andThen(ALLOWED_CHILDREN_HANDLER);
private static final BiConsumer<Source, Target> EDIT_CONFIG_HANDLER = new CqEditConfigHandler()
.andThen(ALLOWED_CHILDREN_HANDLER)
.andThen(MAX_CHILDREN_HANDLER);
private static final BiConsumer<Source, Target> HTML_TAG_HANDLER = new CqHtmlTagHandler();
private static final Map<String, BiConsumer<Source, Target>> UI_HANDLERS = ImmutableMap.<String, BiConsumer<Source, Target>>builder()
.put(Scopes.COMPONENT, COMPONENT_HANDLER)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exadel.aem.toolkit.plugin.handlers.common;

import com.exadel.aem.toolkit.api.annotations.meta.Scopes;
import com.exadel.aem.toolkit.api.annotations.policies.MaxChildren;
import com.exadel.aem.toolkit.api.annotations.policies.PolicyTarget;
import com.exadel.aem.toolkit.api.handlers.Handler;
import com.exadel.aem.toolkit.api.handlers.Source;
import com.exadel.aem.toolkit.api.handlers.Target;
import com.exadel.aem.toolkit.plugin.utils.DialogConstants;

/**
* Implements {@code BiConsumer} to populate a {@link Target} instance with properties originating from a {@link Source}
* object. The source refers to the {@code resolvemaxchildren} listener of the {@code
* cq:editConfig} node of an AEM component
*/
public class MaxChildrenHandler implements Handler {
/**
* Name of the listener to resolve max children limit for `policies` js module
*/
public static final String MAX_CHILDREN_RESOLVER_NAME = "resolvemaxchildren";

/**
* Format of default max children limit resolver
*/
private static final String MAX_CHILDREN_RESOLVER_FORMAT = "() => %d";


/**
* Processes data that can be extracted from the given {@code Source} and stores it into the provided {@code
* Target}
* @param source {@code Source} object used for data retrieval
* @param target Resulting {@code Target} object
*/
@Override
public void accept(Source source, Target target) {
source.tryAdaptTo(MaxChildren.class).ifPresent(adaptation -> populate(adaptation, target));
}

/**
* Processes data from {@code MaxChildren} annotation and stores it into 'cq:listeners' node of the provided
* {@code Target}
* @param rule {@code MaxChildren} object used for data retrieval
* @param target Resulting {@code Target} object
*/
private static void populate(MaxChildren rule, Target target) {
if (isEditConfig(target) == (PolicyTarget.CURRENT == rule.targetContainer())) {
target
.attribute(DialogConstants.PN_PRIMARY_TYPE, DialogConstants.NT_EDIT_CONFIG)
.getOrCreateTarget(DialogConstants.NN_LISTENERS)
.attribute(DialogConstants.PN_PRIMARY_TYPE, DialogConstants.NT_LISTENERS)
.attribute(MAX_CHILDREN_RESOLVER_NAME, String.format(MAX_CHILDREN_RESOLVER_FORMAT, rule.value()));
}
}

/**
* Gets whether the given {@link Target} is a representation of a {@code cq:editConfig} node of an AEM component
* @param target {@code Target} instance
* @return True if the target is a {@code cq:editConfig} node; otherwise, false
*/
private static boolean isEditConfig(Target target) {
return Scopes.CQ_EDIT_CONFIG.equals(target.getScope());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.exadel.aem.toolkit.api.annotations.editconfig.ChildEditConfig;
import com.exadel.aem.toolkit.api.annotations.meta.Scopes;
import com.exadel.aem.toolkit.api.annotations.policies.AllowedChildren;
import com.exadel.aem.toolkit.api.annotations.policies.MaxChildren;
import com.exadel.aem.toolkit.api.annotations.policies.PolicyTarget;
import com.exadel.aem.toolkit.api.handlers.Source;

Expand Down Expand Up @@ -55,6 +56,8 @@ boolean canProcess(Source source) {
Class<?> componentClass = (Class<?>) source.adaptTo(Class.class);
return componentClass.isAnnotationPresent(ChildEditConfig.class)
|| Arrays.stream(componentClass.getAnnotationsByType(AllowedChildren.class))
.anyMatch(ac -> PolicyTarget.CHILD.equals(ac.targetContainer()))
|| Arrays.stream(componentClass.getAnnotationsByType(MaxChildren.class))
.anyMatch(ac -> PolicyTarget.CHILD.equals(ac.targetContainer()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.exadel.aem.toolkit.api.annotations.editconfig.EditConfig;
import com.exadel.aem.toolkit.api.annotations.meta.Scopes;
import com.exadel.aem.toolkit.api.annotations.policies.AllowedChildren;
import com.exadel.aem.toolkit.api.annotations.policies.MaxChildren;
import com.exadel.aem.toolkit.api.annotations.policies.PolicyTarget;
import com.exadel.aem.toolkit.api.handlers.Source;

Expand Down Expand Up @@ -56,6 +57,8 @@ boolean canProcess(Source source) {
Class<?> componentClass = (Class<?>) source.adaptTo(Class.class);
return componentClass.isAnnotationPresent(EditConfig.class)
|| Arrays.stream(componentClass.getAnnotationsByType(AllowedChildren.class))
.anyMatch(ac -> PolicyTarget.CURRENT.equals(ac.targetContainer()))
|| Arrays.stream(componentClass.getAnnotationsByType(MaxChildren.class))
.anyMatch(ac -> PolicyTarget.CURRENT.equals(ac.targetContainer()));
}
}
2 changes: 2 additions & 0 deletions plugin/src/test/com/exadel/aem/toolkit/plugin/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.exadel.aem.toolkit.plugin.handlers.common.ComponentsTest;
import com.exadel.aem.toolkit.plugin.handlers.common.EditConfigTest;
import com.exadel.aem.toolkit.plugin.handlers.common.IgnoreFreshnessTest;
import com.exadel.aem.toolkit.plugin.handlers.common.MaxChildrenTest;
import com.exadel.aem.toolkit.plugin.handlers.common.WriteModeTest;
import com.exadel.aem.toolkit.plugin.handlers.dependson.DependsOnTest;
import com.exadel.aem.toolkit.plugin.handlers.placement.CoincidenceTest;
Expand Down Expand Up @@ -63,6 +64,7 @@
AllowedChildrenTest.class,
DependsOnTest.class,
IgnoreFreshnessTest.class,
MaxChildrenTest.class,

LayoutTest.class,
ReplacementTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.exadel.aem.toolkit.plugin.handlers.common;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import com.exadel.aem.toolkit.plugin.handlers.common.cases.maxchildren.MaxChildrenTestCases;
import com.exadel.aem.toolkit.plugin.maven.FileSystemRule;
import com.exadel.aem.toolkit.plugin.maven.PluginContextRenderingRule;

public class MaxChildrenTest {

@ClassRule
public static FileSystemRule fileSystemHost = new FileSystemRule();

@Rule
public PluginContextRenderingRule pluginContext = new PluginContextRenderingRule(fileSystemHost.getFileSystem());

@Test
public void testSimpleAnnotation() {
pluginContext.test(MaxChildrenTestCases.SimpleMaxLimitAnnotation.class, "handlers/common/maxChildren/simple");
}

@Test
public void testAllowedChildrenWithMaxLimitConflict() {
pluginContext.test(MaxChildrenTestCases.AllowedChildrenWithMaxLimit.class, "handlers/common/maxChildren/withAllowedChildren");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.exadel.aem.toolkit.plugin.handlers.common.cases.maxchildren;

import com.exadel.aem.toolkit.api.annotations.main.AemComponent;
import com.exadel.aem.toolkit.api.annotations.policies.AllowedChildren;
import com.exadel.aem.toolkit.api.annotations.policies.MaxChildren;
import com.exadel.aem.toolkit.api.annotations.policies.PolicyMergeMode;
import com.exadel.aem.toolkit.plugin.handlers.common.cases.components.ComplexComponent1;
import com.exadel.aem.toolkit.plugin.handlers.common.cases.components.ComplexComponent2;
import com.exadel.aem.toolkit.plugin.maven.TestConstants;

public class MaxChildrenTestCases {
@AemComponent(
title = TestConstants.DEFAULT_COMPONENT_TITLE,
path = TestConstants.DEFAULT_COMPONENT_NAME
)
@MaxChildren(5)
public static class SimpleMaxLimitAnnotation {
}

@AemComponent(
title = TestConstants.DEFAULT_COMPONENT_TITLE,
path = TestConstants.DEFAULT_COMPONENT_NAME
)
@AllowedChildren(
classes = {ComplexComponent1.class, ComplexComponent2.class},
pagePaths = {"page/Path1, page/Path2"},
mode = PolicyMergeMode.MERGE
)
@MaxChildren(1)
public static class AllowedChildrenWithMaxLimit {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0"
jcr:primaryType="cq:Component"
jcr:title="Test Component"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:EditConfig">
<cq:listeners jcr:primaryType="cq:EditListenersConfig"
resolvemaxchildren="() => 5"/>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0"
jcr:primaryType="cq:Component"
jcr:title="Test Component"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:EditConfig">
<cq:listeners jcr:primaryType="cq:EditListenersConfig"
resolvemaxchildren="() => 1"
updatecomponentlist="Granite.PolicyResolver.build('{&quot;isEditConfig&quot;:false,&quot;rules&quot;:[{&quot;value&quot;:[&quot;/apps/eak/test-component&quot;],&quot;pagePaths&quot;:[&quot;page/Path1&quot;,&quot;page/Path2&quot;],&quot;mode&quot;:&quot;MERGE&quot;}]}')"/>
</jcr:root>
Loading

0 comments on commit cf63b40

Please sign in to comment.