diff --git a/backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java b/backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java new file mode 100644 index 00000000..61e26802 --- /dev/null +++ b/backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java @@ -0,0 +1,35 @@ +package app.hopps.org.delegates; + +import app.hopps.org.jpa.*; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; +import jakarta.validation.Valid; + +@ApplicationScoped +public class PersistOrganizationDelegate { + + @Inject + OrganizationRepository organizationRepository; + + @Inject + MemberRespository memberRepository; + + @Inject + BommelRepository bommelRepository; + + @Transactional + public void persistOrg(@Valid Organization organization, @Valid Member owner) { + memberRepository.persist(owner); + organizationRepository.persist(organization); + + Bommel rootBommel = new Bommel(); + rootBommel.setName(organization.getName()); + rootBommel.setParent(null); + rootBommel.setOrganization(organization); + rootBommel.setEmoji(Bommel.DEFAULT_ROOT_BOMMEL_EMOJI); + rootBommel.setResponsibleMember(owner); + + bommelRepository.persist(rootBommel); + } +} diff --git a/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java b/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java index a0ac3930..a1980b3c 100644 --- a/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java +++ b/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java @@ -55,6 +55,7 @@ with children_query as ( """) }) public class Bommel extends PanacheEntity { + public static final String DEFAULT_ROOT_BOMMEL_EMOJI="\uD83C\uDF33"; // tree private String name; private String emoji; diff --git a/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn b/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn index 7c3ab83c..78d49da2 100644 --- a/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn +++ b/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn @@ -1,5 +1,5 @@ - + @@ -10,6 +10,8 @@ + + @@ -18,6 +20,7 @@ + @@ -36,8 +39,8 @@ - - + + _7990A710-11AA-44F2-888D-D2FE3B907C70_InMessage _7990A710-11AA-44F2-888D-D2FE3B907C70_OutMessage @@ -66,9 +69,8 @@ _DB0D419F-AB1A-46FD-8093-CD25A927EAA0_OutMessage - - - + + @@ -90,10 +92,10 @@ - + @@ -101,12 +103,12 @@ - + _A7B5AA79-B3CC-4999-9489-46EBA6AF990B @@ -168,10 +170,10 @@ _574498AF-2A70-4024-A4B4-2ECA6360F02D - _F6C8F584-EA6B-4026-839F-67DAFA0877E3 _C7D729AB-0DE5-40BA-8ED0-C2649EBCF884 + _F6C8F584-EA6B-4026-839F-67DAFA0877E3 - + @@ -179,6 +181,22 @@ _0D059BE3-7B64-436C-8931-5C673605C578 _574498AF-2A70-4024-A4B4-2ECA6360F02D + + + + + _7990A710-11AA-44F2-888D-D2FE3B907C70_organizationInputX + _7990A710-11AA-44F2-888D-D2FE3B907C70_ownerInputX + + + + organization + _7990A710-11AA-44F2-888D-D2FE3B907C70_organizationInputX + + + owner + _7990A710-11AA-44F2-888D-D2FE3B907C70_ownerInputX + @@ -229,6 +247,9 @@ + + + @@ -259,12 +280,14 @@ - - - + + + + + @@ -285,15 +308,15 @@ - - - - + + + + @@ -307,11 +330,6 @@ - - - - - @@ -449,7 +467,7 @@ - _SxOV0FA6ED2c8Z-Bgliozg - _SxOV0FA6ED2c8Z-Bgliozg + _xSRJIJe-ED2ocIyyHiENHw + _xSRJIJe-ED2ocIyyHiENHw \ No newline at end of file diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java index b1ddfbf6..2cf9d906 100644 --- a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java @@ -11,6 +11,7 @@ import jakarta.inject.Inject; import jakarta.transaction.Transactional; import jakarta.validation.ConstraintViolationException; +import org.flywaydb.core.Flyway; import org.hamcrest.core.IsInstanceOf; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -23,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @QuarkusTest -public class CreationValidationDelegateTests { +class CreationValidationDelegateTests { @Inject CreationValidationDelegate delegate; @@ -32,13 +33,12 @@ public class CreationValidationDelegateTests { OrganizationRepository organizationRepository; @Inject - MemberRespository memberRespository; + Flyway flyway; @BeforeEach - @Transactional - void setUp() { - organizationRepository.deleteAll(); - memberRespository.deleteAll(); + public void cleanDatabase() { + flyway.clean(); + flyway.migrate(); } @Test diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java new file mode 100644 index 00000000..14ec46ab --- /dev/null +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java @@ -0,0 +1,62 @@ +package app.hopps.org.delegates; + +import app.hopps.org.jpa.*; +import io.quarkus.test.junit.QuarkusTest; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; + +@QuarkusTest +class PersistOrganizationDelegateTests { + + @Inject + PersistOrganizationDelegate persistOrganizationDelegate; + + @Inject + BommelRepository bommelRepository; + + @Inject + OrganizationRepository organizationRepository; + + @Inject + MemberRespository memberRepository; + + @BeforeEach + @Transactional + void cleanupDB() + { + bommelRepository.deleteAll(); + organizationRepository.deleteAll(); + memberRepository.deleteAll(); + } + + @Test + void shouldCreateRootBommel() + { + // given + Organization kegelclub = new Organization(); + kegelclub.setName("Kegelklub 777"); + kegelclub.setType(Organization.TYPE.EINGETRAGENER_VEREIN); + kegelclub.setSlug("kegelklub-777"); + + Member kevin = new Member(); + kevin.setFirstName("Kevin"); + kevin.setLastName("Kegelkönig"); + kevin.setEmail("pinking777@gmail.com"); + + // when + persistOrganizationDelegate.persistOrg(kegelclub, kevin); + + // then + assertThat(organizationRepository.listAll(), iterableWithSize(1)); + assertThat(bommelRepository.listAll(), iterableWithSize(1)); + assertThat(bommelRepository.listAll(), hasItem(hasProperty("emoji", equalTo("\uD83C\uDF33")))); + } +} diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java b/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java index 8e0bd9ac..0796b7e5 100644 --- a/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java @@ -7,6 +7,7 @@ import jakarta.inject.Inject; import jakarta.transaction.Transactional; import jakarta.ws.rs.WebApplicationException; +import org.flywaydb.core.Flyway; import org.hamcrest.Matchers; import org.hamcrest.collection.IsIterableWithSize; import org.instancio.Instancio; @@ -36,11 +37,13 @@ class BommelTest { @Inject BommelTestResourceCreator resourceCreator; + @Inject + Flyway flyway; + @BeforeEach - @Transactional - void clearDatabase() { - orgRepo.deleteAll(); - repo.deleteAll(); + public void cleanDatabase() { + flyway.clean(); + flyway.migrate(); } @Test