Skip to content

Commit

Permalink
Merge pull request #1727 from ProgrammeVitam/bug_12416_balises-avec-a…
Browse files Browse the repository at this point in the history
…ttribut-langues-non-affichees

Bug #12416: handle i18n Title/Description
  • Loading branch information
marob authored Mar 29, 2024
2 parents 0e907e3 + 16ded1a commit 471454e
Show file tree
Hide file tree
Showing 24 changed files with 334 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static fr.gouv.vitamui.commons.api.utils.MetadataSearchCriteriaUtils.cleanString;

Expand Down Expand Up @@ -251,8 +254,7 @@ private ArchiveUnitCsv cleanAndMapArchiveUnitResult(ArchiveUnit archiveUnit, Str
}
ArchiveUnitCsv archiveUnitCsv = new ArchiveUnitCsv();
BeanUtils.copyProperties(archiveUnit, archiveUnitCsv);
archiveUnitCsv.setDescription(
archiveUnit.getDescription() != null ? cleanString(archiveUnit.getDescription()) : null);
archiveUnitCsv.setDescription(cleanString(getArchiveUnitDescription(archiveUnit)));
archiveUnitCsv.setDescriptionLevel(
archiveUnit.getDescriptionLevel() != null ? cleanString(archiveUnit.getDescriptionLevel()) : null);
archiveUnitCsv.setArchiveUnitType(getArchiveUnitType(archiveUnit, language));
Expand All @@ -264,22 +266,30 @@ private ArchiveUnitCsv cleanAndMapArchiveUnitResult(ArchiveUnit archiveUnit, Str
}

private String getArchiveUnitTitle(ArchiveUnit archiveUnit) {
String title = null;
if (archiveUnit != null) {
if (StringUtils.isEmpty(archiveUnit.getTitle()) || StringUtils.isBlank(archiveUnit.getTitle())) {
if (archiveUnit.getTitle_() != null) {
if (!StringUtils.isEmpty(archiveUnit.getTitle_().getFr()) &&
!StringUtils.isBlank(archiveUnit.getTitle_().getFr())) {
title = archiveUnit.getTitle_().getFr();
} else {
title = archiveUnit.getTitle_().getEn();
}
}
} else {
title = archiveUnit.getTitle();
}
return getArchiveUnitI18nAttribute(archiveUnit, ResultsDto::getTitle, ResultsDto::getTitle_);
}

private String getArchiveUnitDescription(ArchiveUnit archiveUnit) {
return getArchiveUnitI18nAttribute(archiveUnit, ResultsDto::getDescription, ResultsDto::getDescription_);
}

private String getArchiveUnitI18nAttribute(ArchiveUnit archiveUnit, Function<ArchiveUnit, String> attributeExtractor, Function<ArchiveUnit, Map<String, String>> i18nAttributeExtractor) {
if (archiveUnit == null) {
return null;
}
final String attribute = attributeExtractor.apply(archiveUnit);
if (StringUtils.isNotBlank(attribute)) {
return attribute;
}
return title;
final Map<String, String> attribute_ = i18nAttributeExtractor.apply(archiveUnit);
return Stream.of("fr", "en")
.map(lang -> attribute_.entrySet().stream().filter(e -> lang.equalsIgnoreCase(e.getKey())).findFirst())
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.map(Map.Entry::getValue)
.or(() -> attribute_.values().stream().findFirst())
.orElse(null);
}

private String getArchiveUnitType(ArchiveUnit archiveUnit, String language) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
import fr.gouv.vitamui.commons.api.domain.AgencyModelDto;
import fr.gouv.vitamui.commons.api.dtos.CriteriaValue;
import fr.gouv.vitamui.commons.api.dtos.ExportSearchResultParam;
import fr.gouv.vitamui.commons.api.dtos.VitamUiOntologyDto;
import fr.gouv.vitamui.commons.api.dtos.SearchCriteriaDto;
import fr.gouv.vitamui.commons.api.dtos.SearchCriteriaEltDto;
import fr.gouv.vitamui.commons.api.dtos.VitamUiOntologyDto;
import fr.gouv.vitamui.commons.api.exception.BadRequestException;
import fr.gouv.vitamui.commons.api.exception.InternalServerException;
import fr.gouv.vitamui.commons.api.exception.InvalidTypeException;
Expand Down Expand Up @@ -103,14 +103,14 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static fr.gouv.vitam.common.database.builder.query.QueryHelper.and;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.eq;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.exists;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.missing;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.not;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.or;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.eq;
import static fr.gouv.vitamui.commons.api.utils.ArchiveSearchConsts.CriteriaCategory.ACCESS_RULE;
import static fr.gouv.vitamui.commons.api.utils.ArchiveSearchConsts.CriteriaCategory.APPRAISAL_RULE;
import static fr.gouv.vitamui.commons.api.utils.ArchiveSearchConsts.CriteriaCategory.DISSEMINATION_RULE;
Expand Down Expand Up @@ -152,7 +152,6 @@
import static fr.gouv.vitamui.commons.api.utils.MetadataSearchCriteriaUtils.getBasicQuery;
import static fr.gouv.vitamui.commons.api.utils.MetadataSearchCriteriaUtils.mapRequestToSelectMultiQuery;
import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class TransactionArchiveUnitInternalService {
public static final String DSL_QUERY_FACETS = "$facets";
Expand Down Expand Up @@ -248,20 +247,31 @@ public ResultsDto findArchiveUnitById(String id, VitamContext vitamContext) thro
}
}

