Skip to content

Commit

Permalink
Merge branch 'master' into redirects-qs
Browse files Browse the repository at this point in the history
  • Loading branch information
YegorKozlov authored Jan 19, 2025
2 parents fd01583 + 6932178 commit a33ab6e
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 27 deletions.
41 changes: 37 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ jobs:
- name: ${{ matrix.namePrefix }} Build with Maven ${{ env.STEP_NAME_SUFFIX }}
run: mvn -e -B -V ${{ env.MVN_GOAL }} ${{ env.MVN_ADDITIONAL_OPTS }}

- name: Publish Test Report
if: ${{ always() }} # make sure to run even if previous Maven execution failed (due to failed test)
uses: scacap/action-surefire-report@v1
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
check_name: Test report (${{ matrix.os }}, JDK ${{ matrix.jdk }})
name: Test Results (${{ matrix.os }}, JDK ${{ matrix.jdk }}))
path: |
**/target/surefire-reports/TEST*.xml
**/target/failsafe-reports/TEST*.xml
**/target/invoker-reports/TEST*.xml
**/target/it/**/build.log
# https://about.codecov.io/blog/javascript-code-coverage-using-github-actions-and-codecov/
- name: Upload code coverage to CodeCov (Main build)
Expand All @@ -107,3 +112,31 @@ jobs:
with:
changeLogPath: 'CHANGELOG.md'
skipLabels: 'Skip-Changelog,skip-changelog'

publish-test-results:
name: "Publish Tests Results"
needs: build
runs-on: ubuntu-latest
permissions:
checks: write

# only needed unless run with comment_mode: off
pull-requests: write

# only needed for private repository
contents: read

# only needed for private repository
issues: read
if: always()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: "artifacts/**/*.xml"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
### Fixed

- #3471 - EmailService not working due to unsatisfied reference to MailTemplateManager in AEM on prem
- #3497 - Redirect Manager: allow creating redirect configurations in a nested hierarchy

## 6.9.10 - 2024-12-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.api.resource.AbstractResourceVisitor;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* ACS AEM Commons
*
* Copyright (C) 2013 - 2023 Adobe
*
/*-
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2013 - 2024 Adobe
* %%
* 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
Expand All @@ -14,27 +15,23 @@
* 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.
* #L%
*/
package com.adobe.acs.commons.redirects.models;

import com.adobe.acs.commons.redirects.filter.RedirectFilter;
import com.adobe.acs.commons.redirects.filter.RedirectFilterMBean;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.AbstractResourceVisitor;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.query.Query;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

/**
Expand All @@ -61,12 +58,24 @@ public Collection<RedirectConfiguration> getConfigurations() {

Resource confRoot = request.getResourceResolver().getResource("/conf");

for (Resource child : confRoot.getChildren()) {
Resource res = child.getChild(storageSuffix);
if (res != null && res.isResourceType(REDIRECTS_RESOURCE_TYPE)) {
configurations.add(new RedirectConfiguration(res, storageSuffix));
new AbstractResourceVisitor() {
@Override
public void accept(Resource res) {
if (res != null) {
this.visit(res);
if(!res.getPath().endsWith(storageSuffix)){
this.traverseChildren(res.listChildren());
}
}
}

@Override
public void visit(Resource res) {
if (res.isResourceType(REDIRECTS_RESOURCE_TYPE)) {
configurations.add(new RedirectConfiguration(res, storageSuffix, false));
}
}
}
}.accept(confRoot);

configurations.sort(Comparator.comparing(RedirectConfiguration::getName));
return configurations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,25 @@ public class RedirectConfiguration {

private RedirectConfiguration(){
pathRules = new LinkedHashMap<>();
caseInsensitiveRules = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
patternRules = new LinkedHashMap<>();
}

public RedirectConfiguration(Resource resource, String storageSuffix) {
pathRules = new LinkedHashMap<>();
caseInsensitiveRules = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
patternRules = new LinkedHashMap<>();
path = resource.getPath();
this(resource, storageSuffix, true);
}

RedirectConfiguration(Resource configResource, String storageSuffix, boolean loadRules) {
this();
path = configResource.getPath();
name = path.replace("/" + storageSuffix, "");
Collection<RedirectRule> rules = RedirectFilter.getRules(resource);
if(loadRules){
loadRules(configResource);
}
}

void loadRules(Resource configResource) {
Collection<RedirectRule> rules = RedirectFilter.getRules(configResource);
for (RedirectRule rule : rules) {
if (rule.getRegex() != null) {
patternRules.put(rule.getRegex(), rule);
Expand All @@ -84,7 +93,6 @@ public RedirectConfiguration(Resource resource, String storageSuffix) {
/**
* @return resource path without .html extension
*/

public static String normalizePath(String resourcePath) {
int sep = resourcePath.lastIndexOf('.');
if (sep != -1 && !resourcePath.startsWith("/content/dam/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse
if (config == null) {
String contextPrefix = StringUtils.defaultString(request.getParameter(REQ_PARAM_CTX_PREFIX));
config = resolver.create(bucket, configName,
ImmutableMap.of(JcrConstants.JCR_PRIMARYTYPE, JcrResourceConstants.NT_SLING_FOLDER,
ImmutableMap.of(JcrConstants.JCR_PRIMARYTYPE, JcrResourceConstants.NT_SLING_ORDERED_FOLDER,
ResourceResolver.PROPERTY_RESOURCE_TYPE, REDIRECTS_RESOURCE_PATH,
REQ_PARAM_CTX_PREFIX, contextPrefix));
log.info("created {} with context prefix '{}'", config.getPath(), contextPrefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -73,6 +75,29 @@ public void createConfig() throws ServletException, IOException {
assertEquals(HttpServletResponse.SC_CONFLICT, context.response().getStatus());
}

@Test
public void createDeepHierarchies() throws ServletException, IOException {
context.build().resource("/conf/level0/level1/level2");

context.request().setParameterMap(Collections.singletonMap("path", "/conf/level0"));
servlet.doPost(context.request(), context.response());

context.request().setParameterMap(Collections.singletonMap("path", "/conf/level0/level1"));
servlet.doPost(context.request(), context.response());

context.request().setParameterMap(Collections.singletonMap("path", "/conf/level0/level1/level2"));
servlet.doPost(context.request(), context.response());

assertEquals(HttpServletResponse.SC_OK, context.response().getStatus());

// Read configurations via Model
Configurations confModel = context.request().adaptTo(Configurations.class);
Iterator<RedirectConfiguration> configurations = confModel.getConfigurations().iterator();
assertEquals("/conf/level0/settings/redirects", configurations.next().getPath());
assertEquals("/conf/level0/level1/settings/redirects", configurations.next().getPath());
assertEquals("/conf/level0/level1/level2/settings/redirects", configurations.next().getPath());
}

@Test
public void createConfigWithContextPrefix() throws ServletException, IOException {
context.build().resource("/conf/global");
Expand Down

0 comments on commit a33ab6e

Please sign in to comment.