Skip to content

Commit cf63b40

Browse files
authored
Merge pull request #508 from exadel-inc/release-2.5.0
[Tech] Merged release-2.5.0 branch to master
2 parents 32248aa + 93bec7f commit cf63b40

File tree

37 files changed

+524
-26
lines changed

37 files changed

+524
-26
lines changed

all/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.exadel.etoolbox</groupId>
99
<artifactId>etoolbox-authoring-kit</artifactId>
10-
<version>2.4.1</version>
10+
<version>2.5.0</version>
1111
</parent>
1212

1313
<artifactId>etoolbox-authoring-kit-all</artifactId>

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.exadel.etoolbox</groupId>
99
<artifactId>etoolbox-authoring-kit</artifactId>
10-
<version>2.4.1</version>
10+
<version>2.5.0</version>
1111
</parent>
1212

1313
<artifactId>etoolbox-authoring-kit-core</artifactId>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License").
3+
* You may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.exadel.aem.toolkit.api.annotations.policies;
15+
16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Retention;
18+
import java.lang.annotation.RetentionPolicy;
19+
import java.lang.annotation.Target;
20+
21+
import com.exadel.aem.toolkit.api.annotations.meta.ValueRestriction;
22+
import com.exadel.aem.toolkit.api.annotations.meta.ValueRestrictions;
23+
24+
@Target(ElementType.TYPE)
25+
@Retention(RetentionPolicy.RUNTIME)
26+
public @interface MaxChildren {
27+
/**
28+
* Specifies the maximum number of children allowed for container component
29+
* @return Long value, 0 or greater
30+
*/
31+
@ValueRestriction(ValueRestrictions.NON_NEGATIVE)
32+
long value();
33+
34+
/**
35+
* Used to specify target node for max children limit. The limitation applies to the current annotated component
36+
* if set to {@link PolicyTarget#CURRENT}. Otherwise, the limitation is applied to a container nested within the current
37+
* component. E.g. if the current component is an inheritor of parsys, setting {@code targetContainer} to {@link
38+
* PolicyTarget#CURRENT} means that the limitation affects which components can be added to the current
39+
* one. But if the current component contains a parsys inside you need to skip {@code targetContainer} or set it to
40+
* {@link PolicyTarget#CHILD} so that the limitation applies to the parsys.
41+
* @return {@link PolicyTarget} value
42+
*/
43+
PolicyTarget targetContainer() default PolicyTarget.CHILD;
44+
}

core/src/main/java/com/exadel/aem/toolkit/api/annotations/policies/PolicyTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package com.exadel.aem.toolkit.api.annotations.policies;
1515

