From 3428d833878a1e79fb41a33f3fbb91811c791549 Mon Sep 17 00:00:00 2001 From: Barry d'Hoine Date: Wed, 19 Jun 2024 21:00:08 +0200 Subject: [PATCH] WIP --- core/pom.xml | 30 ++++++++++++--- .../services/impl/DictionaryServiceImpl.java | 23 ++++++++--- .../AvailableLanguageDatasource.java | 38 ++++++++++++------- pom.xml | 13 ++++++- ui.apps/pom.xml | 6 ++- 5 files changed, 82 insertions(+), 28 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index f9e0163c..8fa48bf1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -52,10 +52,28 @@ Import-Package: javax.annotation;version=0.0.0,* + + + + com.adobe.aem - aem-sdk-api + uber-jar + + + + org.osgi + org.osgi.service.component.annotations + + org.osgi + org.osgi.annotation.versioning + + + org.apache.sling + org.apache.sling.servlets.annotations + + org.apache.commons commons-csv @@ -66,11 +84,11 @@ Import-Package: javax.annotation;version=0.0.0,* - - com.adobe.cq - core.wcm.components.core - test - + + + + + org.junit.jupiter junit-jupiter diff --git a/core/src/main/java/be/orbinson/aem/dictionarytranslator/services/impl/DictionaryServiceImpl.java b/core/src/main/java/be/orbinson/aem/dictionarytranslator/services/impl/DictionaryServiceImpl.java index c574db94..66a2b9ce 100644 --- a/core/src/main/java/be/orbinson/aem/dictionarytranslator/services/impl/DictionaryServiceImpl.java +++ b/core/src/main/java/be/orbinson/aem/dictionarytranslator/services/impl/DictionaryServiceImpl.java @@ -2,10 +2,17 @@ import be.orbinson.aem.dictionarytranslator.services.DictionaryService; import com.adobe.granite.translation.api.TranslationConfig; +import com.adobe.granite.translation.api.TranslationException; import com.day.cq.commons.jcr.JcrConstants; import com.day.cq.commons.jcr.JcrUtil; import org.apache.commons.lang3.StringUtils; -import org.apache.sling.api.resource.*; +import org.apache.sling.api.resource.LoginException; +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.api.resource.ResourceResolverFactory; +import org.apache.sling.api.resource.ResourceUtil; +import org.apache.sling.api.resource.ValueMap; import org.apache.sling.jcr.resource.api.JcrResourceConstants; import org.jetbrains.annotations.NotNull; import org.osgi.service.component.annotations.Component; @@ -13,7 +20,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.atomic.AtomicReference; import static org.apache.jackrabbit.JcrConstants.JCR_LANGUAGE; @@ -58,8 +69,8 @@ private ResourceResolver getServiceResourceResolver() throws LoginException { Resource resource = resourceResolver.getResource(path); if (resource != null && translationConfig != null) { - try (ResourceResolver serviceResourceResolver = getServiceResourceResolver()) { - Map languages = translationConfig.getLanguages(serviceResourceResolver); + try { + Map languages = translationConfig.getLanguages(); resource.getChildren().forEach(child -> { if (child.getValueMap().containsKey(JcrConstants.JCR_LANGUAGE)) { @@ -71,8 +82,8 @@ private ResourceResolver getServiceResourceResolver() throws LoginException { } } }); - } catch (LoginException e) { - LOG.error("Unable to get service resource resolver to get languages", e); + } catch (TranslationException e) { + LOG.error("Unable to get languages", e); } } diff --git a/core/src/main/java/be/orbinson/aem/dictionarytranslator/servlets/datasource/AvailableLanguageDatasource.java b/core/src/main/java/be/orbinson/aem/dictionarytranslator/servlets/datasource/AvailableLanguageDatasource.java index aa5fad81..1e0ee21b 100644 --- a/core/src/main/java/be/orbinson/aem/dictionarytranslator/servlets/datasource/AvailableLanguageDatasource.java +++ b/core/src/main/java/be/orbinson/aem/dictionarytranslator/servlets/datasource/AvailableLanguageDatasource.java @@ -1,6 +1,7 @@ package be.orbinson.aem.dictionarytranslator.servlets.datasource; import com.adobe.granite.translation.api.TranslationConfig; +import com.adobe.granite.translation.api.TranslationException; import com.adobe.granite.ui.components.ds.DataSource; import com.adobe.granite.ui.components.ds.SimpleDataSource; import com.adobe.granite.ui.components.ds.ValueMapResource; @@ -19,7 +20,12 @@ import org.slf4j.LoggerFactory; import javax.servlet.Servlet; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; @Component(service = Servlet.class) @SlingServletResourceTypes( @@ -62,21 +68,27 @@ protected void doGet(SlingHttpServletRequest request, @NotNull SlingHttpServletR ResourceResolver resourceResolver = request.getResourceResolver(); String languageParameter = request.getRequestPathInfo().getSuffix(); - Map languageMap = new HashMap<>(translationConfig.getLanguages(resourceResolver)); - filterExistingLanguages(languageMap, resourceResolver, languageParameter); - Map sortedLanguageMap = sortByValue(languageMap); + Map languageMap = null; + try { + languageMap = new HashMap<>(translationConfig.getLanguages()); - List resourceList = new ArrayList<>(); - sortedLanguageMap.forEach((key, value) -> { - String text = String.format("%s (%s)", value, key); - ValueMap valueMap = new ValueMapDecorator(Map.of("value", key, "text", text)); + filterExistingLanguages(languageMap, resourceResolver, languageParameter); + Map sortedLanguageMap = sortByValue(languageMap); - LOG.debug("Add language '{}' to datasource with key '{}'", text, key); - resourceList.add(new ValueMapResource(resourceResolver, "", "", valueMap)); - }); + List resourceList = new ArrayList<>(); + sortedLanguageMap.forEach((key, value) -> { + String text = String.format("%s (%s)", value, key); + ValueMap valueMap = new ValueMapDecorator(Map.of("value", key, "text", text)); - DataSource dataSource = new SimpleDataSource(resourceList.iterator()); - request.setAttribute(DataSource.class.getName(), dataSource); + LOG.debug("Add language '{}' to datasource with key '{}'", text, key); + resourceList.add(new ValueMapResource(resourceResolver, "", "", valueMap)); + }); + + DataSource dataSource = new SimpleDataSource(resourceList.iterator()); + request.setAttribute(DataSource.class.getName(), dataSource); + } catch (TranslationException e) { + LOG.error("Unable to get languages", e); + } } } diff --git a/pom.xml b/pom.xml index fd4dd5df..b2ade3f1 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,7 @@ Dictionary Translator Orbinson Tools + 6.5.21 2023.6.12255.20230608T053118Z-230400 1.5.8 @@ -559,10 +560,18 @@ Bundle-DocURL: + + + + + + + + io.wcm.maven - io.wcm.maven.aem-cloud-dependencies - ${aem.sdk.api.version}.0000 + io.wcm.maven.aem-dependencies + ${aem.version}.0000 pom import diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 0ea054c8..1fb48d3c 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -84,9 +84,13 @@ zip + + + + com.adobe.aem - aem-sdk-api + uber-jar