import common model description reference change

This commit is contained in:
amentis 2024-06-17 12:53:52 +03:00
parent 5ffc07979f
commit 90ed403376
1 changed files with 22 additions and 10 deletions

View File

@ -1612,18 +1612,30 @@ public class DescriptionServiceImpl implements DescriptionService {
if (model == null) if (model == null)
return null; return null;
if (this.conventionService.isNullOrEmpty(model.getLabel()) && this.conventionService.isNullOrEmpty(model.getReference())) throw new MyApplicationException("Reference without label and reference id ");
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class);
if (!this.conventionService.isNullOrEmpty(model.getLabel())) query = query.like(model.getLabel());
if (!this.conventionService.isNullOrEmpty(model.getReference())) query = query.references(model.getReference());
ReferenceEntity referenceEntity = query.first();
ReferencePersist persist = new ReferencePersist(); ReferencePersist persist = new ReferencePersist();
persist.setId(model.getId()); if (referenceEntity == null) {
persist.setLabel(model.getLabel()); persist.setLabel(model.getLabel());
persist.setDescription(model.getDescription()); persist.setReference(model.getReference());
persist.setReference(model.getReference()); persist.setSource("internal");
persist.setAbbreviation(model.getAbbreviation()); persist.setSourceType(ReferenceSourceType.Internal);
persist.setSource(model.getSource()); } else {
switch (model.getSourceType()){ persist.setId(referenceEntity.getId());
case Internal -> persist.setSourceType(ReferenceSourceType.Internal); persist.setLabel(referenceEntity.getLabel());
case External -> persist.setSourceType(ReferenceSourceType.External); persist.setReference(referenceEntity.getReference());
default -> throw new MyApplicationException("Unrecognized Type " + model.getSourceType().getValue()); persist.setSource(referenceEntity.getSource());
persist.setSourceType(referenceEntity.getSourceType());
persist.setAbbreviation(referenceEntity.getAbbreviation());
persist.setDescription(referenceEntity.getDescription());
persist.setHash(this.conventionService.hashValue(referenceEntity.getUpdatedAt()));
} }
return persist; return persist;