CCM NG/ccm-cms: ContentItemL10NManager now passes all tests.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4379 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
0d184a0c36
commit
44ddf8a8f4
|
|
@ -58,7 +58,7 @@ public class ContentItemL10NManager {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentItemRepository itemRepo;
|
private ContentItemRepository itemRepo;
|
||||||
|
|
||||||
private Locale defaultLocale;
|
private Locale defaultLocale;
|
||||||
private List<Locale> supportedLocales;
|
private List<Locale> supportedLocales;
|
||||||
|
|
||||||
|
|
@ -151,9 +151,18 @@ public class ContentItemL10NManager {
|
||||||
final ContentItem item,
|
final ContentItem item,
|
||||||
final Locale locale) {
|
final Locale locale) {
|
||||||
|
|
||||||
|
if (item == null) {
|
||||||
|
throw new IllegalArgumentException("Can't add language to item null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (locale == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't add language null to an item.");
|
||||||
|
}
|
||||||
|
|
||||||
findLocalizedStringProperties(item)
|
findLocalizedStringProperties(item)
|
||||||
.forEach(property -> addLanguage(item, locale, property));
|
.forEach(property -> addLanguage(item, locale, property));
|
||||||
|
|
||||||
itemRepo.save(item);
|
itemRepo.save(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,12 +170,12 @@ public class ContentItemL10NManager {
|
||||||
final Locale locale,
|
final Locale locale,
|
||||||
final PropertyDescriptor property) {
|
final PropertyDescriptor property) {
|
||||||
|
|
||||||
final Method readMethod = property.getReadMethod();
|
final Method readMethod = property.getReadMethod();
|
||||||
final LocalizedString localizedStr = readLocalizedString(item,
|
final LocalizedString localizedStr = readLocalizedString(item,
|
||||||
readMethod);
|
readMethod);
|
||||||
addLanguage(localizedStr, locale);
|
addLanguage(localizedStr, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLanguage(final LocalizedString localizedString,
|
private void addLanguage(final LocalizedString localizedString,
|
||||||
final Locale locale) {
|
final Locale locale) {
|
||||||
if (localizedString.hasValue(locale)) {
|
if (localizedString.hasValue(locale)) {
|
||||||
|
|
@ -213,6 +222,16 @@ public class ContentItemL10NManager {
|
||||||
final ContentItem item,
|
final ContentItem item,
|
||||||
final Locale locale) {
|
final Locale locale) {
|
||||||
|
|
||||||
|
if (item == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't remove language from item null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (locale == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't remove language null from an item.");
|
||||||
|
}
|
||||||
|
|
||||||
findLocalizedStringProperties(item)
|
findLocalizedStringProperties(item)
|
||||||
.forEach(property -> removeLanguage(item, locale, property));
|
.forEach(property -> removeLanguage(item, locale, property));
|
||||||
|
|
||||||
|
|
@ -249,6 +268,10 @@ public class ContentItemL10NManager {
|
||||||
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_EDIT)
|
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_EDIT)
|
||||||
final ContentItem item) {
|
final ContentItem item) {
|
||||||
|
|
||||||
|
if (item == null) {
|
||||||
|
throw new IllegalArgumentException("Can't normalise item null.");
|
||||||
|
}
|
||||||
|
|
||||||
final Set<Locale> languages = collectLanguages(item);
|
final Set<Locale> languages = collectLanguages(item);
|
||||||
|
|
||||||
findLocalizedStringProperties(item)
|
findLocalizedStringProperties(item)
|
||||||
|
|
@ -256,7 +279,7 @@ public class ContentItemL10NManager {
|
||||||
.map(property -> property.getReadMethod())
|
.map(property -> property.getReadMethod())
|
||||||
.map(readMethod -> readLocalizedString(item, readMethod))
|
.map(readMethod -> readLocalizedString(item, readMethod))
|
||||||
.forEach(str -> normalize(str, languages));
|
.forEach(str -> normalize(str, languages));
|
||||||
|
|
||||||
itemRepo.save(item);
|
itemRepo.save(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +289,7 @@ public class ContentItemL10NManager {
|
||||||
final List<Locale> missingLangs = languages.stream()
|
final List<Locale> missingLangs = languages.stream()
|
||||||
.filter(lang -> !localizedString.hasValue(lang))
|
.filter(lang -> !localizedString.hasValue(lang))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (!missingLangs.isEmpty()) {
|
if (!missingLangs.isEmpty()) {
|
||||||
missingLangs.stream()
|
missingLangs.stream()
|
||||||
.forEach(lang -> addLanguage(localizedString, lang));
|
.forEach(lang -> addLanguage(localizedString, lang));
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,58 @@
|
||||||
locale="en"
|
locale="en"
|
||||||
revtype="0" />
|
revtype="0" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="fr"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10200"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10300"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10400"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="de"
|
||||||
|
localized_value="Description" />
|
||||||
|
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="fr"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10200"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10300"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10400"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="1"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="de"
|
||||||
|
revtype="0" />
|
||||||
|
|
||||||
|
|
||||||
<ccm_cms.content_type_labels object_id="-20100"
|
<ccm_cms.content_type_labels object_id="-20100"
|
||||||
locale="en"
|
locale="en"
|
||||||
localized_value="Article" />
|
localized_value="Article" />
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,56 @@
|
||||||
locale="de"
|
locale="de"
|
||||||
revtype="0" />
|
revtype="0" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="fr"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10200"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10300"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10400"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10200"
|
||||||
|
locale="de"
|
||||||
|
localized_value="Description" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="fr"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10200"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10300"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10400"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="1"
|
||||||
|
object_id="-10200"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="de"
|
||||||
|
revtype="0" />
|
||||||
|
|
||||||
<ccm_cms.content_type_labels object_id="-20100"
|
<ccm_cms.content_type_labels object_id="-20100"
|
||||||
locale="en"
|
locale="en"
|
||||||
localized_value="Article" />
|
localized_value="Article" />
|
||||||
|
|
|
||||||
|
|
@ -248,6 +248,51 @@
|
||||||
locale="en"
|
locale="en"
|
||||||
revtype="0" />
|
revtype="0" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10200"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10300"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10400"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="fr"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10200"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10300"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10400"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="1"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="fr"
|
||||||
|
revtype="2" />
|
||||||
|
|
||||||
|
|
||||||
<ccm_cms.content_type_labels object_id="-20100"
|
<ccm_cms.content_type_labels object_id="-20100"
|
||||||
locale="en"
|
locale="en"
|
||||||
localized_value="Article" />
|
localized_value="Article" />
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,48 @@
|
||||||
locale="en"
|
locale="en"
|
||||||
revtype="0" />
|
revtype="0" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10100"
|
||||||
|
locale="fr"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10200"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10300"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
<ccm_cms.content_item_descriptions object_id="-10400"
|
||||||
|
locale="en"
|
||||||
|
localized_value="Description" />
|
||||||
|
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10100"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="fr"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10200"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10300"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
<ccm_cms.content_item_descriptions_aud rev="0"
|
||||||
|
object_id="-10400"
|
||||||
|
localized_value="Description"
|
||||||
|
locale="en"
|
||||||
|
revtype="0" />
|
||||||
|
|
||||||
<ccm_cms.content_type_labels object_id="-20100"
|
<ccm_cms.content_type_labels object_id="-20100"
|
||||||
locale="en"
|
locale="en"
|
||||||
localized_value="Article" />
|
localized_value="Article" />
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ DELETE FROM ccm_cms.articles;
|
||||||
|
|
||||||
DELETE FROM ccm_cms.articles_aud;
|
DELETE FROM ccm_cms.articles_aud;
|
||||||
|
|
||||||
|
DELETE FROM ccm_cms.content_item_descriptions;
|
||||||
|
|
||||||
|
DELETE FROM ccm_cms.content_item_descriptions_aud;
|
||||||
|
|
||||||
DELETE FROM ccm_cms.content_item_names;
|
DELETE FROM ccm_cms.content_item_names;
|
||||||
|
|
||||||
DELETE FROM ccm_cms.content_item_names_aud;
|
DELETE FROM ccm_cms.content_item_names_aud;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue