ModelMapper as Spring Bean
1 files added
44 files modified
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | @RestController |
| | | |
| | | public class HsOfficeBankAccountController implements HsOfficeBankAccountsApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeBankAccountRepository bankAccountRepo; |
| | |
| | | |
| | | final var entities = bankAccountRepo.findByOptionalHolderLike(holder); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficeBankAccountResource.class); |
| | | final var resources = mapper.mapList(entities, HsOfficeBankAccountResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | |
| | | IbanUtil.validate(body.getIban()); |
| | | BicUtil.validate(body.getBic()); |
| | | |
| | | final var entityToSave = map(body, HsOfficeBankAccountEntity.class); |
| | | final var entityToSave = mapper.map(body, HsOfficeBankAccountEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = bankAccountRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/BankAccounts/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeBankAccountResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficeBankAccountResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficeBankAccountResource.class)); |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficeBankAccountResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | @RestController |
| | | |
| | | public class HsOfficeContactController implements HsOfficeContactsApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeContactRepository contactRepo; |
| | |
| | | |
| | | final var entities = contactRepo.findContactByOptionalLabelLike(label); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficeContactResource.class); |
| | | final var resources = mapper.mapList(entities, HsOfficeContactResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entityToSave = map(body, HsOfficeContactEntity.class); |
| | | final var entityToSave = mapper.map(body, HsOfficeContactEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = contactRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/contacts/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeContactResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficeContactResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficeContactResource.class)); |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficeContactResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | new HsOfficeContactEntityPatch(current).apply(body); |
| | | |
| | | final var saved = contactRepo.save(current); |
| | | final var mapped = map(saved, HsOfficeContactResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficeContactResource.class); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | } |
| | |
| | | |
| | | import static java.lang.String.join; |
| | | import static net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeCoopAssetsTransactionTypeResource.*; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | @RestController |
| | | public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAssetsApi { |
| | |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo; |
| | | |
| | | @Override |
| | | @Transactional(readOnly = true) |
| | | public ResponseEntity<List<HsOfficeCoopAssetsTransactionResource>> listCoopAssets( |
| | | final String currentUser, |
| | | final String assumedRoles, |
| | | final UUID membershipUuid, |
| | | final @DateTimeFormat(iso = ISO.DATE) LocalDate fromValueDate, |
| | | final @DateTimeFormat(iso = ISO.DATE) LocalDate toValueDate) { |
| | | final String currentUser, |
| | | final String assumedRoles, |
| | | final UUID membershipUuid, |
| | | final @DateTimeFormat(iso = ISO.DATE) LocalDate fromValueDate, |
| | | final @DateTimeFormat(iso = ISO.DATE) LocalDate toValueDate) { |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entities = coopAssetsTransactionRepo.findCoopAssetsTransactionByOptionalMembershipUuidAndDateRange( |
| | | membershipUuid, |
| | | fromValueDate, |
| | | toValueDate); |
| | | membershipUuid, |
| | | fromValueDate, |
| | | toValueDate); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficeCoopAssetsTransactionResource.class); |
| | | final var resources = mapper.mapList(entities, HsOfficeCoopAssetsTransactionResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public ResponseEntity<HsOfficeCoopAssetsTransactionResource> addCoopAssetsTransaction( |
| | | final String currentUser, |
| | | final String assumedRoles, |
| | | @Valid final HsOfficeCoopAssetsTransactionInsertResource requestBody) { |
| | | final String currentUser, |
| | | final String assumedRoles, |
| | | @Valid final HsOfficeCoopAssetsTransactionInsertResource requestBody) { |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | validate(requestBody); |
| | | |
| | | final var entityToSave = map(requestBody, HsOfficeCoopAssetsTransactionEntity.class); |
| | | final var entityToSave = mapper.map(requestBody, HsOfficeCoopAssetsTransactionEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = coopAssetsTransactionRepo.save(entityToSave); |
| | | |
| | | final var uri = |
| | | MvcUriComponentsBuilder.fromController(getClass()) |
| | | .path("/api/hs/office/coopassetstransactions/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeCoopAssetsTransactionResource.class); |
| | | MvcUriComponentsBuilder.fromController(getClass()) |
| | | .path("/api/hs/office/coopassetstransactions/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = mapper.map(saved, HsOfficeCoopAssetsTransactionResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private static void validateDebitTransaction( |
| | | final HsOfficeCoopAssetsTransactionInsertResource requestBody, |
| | | final ArrayList<String> violations) { |
| | | final HsOfficeCoopAssetsTransactionInsertResource requestBody, |
| | | final ArrayList<String> violations) { |
| | | if (List.of(DEPOSIT, ADOPTION).contains(requestBody.getTransactionType()) |
| | | && requestBody.getAssetValue().signum() < 0) { |
| | | && requestBody.getAssetValue().signum() < 0) { |
| | | violations.add("for %s, assetValue must be positive but is \"%.2f\"".formatted( |
| | | requestBody.getTransactionType(), requestBody.getAssetValue())); |
| | | requestBody.getTransactionType(), requestBody.getAssetValue())); |
| | | } |
| | | } |
| | | |
| | | private static void validateCreditTransaction( |
| | | final HsOfficeCoopAssetsTransactionInsertResource requestBody, |
| | | final ArrayList<String> violations) { |
| | | final HsOfficeCoopAssetsTransactionInsertResource requestBody, |
| | | final ArrayList<String> violations) { |
| | | if (List.of(DISBURSAL, TRANSFER, CLEARING, LOSS).contains(requestBody.getTransactionType()) |
| | | && requestBody.getAssetValue().signum() > 0) { |
| | | && requestBody.getAssetValue().signum() > 0) { |
| | | violations.add("for %s, assetValue must be negative but is \"%.2f\"".formatted( |
| | | requestBody.getTransactionType(), requestBody.getAssetValue())); |
| | | requestBody.getTransactionType(), requestBody.getAssetValue())); |
| | | } |
| | | } |
| | | |
| | | private static void validateAssetValue( |
| | | final HsOfficeCoopAssetsTransactionInsertResource requestBody, |
| | | final ArrayList<String> violations) { |
| | | final HsOfficeCoopAssetsTransactionInsertResource requestBody, |
| | | final ArrayList<String> violations) { |
| | | if (requestBody.getAssetValue().signum() == 0) { |
| | | violations.add("assetValue must not be 0 but is \"%.2f\"".formatted( |
| | | requestBody.getAssetValue())); |
| | | requestBody.getAssetValue())); |
| | | } |
| | | } |
| | | |
| | |
| | | import java.util.UUID; |
| | | |
| | | import static java.lang.String.join; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeCoopSharesTransactionTypeResource.CANCELLATION; |
| | | import static net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeCoopSharesTransactionTypeResource.SUBSCRIPTION; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeCoopSharesTransactionRepository coopSharesTransactionRepo; |
| | |
| | | fromValueDate, |
| | | toValueDate); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficeCoopSharesTransactionResource.class); |
| | | final var resources = mapper.mapList(entities, HsOfficeCoopSharesTransactionResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | |
| | | context.define(currentUser, assumedRoles); |
| | | validate(requestBody); |
| | | |
| | | final var entityToSave = map(requestBody, HsOfficeCoopSharesTransactionEntity.class); |
| | | final var entityToSave = mapper.map(requestBody, HsOfficeCoopSharesTransactionEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = coopSharesTransactionRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/coopsharestransactions/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeCoopSharesTransactionResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficeCoopSharesTransactionResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | package net.hostsharing.hsadminng.hs.office.debitor; |
| | | |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; |
| | | import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeDebitorsApi; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*; |
| | | import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorResource; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.persistence.EntityManager; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.function.BiConsumer; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | @RestController |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeDebitorRepository debitorRepo; |
| | |
| | | ? debitorRepo.findDebitorByDebitorNumber(debitorNumber) |
| | | : debitorRepo.findDebitorByOptionalNameLike(name); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficeDebitorResource.class, |
| | | DEBITOR_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entityToSave = map(body, HsOfficeDebitorEntity.class, DEBITOR_RESOURCE_TO_ENTITY_POSTMAPPER); |
| | | final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = debitorRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/debitors/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeDebitorResource.class, |
| | | DEBITOR_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | final var mapped = mapper.map(saved, HsOfficeDebitorResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficeDebitorResource.class, DEBITOR_ENTITY_TO_RESOURCE_POSTMAPPER)); |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficeDebitorResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | new HsOfficeDebitorEntityPatcher(em, current).apply(body); |
| | | |
| | | final var saved = debitorRepo.save(current); |
| | | final var mapped = map(saved, HsOfficeDebitorResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficeDebitorResource.class); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | |
| | | |
| | | final BiConsumer<HsOfficeDebitorEntity, HsOfficeDebitorResource> DEBITOR_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { |
| | | resource.setPartner(map(entity.getPartner(), HsOfficePartnerResource.class)); |
| | | resource.setBillingContact(map(entity.getBillingContact(), HsOfficeContactResource.class)); |
| | | if ( entity.getRefundBankAccount() != null ) { |
| | | resource.setRefundBankAccount(map(entity.getRefundBankAccount(), HsOfficeBankAccountResource.class)); |
| | | } |
| | | }; |
| | | |
| | | final BiConsumer<HsOfficeDebitorInsertResource, HsOfficeDebitorEntity> DEBITOR_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { |
| | | entity.setPartner(em.getReference(HsOfficePartnerEntity.class, resource.getPartnerUuid())); |
| | | entity.setBillingContact(em.getReference(HsOfficeContactEntity.class, resource.getBillingContactUuid())); |
| | | if ( resource.getRefundBankAccountUuid() != null ) { |
| | | entity.setRefundBankAccount(em.getReference(HsOfficeBankAccountEntity.class, resource.getRefundBankAccountUuid())); |
| | | } |
| | | }; |
| | | } |
| | |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeMembershipInsertResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeMembershipPatchResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeMembershipResource; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.UUID; |
| | | import java.util.function.BiConsumer; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | |
| | | public class HsOfficeMembershipController implements HsOfficeMembershipsApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeMembershipRepository membershipRepo; |
| | |
| | | final var entities = |
| | | membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(partnerUuid, memberNumber); |
| | | |
| | | final var resources = mapList(entities, HsOfficeMembershipResource.class, |
| | | final var resources = mapper.mapList(entities, HsOfficeMembershipResource.class, |
| | | SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entityToSave = map(body, HsOfficeMembershipEntity.class); |
| | | final var entityToSave = mapper.map(body, HsOfficeMembershipEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = membershipRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/Memberships/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeMembershipResource.class, |
| | | final var mapped = mapper.map(saved, HsOfficeMembershipResource.class, |
| | | SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficeMembershipResource.class, |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficeMembershipResource.class, |
| | | SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER)); |
| | | } |
| | | |
| | |
| | | |
| | | final var current = membershipRepo.findByUuid(membershipUuid).orElseThrow(); |
| | | |
| | | new HsOfficeMembershipEntityPatcher(em, current).apply(body); |
| | | new HsOfficeMembershipEntityPatcher(em, mapper, current).apply(body); |
| | | |
| | | final var saved = membershipRepo.save(current); |
| | | final var mapped = map(saved, HsOfficeMembershipResource.class, SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | final var mapped = mapper.map(saved, HsOfficeMembershipResource.class, SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | |
| | | final BiConsumer<HsOfficeMembershipEntity, HsOfficeMembershipResource> SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { |
| | | // TODO.refa: this should be possible via ModelMapper config |
| | | resource.setValidFrom(entity.getValidity().lower()); |
| | | if (entity.getValidity().hasUpperBound()) { |
| | | resource.setValidTo(entity.getValidity().upper().minusDays(1)); |
| | |
| | | import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeMembershipPatchResource; |
| | | import net.hostsharing.hsadminng.mapper.EntityPatcher; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.mapper.OptionalFromJson; |
| | | |
| | | import javax.persistence.EntityManager; |
| | | import java.util.Optional; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | public class HsOfficeMembershipEntityPatcher implements EntityPatcher<HsOfficeMembershipPatchResource> { |
| | | |
| | | private final EntityManager em; |
| | | private final Mapper mapper; |
| | | private final HsOfficeMembershipEntity entity; |
| | | |
| | | public HsOfficeMembershipEntityPatcher( |
| | | final EntityManager em, |
| | | final Mapper mapper, |
| | | final HsOfficeMembershipEntity entity) { |
| | | this.em = em; |
| | | this.mapper = mapper; |
| | | this.entity = entity; |
| | | } |
| | | |
| | |
| | | OptionalFromJson.of(resource.getValidTo()).ifPresent( |
| | | entity::setValidTo); |
| | | Optional.ofNullable(resource.getReasonForTermination()) |
| | | .map(v -> map(v, HsOfficeReasonForTermination.class)) |
| | | .map(v -> mapper.map(v, HsOfficeReasonForTermination.class)) |
| | | .ifPresent(entity::setReasonForTermination); |
| | | } |
| | | |
| | |
| | | package net.hostsharing.hsadminng.hs.office.partner; |
| | | |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartnersApi; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*; |
| | | import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerInsertResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | import javax.persistence.EntityManager; |
| | | import java.util.List; |
| | | import java.util.NoSuchElementException; |
| | | import java.util.UUID; |
| | | import java.util.function.BiConsumer; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | @RestController |
| | | |
| | |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficePartnerRepository partnerRepo; |
| | | |
| | | @Autowired |
| | | private HsOfficePersonRepository personRepo; |
| | | |
| | | @Autowired |
| | | private HsOfficeContactRepository contactRepo; |
| | | |
| | | @Autowired |
| | | private EntityManager em; |
| | |
| | | |
| | | final var entities = partnerRepo.findPartnerByOptionalNameLike(name); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficePartnerResource.class, |
| | | PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | final var resources = mapper.mapList(entities, HsOfficePartnerResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entityToSave = mapToHsOfficePartnerEntity(body); |
| | | final var entityToSave = mapper.map(body, HsOfficePartnerEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | // TODO.impl: use getReference |
| | | entityToSave.setContact(contactRepo.findByUuid(body.getContactUuid()).orElseThrow( |
| | | () -> new NoSuchElementException("cannot find contact uuid " + body.getContactUuid()) |
| | | )); |
| | | entityToSave.setPerson(personRepo.findByUuid(body.getPersonUuid()).orElseThrow( |
| | | () -> new NoSuchElementException("cannot find person uuid " + body.getPersonUuid()) |
| | | )); |
| | | entityToSave.setDetails(map(body.getDetails(), HsOfficePartnerDetailsEntity.class)); |
| | | entityToSave.setDetails(mapper.map(body.getDetails(), HsOfficePartnerDetailsEntity.class)); |
| | | entityToSave.getDetails().setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = partnerRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/partners/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficePartnerResource.class, |
| | | PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | final var mapped = mapper.map(saved, HsOfficePartnerResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficePartnerResource.class, PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER)); |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficePartnerResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | new HsOfficePartnerEntityPatcher(em, current).apply(body); |
| | | |
| | | final var saved = partnerRepo.save(current); |
| | | final var mapped = map(saved, HsOfficePartnerResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficePartnerResource.class); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | |
| | | final BiConsumer<HsOfficePartnerEntity, HsOfficePartnerResource> PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { |
| | | resource.setPerson(map(entity.getPerson(), HsOfficePersonResource.class)); |
| | | resource.setContact(map(entity.getContact(), HsOfficeContactResource.class)); |
| | | }; |
| | | |
| | | // TODO.impl: user postmapper + getReference |
| | | private HsOfficePartnerEntity mapToHsOfficePartnerEntity(final HsOfficePartnerInsertResource resource) { |
| | | final var entity = new HsOfficePartnerEntity(); |
| | | // entity.setBirthday(resource.getBirthday()); |
| | | // entity.setBirthName(resource.getBirthName()); |
| | | // entity.setDateOfDeath(resource.getDateOfDeath()); |
| | | // entity.setRegistrationNumber(resource.getRegistrationNumber()); |
| | | // entity.setRegistrationOffice(resource.getRegistrationOffice()); |
| | | return entity; |
| | | } |
| | | } |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | |
| | | @RestController |
| | | |
| | | public class HsOfficePersonController implements HsOfficePersonsApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficePersonRepository personRepo; |
| | |
| | | |
| | | final var entities = personRepo.findPersonByOptionalNameLike(label); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficePersonResource.class); |
| | | final var resources = mapper.mapList(entities, HsOfficePersonResource.class); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | | |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entityToSave = map(body, HsOfficePersonEntity.class); |
| | | final var entityToSave = mapper.map(body, HsOfficePersonEntity.class); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = personRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/persons/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficePersonResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficePersonResource.class); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | | |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficePersonResource.class)); |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficePersonResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | new HsOfficePersonEntityPatcher(current).apply(body); |
| | | |
| | | final var saved = personRepo.save(current); |
| | | final var mapped = map(saved, HsOfficePersonResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficePersonResource.class); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | } |
| | |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeRelationshipsApi; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*; |
| | | import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.UUID; |
| | | import java.util.function.BiConsumer; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeRelationshipRepository relationshipRepo; |
| | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entities = relationshipRepo.findRelationshipRelatedToPersonUuid(personUuid, |
| | | map(relationshipType, HsOfficeRelationshipType.class)); |
| | | mapper.map(relationshipType, HsOfficeRelationshipType.class)); |
| | | |
| | | final var resources = mapList(entities, HsOfficeRelationshipResource.class, |
| | | final var resources = mapper.mapList(entities, HsOfficeRelationshipResource.class, |
| | | RELATIONSHIP_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | |
| | | .path("/api/hs/office/relationships/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeRelationshipResource.class, |
| | | final var mapped = mapper.map(saved, HsOfficeRelationshipResource.class, |
| | | RELATIONSHIP_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficeRelationshipResource.class, RELATIONSHIP_ENTITY_TO_RESOURCE_POSTMAPPER)); |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficeRelationshipResource.class, RELATIONSHIP_ENTITY_TO_RESOURCE_POSTMAPPER)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | new HsOfficeRelationshipEntityPatcher(em, current).apply(body); |
| | | |
| | | final var saved = relationshipRepo.save(current); |
| | | final var mapped = map(saved, HsOfficeRelationshipResource.class); |
| | | final var mapped = mapper.map(saved, HsOfficeRelationshipResource.class); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | |
| | | |
| | | final BiConsumer<HsOfficeRelationshipEntity, HsOfficeRelationshipResource> RELATIONSHIP_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { |
| | | resource.setRelAnchor(map(entity.getRelAnchor(), HsOfficePersonResource.class)); |
| | | resource.setRelHolder(map(entity.getRelHolder(), HsOfficePersonResource.class)); |
| | | resource.setContact(map(entity.getContact(), HsOfficeContactResource.class)); |
| | | resource.setRelAnchor(mapper.map(entity.getRelAnchor(), HsOfficePersonResource.class)); |
| | | resource.setRelHolder(mapper.map(entity.getRelHolder(), HsOfficePersonResource.class)); |
| | | resource.setContact(mapper.map(entity.getContact(), HsOfficeContactResource.class)); |
| | | }; |
| | | } |
| | |
| | | |
| | | import javax.persistence.EntityManager; |
| | | import javax.validation.Valid; |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.function.BiConsumer; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange; |
| | | |
| | | @RestController |
| | |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private HsOfficeSepaMandateRepository SepaMandateRepo; |
| | |
| | | |
| | | final var entities = SepaMandateRepo.findSepaMandateByOptionalIban(iban); |
| | | |
| | | final var resources = Mapper.mapList(entities, HsOfficeSepaMandateResource.class, |
| | | final var resources = mapper.mapList(entities, HsOfficeSepaMandateResource.class, |
| | | SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.ok(resources); |
| | | } |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var entityToSave = map(body, HsOfficeSepaMandateEntity.class, SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER); |
| | | final var entityToSave = mapper.map(body, HsOfficeSepaMandateEntity.class, SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER); |
| | | entityToSave.setUuid(UUID.randomUUID()); |
| | | |
| | | final var saved = SepaMandateRepo.save(entityToSave); |
| | |
| | | .path("/api/hs/office/SepaMandates/{id}") |
| | | .buildAndExpand(entityToSave.getUuid()) |
| | | .toUri(); |
| | | final var mapped = map(saved, HsOfficeSepaMandateResource.class, |
| | | final var mapped = mapper.map(saved, HsOfficeSepaMandateResource.class, |
| | | SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.created(uri).body(mapped); |
| | | } |
| | |
| | | if (result.isEmpty()) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result.get(), HsOfficeSepaMandateResource.class, |
| | | return ResponseEntity.ok(mapper.map(result.get(), HsOfficeSepaMandateResource.class, |
| | | SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER)); |
| | | } |
| | | |
| | |
| | | current.setValidity(toPostgresDateRange(current.getValidity().lower(), body.getValidTo())); |
| | | |
| | | final var saved = SepaMandateRepo.save(current); |
| | | final var mapped = map(saved, HsOfficeSepaMandateResource.class, SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | final var mapped = mapper.map(saved, HsOfficeSepaMandateResource.class, SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | |
| | |
| | | /** |
| | | * A nicer API for ModelMapper. |
| | | */ |
| | | public abstract class Mapper { |
| | | public class Mapper extends ModelMapper { |
| | | |
| | | public final static ModelMapper modelMapper = new ModelMapper(); |
| | | public Mapper() { |
| | | getConfiguration().setAmbiguityIgnored(true); |
| | | } |
| | | |
| | | public static <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass) { |
| | | public <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass) { |
| | | return mapList(source, targetClass, null); |
| | | } |
| | | |
| | | public static <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) { |
| | | public <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) { |
| | | return source |
| | | .stream() |
| | | .map(element -> { |
| | |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | public static <S, T> T map(final S source, final Class<T> targetClass) { |
| | | return map(source, targetClass, null); |
| | | } |
| | | |
| | | public static <S, T> T map(final S source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) { |
| | | public <S, T> T map(final S source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) { |
| | | if (source == null) { |
| | | return null; |
| | | } |
| | | final var target = modelMapper.map(source, targetClass); |
| | | if (postMapper != null) { |
| | | postMapper.accept(source, target); |
| | | } |
| | | final var target = map(source, targetClass); |
| | | postMapper.accept(source, target); |
| | | return target; |
| | | } |
| | | } |
New file |
| | |
| | | package net.hostsharing.hsadminng.mapper; |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | @Configuration |
| | | public class MapperConfiguration { |
| | | |
| | | @Bean |
| | | public Mapper modelMapper() { |
| | | return new Mapper(); |
| | | } |
| | | } |
| | |
| | | package net.hostsharing.hsadminng.rbac.rbacgrant; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacGrantsApi; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.model.RbacGrantResource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | |
| | | public class RbacGrantController implements RbacGrantsApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private RbacGrantRepository rbacGrantRepository; |
| | |
| | | if (result == null) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result, RbacGrantResource.class)); |
| | | return ResponseEntity.ok(mapper.map(result, RbacGrantResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | return ResponseEntity.ok(mapList(rbacGrantRepository.findAll(), RbacGrantResource.class)); |
| | | return ResponseEntity.ok(mapper.mapList(rbacGrantRepository.findAll(), RbacGrantResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var granted = rbacGrantRepository.save(map(body, RbacGrantEntity.class)); |
| | | final var granted = rbacGrantRepository.save(mapper.map(body, RbacGrantEntity.class)); |
| | | em.flush(); |
| | | em.refresh(granted); |
| | | |
| | |
| | | .path("/api/rbac.yaml/grants/{roleUuid}") |
| | | .buildAndExpand(body.getGrantedRoleUuid()) |
| | | .toUri(); |
| | | return ResponseEntity.created(uri).body(map(granted, RbacGrantResource.class)); |
| | | return ResponseEntity.created(uri).body(mapper.map(granted, RbacGrantResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | package net.hostsharing.hsadminng.rbac.rbacrole; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacRolesApi; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.model.RbacRoleResource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import java.util.List; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | |
| | | public class RbacRoleController implements RbacRolesApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private RbacRoleRepository rbacRoleRepository; |
| | |
| | | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | return ResponseEntity.ok(mapList(rbacRoleRepository.findAll(), RbacRoleResource.class)); |
| | | final List<RbacRoleEntity> result = rbacRoleRepository.findAll(); |
| | | |
| | | return ResponseEntity.ok(mapper.mapList(result, RbacRoleResource.class)); |
| | | } |
| | | |
| | | } |
| | |
| | | package net.hostsharing.hsadminng.rbac.rbacuser; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacUsersApi; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.model.RbacUserPermissionResource; |
| | | import net.hostsharing.hsadminng.rbac.generated.api.v1.model.RbacUserResource; |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | public class RbacUserController implements RbacUsersApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private RbacUserRepository rbacUserRepository; |
| | |
| | | if (body.getUuid() == null) { |
| | | body.setUuid(UUID.randomUUID()); |
| | | } |
| | | final var saved = map(body, RbacUserEntity.class); |
| | | final var saved = mapper.map(body, RbacUserEntity.class); |
| | | rbacUserRepository.create(saved); |
| | | final var uri = |
| | | MvcUriComponentsBuilder.fromController(getClass()) |
| | | .path("/api/rbac.yaml/users/{id}") |
| | | .buildAndExpand(saved.getUuid()) |
| | | .toUri(); |
| | | return ResponseEntity.created(uri).body(map(saved, RbacUserResource.class)); |
| | | return ResponseEntity.created(uri).body(mapper.map(saved, RbacUserResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (result == null) { |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | return ResponseEntity.ok(map(result, RbacUserResource.class)); |
| | | return ResponseEntity.ok(mapper.map(result, RbacUserResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | ) { |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | return ResponseEntity.ok(mapList(rbacUserRepository.findByOptionalNameLike(userName), RbacUserResource.class)); |
| | | return ResponseEntity.ok(mapper.mapList(rbacUserRepository.findByOptionalNameLike(userName), RbacUserResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | ) { |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | return ResponseEntity.ok(mapList( |
| | | return ResponseEntity.ok(mapper.mapList( |
| | | rbacUserRepository.findPermissionsOfUserByUuid(userUuid), |
| | | RbacUserPermissionResource.class)); |
| | | } |
| | |
| | | package net.hostsharing.hsadminng.test.cust; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.test.generated.api.v1.api.TestCustomersApi; |
| | | import net.hostsharing.hsadminng.test.generated.api.v1.model.TestCustomerResource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | |
| | | public class TestCustomerController implements TestCustomersApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private TestCustomerRepository testCustomerRepository; |
| | |
| | | |
| | | final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(prefix); |
| | | |
| | | return ResponseEntity.ok(mapList(result, TestCustomerResource.class)); |
| | | return ResponseEntity.ok(mapper.mapList(result, TestCustomerResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | customer.setUuid(UUID.randomUUID()); |
| | | } |
| | | |
| | | final var saved = testCustomerRepository.save(map(customer, TestCustomerEntity.class)); |
| | | final var saved = testCustomerRepository.save(mapper.map(customer, TestCustomerEntity.class)); |
| | | |
| | | final var uri = |
| | | MvcUriComponentsBuilder.fromController(getClass()) |
| | | .path("/api/test/customers/{id}") |
| | | .buildAndExpand(customer.getUuid()) |
| | | .toUri(); |
| | | return ResponseEntity.created(uri).body(map(saved, TestCustomerResource.class)); |
| | | return ResponseEntity.created(uri).body(mapper.map(saved, TestCustomerResource.class)); |
| | | } |
| | | |
| | | } |
| | |
| | | package net.hostsharing.hsadminng.test.pac; |
| | | |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.hsadminng.mapper.OptionalFromJson; |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.test.generated.api.v1.api.TestPackagesApi; |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.map; |
| | | import static net.hostsharing.hsadminng.mapper.Mapper.mapList; |
| | | |
| | | @RestController |
| | | public class TestPackageController implements TestPackagesApi { |
| | | |
| | | @Autowired |
| | | private Context context; |
| | | |
| | | @Autowired |
| | | private Mapper mapper; |
| | | |
| | | @Autowired |
| | | private TestPackageRepository testPackageRepository; |
| | |
| | | context.define(currentUser, assumedRoles); |
| | | |
| | | final var result = testPackageRepository.findAllByOptionalNameLike(name); |
| | | return ResponseEntity.ok(mapList(result, TestPackageResource.class)); |
| | | return ResponseEntity.ok(mapper.mapList(result, TestPackageResource.class)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | final var current = testPackageRepository.findByUuid(packageUuid); |
| | | OptionalFromJson.of(body.getDescription()).ifPresent(current::setDescription); |
| | | final var saved = testPackageRepository.save(current); |
| | | final var mapped = map(saved, TestPackageResource.class); |
| | | final var mapped = mapper.map(saved, TestPackageResource.class); |
| | | return ResponseEntity.ok(mapped); |
| | | } |
| | | } |
| | |
| | | |
| | | HsOfficePartnerDetails: |
| | | type: object |
| | | nullable: false |
| | | properties: |
| | | uuid: |
| | | type: string |
| | |
| | | |
| | | HsOfficePartnerDetailsPatch: |
| | | type: object |
| | | nullable: true |
| | | nullable: false |
| | | properties: |
| | | registrationOffice: |
| | | type: string |
| | |
| | | required: |
| | | - personUuid |
| | | - contactUuid |
| | | - details |
| | | |
| | | HsOfficePartnerDetailsInsert: |
| | | type: object |
| | | nullable: false |
| | | properties: |
| | | registrationOffice: |
| | | type: string |
| | |
| | | |
| | | import io.restassured.RestAssured; |
| | | import io.restassured.http.ContentType; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.test.Accepts; |
| | | import net.hostsharing.hsadminng.HsadminNgApplication; |
| | | import net.hostsharing.hsadminng.context.Context; |
| | |
| | | |
| | | @Autowired |
| | | Context context; |
| | | |
| | | @Autowired |
| | | Context contextMock; |
| | | |
| | | @Autowired |
| | | HsOfficeBankAccountRepository bankAccountRepo; |
| | |
| | | package net.hostsharing.hsadminng.hs.office.bankaccount; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.junit.jupiter.params.ParameterizedTest; |
| | | import org.junit.jupiter.params.provider.EnumSource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | Context contextMock; |
| | | |
| | | @MockBean |
| | | Mapper mapper; |
| | | |
| | | @MockBean |
| | | HsOfficeBankAccountRepository bankAccountRepo; |
| | | |
| | | enum InvalidIbanTestCase { |
| | |
| | | import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; |
| | | import net.hostsharing.test.Array; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | import org.junit.jupiter.api.AfterEach; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Nested; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.modelmapper.internal.bytebuddy.utility.RandomString; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | import org.testcontainers.junit.jupiter.Container; |
| | | |
| | | import javax.persistence.EntityManager; |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeBankAccountRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | private HsOfficeBankAccountEntity givenSomeTemporaryBankAccount(final String createdByUser) { |
| | | final var random = RandomString.make(3); |
| | | final var random = RandomStringUtils.randomAlphabetic(3); |
| | | return givenSomeTemporaryBankAccount(createdByUser, () -> |
| | | hsOfficeBankAccount( |
| | | "some temp acc #" + random, |
| | |
| | | import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; |
| | | import net.hostsharing.test.Array; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | import org.junit.jupiter.api.AfterEach; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Nested; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.modelmapper.internal.bytebuddy.utility.RandomString; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | import org.testcontainers.junit.jupiter.Container; |
| | | |
| | |
| | | import static org.assertj.core.api.Assumptions.assumeThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeContactRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | private HsOfficeContactEntity givenSomeTemporaryContact(final String createdByUser) { |
| | | final var random = RandomString.make(12); |
| | | final var random = RandomStringUtils.randomAlphabetic(12); |
| | | return givenSomeTemporaryContact(createdByUser, () -> |
| | | hsOfficeContact( |
| | | "some temporary contact #" + random, |
| | |
| | | package net.hostsharing.hsadminng.hs.office.coopassets; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.test.JsonBuilder; |
| | | import org.junit.jupiter.params.ParameterizedTest; |
| | | import org.junit.jupiter.params.provider.EnumSource; |
| | |
| | | Context contextMock; |
| | | |
| | | @MockBean |
| | | Mapper mapper; |
| | | |
| | | @MockBean |
| | | HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo; |
| | | |
| | | static final String VALID_INSERT_REQUEST_BODY = """ |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeCoopAssetsTransactionRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | package net.hostsharing.hsadminng.hs.office.coopshares; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.test.JsonBuilder; |
| | | import org.junit.jupiter.params.ParameterizedTest; |
| | | import org.junit.jupiter.params.provider.EnumSource; |
| | |
| | | Context contextMock; |
| | | |
| | | @MockBean |
| | | Mapper mapper; |
| | | |
| | | @MockBean |
| | | HsOfficeCoopSharesTransactionRepository coopSharesTransactionRepo; |
| | | |
| | | static final String VALID_INSERT_REQUEST_BODY = """ |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | | import javax.persistence.EntityManager; |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeCoopSharesTransactionRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | Context context; |
| | | |
| | | @Autowired |
| | | Context contextMock; |
| | | |
| | | @Autowired |
| | | HsOfficeDebitorRepository debitorRepo; |
| | | |
| | | @Autowired |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeDebitorRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionRepository; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.boot.test.mock.mockito.SpyBean; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.orm.jpa.JpaObjectRetrievalFailureException; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | import org.springframework.test.web.servlet.MockMvc; |
| | | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
| | | |
| | |
| | | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| | | |
| | | @WebMvcTest(HsOfficeMembershipController.class) |
| | | @Import(Mapper.class) |
| | | @RunWith(SpringRunner.class) |
| | | public class HsOfficeMembershipControllerRestTest { |
| | | |
| | | @Autowired |
| | |
| | | import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeMembershipPatchResource; |
| | | import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeReasonForTerminationResource; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import net.hostsharing.test.PatchUnitTestBase; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.TestInstance; |
| | | import org.junit.jupiter.api.extension.ExtendWith; |
| | | import org.mockito.Mock; |
| | | import org.mockito.junit.jupiter.MockitoExtension; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import javax.persistence.EntityManager; |
| | | import java.time.LocalDate; |
| | |
| | | > { |
| | | |
| | | private static final UUID INITIAL_MEMBERSHIP_UUID = UUID.randomUUID(); |
| | | private static final UUID INITIAL_MAIN_DEBITOR_UUID = UUID.randomUUID(); |
| | | private static final UUID PATCHED_MAIN_DEBITOR_UUID = UUID.randomUUID(); |
| | | private static final LocalDate GIVEN_VALID_FROM = LocalDate.parse("2020-04-15"); |
| | | private static final LocalDate PATCHED_VALID_TO = LocalDate.parse("2022-12-31"); |
| | | |
| | | @Mock |
| | | private EntityManager em; |
| | | |
| | | private Mapper mapper = new Mapper(); |
| | | |
| | | @BeforeEach |
| | | void initMocks() { |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected HsOfficeMembershipEntityPatcher createPatcher(final HsOfficeMembershipEntity Membership) { |
| | | return new HsOfficeMembershipEntityPatcher(em, Membership); |
| | | protected HsOfficeMembershipEntityPatcher createPatcher(final HsOfficeMembershipEntity membership) { |
| | | return new HsOfficeMembershipEntityPatcher(em, mapper, membership); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assumptions.assumeThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeMembershipRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | import io.restassured.RestAssured; |
| | | import io.restassured.http.ContentType; |
| | | import net.hostsharing.test.Accepts; |
| | | import net.hostsharing.hsadminng.HsadminNgApplication; |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; |
| | | import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; |
| | | import net.hostsharing.test.Accepts; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | import org.json.JSONException; |
| | | import org.junit.jupiter.api.AfterEach; |
| | |
| | | .body(""" |
| | | { |
| | | "contactUuid": "%s", |
| | | "personUuid": "%s" |
| | | "personUuid": "%s", |
| | | "details": {} |
| | | } |
| | | """.formatted(givenContactUuid, givenPerson.getUuid())) |
| | | .port(port) |
| | | .when() |
| | | .post("http://localhost/api/hs/office/partners") |
| | | .then().log().all().assertThat() |
| | | .statusCode(404) |
| | | .body("message", is("cannot find contact uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); |
| | | .statusCode(400) |
| | | .body("message", is("Unable to find Contact with uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); |
| | | // @formatter:on |
| | | } |
| | | |
| | |
| | | { |
| | | "contactUuid": "%s", |
| | | "personUuid": "%s", |
| | | "registrationOffice": "Registergericht Hamburg", |
| | | "registrationNumber": "123456", |
| | | "birthName": null, |
| | | "birthday": null, |
| | | "dateOfDeath": null |
| | | "details": {} |
| | | } |
| | | """.formatted(givenContact.getUuid(), givenPersonUuid)) |
| | | .port(port) |
| | | .when() |
| | | .post("http://localhost/api/hs/office/partners") |
| | | .then().log().all().assertThat() |
| | | .statusCode(404) |
| | | .body("message", is("cannot find person uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); |
| | | .statusCode(400) |
| | | .body("message", is("Unable to find Person with uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); |
| | | // @formatter:on |
| | | } |
| | | } |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assumptions.assumeThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficePartnerRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; |
| | | import net.hostsharing.test.Array; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | import org.junit.jupiter.api.AfterEach; |
| | | import org.junit.jupiter.api.Nested; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.modelmapper.internal.bytebuddy.utility.RandomString; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | | import javax.persistence.EntityManager; |
| | |
| | | import static org.assertj.core.api.Assumptions.assumeThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficePersonRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | private HsOfficePersonEntity givenSomeTemporaryPerson(final String createdByUser) { |
| | | return givenSomeTemporaryPerson(createdByUser, () -> |
| | | hsOfficePerson("some temporary person #" + RandomString.make(12))); |
| | | hsOfficePerson("some temporary person #" + RandomStringUtils.random(12))); |
| | | } |
| | | |
| | | void exactlyThesePersonsAreReturned(final List<HsOfficePersonEntity> actualResult, final String... personLabels) { |
| | |
| | | package net.hostsharing.hsadminng.hs.office.relationship; |
| | | |
| | | import net.hostsharing.hsadminng.HsadminNgApplication; |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.context.ContextBasedTest; |
| | | import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeRelationshipRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assumptions.assumeThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { HsOfficeSepaMandateRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | |
| | | import static org.assertj.core.api.Assumptions.assumeThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { RbacGrantRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class RbacGrantRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | package net.hostsharing.hsadminng.rbac.rbacrole; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | import org.springframework.test.web.servlet.MockMvc; |
| | | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
| | | |
| | |
| | | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| | | |
| | | @WebMvcTest(RbacRoleController.class) |
| | | @Import(Mapper.class) |
| | | @RunWith(SpringRunner.class) |
| | | class RbacRoleControllerRestTest { |
| | | |
| | | @Autowired |
| | | MockMvc mockMvc; |
| | | |
| | | @MockBean |
| | | Context contextMock; |
| | | |
| | | @MockBean |
| | | RbacRoleRepository rbacRoleRepository; |
| | | |
| | |
| | | |
| | | // given |
| | | when(rbacRoleRepository.findAll()).thenReturn( |
| | | asList(hostmasterRole, customerXxxOwner, customerXxxAdmin)); |
| | | asList(hostmasterRole, customerXxxOwner, customerXxxAdmin)); |
| | | |
| | | // when |
| | | mockMvc.perform(MockMvcRequestBuilders |
| | | .get("/api/rbac/roles") |
| | | .header("current-user", "superuser-alex@hostsharing.net") |
| | | .accept(MediaType.APPLICATION_JSON)) |
| | | .get("/api/rbac/roles") |
| | | .header("current-user", "superuser-alex@hostsharing.net") |
| | | .accept(MediaType.APPLICATION_JSON)) |
| | | |
| | | // then |
| | | .andExpect(status().isOk()) |
| | | .andExpect(jsonPath("$", hasSize(3))) |
| | | .andExpect(jsonPath("$[0].roleName", is("global#global.admin"))) |
| | | .andExpect(jsonPath("$[1].roleName", is("test_customer#xxx.owner"))) |
| | | .andExpect(jsonPath("$[2].roleName", is("test_customer#xxx.admin"))) |
| | | .andExpect(jsonPath("$[2].uuid", is(customerXxxAdmin.getUuid().toString()))) |
| | | .andExpect(jsonPath("$[2].objectUuid", is(customerXxxAdmin.getObjectUuid().toString()))) |
| | | .andExpect(jsonPath("$[2].objectTable", is(customerXxxAdmin.getObjectTable().toString()))) |
| | | .andExpect(jsonPath("$[2].objectIdName", is(customerXxxAdmin.getObjectIdName().toString()))); |
| | | // then |
| | | .andExpect(status().isOk()) |
| | | .andExpect(jsonPath("$", hasSize(3))) |
| | | .andExpect(jsonPath("$[0].roleName", is("global#global.admin"))) |
| | | .andExpect(jsonPath("$[1].roleName", is("test_customer#xxx.owner"))) |
| | | .andExpect(jsonPath("$[2].roleName", is("test_customer#xxx.admin"))) |
| | | .andExpect(jsonPath("$[2].uuid", is(customerXxxAdmin.getUuid().toString()))) |
| | | .andExpect(jsonPath("$[2].objectUuid", is(customerXxxAdmin.getObjectUuid().toString()))) |
| | | .andExpect(jsonPath("$[2].objectTable", is(customerXxxAdmin.getObjectTable().toString()))) |
| | | .andExpect(jsonPath("$[2].objectIdName", is(customerXxxAdmin.getObjectIdName().toString()))); |
| | | } |
| | | } |
| | |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.test.Array; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | import org.junit.jupiter.api.Nested; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { Context.class, RbacRoleRepository.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class RbacRoleRepositoryIntegrationTest { |
| | | |
| | | @Autowired |
| | |
| | | package net.hostsharing.hsadminng.rbac.rbacuser; |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | import org.springframework.test.web.servlet.MockMvc; |
| | | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
| | | |
| | |
| | | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| | | |
| | | @WebMvcTest(RbacUserController.class) |
| | | @Import(Mapper.class) |
| | | @RunWith(SpringRunner.class) |
| | | class RbacUserControllerRestTest { |
| | | |
| | | @Autowired |
| | | MockMvc mockMvc; |
| | | |
| | | @MockBean |
| | | Context contextMock; |
| | | |
| | | @MockBean |
| | | RbacUserRepository rbacUserRepository; |
| | | |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.jpa.JpaSystemException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { RbacUserRepository.class, Context.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class RbacUserRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | import net.hostsharing.hsadminng.context.Context; |
| | | import net.hostsharing.hsadminng.context.ContextBasedTest; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | import org.junit.jupiter.api.Nested; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | | import javax.persistence.EntityManager; |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class TestCustomerRepositoryIntegrationTest extends ContextBasedTest { |
| | | |
| | | @Autowired |
| | |
| | | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| | | import org.springframework.boot.test.mock.mockito.MockBean; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.Import; |
| | | import org.springframework.orm.ObjectOptimisticLockingFailureException; |
| | | import org.springframework.test.annotation.DirtiesContext; |
| | | |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | @DataJpaTest |
| | | @ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class, JpaAttempt.class }) |
| | | @DirtiesContext |
| | | @Import( { Context.class, JpaAttempt.class }) |
| | | class TestPackageRepositoryIntegrationTest { |
| | | |
| | | @Autowired |
| | |
| | | import net.hostsharing.hsadminng.mapper.Mapper; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.util.List; |
| | | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | import static org.junit.jupiter.api.Assertions.*; |
| | | import static org.junit.jupiter.api.Assertions.fail; |
| | | |
| | | class MapperUnitTest { |
| | | |
| | | private Mapper mapper = new Mapper(); |
| | | |
| | | @Getter |
| | | @Setter |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public static class SourceBean { |
| | | |
| | | private String a; |
| | | private String b; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public static class TargetBean { |
| | | |
| | | private String a; |
| | | private String b; |
| | | private String c; |
| | |
| | | @Test |
| | | void mapsNullBeanToNull() { |
| | | final SourceBean givenSource = null; |
| | | final var result = Mapper.map(givenSource, TargetBean.class, (s, t) -> { fail("should not have been called"); }); |
| | | final var result = mapper.map(givenSource, TargetBean.class, (s, t) -> {fail("should not have been called");}); |
| | | assertThat(result).isNull(); |
| | | } |
| | | |
| | | @Test |
| | | void mapsBean() { |
| | | final SourceBean givenSource = new SourceBean("1234", "Text"); |
| | | final var result = Mapper.map(givenSource, TargetBean.class, null); |
| | | final var result = mapper.map(givenSource, TargetBean.class); |
| | | assertThat(result).usingRecursiveComparison().isEqualTo( |
| | | new TargetBean("1234", "Text", null) |
| | | ); |
| | |
| | | @Test |
| | | void mapsBeanWithPostmapper() { |
| | | final SourceBean givenSource = new SourceBean("1234", "Text"); |
| | | final var result = Mapper.map(givenSource, TargetBean.class, (s, t) -> { t.setC("Extra"); }); |
| | | final var result = mapper.map(givenSource, TargetBean.class, (s, t) -> {t.setC("Extra");}); |
| | | assertThat(result).usingRecursiveComparison().isEqualTo( |
| | | new TargetBean("1234", "Text", "Extra") |
| | | ); |
| | | } |
| | | |
| | | @Test |
| | | void mapsList() { |
| | | final var givenSource = List.of( |
| | | new SourceBean("111", "Text A"), |
| | | new SourceBean("222", "Text B"), |
| | | new SourceBean("333", "Text C")); |
| | | final var result = mapper.mapList(givenSource, TargetBean.class); |
| | | assertThat(result).usingRecursiveComparison().isEqualTo( |
| | | List.of( |
| | | new TargetBean("111", "Text A", null), |
| | | new TargetBean("222", "Text B", null), |
| | | new TargetBean("333", "Text C", null))); |
| | | } |
| | | |
| | | @Test |
| | | void mapsListWithPostMapper() { |
| | | final var givenSource = List.of( |
| | | new SourceBean("111", "Text A"), |
| | | new SourceBean("222", "Text B"), |
| | | new SourceBean("333", "Text C")); |
| | | final var result = mapper.mapList(givenSource, TargetBean.class, (s, t) -> {t.setC("Extra");}); |
| | | assertThat(result).usingRecursiveComparison().isEqualTo( |
| | | List.of( |
| | | new TargetBean("111", "Text A", "Extra"), |
| | | new TargetBean("222", "Text B", "Extra"), |
| | | new TargetBean("333", "Text C", "Extra"))); |
| | | } |
| | | |
| | | } |