From 291cb9f255241d150ea271b94cae12cd139ca770 Mon Sep 17 00:00:00 2001 From: Michael Schnell Date: Mon, 30 Dec 2019 18:49:39 +0100 Subject: [PATCH] Refactored module structure --- aggregates/pom.xml | 2 +- java-se-cdi/pom.xml | 8 +- .../javasecdi/cmd/app/CmdExampleApp.java | 6 +- .../cmd/domain/PersonRepositoryFactory.java | 4 +- quarkus/command/pom.xml | 45 ++-- .../quarkus/command/api/PersonResource.java | 11 +- .../command/app/EventStoreFactory.java | 64 ----- .../domain/DuplicatePersonNameException.java | 63 ----- .../quarkus/command/domain/Person.java | 116 -------- .../command/domain/PersonRepository.java | 63 ----- .../domain/PersonRepositoryFactory.java | 5 +- .../quarkus/command/api/PersonResourceIT.java | 21 +- quarkus/query/pom.xml | 41 ++- ...onResource.java => QryPersonResource.java} | 8 +- .../example/quarkus/query/app/QryConfig.java | 148 ----------- .../quarkus/query/app/QryJsonbFactory.java | 44 --- .../QrySerDeserializerRegistryFactory.java | 47 ---- .../common/ProjectionPosition.java} | 8 +- .../common/ProjectionPositionRepository.java} | 12 +- .../{handler => views}/package-info.java | 5 +- .../PersonCreatedEventHandler.java | 11 +- .../personlist/PersonListEntry.java} | 22 +- .../PersonListEventChunkHandler.java} | 6 +- .../PersonListEventDispatcherFactory.java} | 4 +- .../personlist/PersonListProjector.java} | 20 +- .../personlist}/package-info.java | 4 +- ...sourceIT.java => QryPersonResourceIT.java} | 26 +- quarkus/shared/pom.xml | 251 ++++++++++-------- .../example/quarkus/shared}/Config.java | 2 +- .../quarkus/shared/CreatePersonCommand.java | 88 ------ .../shared}/EsjcEventStoreFactory.java | 2 +- .../quarkus/shared/EventStoreFactory.java} | 48 +++- .../example/quarkus/shared}/JsonbFactory.java | 7 +- .../quarkus/shared/PersonCreatedEvent.java | 87 ------ .../example/quarkus/shared/PersonId.java | 148 ----------- .../example/quarkus/shared/PersonName.java | 216 --------------- .../SerDeserializerRegistryFactory.java | 8 +- .../quarkus/shared/SharedEntityIdFactory.java | 70 ----- .../example/quarkus/shared/SharedUtils.java | 189 ------------- .../example/quarkus/shared/package-info.java | 2 +- .../shared/CreatePersonCommandTest.java | 108 -------- .../shared/PersonCreatedEventTest.java | 108 -------- .../example/quarkus/shared/PersonIdTest.java | 91 ------- .../quarkus/shared/PersonNameTest.java | 134 ---------- shared/pom.xml | 8 +- 45 files changed, 329 insertions(+), 2052 deletions(-) delete mode 100644 quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EventStoreFactory.java delete mode 100644 quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/DuplicatePersonNameException.java delete mode 100644 quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/Person.java delete mode 100644 quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepository.java rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/{PersonResource.java => QryPersonResource.java} (84%) delete mode 100644 quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryConfig.java delete mode 100644 quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryJsonbFactory.java delete mode 100644 quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QrySerDeserializerRegistryFactory.java rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler/QryPersonProjectionPosition.java => views/common/ProjectionPosition.java} (91%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler/QryPersonProjectionPositionRepository.java => views/common/ProjectionPositionRepository.java} (78%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler => views}/package-info.java (70%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler => views/personlist}/PersonCreatedEventHandler.java (81%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{domain/QryPerson.java => views/personlist/PersonListEntry.java} (82%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler/QryEventChunkHandler.java => views/personlist/PersonListEventChunkHandler.java} (91%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler/QryEventDispatcherFactory.java => views/personlist/PersonListEventDispatcherFactory.java} (91%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{handler/QryProjector.java => views/personlist/PersonListProjector.java} (85%) rename quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/{domain => views/personlist}/package-info.java (85%) rename quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/{PersonResourceIT.java => QryPersonResourceIT.java} (80%) rename quarkus/{command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app => shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared}/Config.java (98%) delete mode 100644 quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommand.java rename quarkus/{command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app => shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared}/EsjcEventStoreFactory.java (96%) rename quarkus/{query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryEventStoreFactory.java => shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EventStoreFactory.java} (64%) rename quarkus/{command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app => shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared}/JsonbFactory.java (88%) delete mode 100644 quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEvent.java delete mode 100644 quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonId.java delete mode 100644 quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonName.java rename quarkus/{command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app => shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared}/SerDeserializerRegistryFactory.java (86%) delete mode 100644 quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedEntityIdFactory.java delete mode 100644 quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedUtils.java delete mode 100644 quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommandTest.java delete mode 100644 quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEventTest.java delete mode 100644 quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonIdTest.java delete mode 100644 quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonNameTest.java diff --git a/aggregates/pom.xml b/aggregates/pom.xml index ce6b96a..bcc2527 100644 --- a/aggregates/pom.xml +++ b/aggregates/pom.xml @@ -15,7 +15,7 @@ 1.8 1.8 1.8 - 0.3.1-SNAPSHOT + 0.3.1 diff --git a/java-se-cdi/pom.xml b/java-se-cdi/pom.xml index e46ffb7..7f45b76 100644 --- a/java-se-cdi/pom.xml +++ b/java-se-cdi/pom.xml @@ -31,7 +31,7 @@ UTF-8 1.8 1.8 - 0.3.1-SNAPSHOT + 0.3.1 @@ -63,13 +63,13 @@ org.fuin ddd-4-java - 0.2.1-SNAPSHOT + 0.2.1 org.fuin cqrs-4-java - 0.2.1-SNAPSHOT + 0.2.1 @@ -250,7 +250,7 @@ org.fuin units4j - 0.8.3 + 0.8.4 test diff --git a/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/app/CmdExampleApp.java b/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/app/CmdExampleApp.java index 9268acc..64e1df3 100644 --- a/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/app/CmdExampleApp.java +++ b/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/app/CmdExampleApp.java @@ -25,7 +25,7 @@ import org.fuin.cqrs4j.example.javasecdi.cmd.domain.PersonRepository; import org.fuin.cqrs4j.example.javasecdi.cmd.domain.PersonRepositoryFactory; import org.fuin.cqrs4j.example.shared.PersonId; import org.fuin.cqrs4j.example.shared.PersonName; -import org.fuin.esc.api.EventStore; +import org.fuin.esc.esjc.IESJCEventStore; import org.fuin.ext4logback.LogbackStandalone; import org.fuin.ext4logback.NewLogConfigFileParams; import org.slf4j.Logger; @@ -39,7 +39,7 @@ public class CmdExampleApp { private static final Logger LOG = LoggerFactory.getLogger(CmdExampleApp.class); @Inject - private Instance eventStoreInstance; + private Instance eventStoreInstance; /** * Executes the application. @@ -49,7 +49,7 @@ public class CmdExampleApp { LOG.info("Executing..."); - try (final EventStore eventStore = eventStoreInstance.get()) { + try (final IESJCEventStore eventStore = eventStoreInstance.get()) { final PersonId id = new PersonId(UUID.fromString("f645969a-402d-41a9-882b-d2d8000d0f43")); final PersonName name = new PersonName("Peter Parker Inc."); diff --git a/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/domain/PersonRepositoryFactory.java b/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/domain/PersonRepositoryFactory.java index 7862552..6aef48b 100644 --- a/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/domain/PersonRepositoryFactory.java +++ b/java-se-cdi/src/main/java/org/fuin/cqrs4j/example/javasecdi/cmd/domain/PersonRepositoryFactory.java @@ -4,7 +4,7 @@ import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.Dependent; import javax.enterprise.inject.Produces; -import org.fuin.esc.api.EventStore; +import org.fuin.esc.esjc.IESJCEventStore; /** * CDI factory that creates an event store connection and repositories. @@ -22,7 +22,7 @@ public class PersonRepositoryFactory { */ @Produces @Dependent - public PersonRepository create(final EventStore eventStore) { + public PersonRepository create(final IESJCEventStore eventStore) { return new PersonRepository(eventStore); } diff --git a/quarkus/command/pom.xml b/quarkus/command/pom.xml index 1e1a253..54f1fdb 100644 --- a/quarkus/command/pom.xml +++ b/quarkus/command/pom.xml @@ -11,19 +11,12 @@ 1.0-SNAPSHOT - 3.8.1 true 1.8 1.8 UTF-8 UTF-8 - 1.0.1.Final - quarkus-universe-bom - io.quarkus - 1.0.1.Final - 2.22.1 - 2.22.2 - 0.3.1-SNAPSHOT + 0.3.1 @@ -31,9 +24,9 @@ - ${quarkus.platform.group-id} - ${quarkus.platform.artifact-id} - ${quarkus.platform.version} + io.quarkus + quarkus-universe-bom + 1.0.1.Final pom import @@ -81,28 +74,34 @@ quarkus-mailer + + org.fuin.cqrs4j.example + cqrs4j-example-aggregates + 0.1.0-SNAPSHOT + + org.fuin.cqrs4j.example.quarkus cqrs4j-quarkus-example-shared 0.1.0-SNAPSHOT - - - logback-classic - ch.qos.logback - - org.fuin.esc esc-esjc ${esc.version} + + + ch.qos.logback + logback-classic + + org.fuin cqrs-4-java - 0.2.1-SNAPSHOT + 0.2.1 @@ -134,7 +133,7 @@ io.quarkus quarkus-maven-plugin - ${quarkus-plugin.version} + 1.0.1.Final @@ -146,12 +145,12 @@ maven-compiler-plugin - ${compiler-plugin.version} + 3.8.1 maven-surefire-plugin - ${surefire-plugin.version} + 2.22.1 org.jboss.logmanager.LogManager @@ -161,7 +160,7 @@ maven-failsafe-plugin - ${failsafe-plugin.version} + 2.22.2 @@ -241,7 +240,7 @@ - + diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResource.java b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResource.java index 5ebbf03..b076a66 100644 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResource.java +++ b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResource.java @@ -12,6 +12,7 @@ */ package org.fuin.cqrs4j.example.quarkus.command.api; +import java.util.Optional; import java.util.Set; import javax.inject.Inject; @@ -29,10 +30,10 @@ import javax.ws.rs.core.UriInfo; import org.fuin.cqrs4j.CommandExecutionFailedException; import org.fuin.cqrs4j.SimpleResult; -import org.fuin.cqrs4j.example.quarkus.command.domain.DuplicatePersonNameException; -import org.fuin.cqrs4j.example.quarkus.command.domain.Person; -import org.fuin.cqrs4j.example.quarkus.command.domain.PersonRepository; -import org.fuin.cqrs4j.example.quarkus.shared.CreatePersonCommand; +import org.fuin.cqrs4j.example.aggregates.DuplicatePersonNameException; +import org.fuin.cqrs4j.example.aggregates.Person; +import org.fuin.cqrs4j.example.aggregates.PersonRepository; +import org.fuin.cqrs4j.example.shared.CreatePersonCommand; import org.fuin.ddd4j.ddd.AggregateAlreadyExistsException; import org.fuin.ddd4j.ddd.AggregateDeletedException; @@ -65,7 +66,7 @@ public class PersonResource { // Create aggregate final Person person = new Person(cmd.getAggregateRootId(), cmd.getName(), (name) -> { // TODO Execute a call to the query side to verify if the name already exists - return null; + return Optional.empty(); }); repo.add(person); diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EventStoreFactory.java b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EventStoreFactory.java deleted file mode 100644 index 591c1b7..0000000 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EventStoreFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.command.app; - -import java.nio.charset.Charset; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.inject.Disposes; -import javax.enterprise.inject.Produces; - -import org.fuin.esc.api.EventStore; -import org.fuin.esc.esjc.ESJCEventStore; -import org.fuin.esc.spi.EnhancedMimeType; -import org.fuin.esc.spi.SerDeserializerRegistry; - -/** - * CDI factory that creates an event store connection and repositories. - */ -@ApplicationScoped -public class EventStoreFactory { - - /** - * Creates an event store.
- *
- * CAUTION: The returned event store instance is NOT thread safe. - * - * @param es Native event store API. - * @param registry Serialization registry. - * - * @return Dependent scope event store. - */ - @Produces - @RequestScoped - public EventStore createEventStore(final com.github.msemys.esjc.EventStore es, - final SerDeserializerRegistry registry) { - - final EventStore eventstore = new ESJCEventStore(es, registry, registry, - EnhancedMimeType.create("application", "json", Charset.forName("utf-8"))); - eventstore.open(); - return eventstore; - - } - - /** - * Closes the event store when the context is disposed. - * - * @param es Event store to close. - */ - public void closeEventStore(@Disposes final EventStore es) { - es.close(); - } - -} diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/DuplicatePersonNameException.java b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/DuplicatePersonNameException.java deleted file mode 100644 index 47eb0b4..0000000 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/DuplicatePersonNameException.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.command.domain; - -import javax.validation.constraints.NotNull; - -import org.fuin.cqrs4j.example.quarkus.shared.PersonId; -import org.fuin.cqrs4j.example.quarkus.shared.PersonName; - -/** - * A name that should be unique does already exist. - */ -public final class DuplicatePersonNameException extends Exception { - - private static final long serialVersionUID = 1000L; - - private PersonId personId; - - private PersonName name; - - /** - * Constructor with mandatory data. - * - * @param personId - * Identifier of the resource that caused the problem. - * @param name - * Name of the resource that caused the problem. - */ - public DuplicatePersonNameException(@NotNull final PersonId personId, @NotNull final PersonName name) { - super("The name '" + name + "' already exists: " + personId.asString()); - this.personId = personId; - this.name = name; - } - - /** - * Returns the identifier of the entity that has the name. - * - * @return Identifier. - */ - public final PersonId getPersonId() { - return personId; - } - - /** - * Returns the name that already exists. - * - * @return Name. - */ - public final PersonName getName() { - return name; - } - -} \ No newline at end of file diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/Person.java b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/Person.java deleted file mode 100644 index a7a8846..0000000 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/Person.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.command.domain; - -import java.io.Serializable; - -import javax.validation.constraints.NotNull; - -import org.fuin.cqrs4j.example.quarkus.shared.PersonCreatedEvent; -import org.fuin.cqrs4j.example.quarkus.shared.PersonId; -import org.fuin.cqrs4j.example.quarkus.shared.PersonName; -import org.fuin.ddd4j.ddd.AbstractAggregateRoot; -import org.fuin.ddd4j.ddd.ApplyEvent; -import org.fuin.ddd4j.ddd.EntityType; -import org.fuin.objects4j.common.Contract; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -/** - * A medical practitioner most likely also holder of an accredited academic degree. - */ -@RegisterForReflection -public class Person extends AbstractAggregateRoot implements Serializable { - - private static final long serialVersionUID = 1000L; - - @NotNull - private PersonId id; - - @NotNull - private PersonName name; - - /** - * Default constructor that is mandatory for aggregate roots. - */ - public Person() { - super(); - } - - /** - * Constructor with all data. - * - * @param id - * Unique identifier of the person. - * @param name - * Unique name of the person. - * @param service - * Service required by the method. - * - * @throws DuplicatePersonNameException - * The name already exists for another person. - */ - public Person(@NotNull final PersonId id, @NotNull final PersonName name, final PersonService service) throws DuplicatePersonNameException { - super(); - - // VERIFY PRECONDITIONS - Contract.requireArgNotNull("id", id); - Contract.requireArgNotNull("name", name); - - // VERIFY BUSINESS RULES - - // Rule 1: The name of the person must be unique - final PersonId otherId = service.loadPersonIdByName(name); - if (otherId != null) { - throw new DuplicatePersonNameException(otherId, name); - } - - // CREATE EVENT - apply(new PersonCreatedEvent(id, name)); - - } - - @Override - public PersonId getId() { - return id; - } - - @Override - public EntityType getType() { - return PersonId.TYPE; - } - - @ApplyEvent - public void applyEvent(final PersonCreatedEvent event) { - this.id = event.getEntityId(); - this.name = event.getName(); - } - - /** - * Service for the constructor. - */ - public static interface PersonService { - - /** - * Loads the person's identifier for a given name. - * - * @param name - * Person's name. - * - * @return Office identifier or {@literal null} if not found. - */ - public PersonId loadPersonIdByName(@NotNull PersonName name); - - } - -} diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepository.java b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepository.java deleted file mode 100644 index c7a9d53..0000000 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepository.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.command.domain; - -import javax.annotation.concurrent.NotThreadSafe; -import javax.validation.constraints.NotNull; - -import org.fuin.cqrs4j.example.quarkus.shared.PersonId; -import org.fuin.ddd4j.ddd.EntityType; -import org.fuin.ddd4j.esrepo.EventStoreRepository; -import org.fuin.esc.api.EventStore; - -/** - * Event sourced repository for storing a {@link Person} aggregate. - */ -@NotThreadSafe -public class PersonRepository extends EventStoreRepository { - - /** - * Constructor all mandatory data. - * - * @param eventStore - * Event store. - */ - public PersonRepository(final EventStore eventStore) { - super(eventStore); - } - - @Override - @NotNull - public Class getAggregateClass() { - return Person.class; - } - - @Override - @NotNull - public EntityType getAggregateType() { - return PersonId.TYPE; - } - - @Override - @NotNull - public Person create() { - return new Person(); - } - - @Override - @NotNull - public String getIdParamName() { - return "personId"; - } - -} \ No newline at end of file diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepositoryFactory.java b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepositoryFactory.java index 4d7eb7f..028b666 100644 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepositoryFactory.java +++ b/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/domain/PersonRepositoryFactory.java @@ -16,7 +16,8 @@ import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.Dependent; import javax.enterprise.inject.Produces; -import org.fuin.esc.api.EventStore; +import org.fuin.cqrs4j.example.aggregates.PersonRepository; +import org.fuin.esc.esjc.IESJCEventStore; /** * CDI factory that creates an event store connection and repositories. @@ -34,7 +35,7 @@ public class PersonRepositoryFactory { */ @Produces @Dependent - public PersonRepository create(final EventStore eventStore) { + public PersonRepository create(final IESJCEventStore eventStore) { return new PersonRepository(eventStore); } diff --git a/quarkus/command/src/test/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResourceIT.java b/quarkus/command/src/test/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResourceIT.java index 22a8c5c..8a1e935 100644 --- a/quarkus/command/src/test/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResourceIT.java +++ b/quarkus/command/src/test/java/org/fuin/cqrs4j/example/quarkus/command/api/PersonResourceIT.java @@ -1,10 +1,5 @@ package org.fuin.cqrs4j.example.quarkus.command.api; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; - -import org.junit.jupiter.api.Test; - import static io.restassured.RestAssured.given; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; @@ -21,21 +16,25 @@ import javax.json.bind.Jsonb; import org.fuin.cqrs4j.ResultType; import org.fuin.cqrs4j.SimpleResult; -import org.fuin.cqrs4j.example.quarkus.shared.CreatePersonCommand; -import org.fuin.cqrs4j.example.quarkus.shared.PersonCreatedEvent; -import org.fuin.cqrs4j.example.quarkus.shared.PersonId; -import org.fuin.cqrs4j.example.quarkus.shared.PersonName; +import org.fuin.cqrs4j.example.shared.CreatePersonCommand; +import org.fuin.cqrs4j.example.shared.PersonCreatedEvent; +import org.fuin.cqrs4j.example.shared.PersonId; +import org.fuin.cqrs4j.example.shared.PersonName; import org.fuin.esc.api.CommonEvent; -import org.fuin.esc.api.EventStore; import org.fuin.esc.api.SimpleStreamId; import org.fuin.esc.api.StreamEventsSlice; import org.fuin.esc.api.TypeName; +import org.fuin.esc.esjc.IESJCEventStore; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; @QuarkusTest public class PersonResourceIT { @Inject - EventStore eventStore; + IESJCEventStore eventStore; @Inject Jsonb jsonb; diff --git a/quarkus/query/pom.xml b/quarkus/query/pom.xml index 9afaf9e..99e6f52 100644 --- a/quarkus/query/pom.xml +++ b/quarkus/query/pom.xml @@ -11,19 +11,12 @@ 1.0-SNAPSHOT - 3.8.1 - 0.3.1-SNAPSHOT true 1.8 1.8 UTF-8 UTF-8 - 1.0.1.Final - quarkus-universe-bom - io.quarkus - 1.0.1.Final - 2.22.1 - 2.22.2 + 0.3.1 @@ -31,9 +24,9 @@ - ${quarkus.platform.group-id} - ${quarkus.platform.artifact-id} - ${quarkus.platform.version} + io.quarkus + quarkus-universe-bom + 1.0.1.Final pom import @@ -83,22 +76,28 @@ jakarta.security.jacc-api
+ + org.fuin.cqrs4j.example + cqrs4j-example-aggregates + 0.1.0-SNAPSHOT + + org.fuin.cqrs4j.example.quarkus cqrs4j-quarkus-example-shared 0.1.0-SNAPSHOT - - - logback-classic - ch.qos.logback - - org.fuin.esc esc-eshttp ${esc.version} + + + ch.qos.logback + logback-classic + + @@ -130,7 +129,7 @@ io.quarkus quarkus-maven-plugin - ${quarkus-plugin.version} + 1.0.1.Final @@ -142,12 +141,12 @@ maven-compiler-plugin - ${compiler-plugin.version} + 3.8.1 maven-surefire-plugin - ${surefire-plugin.version} + 2.22.1 org.jboss.logmanager.LogManager @@ -157,7 +156,7 @@ maven-failsafe-plugin - ${failsafe-plugin.version} + 2.22.2 diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/PersonResource.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResource.java similarity index 84% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/PersonResource.java rename to quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResource.java index 31694ef..23b8c67 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/PersonResource.java +++ b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResource.java @@ -23,11 +23,11 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.fuin.cqrs4j.example.quarkus.query.domain.QryPerson; +import org.fuin.cqrs4j.example.quarkus.query.views.personlist.PersonListEntry; import org.fuin.objects4j.vo.UUIDStrValidator; @Path("/persons") -public class PersonResource { +public class QryPersonResource { @Inject EntityManager em; @@ -35,7 +35,7 @@ public class PersonResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAll() { - final List persons = em.createNamedQuery(QryPerson.FIND_ALL, QryPerson.class).getResultList(); + final List persons = em.createNamedQuery(PersonListEntry.FIND_ALL, PersonListEntry.class).getResultList(); return Response.ok(persons).build(); } @@ -46,7 +46,7 @@ public class PersonResource { if (!UUIDStrValidator.isValid(id)) { return Response.status(Response.Status.BAD_REQUEST).entity("Invalid Person UUID").build(); } - final QryPerson person = em.find(QryPerson.class, id); + final PersonListEntry person = em.find(PersonListEntry.class, id); if (person == null) { return Response.status(Response.Status.NOT_FOUND).build(); } diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryConfig.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryConfig.java deleted file mode 100644 index 72e59a0..0000000 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryConfig.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.query.app; - -import java.net.MalformedURLException; -import java.net.URL; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; - -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * Application configuration. - */ -@ApplicationScoped -public class QryConfig { - - private static final String EVENT_STORE_HOST = "127.0.0.1"; - - private static final int EVENT_STORE_HTTP_PORT = 2113; - - private static final int EVENT_STORE_TCP_PORT = 1113; - - private static final String EVENT_STORE_USER = "admin"; - - private static final String EVENT_STORE_PASSWORD = "changeit"; - - @Inject - @ConfigProperty(name = "EVENT_STORE_HOST", defaultValue = EVENT_STORE_HOST) - String eventStoreHost; - - @Inject - @ConfigProperty(name = "EVENT_STORE_HTTP_PORT", defaultValue = "" + EVENT_STORE_HTTP_PORT) - int eventStoreHttpPort; - - @Inject - @ConfigProperty(name = "EVENT_STORE_TCP_PORT", defaultValue = "" + EVENT_STORE_TCP_PORT) - int eventStoreTcpPort; - - @Inject - @ConfigProperty(name = "EVENT_STORE_USER", defaultValue = EVENT_STORE_USER) - String eventStoreUser; - - @Inject - @ConfigProperty(name = "EVENT_STORE_PASSWORD", defaultValue = EVENT_STORE_PASSWORD) - String eventStorePassword; - - /** - * Constructor using default values internally. - */ - public QryConfig() { - super(); - this.eventStoreHost = EVENT_STORE_HOST; - this.eventStoreHttpPort = EVENT_STORE_HTTP_PORT; - this.eventStoreTcpPort = EVENT_STORE_TCP_PORT; - this.eventStoreUser = EVENT_STORE_USER; - this.eventStorePassword = EVENT_STORE_PASSWORD; - } - - /** - * Constructor with all data. - * - * @param eventStoreHost Host. - * @param eventStoreHttpPort HTTP port - * @param eventStoreTcpPort TCP port. - * @param eventStoreUser User. - * @param eventStorePassword Password. - */ - public QryConfig(final String eventStoreHost, final int eventStoreHttpPort, final int eventStoreTcpPort, - final String eventStoreUser, final String eventStorePassword) { - super(); - this.eventStoreHost = eventStoreHost; - this.eventStoreHttpPort = eventStoreHttpPort; - this.eventStoreTcpPort = eventStoreTcpPort; - this.eventStoreUser = eventStoreUser; - this.eventStorePassword = eventStorePassword; - } - - /** - * Returns the host name of the event store. - * - * @return Name. - */ - public String getEventStoreHost() { - return eventStoreHost; - } - - /** - * Returns the HTTP port of the event store. - * - * @return Port. - */ - public int getEventStoreHttpPort() { - return eventStoreHttpPort; - } - - /** - * Returns the TCP port of the event store. - * - * @return Port. - */ - public int getEventStoreTcpPort() { - return eventStoreTcpPort; - } - - /** - * Returns the username of the event store. - * - * @return Username. - */ - public String getEventStoreUser() { - return eventStoreUser; - } - - /** - * Returns the password of the event store. - * - * @return Password. - */ - public String getEventStorePassword() { - return eventStorePassword; - } - - /** - * Creates a URL with parameters from the config. - * - * @return Event store base URL. - */ - public URL getEventStoreURL() { - try { - return new URL("http", eventStoreHost, eventStoreHttpPort, "/"); - } catch (final MalformedURLException ex) { - throw new RuntimeException("Failed to create event store URL", ex); - } - } - -} \ No newline at end of file diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryJsonbFactory.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryJsonbFactory.java deleted file mode 100644 index d305ced..0000000 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryJsonbFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.query.app; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Produces; -import javax.json.bind.Jsonb; -import javax.json.bind.JsonbBuilder; -import javax.json.bind.JsonbConfig; - -import org.eclipse.yasson.FieldAccessStrategy; -import org.fuin.cqrs4j.example.quarkus.shared.SharedUtils; - -/** - * CDI factory that creates a JSON-B instance. - */ -@ApplicationScoped -public class QryJsonbFactory { - - /** - * Creates a JSON-B instance. - * - * @return Fully configured instance. - */ - @Produces - public Jsonb createJsonb() { - final JsonbConfig config = new JsonbConfig() - .withAdapters(SharedUtils.JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - return jsonb; - } - -} diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QrySerDeserializerRegistryFactory.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QrySerDeserializerRegistryFactory.java deleted file mode 100644 index aa507cf..0000000 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QrySerDeserializerRegistryFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see - * http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.query.app; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Produces; - -import org.fuin.cqrs4j.example.quarkus.shared.SharedUtils; -import org.fuin.esc.spi.JsonbDeSerializer; -import org.fuin.esc.spi.SerDeserializerRegistry; -import org.fuin.esc.spi.SerializedDataTypeRegistry; - -/** - * CDI bean that creates a {@link SerDeserializerRegistry}. - */ -@ApplicationScoped -public class QrySerDeserializerRegistryFactory { - - @Produces - @ApplicationScoped - public SerDeserializerRegistry createRegistry() { - - // Knows about all types for usage with JSON-B - final SerializedDataTypeRegistry typeRegistry = SharedUtils.createTypeRegistry(); - - // Does the actual marshalling/unmarshalling - final JsonbDeSerializer jsonbDeSer = SharedUtils.createJsonbDeSerializer(); - - // Registry connects the type with the appropriate serializer and de-serializer - final SerDeserializerRegistry serDeserRegistry = SharedUtils.createSerDeserializerRegistry(typeRegistry, - jsonbDeSer); - - return serDeserRegistry; - - } - -} \ No newline at end of file diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/QryPersonProjectionPosition.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/common/ProjectionPosition.java similarity index 91% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/QryPersonProjectionPosition.java rename to quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/common/ProjectionPosition.java index 56b176c..44a6468 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/QryPersonProjectionPosition.java +++ b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/common/ProjectionPosition.java @@ -10,7 +10,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.query.handler; +package org.fuin.cqrs4j.example.quarkus.query.views.common; import javax.persistence.Column; import javax.persistence.Entity; @@ -27,7 +27,7 @@ import org.fuin.objects4j.common.Contract; */ @Entity @Table(name = "QRY_PERSON_PROJECTION_POS") -public class QryPersonProjectionPosition { +public class ProjectionPosition { @Id @Column(name = "STREAM_ID", nullable = false, length = 250, updatable = false) @@ -41,7 +41,7 @@ public class QryPersonProjectionPosition { /** * JPA constructor. */ - protected QryPersonProjectionPosition() { + protected ProjectionPosition() { super(); } @@ -53,7 +53,7 @@ public class QryPersonProjectionPosition { * @param nextPos * Next position from the stream to read. */ - public QryPersonProjectionPosition(@NotNull final StreamId streamId, @NotNull final Long nextPos) { + public ProjectionPosition(@NotNull final StreamId streamId, @NotNull final Long nextPos) { super(); Contract.requireArgNotNull("streamId", streamId); Contract.requireArgNotNull("nextPos", nextPos); diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/QryPersonProjectionPositionRepository.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/common/ProjectionPositionRepository.java similarity index 78% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/QryPersonProjectionPositionRepository.java rename to quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/common/ProjectionPositionRepository.java index 4b9ef89..474e444 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/QryPersonProjectionPositionRepository.java +++ b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/common/ProjectionPositionRepository.java @@ -10,7 +10,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.query.handler; +package org.fuin.cqrs4j.example.quarkus.query.views.common; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -25,7 +25,7 @@ import org.fuin.objects4j.common.Contract; * Repository that contains the position of the stream. */ @ApplicationScoped -public class QryPersonProjectionPositionRepository implements ProjectionService { +public class ProjectionPositionRepository implements ProjectionService { @Inject EntityManager em; @@ -33,7 +33,7 @@ public class QryPersonProjectionPositionRepository implements ProjectionService @Override public void resetProjectionPosition(@NotNull final StreamId streamId) { Contract.requireArgNotNull("streamId", streamId); - final QryPersonProjectionPosition pos = em.find(QryPersonProjectionPosition.class, streamId.asString()); + final ProjectionPosition pos = em.find(ProjectionPosition.class, streamId.asString()); if (pos != null) { pos.setNextPosition(0L); } @@ -42,7 +42,7 @@ public class QryPersonProjectionPositionRepository implements ProjectionService @Override public Long readProjectionPosition(@NotNull StreamId streamId) { Contract.requireArgNotNull("streamId", streamId); - final QryPersonProjectionPosition pos = em.find(QryPersonProjectionPosition.class, streamId.asString()); + final ProjectionPosition pos = em.find(ProjectionPosition.class, streamId.asString()); if (pos == null) { return 0L; } @@ -53,9 +53,9 @@ public class QryPersonProjectionPositionRepository implements ProjectionService public void updateProjectionPosition(@NotNull StreamId streamId, @NotNull Long nextEventNumber) { Contract.requireArgNotNull("streamId", streamId); Contract.requireArgNotNull("nextEventNumber", nextEventNumber); - final QryPersonProjectionPosition pos = em.find(QryPersonProjectionPosition.class, streamId.asString()); + final ProjectionPosition pos = em.find(ProjectionPosition.class, streamId.asString()); if (pos == null) { - em.persist(new QryPersonProjectionPosition(streamId, nextEventNumber)); + em.persist(new ProjectionPosition(streamId, nextEventNumber)); } else { pos.setNextPosition(nextEventNumber); em.merge(pos); diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/package-info.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/package-info.java similarity index 70% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/package-info.java rename to quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/package-info.java index 70ff56b..5a3bd31 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/package-info.java +++ b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/package-info.java @@ -10,8 +10,9 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.query.handler; +package org.fuin.cqrs4j.example.quarkus.query.views; /** - * Code related to event handlers. + * Contains the views used in this query application. A view never uses code of another view, means all views are completely independent of + * each other. As an exception, the 'commons' package has some small classes that are not view specific. */ diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/PersonCreatedEventHandler.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/personlist/PersonCreatedEventHandler.java similarity index 81% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/PersonCreatedEventHandler.java rename to quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/personlist/PersonCreatedEventHandler.java index 9d81608..def4e02 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/handler/PersonCreatedEventHandler.java +++ b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/personlist/PersonCreatedEventHandler.java @@ -10,7 +10,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.query.handler; +package org.fuin.cqrs4j.example.quarkus.query.views.personlist; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -18,9 +18,8 @@ import javax.persistence.EntityManager; import javax.transaction.Transactional; import org.fuin.cqrs4j.EventHandler; -import org.fuin.cqrs4j.example.quarkus.query.domain.QryPerson; -import org.fuin.cqrs4j.example.quarkus.shared.PersonCreatedEvent; -import org.fuin.cqrs4j.example.quarkus.shared.PersonId; +import org.fuin.cqrs4j.example.shared.PersonCreatedEvent; +import org.fuin.cqrs4j.example.shared.PersonId; import org.fuin.ddd4j.ddd.EventType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,8 +45,8 @@ public class PersonCreatedEventHandler implements EventHandler { + eventstore.readAllEventsForward(PROJECTION_STREAM_ID, nextEventNumber, 100, (currentSlice) -> { chunkHandler.handleChunk(currentSlice); }); diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/domain/package-info.java b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/personlist/package-info.java similarity index 85% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/domain/package-info.java rename to quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/personlist/package-info.java index 9633a98..ec84117 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/domain/package-info.java +++ b/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/views/personlist/package-info.java @@ -10,8 +10,8 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.query.domain; +package org.fuin.cqrs4j.example.quarkus.query.views.personlist; /** - * Domain specific code like view objects. + * Classes building the 'person list' view. */ diff --git a/quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/PersonResourceIT.java b/quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResourceIT.java similarity index 80% rename from quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/PersonResourceIT.java rename to quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResourceIT.java index 27e3747..ec48fad 100644 --- a/quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/PersonResourceIT.java +++ b/quarkus/query/src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResourceIT.java @@ -16,25 +16,25 @@ import javax.enterprise.context.control.ActivateRequestContext; import javax.inject.Inject; import javax.persistence.EntityManager; -import org.fuin.cqrs4j.example.quarkus.query.domain.QryPerson; -import org.fuin.cqrs4j.example.quarkus.shared.PersonCreatedEvent; -import org.fuin.cqrs4j.example.quarkus.shared.PersonId; -import org.fuin.cqrs4j.example.quarkus.shared.PersonName; +import org.fuin.cqrs4j.example.quarkus.query.views.personlist.PersonListEntry; +import org.fuin.cqrs4j.example.shared.PersonCreatedEvent; +import org.fuin.cqrs4j.example.shared.PersonId; +import org.fuin.cqrs4j.example.shared.PersonName; import org.fuin.esc.api.CommonEvent; import org.fuin.esc.api.EventId; -import org.fuin.esc.api.EventStore; import org.fuin.esc.api.SimpleCommonEvent; import org.fuin.esc.api.SimpleStreamId; import org.fuin.esc.api.TypeName; +import org.fuin.esc.eshttp.IESHttpEventStore; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -public class PersonResourceIT { +public class QryPersonResourceIT { @Inject - EventStore eventStore; + IESHttpEventStore eventStore; @Inject EntityManager em; @@ -51,7 +51,7 @@ public class PersonResourceIT { @ActivateRequestContext public boolean findPerson(final PersonId personId) { - return em.find(QryPerson.class, personId.asString()) != null; + return em.find(PersonListEntry.class, personId.asString()) != null; } @Test @@ -70,7 +70,7 @@ public class PersonResourceIT { // TEST & VERIFY - final QryPerson person = + final PersonListEntry person = given() .pathParam("id", personId.asString()) .when() @@ -78,21 +78,21 @@ public class PersonResourceIT { .then() .statusCode(200) .extract() - .as(QryPerson.class); + .as(PersonListEntry.class); assertThat(person.getId(), is(equalTo(personId))); assertThat(person.getName(), is(equalTo(personName))); - final QryPerson[] persons = + final PersonListEntry[] persons = given() .when() .get("/persons") .then() .statusCode(200) .extract() - .as(QryPerson[].class); + .as(PersonListEntry[].class); assertThat(Arrays.asList(persons), is(not(empty()))); - final QryPerson person0 = persons[0]; + final PersonListEntry person0 = persons[0]; assertThat(person0.getId(), is(equalTo(personId))); assertThat(person0.getName(), is(equalTo(personName))); diff --git a/quarkus/shared/pom.xml b/quarkus/shared/pom.xml index b6c45a5..3828be5 100644 --- a/quarkus/shared/pom.xml +++ b/quarkus/shared/pom.xml @@ -1,135 +1,168 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.fuin.cqrs4j.example.quarkus - cqrs4j-quarkus-example-shared - 0.1.0-SNAPSHOT - cqrs4j-quarkus-example-shared - Quarkus CQRS Shared Code for Demo Application + org.fuin.cqrs4j.example.quarkus + cqrs4j-quarkus-example-shared + 0.1.0-SNAPSHOT + cqrs4j-quarkus-example-shared + Quarkus CQRS Shared Code for Demo Application - - UTF-8 - 1.8 - 1.8 - 1.8 - 0.3.1-SNAPSHOT - + + UTF-8 + 1.8 + 1.8 + 1.8 + 0.3.1 + - + - + - - org.fuin - ddd-4-java - 0.2.1-SNAPSHOT - + + io.quarkus + quarkus-universe-bom + 1.0.1.Final + pom + import + - - org.fuin - cqrs-4-java - 0.2.1-SNAPSHOT - + - - org.fuin - objects4j - 0.6.9-SNAPSHOT - + - - org.fuin.esc - esc-spi - ${esc.version} - + - - org.fuin.esc - esc-api - ${esc.version} - + - - org.slf4j - slf4j-api - 1.7.25 - + + org.fuin.cqrs4j.example + cqrs4j-example-shared + 0.1.0-SNAPSHOT + - - org.hibernate.validator - hibernate-validator - 6.0.10.Final - - - jaxb-impl - com.sun.xml.bind - - - jaxb-api - javax.xml.bind - - - + + org.fuin + ddd-4-java + 0.2.1 + - - org.glassfish - javax.json - 1.1.4 - + + org.fuin + cqrs-4-java + 0.2.1 + - - org.eclipse - yasson - 1.0.3 - + + org.fuin + objects4j + 0.6.9 + - - jakarta.persistence - jakarta.persistence-api - 2.2.3 - + + org.fuin.esc + esc-esjc + ${esc.version} + - + + org.fuin.esc + esc-eshttp + ${esc.version} + - - junit - junit - 4.12 - test - + + org.slf4j + slf4j-api + - - org.assertj - assertj-core - 3.10.0 - test - + + io.quarkus + quarkus-smallrye-context-propagation + - - org.fuin - units4j - 0.8.3 - test - + + jakarta.enterprise + jakarta.enterprise.cdi-api + - - nl.jqno.equalsverifier - equalsverifier - 2.4.6 - test - + + org.eclipse.microprofile.config + microprofile-config-api + - - commons-io - commons-io - 2.6 - test - + + org.hibernate.validator + hibernate-validator + + + jaxb-impl + com.sun.xml.bind + + + jaxb-api + javax.xml.bind + + + - + + org.glassfish + javax.json + 1.1.4 + + + + org.eclipse + yasson + + + + jakarta.persistence + jakarta.persistence-api + + + + + + junit + junit + 4.12 + test + + + + org.assertj + assertj-core + 3.10.0 + test + + + + org.fuin + units4j + 0.8.3 + test + + + + nl.jqno.equalsverifier + equalsverifier + 2.4.6 + test + + + + commons-io + commons-io + 2.6 + test + + + diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/Config.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/Config.java similarity index 98% rename from quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/Config.java rename to quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/Config.java index df5ae7f..10d70f8 100644 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/Config.java +++ b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/Config.java @@ -10,7 +10,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.command.app; +package org.fuin.cqrs4j.example.quarkus.shared; import java.net.MalformedURLException; import java.net.URL; diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommand.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommand.java deleted file mode 100644 index e01dbd4..0000000 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommand.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import javax.annotation.concurrent.Immutable; -import javax.json.bind.annotation.JsonbProperty; -import javax.validation.constraints.NotNull; - -import org.fuin.cqrs4j.AbstractAggregateCommand; -import org.fuin.ddd4j.ddd.DomainEventExpectedEntityIdPath; -import org.fuin.ddd4j.ddd.EventType; -import org.fuin.esc.spi.SerializedDataType; -import org.fuin.objects4j.common.Contract; - -/** - * A new person should be created in the system. - */ -@Immutable -@DomainEventExpectedEntityIdPath(PersonId.class) -public final class CreatePersonCommand extends AbstractAggregateCommand { - - private static final long serialVersionUID = 1000L; - - /** Never changing unique event type name. */ - public static final EventType TYPE = new EventType("CreatePersonCommand"); - - /** Unique name used for marshalling/unmarshalling the event. */ - public static final SerializedDataType SER_TYPE = new SerializedDataType(CreatePersonCommand.TYPE.asBaseType()); - - @NotNull - @JsonbProperty("name") - private PersonName name; - - /** - * Protected default constructor for deserialization. - */ - protected CreatePersonCommand() { - super(); - } - - /** - * A new person was created in the system. - * - * @param id Identifies uniquely a person. - * @param name Name of a person. - */ - public CreatePersonCommand(@NotNull final PersonId id, @NotNull final PersonName name) { - super(id, null); - Contract.requireArgNotNull("name", name); - this.name = name; - } - - @Override - public final EventType getEventType() { - return CreatePersonCommand.TYPE; - } - - /** - * Returns: Name of a person. - * - * @return Current value. - */ - @NotNull - public final PersonName getName() { - return name; - } - - @Override - public final String toString() { - return "Create person '" + name + "' with identifier '" + getAggregateRootId() + "'"; - } - -} \ No newline at end of file diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EsjcEventStoreFactory.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EsjcEventStoreFactory.java similarity index 96% rename from quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EsjcEventStoreFactory.java rename to quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EsjcEventStoreFactory.java index f5b81b7..bbba8d2 100644 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/EsjcEventStoreFactory.java +++ b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EsjcEventStoreFactory.java @@ -10,7 +10,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.command.app; +package org.fuin.cqrs4j.example.quarkus.shared; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Produces; diff --git a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryEventStoreFactory.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EventStoreFactory.java similarity index 64% rename from quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryEventStoreFactory.java rename to quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EventStoreFactory.java index 54d6b96..5ad29cb 100644 --- a/quarkus/query/src/main/java/org/fuin/cqrs4j/example/quarkus/query/app/QryEventStoreFactory.java +++ b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/EventStoreFactory.java @@ -10,13 +10,15 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.query.app; +package org.fuin.cqrs4j.example.quarkus.shared; +import java.nio.charset.Charset; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.Dependent; +import javax.enterprise.context.RequestScoped; import javax.enterprise.inject.Disposes; import javax.enterprise.inject.Produces; @@ -27,16 +29,50 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import org.fuin.esc.eshttp.ESEnvelopeType; import org.fuin.esc.eshttp.ESHttpEventStore; import org.fuin.esc.eshttp.IESHttpEventStore; +import org.fuin.esc.esjc.ESJCEventStore; +import org.fuin.esc.esjc.IESJCEventStore; +import org.fuin.esc.spi.EnhancedMimeType; import org.fuin.esc.spi.SerDeserializerRegistry; /** * CDI factory that creates an event store connection and repositories. */ @ApplicationScoped -public class QryEventStoreFactory { +public class EventStoreFactory { /** - * Creates an event store.
+ * Creates an ESJC event store.
+ *
+ * CAUTION: The returned event store instance is NOT thread safe. + * + * @param es Native event store API. + * @param registry Serialization registry. + * + * @return Dependent scope event store. + */ + @Produces + @RequestScoped + public IESJCEventStore createEventStore(final com.github.msemys.esjc.EventStore es, + final SerDeserializerRegistry registry) { + + final IESJCEventStore eventstore = new ESJCEventStore(es, registry, registry, + EnhancedMimeType.create("application", "json", Charset.forName("utf-8"))); + eventstore.open(); + return eventstore; + + } + + /** + * Closes the ESJC event store when the context is disposed. + * + * @param es Event store to close. + */ + public void closeEventStore(@Disposes final IESJCEventStore es) { + es.close(); + } + + /** + * Creates an HTTP event store.
*
* CAUTION: The returned event store instance is NOT thread safe. * @@ -49,7 +85,7 @@ public class QryEventStoreFactory { */ @Produces @Dependent - public IESHttpEventStore createEventStore(final QryConfig config, final SerDeserializerRegistry registry) { + public IESHttpEventStore createEventStore(final Config config, final SerDeserializerRegistry registry) { final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(config.getEventStoreUser(), @@ -64,7 +100,7 @@ public class QryEventStoreFactory { } /** - * Closes the event store when the context is disposed. + * Closes the HTTP event store when the context is disposed. * * @param es * Event store to close. @@ -72,5 +108,5 @@ public class QryEventStoreFactory { public void closeEventStore(@Disposes final IESHttpEventStore es) { es.close(); } - + } diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/JsonbFactory.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/JsonbFactory.java similarity index 88% rename from quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/JsonbFactory.java rename to quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/JsonbFactory.java index d192f75..e5d8d04 100644 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/JsonbFactory.java +++ b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/JsonbFactory.java @@ -10,7 +10,7 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.command.app; +package org.fuin.cqrs4j.example.quarkus.shared; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Produces; @@ -19,7 +19,7 @@ import javax.json.bind.JsonbBuilder; import javax.json.bind.JsonbConfig; import org.eclipse.yasson.FieldAccessStrategy; -import org.fuin.cqrs4j.example.quarkus.shared.SharedUtils; +import org.fuin.cqrs4j.example.shared.SharedUtils; /** * CDI factory that creates a JSON-B instance. @@ -37,8 +37,7 @@ public class JsonbFactory { final JsonbConfig config = new JsonbConfig() .withAdapters(SharedUtils.JSONB_ADAPTERS) .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - return jsonb; + return JsonbBuilder.create(config); } } diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEvent.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEvent.java deleted file mode 100644 index 12d0485..0000000 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEvent.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import javax.annotation.concurrent.Immutable; -import javax.json.bind.annotation.JsonbProperty; -import javax.validation.constraints.NotNull; - -import org.fuin.ddd4j.ddd.AbstractDomainEvent; -import org.fuin.ddd4j.ddd.EntityIdPath; -import org.fuin.ddd4j.ddd.EventType; -import org.fuin.esc.spi.SerializedDataType; -import org.fuin.objects4j.common.Contract; - -/** - * A new person was created in the system. - */ -@Immutable -public final class PersonCreatedEvent extends AbstractDomainEvent { - - private static final long serialVersionUID = 1000L; - - /** Never changing unique event type name. */ - public static final EventType TYPE = new EventType("PersonCreatedEvent"); - - /** Unique name used for marshalling/unmarshalling the event. */ - public static final SerializedDataType SER_TYPE = new SerializedDataType(PersonCreatedEvent.TYPE.asBaseType()); - - @NotNull - @JsonbProperty("name") - private PersonName name; - - /** - * Protected default constructor for deserialization. - */ - protected PersonCreatedEvent() { - super(); - } - - /** - * A new person was created in the system. - * - * @param id Identifies uniquely a person. - * @param name Name of a person. - */ - public PersonCreatedEvent(@NotNull final PersonId id, @NotNull final PersonName name) { - super(new EntityIdPath(id)); - Contract.requireArgNotNull("name", name); - this.name = name; - } - - @Override - public final EventType getEventType() { - return PersonCreatedEvent.TYPE; - } - - /** - * Returns: Name of a person. - * - * @return Current value. - */ - @NotNull - public final PersonName getName() { - return name; - } - - @Override - public final String toString() { - return "Person '" + name + "' was created"; - } - -} diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonId.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonId.java deleted file mode 100644 index 4b7dc76..0000000 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonId.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import java.util.UUID; - -import javax.annotation.concurrent.Immutable; -import javax.json.bind.adapter.JsonbAdapter; -import javax.validation.constraints.NotNull; - -import org.fuin.ddd4j.ddd.AggregateRootUuid; -import org.fuin.ddd4j.ddd.EntityType; -import org.fuin.ddd4j.ddd.StringBasedEntityType; -import org.fuin.objects4j.ui.Label; -import org.fuin.objects4j.ui.ShortLabel; -import org.fuin.objects4j.ui.Tooltip; -import org.fuin.objects4j.vo.ValueObjectConverter; - -/** - * Identifies uniquely a person. - */ -@ShortLabel(bundle = "ddd-cqrs-4-java-example", key = "PersonId.slabel", value = "PID") -@Label(bundle = "ddd-cqrs-4-java-example", key = "PersonId.label", value = "Person's ID") -@Tooltip(bundle = "ddd-cqrs-4-java-example", key = "PersonId.tooltip", value = "Unique identifier of a person") -@Immutable -public final class PersonId extends AggregateRootUuid { - - private static final long serialVersionUID = 1000L; - - /** Unique name of the aggregate this identifier refers to. */ - public static final EntityType TYPE = new StringBasedEntityType("PERSON"); - - /** - * Default constructor. - */ - protected PersonId() { - super(PersonId.TYPE); - } - - /** - * Constructor with all data. - * - * @param value - * Persistent value. - */ - public PersonId(@NotNull final UUID value) { - super(PersonId.TYPE, value); - } - - /** - * Verifies if the given string can be converted into a Person ID. - * - * @param value - * String with valid UUID string. A null value ris also valid. - * - * @return {@literal true} if the string is a valid UUID. - */ - public static boolean isValid(final String value) { - if (value == null) { - return true; - } - return AggregateRootUuid.isValid(value); - } - - /** - * Parses a given string and returns a new instance of PersonId. - * - * @param value - * String with valid UUID to convert. A null value returns null. - * - * @return Converted value. - */ - public static PersonId valueOf(final String value) { - if (value == null) { - return null; - } - AggregateRootUuid.requireArgValid("value", value); - return new PersonId(UUID.fromString(value)); - } - - /** - * Converts the value object from/to UUID. - */ - public static final class Converter implements ValueObjectConverter, JsonbAdapter { - - // Attribute Converter - - @Override - public final Class getBaseTypeClass() { - return UUID.class; - } - - @Override - public final Class getValueObjectClass() { - return PersonId.class; - } - - @Override - public boolean isValid(final UUID value) { - return true; - } - - @Override - public final PersonId toVO(final UUID value) { - if (value == null) { - return null; - } - return new PersonId(value); - } - - @Override - public final UUID fromVO(final PersonId value) { - if (value == null) { - return null; - } - return value.asBaseType(); - } - - // JSONB Adapter - - @Override - public final UUID adaptToJson(final PersonId obj) throws Exception { - return fromVO(obj); - } - - @Override - public final PersonId adaptFromJson(final UUID value) throws Exception { - return toVO(value); - } - - } - -} \ No newline at end of file diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonName.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonName.java deleted file mode 100644 index 7c1068f..0000000 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/PersonName.java +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.annotation.concurrent.Immutable; -import javax.json.bind.adapter.JsonbAdapter; -import javax.validation.Constraint; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; -import javax.validation.Payload; -import javax.validation.constraints.NotNull; - -import org.fuin.objects4j.common.ConstraintViolationException; -import org.fuin.objects4j.ui.Label; -import org.fuin.objects4j.ui.ShortLabel; -import org.fuin.objects4j.ui.Tooltip; -import org.fuin.objects4j.vo.AbstractStringValueObject; -import org.fuin.objects4j.vo.ValueObjectConverter; - -/** - * Name of a person. - */ -@ShortLabel(bundle = "ddd-cqrs-4-java-example", key = "PersonName.slabel", value = "PNAME") -@Label(bundle = "ddd-cqrs-4-java-example", key = "PersonName.label", value = "Person's name") -@Tooltip(bundle = "ddd-cqrs-4-java-example", key = "PersonName.tooltip", value = "Name of a person") -@Immutable -public final class PersonName extends AbstractStringValueObject { - - private static final long serialVersionUID = 1000L; - - /** Max length of a person's name. */ - public static final int MAX_LENGTH = 100; - - @NotNull - @PersonNameStr - private String value; - - /** - * Protected default constructor for deserialization. - */ - protected PersonName() { - super(); - } - - /** - * Constructor with mandatory data. - * - * @param value Value. - */ - public PersonName(final String value) { - super(); - PersonName.requireArgValid("value", value); - this.value = value; - } - - @Override - public final String asBaseType() { - return value; - } - - @Override - public final String toString() { - return value; - } - - /** - * Verifies that a given string can be converted into the type. - * - * @param value Value to validate. - * - * @return Returns true if it's a valid type else - * false. - */ - public static boolean isValid(final String value) { - if (value == null) { - return true; - } - if (value.length() == 0) { - return false; - } - final String trimmed = value.trim(); - if (trimmed.length() > PersonName.MAX_LENGTH) { - return false; - } - return true; - } - - /** - * Verifies if the argument is valid and throws an exception if this is not the - * case. - * - * @param name Name of the value for a possible error message. - * @param value Value to check. - * - * @throws ConstraintViolationException The value was not valid. - */ - public static void requireArgValid(@NotNull final String name, @NotNull final String value) - throws ConstraintViolationException { - - if (!PersonName.isValid(value)) { - throw new ConstraintViolationException("The argument '" + name + "' is not valid: '" + value + "'"); - } - - } - - /** - * Ensures that the string can be converted into the type. - */ - @Target({ ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE }) - @Retention(RetentionPolicy.RUNTIME) - @Constraint(validatedBy = { Validator.class }) - @Documented - public static @interface PersonNameStr { - - String message() - - default "{org.fuin.cqrs4j.example.javasecdi.PersonName.message}"; - - Class[] groups() default {}; - - Class[] payload() default {}; - - } - - /** - * Validates if a string is compliant with the type. - */ - public static final class Validator implements ConstraintValidator { - - @Override - public final void initialize(final PersonNameStr annotation) { - // Not used - } - - @Override - public final boolean isValid(final String value, final ConstraintValidatorContext context) { - return PersonName.isValid(value); - } - - } - - /** - * Converts the value object from/to string. - */ - public static final class Converter - implements ValueObjectConverter, JsonbAdapter { - - // Attribute Converter - - @Override - public final Class getBaseTypeClass() { - return String.class; - } - - @Override - public final Class getValueObjectClass() { - return PersonName.class; - } - - @Override - public boolean isValid(final String value) { - return PersonName.isValid(value); - } - - @Override - public final PersonName toVO(final String value) { - if (value == null) { - return null; - } - return new PersonName(value); - } - - @Override - public final String fromVO(final PersonName value) { - if (value == null) { - return null; - } - return value.asBaseType(); - } - - // JSONB Adapter - - @Override - public final String adaptToJson(final PersonName obj) throws Exception { - return fromVO(obj); - } - - @Override - public final PersonName adaptFromJson(final String str) throws Exception { - return toVO(str); - } - - } - -} diff --git a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/SerDeserializerRegistryFactory.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SerDeserializerRegistryFactory.java similarity index 86% rename from quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/SerDeserializerRegistryFactory.java rename to quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SerDeserializerRegistryFactory.java index 74b126f..02fb86f 100644 --- a/quarkus/command/src/main/java/org/fuin/cqrs4j/example/quarkus/command/app/SerDeserializerRegistryFactory.java +++ b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SerDeserializerRegistryFactory.java @@ -10,12 +10,12 @@ * You should have received a copy of the GNU Lesser General Public License along with this library. If not, see * http://www.gnu.org/licenses/. */ -package org.fuin.cqrs4j.example.quarkus.command.app; +package org.fuin.cqrs4j.example.quarkus.shared; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Produces; -import org.fuin.cqrs4j.example.quarkus.shared.SharedUtils; +import org.fuin.cqrs4j.example.shared.SharedUtils; import org.fuin.esc.spi.JsonbDeSerializer; import org.fuin.esc.spi.SerDeserializerRegistry; import org.fuin.esc.spi.SerializedDataTypeRegistry; @@ -37,11 +37,9 @@ public class SerDeserializerRegistryFactory { final JsonbDeSerializer jsonbDeSer = SharedUtils.createJsonbDeSerializer(); // Registry connects the type with the appropriate serializer and de-serializer - final SerDeserializerRegistry serDeserRegistry = SharedUtils.createSerDeserializerRegistry(typeRegistry, + return SharedUtils.createSerDeserializerRegistry(typeRegistry, jsonbDeSer); - return serDeserRegistry; - } } \ No newline at end of file diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedEntityIdFactory.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedEntityIdFactory.java deleted file mode 100644 index 65552f6..0000000 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedEntityIdFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import org.fuin.ddd4j.ddd.EntityId; -import org.fuin.ddd4j.ddd.EntityIdFactory; - -/** - * Factory that creates entity identifier instances based on the type. - */ -public final class SharedEntityIdFactory implements EntityIdFactory { - - private Map> valueOfMap; - - private Map> isValidMap; - - /** - * Default constructor. - */ - public SharedEntityIdFactory() { - super(); - valueOfMap = new HashMap<>(); - isValidMap = new HashMap<>(); - valueOfMap.put(PersonId.TYPE.asString(), PersonId::valueOf); - isValidMap.put(PersonId.TYPE.asString(), PersonId::isValid); - } - - @Override - public EntityId createEntityId(final String type, final String id) { - final Function factory = valueOfMap.get(type); - if (factory == null) { - throw new IllegalArgumentException("Unknown type: " + type); - } - return factory.apply(id); - } - - @Override - public boolean containsType(final String type) { - return valueOfMap.containsKey(type); - } - - @Override - public boolean isValid(String type, String id) { - final Function func = isValidMap.get(type); - if (func == null) { - return false; - } - return func.apply(id); - } - -} diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedUtils.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedUtils.java deleted file mode 100644 index 4c1b8cf..0000000 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/SharedUtils.java +++ /dev/null @@ -1,189 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import java.nio.charset.Charset; - -import javax.json.bind.adapter.JsonbAdapter; - -import org.eclipse.yasson.FieldAccessStrategy; -import org.fuin.ddd4j.ddd.AggregateVersionConverter; -import org.fuin.ddd4j.ddd.EntityIdConverter; -import org.fuin.ddd4j.ddd.EntityIdPathConverter; -import org.fuin.ddd4j.ddd.EventIdConverter; -import org.fuin.esc.spi.Base64Data; -import org.fuin.esc.spi.EscEvent; -import org.fuin.esc.spi.EscEvents; -import org.fuin.esc.spi.EscMeta; -import org.fuin.esc.spi.EscSpiUtils; -import org.fuin.esc.spi.JsonbDeSerializer; -import org.fuin.esc.spi.SerDeserializerRegistry; -import org.fuin.esc.spi.SerializedDataType; -import org.fuin.esc.spi.SerializedDataTypeRegistry; -import org.fuin.esc.spi.SimpleSerializedDataTypeRegistry; -import org.fuin.esc.spi.SimpleSerializerDeserializerRegistry; - -/** - * Utility code shared between command (write) and query (read) module. - */ -public final class SharedUtils { - - /** All types that will be written into and read from the event store. */ - private static TypeClass[] USER_DEFINED_TYPES = new TypeClass[] { - new TypeClass(PersonCreatedEvent.SER_TYPE, PersonCreatedEvent.class) }; - - /** All JSON-B adapters from this module. */ - public static JsonbAdapter[] JSONB_ADAPTERS = new JsonbAdapter[] { new EventIdConverter(), - new EntityIdPathConverter(new SharedEntityIdFactory()), new EntityIdConverter(new SharedEntityIdFactory()), - new AggregateVersionConverter(), new PersonId.Converter(), new PersonName.Converter() }; - - private SharedUtils() { - throw new UnsupportedOperationException("It is not allowed to create an instance of a utiliy class"); - } - - /** - * Create a registry that allows finding types (classes) based on their unique type name. - * - * @return New instance. - */ - public static SerializedDataTypeRegistry createTypeRegistry() { - - // Contains all types for usage with JSON-B - final SimpleSerializedDataTypeRegistry typeRegistry = new SimpleSerializedDataTypeRegistry(); - - // Base types always needed - typeRegistry.add(EscEvent.SER_TYPE, EscEvent.class); - typeRegistry.add(EscEvents.SER_TYPE, EscEvents.class); - typeRegistry.add(EscMeta.SER_TYPE, EscMeta.class); - typeRegistry.add(Base64Data.SER_TYPE, Base64Data.class); - - // User defined types - for (final TypeClass tc : USER_DEFINED_TYPES) { - typeRegistry.add(tc.getType(), tc.getClasz()); - } - return typeRegistry; - - } - - /** - * Creates a registry that connects the type with the appropriate serializer and de-serializer. - * - * @param typeRegistry - * Type registry (Mapping from type name to class). - * @param jsonbDeSer - * JSON-B serializer/deserializer to use. - * - * @return New instance. - */ - public static SerDeserializerRegistry createSerDeserializerRegistry(final SerializedDataTypeRegistry typeRegistry, - final JsonbDeSerializer jsonbDeSer) { - - final SimpleSerializerDeserializerRegistry registry = new SimpleSerializerDeserializerRegistry(); - - // Base types always needed - registry.add(EscEvents.SER_TYPE, "application/json", jsonbDeSer); - registry.add(EscEvent.SER_TYPE, "application/json", jsonbDeSer); - registry.add(EscMeta.SER_TYPE, "application/json", jsonbDeSer); - registry.add(Base64Data.SER_TYPE, "application/json", jsonbDeSer); - - // User defined types - for (final TypeClass tc : USER_DEFINED_TYPES) { - registry.add(tc.getType(), "application/json", jsonbDeSer); - } - jsonbDeSer.init(typeRegistry, registry, registry); - - return registry; - } - - /** - * Creates a registry that connects the type with the appropriate serializer and de-serializer. - * - * @return New instance. - */ - public static SerDeserializerRegistry createRegistry() { - - // Knows about all types for usage with JSON-B - final SerializedDataTypeRegistry typeRegistry = SharedUtils.createTypeRegistry(); - - // Does the actual marshalling/unmarshalling - final JsonbDeSerializer jsonbDeSer = SharedUtils.createJsonbDeSerializer(); - - // Registry connects the type with the appropriate serializer and de-serializer - final SerDeserializerRegistry serDeserRegistry = SharedUtils.createSerDeserializerRegistry(typeRegistry, jsonbDeSer); - - return serDeserRegistry; - - } - - /** - * Creates an instance of the JSON-B serializer/deserializer. - * - * @return New instance that is fully initialized with al necessary settings. - */ - public static JsonbDeSerializer createJsonbDeSerializer() { - - return JsonbDeSerializer.builder().withSerializers(EscSpiUtils.createEscJsonbSerializers()) - .withDeserializers(EscSpiUtils.createEscJsonbDeserializers()).withAdapters(JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()).withEncoding(Charset.forName("utf-8")).build(); - - } - - /** - * Helper class for type/class combination. - */ - private static final class TypeClass { - - private final SerializedDataType type; - - private final Class clasz; - - /** - * Constructor with all data. - * - * @param type - * Type. - * @param clasz - * Class. - */ - public TypeClass(final SerializedDataType type, final Class clasz) { - super(); - this.type = type; - this.clasz = clasz; - } - - /** - * Returns the type. - * - * @return Type. - */ - public SerializedDataType getType() { - return type; - } - - /** - * Returns the class. - * - * @return Class. - */ - public Class getClasz() { - return clasz; - } - - } - -} \ No newline at end of file diff --git a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/package-info.java b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/package-info.java index aa8fe95..3c3c81c 100644 --- a/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/package-info.java +++ b/quarkus/shared/src/main/java/org/fuin/cqrs4j/example/quarkus/shared/package-info.java @@ -13,5 +13,5 @@ package org.fuin.cqrs4j.example.quarkus.shared; /** - * Domain specific code to be shared between all modules. + * Quarkus specific code to be shared between command / query service. */ diff --git a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommandTest.java b/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommandTest.java deleted file mode 100644 index 683afe5..0000000 --- a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/CreatePersonCommandTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.time.ZonedDateTime; -import java.util.UUID; - -import javax.json.bind.Jsonb; -import javax.json.bind.JsonbBuilder; -import javax.json.bind.JsonbConfig; - -import org.apache.commons.io.IOUtils; -import org.eclipse.yasson.FieldAccessStrategy; -import org.fuin.utils4j.Utils4J; -import org.junit.Test; - -// CHECKSTYLE:OFF -public final class CreatePersonCommandTest { - - private static final String PERSON_UUID = "84565d62-115e-4502-b7c9-38ad69c64b05"; - - - @Test - public final void testSerializeDeserialize() { - - // PREPARE - final CreatePersonCommand original = createTestee(); - - // TEST - final CreatePersonCommand copy = Utils4J.deserialize(Utils4J.serialize(original)); - - // VERIFY - assertThat(copy).isEqualTo(original); - assertThat(copy.getAggregateRootId()).isEqualTo(original.getAggregateRootId()); - assertThat(copy.getName()).isEqualTo(original.getName()); - - } - - @Test - public final void testMarshalUnmarshalJson() { - - // PREPARE - final CreatePersonCommand original = createTestee(); - - final JsonbConfig config = new JsonbConfig().withAdapters(SharedUtils.JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - - // TEST - final String json = jsonb.toJson(original, CreatePersonCommand.class); - final CreatePersonCommand copy = jsonb.fromJson(json, CreatePersonCommand.class); - - // VERIFY - assertThat(copy).isEqualTo(original); - assertThat(copy.getAggregateRootId()).isEqualTo(original.getAggregateRootId()); - assertThat(copy.getName()).isEqualTo(original.getName()); - - } - - @Test - public final void testUnmarshalJsonFromFile() throws IOException { - - // PREPARE - final String json = IOUtils.toString(this.getClass().getResourceAsStream("/commands/CreatePersonCommand.json"), - Charset.forName("utf-8")); - final JsonbConfig config = new JsonbConfig().withAdapters(SharedUtils.JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - - - // TEST - final CreatePersonCommand copy = jsonb.fromJson(json, CreatePersonCommand.class); - - // VERIFY - assertThat(copy.getEventId().asBaseType()).isEqualTo(UUID.fromString("109a77b2-1de2-46fc-aee1-97fa7740a552")); - assertThat(copy.getTimestamp()).isEqualTo(ZonedDateTime.parse("2019-11-17T10:27:13.183+01:00[Europe/Berlin]")); - assertThat(copy.getAggregateRootId().asString()).isEqualTo(PERSON_UUID); - assertThat(copy.getName().asString()).isEqualTo("Peter Parker"); - - } - - private CreatePersonCommand createTestee() { - final PersonId personId = new PersonId(UUID.fromString(PERSON_UUID)); - final PersonName personName = new PersonName("Peter Parker"); - return new CreatePersonCommand(personId, personName); - } - -} -// CHECKSTYLE:ON diff --git a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEventTest.java b/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEventTest.java deleted file mode 100644 index 071c517..0000000 --- a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonCreatedEventTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.fuin.utils4j.Utils4J.deserialize; -import static org.fuin.utils4j.Utils4J.serialize; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.UUID; - -import javax.json.bind.Jsonb; -import javax.json.bind.JsonbBuilder; -import javax.json.bind.JsonbConfig; - -import org.apache.commons.io.IOUtils; -import org.eclipse.yasson.FieldAccessStrategy; -import org.junit.Test; - - -// CHECKSTYLE:OFF -public final class PersonCreatedEventTest { - - @Test - public final void testSerializeDeserialize() { - - // PREPARE - final PersonCreatedEvent original = createTestee(); - - // TEST - final PersonCreatedEvent copy = deserialize(serialize(original)); - - // VERIFY - assertThat(copy).isEqualTo(original); - assertThat(copy.getName()).isEqualTo(original.getName()); - - } - - @Test - public final void testMarshalUnmarshalJson() { - - // PREPARE - final PersonCreatedEvent original = createTestee(); - - final JsonbConfig config = new JsonbConfig().withAdapters(SharedUtils.JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - - // TEST - final String json = jsonb.toJson(original, PersonCreatedEvent.class); - final PersonCreatedEvent copy = jsonb.fromJson(json, PersonCreatedEvent.class); - - // VERIFY - assertThat(copy).isEqualTo(original); - assertThat(copy.getName()).isEqualTo(original.getName()); - - } - - @Test - public final void testUnmarshalJson() throws IOException { - - // PREPARE - final PersonCreatedEvent original = createTestee(); - final JsonbConfig config = new JsonbConfig().withAdapters(SharedUtils.JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - - // TEST - final String json = IOUtils.toString(this.getClass().getResourceAsStream("/events/PersonCreatedEvent.json"), - Charset.forName("utf-8")); - final PersonCreatedEvent copy = jsonb.fromJson(json, PersonCreatedEvent.class); - - // VERIFY - assertThat(copy.getEntityIdPath()).isEqualTo(original.getEntityIdPath()); - assertThat(copy.getName()).isEqualTo(original.getName()); - - } - - - @Test - public final void testToString() { - assertThat(createTestee().toString()) - .isEqualTo("Person 'Peter Parker' was created"); - } - - private PersonCreatedEvent createTestee() { - final PersonId personId = new PersonId(UUID.fromString("f645969a-402d-41a9-882b-d2d8000d0f43")); - final PersonName personName = new PersonName("Peter Parker"); - return new PersonCreatedEvent(personId, personName); - } - -} diff --git a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonIdTest.java b/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonIdTest.java deleted file mode 100644 index c5387bf..0000000 --- a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonIdTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -import java.util.UUID; - -import org.fuin.ddd4j.ddd.EntityType; -import org.fuin.ddd4j.ddd.StringBasedEntityType; -import org.fuin.objects4j.common.ConstraintViolationException; -import org.junit.Test; - -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -/** - * Test for {@link PersonId}. - */ -public final class PersonIdTest { - - private static final String PERSON_UUID = "84565d62-115e-4502-b7c9-38ad69c64b05"; - - @Test - public void testEquals() { - EqualsVerifier.forClass(PersonId.class).suppress(Warning.NONFINAL_FIELDS) - .withNonnullFields("entityType", "uuid") - .withPrefabValues(EntityType.class, new StringBasedEntityType("A"), new StringBasedEntityType("B")) - .verify(); - } - - @Test - public void testValueOf() { - final PersonId personId = PersonId.valueOf(PERSON_UUID); - - assertThat(personId.asString()).isEqualTo(PERSON_UUID); - - } - - @Test - public void testValueOfIllegalArgumentCharacter() { - try { - PersonId.valueOf("abc"); - fail(); - } catch (final ConstraintViolationException ex) { - assertThat(ex.getMessage()).isEqualTo("The argument 'value' is not valid: 'abc'"); - } - } - - @Test - public final void testConverterUnmarshal() throws Exception { - - // PREPARE - final String personIdValue = PERSON_UUID; - - // TEST - final PersonId personId = new PersonId.Converter().adaptFromJson(UUID.fromString(PERSON_UUID)); - - // VERIFY - assertThat(personId.asString()).isEqualTo(personIdValue); - } - - @Test - public void testConverterMarshal() throws Exception { - - final PersonId personId = PersonId.valueOf(PERSON_UUID); - - // TEST - final UUID uuid = new PersonId.Converter().adaptToJson(personId); - - // VERIFY - assertThat(uuid).isEqualTo(UUID.fromString(PERSON_UUID)); - } - -} diff --git a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonNameTest.java b/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonNameTest.java deleted file mode 100644 index 0b71494..0000000 --- a/quarkus/shared/src/test/java/org/fuin/cqrs4j/example/quarkus/shared/PersonNameTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Copyright (C) 2015 Michael Schnell. All rights reserved. - * http://www.fuin.org/ - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) any - * later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see http://www.gnu.org/licenses/. - */ -package org.fuin.cqrs4j.example.quarkus.shared; - - -import static org.assertj.core.api.Assertions.assertThat; - -import org.fuin.objects4j.common.ConstraintViolationException; -import org.fuin.utils4j.Utils4J; -import org.junit.Assert; -import org.junit.Test; - -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -// CHECKSTYLE:OFF -public final class PersonNameTest { - - @Test - public void testSerialize() { - final PersonName original = new PersonName("Peter Parker"); - final PersonName copy = Utils4J.deserialize(Utils4J.serialize(original)); - assertThat(original).isEqualTo(copy); - } - - @Test - public void testHashCodeEquals() { - EqualsVerifier.forClass(PersonName.class).suppress(Warning.NULL_FIELDS).withRedefinedSuperclass().verify(); - } - - @Test - public void testMarshalJson() throws Exception { - - // PREPARE - final String str = "Peter Parker"; - final PersonName testee = new PersonName(str); - - // TEST & VERIFY - assertThat(new PersonName.Converter().adaptToJson(testee)).isEqualTo(str); - assertThat(new PersonName.Converter().adaptToJson(null)).isNull(); - - } - - @Test - public void testUnmarshalJson() throws Exception { - - // PREPARE - final String str = "Peter Parker"; - final PersonName testee = new PersonName(str); - - // TEST & VERIFY - assertThat(new PersonName.Converter().adaptFromJson(str)).isEqualTo(testee); - assertThat(new PersonName.Converter().adaptFromJson(null)).isNull(); - - } - - @Test - public void testIsValid() { - - assertThat(PersonName.isValid(null)).isTrue(); - assertThat(PersonName.isValid("Peter Parker")).isTrue(); - - assertThat(PersonName.isValid("")).isFalse(); - assertThat(PersonName.isValid("123456789.123456789.123456789.123456789.123456789." - + "123456789.123456789.123456789.123456789.123456789." + "12345")).isFalse(); - - } - - @Test - public void testRequireArgValid() { - - PersonName.requireArgValid("a", "Peter Parker"); - PersonName.requireArgValid("b", null); - - try { - PersonName.requireArgValid("c", ""); - Assert.fail(); - } catch (final ConstraintViolationException ex) { - assertThat(ex.getMessage()).isEqualTo("The argument 'c' is not valid: ''"); - } - - try { - PersonName.requireArgValid("d", "123456789.123456789.123456789.123456789.123456789." - + "123456789.123456789.123456789.123456789.123456789." + "12345"); - Assert.fail(); - } catch (final ConstraintViolationException ex) { - assertThat(ex.getMessage()) - .isEqualTo("The argument 'd' is not valid: '" + "123456789.123456789.123456789.123456789.123456789." - + "123456789.123456789.123456789.123456789.123456789." + "12345" + "'"); - } - - } - - @Test - public void testValidator() { - - assertThat(new PersonName.Validator().isValid(null, null)).isTrue(); - assertThat(new PersonName.Validator().isValid("Peter Parker", null)).isTrue(); - - assertThat(new PersonName.Validator().isValid("", null)).isFalse(); - assertThat(new PersonName.Validator().isValid("123456789.123456789.123456789.123456789.123456789." - + "123456789.123456789.123456789.123456789.123456789." + "12345", null)).isFalse(); - - } - - @Test - public void testValueObjectConverter() { - - assertThat(new PersonName.Converter().getBaseTypeClass()).isEqualTo(String.class); - assertThat(new PersonName.Converter().getValueObjectClass()).isEqualTo(PersonName.class); - assertThat(new PersonName.Converter().isValid(null)).isTrue(); - assertThat(new PersonName.Converter().isValid("Peter Parker")).isTrue(); - - assertThat(new PersonName.Converter().isValid("123456789.123456789.123456789.123456789.123456789." - + "123456789.123456789.123456789.123456789.123456789." + "12345")).isFalse(); - - } - -} diff --git a/shared/pom.xml b/shared/pom.xml index cb2fd01..9cee2a2 100644 --- a/shared/pom.xml +++ b/shared/pom.xml @@ -15,7 +15,7 @@ 1.8 1.8 1.8 - 0.3.1-SNAPSHOT + 0.3.1 @@ -25,19 +25,19 @@ org.fuin ddd-4-java - 0.2.1-SNAPSHOT + 0.2.1 org.fuin cqrs-4-java - 0.2.1-SNAPSHOT + 0.2.1 org.fuin objects4j - 0.6.9-SNAPSHOT + 0.6.9