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.List;
import java.util.Map;
import java.util.UUID;
public class DmpPropertiesPersist {
private List<DmpBlueprintValuePersist> dmpBlueprintValues;
private Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues;
public static final String _dmpBlueprintValues = "dmpBlueprintValues";
@ -24,11 +26,11 @@ public class DmpPropertiesPersist {
public static final String _contacts = "contacts";
public List<DmpBlueprintValuePersist> getDmpBlueprintValues() {
public Map<UUID, DmpBlueprintValuePersist> getDmpBlueprintValues() {
return dmpBlueprintValues;
}
public void setDmpBlueprintValues(List<DmpBlueprintValuePersist> dmpBlueprintValues) {
public void setDmpBlueprintValues(Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues) {
this.dmpBlueprintValues = dmpBlueprintValues;
}
@ -63,16 +65,17 @@ public class DmpPropertiesPersist {
@Override
protected List<Specification> specifications(DmpPropertiesPersist item) {
return Arrays.asList(
this.refSpec()
this.mapSpec()
.iff(() -> this.status == DmpStatus.Finalized && !this.isNull(item.getDmpBlueprintValues()))
.on(DmpPropertiesPersist._dmpBlueprintValues)
.over(item.getDmpBlueprintValues())
.using(() -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class)),
this.refSpec()
.mapKey((k) -> ((UUID)k).toString())
.using((itm) -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class)),
this.navSpec()
.iff(() -> this.status == DmpStatus.Finalized && !this.isNull(item.getContacts()))
.on(DmpPropertiesPersist._contacts)
.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));
}
}
if (!this.conventionService.isListNullOrEmpty(persist.getDmpBlueprintValues())){
if (persist.getDmpBlueprintValues() == null && !persist.getDmpBlueprintValues().isEmpty()){
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));
}
}
@ -596,8 +596,8 @@ public class DmpServiceImpl implements DmpService {
private @NotNull List<DmpReferencePersist> buildDmpReferencePersists(DmpPropertiesPersist persist){
List<DmpReferencePersist> dmpReferencePersists = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(persist.getDmpBlueprintValues())){
for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues()) {
if (persist.getDmpBlueprintValues() == null && !persist.getDmpBlueprintValues().isEmpty()){
for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues().values()) {
if (this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) && !this.conventionService.isListNullOrEmpty( fieldValuePersist.getReferences())) {
for (ReferencePersist referencePersist : fieldValuePersist.getReferences()) {
DmpReferencePersist dmpReferencePersist = new DmpReferencePersist();