refactoring for implicit creation of dependend hosting-assets #108

Merged
hsh-michaelhoennig merged 22 commits from refactoring-for-implicit-creation-of-dependend-hosting-assets into master 2024-09-26 10:51:30 +02:00
3 changed files with 8 additions and 5 deletions
Showing only changes of commit 900d3bdc75 - Show all commits

View File

@ -17,8 +17,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

View File

@ -1,6 +1,8 @@
package net.hostsharing.hsadminng.hs.office.sepamandate;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeSepaMandatesApi;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateInsertResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandatePatchResource;
@ -135,6 +137,8 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
};
final BiConsumer<HsOfficeSepaMandateInsertResource, HsOfficeSepaMandateEntity> SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
entity.setDebitor(mapper.fetchEntity(HsOfficeDebitorEntity.class, resource.getDebitorUuid()));
entity.setBankAccount(mapper.fetchEntity(HsOfficeBankAccountEntity.class, resource.getBankAccountUuid()));
entity.setValidity(toPostgresDateRange(resource.getValidFrom(), resource.getValidTo()));
};
}

View File

@ -26,6 +26,7 @@ public class Mapper extends ModelMapper {
EntityManager em;
public Mapper() {
// make sure that resource.whateverUuid does not get mapped to entity.uuid, if resource.uuid does not exist
getConfiguration().setMatchingStrategy(STRICT);
}
@ -67,7 +68,7 @@ public class Mapper extends ModelMapper {
if (subEntityUuid == null) {
continue;
}
ReflectionUtils.setField(f, target, findEntityById(f.getType(), subEntityUuid));
ReflectionUtils.setField(f, target, fetchEntity(f.getType(), subEntityUuid));
}
return target;
}
@ -83,9 +84,9 @@ public class Mapper extends ModelMapper {
.toArray(Field[]::new);
}
private Object findEntityById(final Class<?> entityClass, final Object subEntityUuid) {
public <E> E fetchEntity(final Class<E> entityClass, final Object subEntityUuid) {
// using getReference would be more efficent, but results in very technical error messages
final var entity = em.find(entityClass, subEntityUuid);
final var entity = em.find(entityClass, subEntityUuid); // FIXME: try getReference
if (entity != null) {
return entity;
}