Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void init() {
addLanguageCode(languageCodes, languageResource);
languageResource.listChildren().forEachRemaining(dictionaryKeyResource -> {
addTranslationKeys(translationKeys, dictionaryKeyResource);
if(isNewTranslationSinceLastReplication(dictionaryKeyResource)){
if (isNewTranslationSinceLastReplication(dictionaryKeyResource)) {
numberOfNewTranslations++;
}
});
Expand All @@ -56,22 +56,16 @@ private void init() {
setDescription(languageCodes);
}

private void setDescription(List<String> languageCodes) {
if (languageCodes.size() < 10) {
description = String.join(", ", languageCodes);
} else {
description = languageCodes.size() + " languages";
}
}

private boolean isNewTranslationSinceLastReplication(Resource dictionaryKeyResource) {
Calendar created = dictionaryKeyResource.getValueMap().get("jcr:created", Calendar.class);
return lastReplicated == null || lastReplicated.before(created);
}

private void addLanguageCode(List<String> languageCodes, Resource languageResource) {
String languageCode = languageResource.getValueMap().get("jcr:language", String.class);
languageCodes.add(languageCode);
if (languageCode != null && !languageCode.isEmpty()) {
languageCodes.add(languageCode);
}
}

private void addTranslationKeys(Set<String> uniqueKeys, Resource dictionaryKey) {
Expand Down Expand Up @@ -106,6 +100,14 @@ public String getDescription() {
return description;
}

private void setDescription(List<String> languageCodes) {
if (languageCodes.size() < 10) {
description = String.join(", ", languageCodes);
} else {
description = languageCodes.size() + " languages";
}
}

public String getReplicationDate() {
return formatDateRDF(lastReplicated, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void setUp() {
context.load().json("/mocks/dictionary.json", "/apps/test-dictionary");
context.load().json("/mocks/activated-dictionary.json", "/apps/test-dictionary-2");
context.load().json("/mocks/activated-dictionary-more-languages.json", "/apps/test-dictionary-3");
context.load().json("/mocks/dictionary-with-non-language-folders.json", "/apps/test-dictionary-4");
context.addModelsForClasses(Dictionary.class);
}

Expand Down Expand Up @@ -81,4 +82,17 @@ public void testActivatedDictionary_moreLanguages() {
assertThat(dictionary.getReplicationDate()).isNotBlank();
assertThat(dictionary.getReplicationBy()).isNotBlank();
}

@Test
public void testDictionary_nonLanguageFolder() {
//given
Resource resource = context.resourceResolver().getResource("/apps/test-dictionary-4");
context.request().setResource(resource);

Dictionary dictionary = context.request().adaptTo(Dictionary.class);

assertThat(dictionary).isNotNull();
assertThat(dictionary.getTitle()).isEqualTo("/apps/test-dictionary-4");
assertThat(dictionary.getDescription()).isEqualTo("en, en-us");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"jcr:primaryType": "nt:folder",
"jcr:createdBy": "admin",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200",
"en": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"mix:language"
],
"jcr:createdBy": "admin",
"jcr:language": "en",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200",
"foundation.u65-news-letter-registration.placeholder-msg.email": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"sling:Message"
],
"jcr:createdBy": "admin",
"sling:message": "E-mail address",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
},
"foundation.s08-specification-details.seeless": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"sling:Message"
],
"jcr:createdBy": "admin",
"sling:message": "See less specifications",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
},
"foundation.u65-news-letter-registration.submit": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"sling:Message"
],
"jcr:createdBy": "admin",
"sling:message": "Subscribe",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
}
},
"en-us": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"mix:language"
],
"jcr:createdBy": "admin",
"jcr:language": "en-us",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200",
"foundation.u65-news-letter-registration.placeholder-msg.email": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"sling:Message"
],
"jcr:createdBy": "admin",
"sling:message": "E-mail address",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
},
"foundation.s08-specification-details.seeless": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"sling:Message"
],
"jcr:createdBy": "admin",
"sling:message": "See less specifications",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
},
"foundation.u65-news-letter-registration.submit": {
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": [
"sling:Message"
],
"jcr:createdBy": "admin",
"sling:message": "Subscribe",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
}
},
"no-translations": {
"jcr:primaryType": "nt:folder",
"jcr:createdBy": "admin",
"jcr:created": "Thu Sep 06 2018 15:16:06 GMT+0200"
}
}