private static String getArchiveUnitTitle(ArchiveUnit archiveUnit) {
private String getArchiveUnitTitle(ArchiveUnit archiveUnit) {
return getArchiveUnitI18nAttribute(archiveUnit, ResultsDto::getTitle, ResultsDto::getTitle_);
}

private String getArchiveUnitDescription(ArchiveUnit archiveUnit) {
return getArchiveUnitI18nAttribute(archiveUnit, ResultsDto::getDescription, ResultsDto::getDescription_);
}

private String getArchiveUnitI18nAttribute(ArchiveUnit archiveUnit, Function<ArchiveUnit, String> attributeExtractor, Function<ArchiveUnit, Map<String, String>> i18nAttributeExtractor) {
if (archiveUnit == null) {
return null;
}
if (isNotBlank(archiveUnit.getTitle())) {
return archiveUnit.getTitle();
}
if (archiveUnit.getTitle_() != null) {
return isNotBlank(archiveUnit.getTitle_().getFr()) ?
archiveUnit.getTitle_().getFr() :
archiveUnit.getTitle_().getEn();
final String attribute = attributeExtractor.apply(archiveUnit);
if (StringUtils.isNotBlank(attribute)) {
return attribute;
}
LOGGER.debug("Archive unit Title and Title_ are empty!");
return null;
final Map<String, String> attribute_ = i18nAttributeExtractor.apply(archiveUnit);
return Stream.of("fr", "en")
.map(lang -> attribute_.entrySet().stream().filter(e -> lang.equalsIgnoreCase(e.getKey())).findFirst())
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.map(Map.Entry::getValue)
.or(() -> attribute_.values().stream().findFirst())
.orElse(null);
}

private String getArchiveUnitType(ArchiveUnit archiveUnit, String language) {
Expand Down Expand Up @@ -827,8 +837,7 @@ private ArchiveUnitCsv cleanAndMapArchiveUnitResult(ArchiveUnit archiveUnit, Str
}
ArchiveUnitCsv archiveUnitCsv = new ArchiveUnitCsv();
BeanUtils.copyProperties(archiveUnit, archiveUnitCsv);
archiveUnitCsv.setDescription(
archiveUnit.getDescription() != null ? cleanString(archiveUnit.getDescription()) : null);
archiveUnitCsv.setDescription(cleanString(getArchiveUnitDescription(archiveUnit)));
archiveUnitCsv.setDescriptionLevel(
archiveUnit.getDescriptionLevel() != null ? cleanString(archiveUnit.getDescriptionLevel()) : null);
archiveUnitCsv.setArchiveUnitType(getArchiveUnitType(archiveUnit, language));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,14 @@ public enum CriteriaOperators {

/* Title and Description Query fields */
public static final String TITLE = "Title";
// FIXME: shouldn't be used, but how can we search on Title_.*?
public static final String TITLE_FR = "Title_.fr";
// FIXME: shouldn't be used, but how can we search on Title_.*?
public static final String TITLE_EN = "Title_.en";
public static final String DESCRIPTION = "Description";
// FIXME: shouldn't be used, but how can we search on Description_.*?
public static final String DESCRIPTION_FR = "Description_.fr";
// FIXME: shouldn't be used, but how can we search on Description_.*?
public static final String DESCRIPTION_EN = "Description_.en";
public static final String TITLE_CRITERIA = "TITLE";
public static final String DESCRIPTION_CRITERIA = "DESCRIPTION";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class ResultsDto {
private String title;

@JsonProperty("Title_")
private TitleDto title_;
private Map<String, String> title_;

@JsonProperty("DescriptionLevel")
private String descriptionLevel;
Expand All @@ -75,7 +75,7 @@ public class ResultsDto {
private String description;

@JsonProperty("Description_")
private DescriptionDto description_;
private Map<String, String> description_;

@JsonProperty("OriginatingAgencyArchiveUnitIdentifier")
private List<String> originatingAgencyArchiveUnitIdentifier = new ArrayList<>();
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions ui/ui-frontend-common/src/app/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ export * from './vitamui-global-error-handler';
export * from './vitamui-icons.enum';
export * from './vitamui-roles.enum';
export * from './vitamui-table/index';

export * from './pipes/unitI18n.pipe';
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
*/
import { isEmpty } from 'lodash';
import { getUnitI18nAttribute } from '../../pipes/unitI18n.pipe';
import { ResultFacet } from '../criteria';
import { DescriptionLevel, Unit } from '../units';
import { FilingHoldingSchemeNode, MatchingNodesNumbers } from './node.interface';
Expand Down Expand Up @@ -340,7 +341,7 @@ export class FilingHoldingSchemeHandler {
public static convertUnitToNode(unit: Unit): FilingHoldingSchemeNode {
return {
id: unit['#id'],
title: unit.Title ? unit.Title : unit.Title_ ? (unit.Title_.fr ? unit.Title_.fr : unit.Title_.en) : unit.Title_.en,
title: getUnitI18nAttribute(unit, 'Title'),
unitType: unit['#unitType'],
descriptionLevel: unit.DescriptionLevel,
children: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export interface Unit {

originating_agencyName?: string;
Title?: string;
Title_?: any;
Title_?: { [key: string]: string };
Description?: string;
Description_?: any;
Description_?: { [key: string]: string };
DescriptionLevel?: DescriptionLevel;
CreatedDate?: Date;
StartDate?: Date;
Expand Down
41 changes: 17 additions & 24 deletions ui/ui-frontend-common/src/app/modules/pipes/pipes.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,27 @@ import { PluralPipe } from './plural.pipe';
import { SafeStylePipe } from './safe-style.pipe';
import { StrongifyPipe } from './strongify.pipe';
import { TruncatePipe } from './truncate.pipe';
import { UnitI18nPipe } from './unitI18n.pipe';
import { YesNoPipe } from './yes-no.pipe';

const pipes = [
BytesPipe,
DateTimePipe,
EmptyPipe,
FileSizePipe,
HighlightPipe,
PluralPipe,
SafeStylePipe,
StrongifyPipe,
TruncatePipe,
UnitI18nPipe,
YesNoPipe,
];

@NgModule({
imports: [CommonModule],
declarations: [
BytesPipe,
HighlightPipe,
StrongifyPipe,
TruncatePipe,
SafeStylePipe,
EmptyPipe,
YesNoPipe,
DateTimePipe,
FileSizePipe,
PluralPipe,
],
exports: [
BytesPipe,
HighlightPipe,
StrongifyPipe,
TruncatePipe,
SafeStylePipe,
EmptyPipe,
YesNoPipe,
DateTimePipe,
FileSizePipe,
PluralPipe,
],
declarations: pipes,
exports: pipes,
providers: [DatePipe],
})
export class PipesModule {}
Loading

0 comments on commit 471454e

Please sign in to comment.