change DmpPropertiesPersist to use map

This commit is contained in:
Efstratios Giannopoulos 2024-01-19 15:12:03 +02:00
parent d4739ed1d0
commit 698c27747d
2 changed files with 14 additions and 11 deletions

View File

@ -13,10 +13,12 @@ import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID;
public class DmpPropertiesPersist { public class DmpPropertiesPersist {
private List<DmpBlueprintValuePersist> dmpBlueprintValues; private Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues;
public static final String _dmpBlueprintValues = "dmpBlueprintValues"; public static final String _dmpBlueprintValues = "dmpBlueprintValues";
@ -24,11 +26,11 @@ public class DmpPropertiesPersist {
public static final String _contacts = "contacts"; public static final String _contacts = "contacts";
public List<DmpBlueprintValuePersist> getDmpBlueprintValues() { public Map<UUID, DmpBlueprintValuePersist> getDmpBlueprintValues() {
return dmpBlueprintValues; return dmpBlueprintValues;
} }
public void setDmpBlueprintValues(List<DmpBlueprintValuePersist> dmpBlueprintValues) { public void setDmpBlueprintValues(Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues) {
this.dmpBlueprintValues = dmpBlueprintValues; this.dmpBlueprintValues = dmpBlueprintValues;
} }
@ -63,16 +65,17 @@ public class DmpPropertiesPersist {
@Override @Override
protected List<Specification> specifications(DmpPropertiesPersist item) { protected List<Specification> specifications(DmpPropertiesPersist item) {
return Arrays.asList( return Arrays.asList(
this.refSpec() this.mapSpec()
.iff(() -> this.status == DmpStatus.Finalized && !this.isNull(item.getDmpBlueprintValues())) .iff(() -> this.status == DmpStatus.Finalized && !this.isNull(item.getDmpBlueprintValues()))
.on(DmpPropertiesPersist._dmpBlueprintValues) .on(DmpPropertiesPersist._dmpBlueprintValues)
.over(item.getDmpBlueprintValues()) .over(item.getDmpBlueprintValues())
.using(() -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class)), .mapKey((k) -> ((UUID)k).toString())
this.refSpec() .using((itm) -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class)),
this.navSpec()
.iff(() -> this.status == DmpStatus.Finalized && !this.isNull(item.getContacts())) .iff(() -> this.status == DmpStatus.Finalized && !this.isNull(item.getContacts()))
.on(DmpPropertiesPersist._contacts) .on(DmpPropertiesPersist._contacts)
.over(item.getContacts()) .over(item.getContacts())
.using(() -> this.validatorFactory.validator(DmpContactPersist.DmpContactPersistValidator.class)) .using((itm) -> this.validatorFactory.validator(DmpContactPersist.DmpContactPersistValidator.class))
); );
} }

View File

@ -561,9 +561,9 @@ public class DmpServiceImpl implements DmpService {
data.getContacts().add(this.buildDmpContactEntity(contactPersist)); data.getContacts().add(this.buildDmpContactEntity(contactPersist));
} }
} }
if (!this.conventionService.isListNullOrEmpty(persist.getDmpBlueprintValues())){ if (persist.getDmpBlueprintValues() == null && !persist.getDmpBlueprintValues().isEmpty()){
data.setDmpBlueprintValues(new ArrayList<>()); data.setDmpBlueprintValues(new ArrayList<>());
for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues()) { for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues().values()) {
if (!this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue())) data.getDmpBlueprintValues().add(this.buildDmpBlueprintValueEntity(fieldValuePersist)); if (!this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue())) data.getDmpBlueprintValues().add(this.buildDmpBlueprintValueEntity(fieldValuePersist));
} }
} }
@ -596,8 +596,8 @@ public class DmpServiceImpl implements DmpService {
private @NotNull List<DmpReferencePersist> buildDmpReferencePersists(DmpPropertiesPersist persist){ private @NotNull List<DmpReferencePersist> buildDmpReferencePersists(DmpPropertiesPersist persist){
List<DmpReferencePersist> dmpReferencePersists = new ArrayList<>(); List<DmpReferencePersist> dmpReferencePersists = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(persist.getDmpBlueprintValues())){ if (persist.getDmpBlueprintValues() == null && !persist.getDmpBlueprintValues().isEmpty()){
for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues()) { for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues().values()) {
if (this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) && !this.conventionService.isListNullOrEmpty( fieldValuePersist.getReferences())) { if (this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) && !this.conventionService.isListNullOrEmpty( fieldValuePersist.getReferences())) {
for (ReferencePersist referencePersist : fieldValuePersist.getReferences()) { for (ReferencePersist referencePersist : fieldValuePersist.getReferences()) {
DmpReferencePersist dmpReferencePersist = new DmpReferencePersist(); DmpReferencePersist dmpReferencePersist = new DmpReferencePersist();