Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bdhoine committed Nov 14, 2024
2 parents c951f56 + 0628b5a commit e888b01
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Updated terminology to message entry and key instead of label [#33] [#33](https://github.com/orbinson/aem-dictionary-translator/issues/24)
- Updated terminology to message entry and key instead of label [#33](https://github.com/orbinson/aem-dictionary-translator/issues/33)
- Added /conf as editable root for dictionaries [#46](https://github.com/orbinson/aem-dictionary-translator/issues/46)
- Bump all maven dependencies to latest version [#51](https://github.com/orbinson/aem-dictionary-translator/pull/51)

## [1.1.4] - 2024-09-16
Expand Down Expand Up @@ -130,4 +131,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[1.0.1]: https://github.com/orbinson/aem-dictionary-translator/compare/1.0.0...1.0.1

[1.0.0]: https://github.com/orbinson/aem-dictionary-translator/compare/aef9658ce0967039de44f69228c16744d45e2764...1.0.0
[1.0.0]: https://github.com/orbinson/aem-dictionary-translator/compare/aef9658ce0967039de44f69228c16744d45e2764...1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<String> getLanguages() {

@Override
public boolean isEditable() {
return resource.getPath().startsWith("/content");
return dictionaryService.isEditableDictionary(resource.getPath());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public interface DictionaryService {

boolean isEditableDictionary(String path);

List<Resource> getDictionaries(ResourceResolver resourceResolver);

void createDictionary(Resource parent, String name, String[] languages, String basename) throws PersistenceException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class DictionaryServiceImpl implements DictionaryService {

private static final Logger LOG = LoggerFactory.getLogger(DictionaryServiceImpl.class);
private static final String SLING_BASENAME = "sling:basename";
private static final List<String> EDITABLE_ROOTS = List.of("/content/", "/conf/");

@Reference
private TranslationConfig translationConfig;
Expand All @@ -42,6 +43,10 @@ public class DictionaryServiceImpl implements DictionaryService {
@Reference
private Replicator replicator;

public boolean isEditableDictionary(String path) {
return EDITABLE_ROOTS.stream().anyMatch(path::startsWith);
}

public void addLanguage(Resource dictionary, String language, String basename) throws PersistenceException {
Map<String, Object> properties = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package be.orbinson.aem.dictionarytranslator.servlets.rendercondition;

import be.orbinson.aem.dictionarytranslator.services.DictionaryService;
import com.adobe.granite.ui.components.Config;
import com.adobe.granite.ui.components.ExpressionHelper;
import com.adobe.granite.ui.components.ExpressionResolver;
import com.adobe.granite.ui.components.rendercondition.RenderCondition;
import com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;

@Component(service = Servlet.class)
@SlingServletResourceTypes(resourceTypes = "aem-dictionary-translator/components/rendercondition/editable-dictionary")
public class EditableDictionaryRenderCondition extends SlingSafeMethodsServlet {

@Reference
private DictionaryService dictionaryService;

@Reference
private ExpressionResolver expressionResolver;

@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
ExpressionHelper expressionHelper = new ExpressionHelper(expressionResolver, request);
String path = expressionHelper.getString(new Config(request.getResource()).get("path"));
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(dictionaryService.isEditableDictionary(path)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -17,7 +16,7 @@
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -73,4 +72,17 @@ void returnsCorrectLanguages() {
assertEquals("en", languages.get(1));
}


@Test
public void testIsEditableDictionary() {
// Test cases where the path should be editable
assertTrue(dictionaryService.isEditableDictionary("/content/example"), "Path starting with /content/ should be editable");
assertTrue(dictionaryService.isEditableDictionary("/conf/example"), "Path starting with /conf/ should be editable");

// Test cases where the path should not be editable
assertFalse(dictionaryService.isEditableDictionary("/other/example"), "Path not starting with /content/ or /conf/ should not be editable");
assertFalse(dictionaryService.isEditableDictionary("/configuration"), "Path starting with /configuration should not be editable");
assertFalse(dictionaryService.isEditableDictionary("/contents"), "Path starting with /contents should not be editable");
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<componentName>Dictionary Translator</componentName>
<componentGroupName>Orbinson Tools</componentGroupName>

<aem.sdk.api.version>2024.10.18459.20241031T210302Z-241000</aem.sdk.api.version>
<aem.sdk.api.version>2023.6.12255.20230608T053118Z-230400</aem.sdk.api.version>
<aemanalyser.version>1.6.4</aemanalyser.version>

<sonar.organization>orbinson</sonar.organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/create.html${requestPathInfo.suffix}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</create-key>
</primary>
<selection jcr:primaryType="nt:unstructured">
Expand All @@ -55,8 +55,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/update.html{?item*}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</edit>
<delete
jcr:primaryType="nt:unstructured"
Expand All @@ -71,8 +71,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/delete.html{?item*}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</delete>
<publish
jcr:primaryType="nt:unstructured"
Expand All @@ -87,8 +87,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/publish.html{?item*}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</publish>
</selection>
</actions>
Expand Down

0 comments on commit e888b01

Please sign in to comment.