Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
d2b370e7
by Tony Chemit at 2022-03-09T23:16:19+01:00
-
5645462a
by Tony Chemit at 2022-03-09T23:40:16+01:00
3 changed files:
- core/services/local/src/main/java/fr/ird/observe/services/local/service/ObserveServiceLocal.java
- core/services/local/src/main/java/fr/ird/observe/services/local/service/api/DataEntityServiceLocalSupport.java
- core/services/local/src/main/java/fr/ird/observe/services/local/service/api/ReferentialEntityServiceLocalSupport.java
Changes:
| ... | ... | @@ -35,6 +35,7 @@ import fr.ird.observe.dto.data.SimpleDto; |
| 35 | 35 | import fr.ird.observe.dto.db.DataSourceValidationMode;
|
| 36 | 36 | import fr.ird.observe.dto.db.configuration.ObserveDataSourceInformation;
|
| 37 | 37 | import fr.ird.observe.dto.reference.DataDtoReference;
|
| 38 | +import fr.ird.observe.dto.reference.DtoReference;
|
|
| 38 | 39 | import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 39 | 40 | import fr.ird.observe.dto.referential.ReferentialDto;
|
| 40 | 41 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| ... | ... | @@ -66,6 +67,7 @@ import fr.ird.observe.spi.ObservePersistenceBusinessProject; |
| 66 | 67 | import fr.ird.observe.spi.context.ContainerDtoEntityContext;
|
| 67 | 68 | import fr.ird.observe.spi.context.DataDtoEntityContext;
|
| 68 | 69 | import fr.ird.observe.spi.context.DataGroupByReferentialHelper;
|
| 70 | +import fr.ird.observe.spi.context.DtoEntityContext;
|
|
| 69 | 71 | import fr.ird.observe.spi.context.EditableDtoEntityContext;
|
| 70 | 72 | import fr.ird.observe.spi.context.OpenableDtoEntityContext;
|
| 71 | 73 | import fr.ird.observe.spi.context.ReferentialDtoEntityContext;
|
| ... | ... | @@ -211,10 +213,10 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 211 | 213 | |
| 212 | 214 | @Override
|
| 213 | 215 | public final <D extends DataDto,
|
| 214 | - R extends DataDtoReference,
|
|
| 215 | - E extends DataEntity,
|
|
| 216 | - T extends ToolkitTopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataEntity(E dtoType) {
|
|
| 217 | - return ObservePersistenceBusinessProject.fromDataEntity(dtoType);
|
|
| 216 | + R extends DtoReference,
|
|
| 217 | + E extends Entity,
|
|
| 218 | + T extends ToolkitTopiaDao<E>> DtoEntityContext<D, R, E, T> fromEntity(E dtoType) {
|
|
| 219 | + return ObservePersistenceBusinessProject.fromEntity(dtoType);
|
|
| 218 | 220 | }
|
| 219 | 221 | |
| 220 | 222 | @Override
|
| ... | ... | @@ -379,10 +381,10 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 379 | 381 | return serviceContext;
|
| 380 | 382 | }
|
| 381 | 383 | |
| 382 | - protected ReferentialValidationRequest newReferentialValidationRequest(String validationContextName, Set<Class<? extends ReferentialDto>> referentialTypes) {
|
|
| 384 | + protected ReferentialValidationRequest newReferentialValidationRequest(Set<Class<? extends ReferentialDto>> referentialTypes) {
|
|
| 383 | 385 | ReferentialValidationRequest request = new ReferentialValidationRequest();
|
| 384 | 386 | request.setScopes(new LinkedHashSet<>(List.of(NuitonValidatorScope.ERROR, NuitonValidatorScope.FATAL)));
|
| 385 | - request.setValidationContext(validationContextName);
|
|
| 387 | + request.setValidationContext(fr.ird.observe.spi.validation.ValidationContextSupport.UPDATE_VALIDATION_CONTEXT);
|
|
| 386 | 388 | request.setReferentialTypes(referentialTypes);
|
| 387 | 389 | return request;
|
| 388 | 390 | }
|
| ... | ... | @@ -391,15 +393,15 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 391 | 393 | return DataSourceValidationMode.NONE == getValidationMode();
|
| 392 | 394 | }
|
| 393 | 395 | |
| 394 | - protected DataValidationRequest newDataValidationRequest(String validationContextName, String id) {
|
|
| 396 | + protected DataValidationRequest newDataValidationRequest(String id) {
|
|
| 395 | 397 | DataValidationRequest request = new DataValidationRequest();
|
| 396 | 398 | request.setScopes(new LinkedHashSet<>(List.of(NuitonValidatorScope.ERROR, NuitonValidatorScope.FATAL)));
|
| 397 | - request.setValidationContext(validationContextName);
|
|
| 399 | + request.setValidationContext(fr.ird.observe.spi.validation.ValidationContextSupport.UPDATE_VALIDATION_CONTEXT);
|
|
| 398 | 400 | request.setDataIds(Set.of(id == null ? "__create" : id));
|
| 399 | 401 | return request;
|
| 400 | 402 | }
|
| 401 | 403 | |
| 402 | - protected final void checkValidationResult(String content, ValidationResult<?> result) throws InvalidDataException {
|
|
| 404 | + protected final void checkValidationResult(ValidationResult<?> result) throws InvalidDataException {
|
|
| 403 | 405 | Set<ValidationResultDto> data = result.getData();
|
| 404 | 406 | if (data.isEmpty()) {
|
| 405 | 407 | return;
|
| ... | ... | @@ -415,7 +417,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 415 | 417 | }
|
| 416 | 418 | }
|
| 417 | 419 | if (withError) {
|
| 418 | - String message = String.format("Invalid content:\n%s\n%s", content, newGsonSupplier(true, false).get().toJson(result));
|
|
| 420 | + String message = String.format("Invalid content:\n%s", newGsonSupplier(true, false).get().toJson(result));
|
|
| 419 | 421 | throw new InvalidDataException(message, result);
|
| 420 | 422 | }
|
| 421 | 423 | //FIXME We should may be return the result for warning messages?
|
| ... | ... | @@ -34,7 +34,6 @@ import fr.ird.observe.services.local.service.ObserveServiceLocal; |
| 34 | 34 | import fr.ird.observe.services.service.api.DataEntityService;
|
| 35 | 35 | import fr.ird.observe.services.service.api.InvalidDataException;
|
| 36 | 36 | import fr.ird.observe.spi.context.DataDtoEntityContext;
|
| 37 | -import fr.ird.observe.spi.validation.DtoValidationContext;
|
|
| 38 | 37 | import fr.ird.observe.spi.validation.ValidationHelper;
|
| 39 | 38 | import org.nuiton.topia.persistence.filter.OrderEnum;
|
| 40 | 39 | import org.nuiton.topia.persistence.filter.ToolkitRequestFilter;
|
| ... | ... | @@ -64,17 +63,15 @@ public class DataEntityServiceLocalSupport extends ObserveServiceLocal implement |
| 64 | 63 | |
| 65 | 64 | @Override
|
| 66 | 65 | public ToolkitId create(Class<? extends DataDto> dtoType, String content) throws InvalidDataException {
|
| 67 | - DataDtoEntityContext<?, ?, DataEntity, ?> spi = fromDataDto(dtoType);
|
|
| 68 | - return spi.create(this, content, withoutValidation() ? e -> {
|
|
| 69 | - } : e -> doValidate(DtoValidationContext.CREATE_VALIDATION_CONTEXT, content, e));
|
|
| 66 | + DataDtoEntityContext<?, ?, ?, ?> spi = fromDataDto(dtoType);
|
|
| 67 | + return spi.create(this, content, this::doValidate);
|
|
| 70 | 68 | }
|
| 71 | 69 | |
| 72 | 70 | @Override
|
| 73 | 71 | public ToolkitId update(Class<? extends DataDto> dtoType, String id, String content) throws InvalidDataException {
|
| 74 | 72 | id = ToolkitId.decodeId(id);
|
| 75 | - DataDtoEntityContext<?, ?, DataEntity, ?> spi = fromDataDto(dtoType);
|
|
| 76 | - return spi.update(this, id, content, withoutValidation() ? e -> {
|
|
| 77 | - } : e -> doValidate(DtoValidationContext.UPDATE_VALIDATION_CONTEXT, content, e));
|
|
| 73 | + DataDtoEntityContext<?, ?, ?, ?> spi = fromDataDto(dtoType);
|
|
| 74 | + return spi.update(this, id, content, this::doValidate);
|
|
| 78 | 75 | }
|
| 79 | 76 | |
| 80 | 77 | @Override
|
| ... | ... | @@ -84,11 +81,14 @@ public class DataEntityServiceLocalSupport extends ObserveServiceLocal implement |
| 84 | 81 | spi.delete(this, id);
|
| 85 | 82 | }
|
| 86 | 83 | |
| 87 | - protected <E extends DataEntity> void doValidate(String validationContextName, String content, E entity) throws InvalidDataException {
|
|
| 84 | + protected <E extends DataEntity> void doValidate(E entity) throws InvalidDataException {
|
|
| 85 | + if (withoutValidation()) {
|
|
| 86 | + return;
|
|
| 87 | + }
|
|
| 88 | 88 | //FIXME Must have this somewhere on server or request
|
| 89 | 89 | ValidationRequestConfiguration configuration = newValidationRequestConfiguration(true);
|
| 90 | - DataValidationRequest request = newDataValidationRequest(validationContextName, entity.getTopiaId());
|
|
| 90 | + DataValidationRequest request = newDataValidationRequest(entity.getTopiaId());
|
|
| 91 | 91 | DataValidationResult result = ValidationHelper.validateApiData(this, configuration, request, entity);
|
| 92 | - checkValidationResult(content, result);
|
|
| 92 | + checkValidationResult(result);
|
|
| 93 | 93 | }
|
| 94 | 94 | } |
| ... | ... | @@ -44,7 +44,6 @@ import fr.ird.observe.spi.module.BusinessProjectVisitor; |
| 44 | 44 | import fr.ird.observe.spi.module.BusinessReferentialPackage;
|
| 45 | 45 | import fr.ird.observe.spi.module.BusinessSubModule;
|
| 46 | 46 | import fr.ird.observe.spi.module.ObserveBusinessProject;
|
| 47 | -import fr.ird.observe.spi.validation.DtoValidationContext;
|
|
| 48 | 47 | import fr.ird.observe.spi.validation.ValidationHelper;
|
| 49 | 48 | import org.apache.logging.log4j.LogManager;
|
| 50 | 49 | import org.apache.logging.log4j.Logger;
|
| ... | ... | @@ -124,25 +123,26 @@ public class ReferentialEntityServiceLocalSupport extends ObserveServiceLocal im |
| 124 | 123 | @Override
|
| 125 | 124 | public ToolkitId create(Class<? extends ReferentialDto> dtoType, String content) throws InvalidDataException {
|
| 126 | 125 | ReferentialDtoEntityContext<?, ?, ?, ?> spi = fromReferentialDto(dtoType);
|
| 127 | - return spi.create(this, content, withoutValidation() ? e -> {
|
|
| 128 | - } : e -> doValidate(spi.toDtoType(), DtoValidationContext.CREATE_VALIDATION_CONTEXT, content, e));
|
|
| 126 | + return spi.create(this, content, e -> doValidate(spi.toDtoType(), e));
|
|
| 129 | 127 | }
|
| 130 | 128 | |
| 131 | 129 | @Override
|
| 132 | 130 | public ToolkitId update(Class<? extends ReferentialDto> dtoType, String id, String content) throws InvalidDataException {
|
| 133 | 131 | id = ToolkitId.decodeId(id);
|
| 134 | 132 | ReferentialDtoEntityContext<?, ?, ?, ?> spi = fromReferentialDto(dtoType);
|
| 135 | - return spi.update(this, id, content, withoutValidation() ? e -> {
|
|
| 136 | - } : e -> doValidate(spi.toDtoType(), DtoValidationContext.CREATE_VALIDATION_CONTEXT, content, e));
|
|
| 133 | + return spi.update(this, id, content, e -> doValidate(spi.toDtoType(), e));
|
|
| 137 | 134 | }
|
| 138 | 135 | |
| 139 | - protected <D extends ReferentialDto, E extends ReferentialEntity> void doValidate(Class<D> dtoType, String validationContextName, String content, E entity) throws InvalidDataException {
|
|
| 136 | + private <D extends ReferentialDto, E extends ReferentialEntity> void doValidate(Class<D> dtoType, E entity) throws InvalidDataException {
|
|
| 137 | + if (withoutValidation()) {
|
|
| 138 | + return;
|
|
| 139 | + }
|
|
| 140 | 140 | //FIXME Must have this somewhere on server or request
|
| 141 | 141 | ValidationRequestConfiguration configuration = newValidationRequestConfiguration(false);
|
| 142 | - ReferentialValidationRequest request = newReferentialValidationRequest(validationContextName, Set.of(dtoType));
|
|
| 142 | + ReferentialValidationRequest request = newReferentialValidationRequest(Set.of(dtoType));
|
|
| 143 | 143 | //FIXME What about the not persisted case ? See Data
|
| 144 | 144 | ReferentialValidationResult result = ValidationHelper.validateApiReferential(this, configuration, request, dtoType, entity);
|
| 145 | - checkValidationResult(content, result);
|
|
| 145 | + checkValidationResult(result);
|
|
| 146 | 146 | }
|
| 147 | 147 | |
| 148 | 148 | protected ToolkitTreeNodeStates getByType(ToolkitRequestConfig config, Set<Class<? extends ReferentialDto>> dtoTypes) {
|