Skip to content

Commit

Permalink
Story #11987: update schema response model (#1631)
Browse files Browse the repository at this point in the history
Co-authored-by: Benaissa BENARBIA <benaissa.benarbia.ext@culture.gouv.fr>
  • Loading branch information
bbenaissa and Benaissa BENARBIA authored Jan 30, 2024
1 parent 7d7dd21 commit 67245f8
Show file tree
Hide file tree
Showing 5 changed files with 699 additions and 702 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
package fr.gouv.vitamui.referential.common.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import fr.gouv.vitam.common.model.administration.OntologyOrigin;
import fr.gouv.vitam.common.model.administration.SchemaCategory;
import fr.gouv.vitam.common.model.administration.SchemaType;
import fr.gouv.vitam.common.model.administration.schema.SchemaCategory;
import fr.gouv.vitam.common.model.administration.schema.SchemaOrigin;
import fr.gouv.vitam.common.model.administration.schema.SchemaType;
import fr.gouv.vitamui.referential.common.model.Cardinality;
import fr.gouv.vitamui.referential.common.model.Collection;
import lombok.Data;
Expand All @@ -54,8 +54,8 @@ public class SchemaElementCreateDto {
@JsonProperty("SedaField") private String sedaField;
@JsonProperty("ApiField") private String apiField;
@JsonProperty("Type") private SchemaType type;
@JsonProperty("Origin") private OntologyOrigin origin;
@JsonProperty("Collections") private List<Collection> collections;
@JsonProperty("Origin") private SchemaOrigin origin;
@JsonProperty("Collection") private Collection collection;
@JsonProperty("SedaVersions") private List<String> sedaVersions;
@JsonProperty("RootPaths") private List<String> rootPaths;
@JsonProperty("Category") private SchemaCategory category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@
package fr.gouv.vitamui.referential.internal.server.schema;

import com.fasterxml.jackson.databind.util.StdConverter;
import fr.gouv.vitam.common.model.administration.OntologyStringTypeSize;
import fr.gouv.vitam.common.model.administration.SchemaModel;
import fr.gouv.vitam.common.model.administration.schema.SchemaResponse;
import fr.gouv.vitam.common.model.administration.schema.SchemaStringSizeType;
import fr.gouv.vitamui.referential.common.dto.SchemaElementDto;
import fr.gouv.vitamui.referential.common.model.Cardinality;
import fr.gouv.vitamui.referential.common.model.Collection;

import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Collectors;

public class SchemaModelToSchemaElementDtoConverter extends StdConverter<SchemaModel, SchemaElementDto> {
public class SchemaModelToSchemaElementDtoConverter extends StdConverter<SchemaResponse, SchemaElementDto> {
@Override
public SchemaElementDto convert(SchemaModel schemaModel) {
final OntologyStringTypeSize stringTypeSize = schemaModel.getStringSize();
public SchemaElementDto convert(SchemaResponse schemaModel) {
final SchemaStringSizeType stringTypeSize = schemaModel.getStringSize();
final String stringSize = stringTypeSize != null ? stringTypeSize.value().toLowerCase(Locale.ROOT) : null;

return (SchemaElementDto) new SchemaElementDto()
Expand All @@ -56,18 +54,16 @@ public SchemaElementDto convert(SchemaModel schemaModel) {
.setApiField(schemaModel.getApiField())
.setType(schemaModel.getType())
.setOrigin(schemaModel.getOrigin())
.setCollections(mapCollections(schemaModel))
.setCollection(mapCollections(schemaModel))
.setSedaVersions(schemaModel.getSedaVersions())
.setCategory(schemaModel.getCategory())
.setApiPath(schemaModel.getApiPath());
}

private List<Collection> mapCollections(final SchemaModel schemaModel) {
return schemaModel.getCollections().stream().map(collection -> {
if (Objects.equals(collection, "Unit")) {
return Collection.ARCHIVE_UNIT;
}
return Collection.of(collection);
}).collect(Collectors.toList());
private Collection mapCollections(final SchemaResponse schemaResponse) {
if (Objects.equals(schemaResponse.getCollection(), "Unit")) {
return Collection.ARCHIVE_UNIT;
}
return Collection.valueOf(schemaResponse.getCollection());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import fr.gouv.vitam.common.exception.VitamClientException;
import fr.gouv.vitam.common.model.RequestResponse;
import fr.gouv.vitam.common.model.RequestResponseOK;
import fr.gouv.vitam.common.model.administration.SchemaModel;
import fr.gouv.vitam.common.model.administration.schema.SchemaResponse;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.iam.security.service.InternalSecurityService;
Expand Down Expand Up @@ -62,8 +62,8 @@ public SchemaService(final InternalSecurityService internalSecurityService,

public Optional<SchemaDto> getSchema(final Collection collection) {
try {
final RequestResponse<SchemaModel> payload = getSchemaModels(collection).orElseThrow();
final List<SchemaModel> schemaModels = ((RequestResponseOK<SchemaModel>) payload).getResults();
final RequestResponse<SchemaResponse> payload = getSchemaModels(collection).orElseThrow();
final List<SchemaResponse> schemaModels = ((RequestResponseOK<SchemaResponse>) payload).getResults();
final SchemaModelToSchemaElementDtoConverter converter = new SchemaModelToSchemaElementDtoConverter();
final SchemaDto schemaDto = new SchemaDto();
schemaDto.addAll(schemaModels.stream()
Expand All @@ -83,7 +83,8 @@ public List<SchemaDto> getSchemas(final Set<Collection> collections) {
.collect(Collectors.toList());
}

private Optional<RequestResponse<SchemaModel>> getSchemaModels(Collection collection) throws VitamClientException {
private Optional<RequestResponse<SchemaResponse>> getSchemaModels(Collection collection)
throws VitamClientException {
final VitamContext vitamContext = internalSecurityService.getVitamContext();
if (Objects.equals(collection, Collection.ARCHIVE_UNIT)) {
return Optional.of(adminExternalClient.getUnitSchema(vitamContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Cardinality, SedaVersion } from '../types';
import { WithPath } from './with-path.model';
import {Cardinality, SedaVersion} from '../types';
import {WithPath} from './with-path.model';

export interface SchemaElement extends WithPath {
readonly id?: string;
Expand All @@ -53,7 +53,7 @@ export interface SchemaElement extends WithPath {
readonly StringSize?: 'SHORT' | 'MEDIUM' | 'LARGE';
readonly Cardinality: Cardinality;
readonly SedaVersions: SedaVersion[];
readonly Collections: string[];
readonly Collection: string;
readonly ApiPath: string;
readonly Category: 'DESCRIPTION' | 'MANAGEMENT' | 'OTHER';
}
Loading

0 comments on commit 67245f8

Please sign in to comment.