-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #508 from exadel-inc/release-2.5.0
[Tech] Merged release-2.5.0 branch to master
- Loading branch information
Showing
37 changed files
with
524 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/main/java/com/exadel/aem/toolkit/api/annotations/policies/MaxChildren.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
plugin/src/main/java/com/exadel/aem/toolkit/plugin/handlers/common/MaxChildrenHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
plugin/src/test/com/exadel/aem/toolkit/plugin/handlers/common/MaxChildrenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...com/exadel/aem/toolkit/plugin/handlers/common/cases/maxchildren/MaxChildrenTestCases.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
plugin/src/test/resources/handlers/common/maxChildren/simple/.content.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
7 changes: 7 additions & 0 deletions
7
plugin/src/test/resources/handlers/common/maxChildren/simple/_cq_childEditConfig.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
plugin/src/test/resources/handlers/common/maxChildren/withAllowedChildren/.content.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
8 changes: 8 additions & 0 deletions
8
...rc/test/resources/handlers/common/maxChildren/withAllowedChildren/_cq_childEditConfig.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('{"isEditConfig":false,"rules":[{"value":["/apps/eak/test-component"],"pagePaths":["page/Path1","page/Path2"],"mode":"MERGE"}]}')"/> | ||
</jcr:root> |
Oops, something went wrong.