1616
/**
17-
* Defines possible values of {@link AllowedChildren#targetContainer()} property
17+
* Defines possible values of {@link AllowedChildren#targetContainer()} and {@link MaxChildren#targetContainer()} properties
1818
*/
1919
public enum PolicyTarget {
2020
CHILD,

docs/content/getting-started/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ seoTitle: Installation - Exadel Authoring Kit
1111
<dependency>
1212
<groupId>com.exadel.etoolbox</groupId>
1313
<artifactId>etoolbox-authoring-kit-core</artifactId>
14-
<version>2.4.1</version> <!-- Prefer the latest stable version whenever possible -->
14+
<version>2.5.0</version> <!-- Prefer the latest stable version whenever possible -->
1515
<scope>provided</scope> <!-- Do not use compile or runtime scope!-->
1616
</dependency>
1717
```
@@ -21,7 +21,7 @@ seoTitle: Installation - Exadel Authoring Kit
2121
<plugin>
2222
<groupId>com.exadel.etoolbox</groupId>
2323
<artifactId>etoolbox-authoring-kit-plugin</artifactId>
24-
<version>2.4.1</version>
24+
<version>2.5.0</version>
2525
<executions>
2626
<execution>
2727
<goals>
@@ -79,7 +79,7 @@ You need to do two steps.
7979
<dependency>
8080
<groupId>com.exadel.etoolbox</groupId>
8181
<artifactId>etoolbox-authoring-kit-all</artifactId>
82-
<version>2.4.1</version>
82+
<version>2.5.0</version>
8383
<type>content-package</type>
8484
</dependency>
8585
```

docs/website/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

it.tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.exadel.etoolbox</groupId>
2222
<artifactId>etoolbox-authoring-kit</artifactId>
23-
<version>2.4.1</version>
23+
<version>2.5.0</version>
2424
</parent>
2525

2626
<artifactId>etoolbox-authoring-kit-it.tests</artifactId>

plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.exadel.etoolbox</groupId>
99
<artifactId>etoolbox-authoring-kit</artifactId>
10-
<version>2.4.1</version>
10+
<version>2.5.0</version>
1111
</parent>
1212

1313
<artifactId>etoolbox-authoring-kit-plugin</artifactId>

plugin/src/main/java/com/exadel/aem/toolkit/plugin/handlers/Handlers.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.exadel.aem.toolkit.plugin.handlers.common.CqDialogHandler;
2929
import com.exadel.aem.toolkit.plugin.handlers.common.CqEditConfigHandler;
3030
import com.exadel.aem.toolkit.plugin.handlers.common.CqHtmlTagHandler;
31+
import com.exadel.aem.toolkit.plugin.handlers.common.MaxChildrenHandler;
3132
import com.exadel.aem.toolkit.plugin.handlers.common.PropertyMappingHandler;
3233
import com.exadel.aem.toolkit.plugin.handlers.dependson.DependsOnHandler;
3334
import com.exadel.aem.toolkit.plugin.handlers.editconfig.DropTargetsHandler;
@@ -54,12 +55,17 @@ public class Handlers {
5455
private static final BiConsumer<Source, Target> CASUAL_ANNOTATIONS_HANDLER = new CasualAnnotationsHandler();
5556
private static final BiConsumer<Source, Target> PROPERTY_MAPPING_HANDLER = new PropertyMappingHandler();
5657
private static final BiConsumer<Source, Target> ALLOWED_CHILDREN_HANDLER = new AllowedChildrenHandler();
58+
private static final BiConsumer<Source, Target> MAX_CHILDREN_HANDLER = new MaxChildrenHandler();
5759

5860
// UI-specific handlers
59-
private static final BiConsumer<Source, Target> CHILD_EDIT_CONFIG_HANDLER = new CqChildEditConfigHandler().andThen(ALLOWED_CHILDREN_HANDLER);
61+
private static final BiConsumer<Source, Target> CHILD_EDIT_CONFIG_HANDLER = new CqChildEditConfigHandler()
62+
.andThen(ALLOWED_CHILDREN_HANDLER)
63+
.andThen(MAX_CHILDREN_HANDLER);
6064
private static final BiConsumer<Source, Target> COMPONENT_HANDLER = new ComponentHandler();
6165
private static final BiConsumer<Source, Target> DIALOG_HANDLER = new CqDialogHandler();
62-
private static final BiConsumer<Source, Target> EDIT_CONFIG_HANDLER = new CqEditConfigHandler().andThen(ALLOWED_CHILDREN_HANDLER);
66+
private static final BiConsumer<Source, Target> EDIT_CONFIG_HANDLER = new CqEditConfigHandler()
67+
.andThen(ALLOWED_CHILDREN_HANDLER)
68+
.andThen(MAX_CHILDREN_HANDLER);
6369
private static final BiConsumer<Source, Target> HTML_TAG_HANDLER = new CqHtmlTagHandler();
6470
private static final Map<String, BiConsumer<Source, Target>> UI_HANDLERS = ImmutableMap.<String, BiConsumer<Source, Target>>builder()
6571
.put(Scopes.COMPONENT, COMPONENT_HANDLER)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License").
3+
* You may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.exadel.aem.toolkit.plugin.handlers.common;
15+
16+
import com.exadel.aem.toolkit.api.annotations.meta.Scopes;
17+
import com.exadel.aem.toolkit.api.annotations.policies.MaxChildren;
18+
import com.exadel.aem.toolkit.api.annotations.policies.PolicyTarget;
19+
import com.exadel.aem.toolkit.api.handlers.Handler;
20+
import com.exadel.aem.toolkit.api.handlers.Source;
21+
import com.exadel.aem.toolkit.api.handlers.Target;
22+
import com.exadel.aem.toolkit.plugin.utils.DialogConstants;
23+
24+
/**
25+
* Implements {@code BiConsumer} to populate a {@link Target} instance with properties originating from a {@link Source}
26+
* object. The source refers to the {@code resolvemaxchildren} listener of the {@code
27+
* cq:editConfig} node of an AEM component
28+
*/
29+
public class MaxChildrenHandler implements Handler {
30+
/**
31+
* Name of the listener to resolve max children limit for `policies` js module
32+
*/
33+
public static final String MAX_CHILDREN_RESOLVER_NAME = "resolvemaxchildren";
34+
35+
/**
36+
* Format of default max children limit resolver
37+
*/
38+
private static final String MAX_CHILDREN_RESOLVER_FORMAT = "() => %d";
39+
40+
41+
/**
42+
* Processes data that can be extracted from the given {@code Source} and stores it into the provided {@code
43+
* Target}
44+
* @param source {@code Source} object used for data retrieval
45+
* @param target Resulting {@code Target} object
46+
*/
47+
@Override
48+
public void accept(Source source, Target target) {
49+
source.tryAdaptTo(MaxChildren.class).ifPresent(adaptation -> populate(adaptation, target));
50+
}
51+
52+
/**
53+
* Processes data from {@code MaxChildren} annotation and stores it into 'cq:listeners' node of the provided
54+
* {@code Target}
55+
* @param rule {@code MaxChildren} object used for data retrieval
56+
* @param target Resulting {@code Target} object
57+
*/
58+
private static void populate(MaxChildren rule, Target target) {
59+
if (isEditConfig(target) == (PolicyTarget.CURRENT == rule.targetContainer())) {
60+
target
61+
.attribute(DialogConstants.PN_PRIMARY_TYPE, DialogConstants.NT_EDIT_CONFIG)
62+
.getOrCreateTarget(DialogConstants.NN_LISTENERS)
63+
.attribute(DialogConstants.PN_PRIMARY_TYPE, DialogConstants.NT_LISTENERS)
64+
.attribute(MAX_CHILDREN_RESOLVER_NAME, String.format(MAX_CHILDREN_RESOLVER_FORMAT, rule.value()));
65+
}
66+
}
67+
68+
/**
69+
* Gets whether the given {@link Target} is a representation of a {@code cq:editConfig} node of an AEM component
70+
* @param target {@code Target} instance
71+
* @return True if the target is a {@code cq:editConfig} node; otherwise, false
72+
*/
73+
private static boolean isEditConfig(Target target) {
74+
return Scopes.CQ_EDIT_CONFIG.equals(target.getScope());
75+
}
76+
}

0 commit comments

Comments
 (0)