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 #13004 #2002

Merged
merged 2 commits into from
Aug 29, 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 @@ -37,22 +37,29 @@
import fr.gouv.vitamui.referential.common.model.ControlType;
import fr.gouv.vitamui.referential.common.model.DataType;
import fr.gouv.vitamui.referential.common.model.EffectiveCardinality;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;
import java.util.Optional;

import static java.util.Objects.isNull;

@Slf4j
public class CombinedSchemaModelToSchemaElementDtoConverter
extends StdConverter<CombinedSchemaModel, SchemaElementDto> {

@Override
public SchemaElementDto convert(CombinedSchemaModel schemaModel) {
final SchemaStringSizeType stringTypeSize = SchemaStringSizeType.fromValue(schemaModel.getStringSize().name());
SchemaStringSizeType stringTypeSize = null;

if (schemaModel.getStringSize() != null) {
stringTypeSize = SchemaStringSizeType.fromValue(schemaModel.getStringSize().name());
}

final SchemaElementDto schemaElementDto = (SchemaElementDto) new SchemaElementDto()
.setPath(schemaModel.getPath())
.setStringSize(Optional.ofNullable(stringTypeSize).map(SchemaStringSizeType::value).orElse(null))
.setCardinality(Cardinality.of(schemaModel.getCardinality().name()))
.setCardinality(Cardinality.valueOf(schemaModel.getCardinality().name()))
.setFieldName(schemaModel.getFieldName())
.setShortName(schemaModel.getShortName())
.setDescription(schemaModel.getDescription())
Expand All @@ -66,18 +73,19 @@ public SchemaElementDto convert(CombinedSchemaModel schemaModel) {
.setApiPath(Optional.ofNullable(schemaModel.getApiPath()).orElse(schemaModel.getPath()))
.setDataType(convertFromIndexationType(schemaModel.getType().name()));

if (schemaModel.getControl() != null) {
final ControlDto controlDto = new ControlDto();
schemaElementDto.setEffectiveCardinality(EffectiveCardinality.valueOf(schemaModel.getEffectiveCardinality()));

controlDto.setType(ControlType.valueOf(schemaModel.getControl().getType()));
controlDto.setValue(schemaModel.getControl().getValue());
controlDto.setValues(schemaModel.getControl().getValues());
controlDto.setComment(schemaModel.getControl().getComment());
if (schemaModel.getControl() == null) return schemaElementDto;

schemaElementDto.setControl(controlDto);
final ControlDto controlDto = new ControlDto();
if (schemaModel.getControl().getType() != null) {
controlDto.setType(ControlType.valueOf(schemaModel.getControl().getType()));
}
controlDto.setValue(schemaModel.getControl().getValue());
controlDto.setValues(schemaModel.getControl().getValues());
controlDto.setComment(schemaModel.getControl().getComment());

schemaElementDto.setEffectiveCardinality(EffectiveCardinality.valueOf(schemaModel.getEffectiveCardinality()));
schemaElementDto.setControl(controlDto);

return schemaElementDto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import fr.gouv.vitamui.iam.security.service.InternalSecurityService;
import fr.gouv.vitamui.referential.common.dto.SchemaDto;
import fr.gouv.vitamui.referential.common.model.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -51,7 +49,6 @@
@Service
public class SchemaService {

private static final Logger log = LoggerFactory.getLogger(SchemaService.class);
private final InternalSecurityService internalSecurityService;
private final AdminExternalClient adminExternalClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ export class ArchiveUnitEditObjectService {
}
}

public hideCardinalityZero(editObject: EditObject): void {
if (editObject.cardinality === 'ZERO') {
editObject.displayRule = { ...editObject.displayRule, ui: { ...editObject.displayRule.ui, display: false } };
}

editObject.children.forEach((child) => this.hideCardinalityZero(child));
}

public setMissingTypes(editObject: EditObject): void {
const { kind } = editObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class ArchiveUnitEditorService {
this.archiveUnitEditObjectService.expand('', editObject);
this.archiveUnitEditObjectService.expand('Generalities', editObject);
this.archiveUnitEditObjectService.hideSpsFieldWithOneValue(editObject);
this.archiveUnitEditObjectService.hideCardinalityZero(editObject);

return editObject;
}
Expand Down