Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story #11987: update schema response model #1631

Merged
merged 2 commits into from
Jan 30, 2024
Merged
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 @@ -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) {
bbenaissa marked this conversation as resolved.
Show resolved Hide resolved
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