Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Update all user commands/events/valueObjects to Kotlin equivalents
Browse files Browse the repository at this point in the history
Update all user commands/events/valueObjects to Kotlin equivalents

#28
  • Loading branch information
smcvb committed Jun 1, 2018
1 parent 17a733e commit 1f03f05
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 270 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,41 @@
package org.axonframework.samples.trader.api.users

import org.axonframework.commandhandling.TargetAggregateIdentifier
import java.util.*
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size

abstract class UserCommand(@TargetAggregateIdentifier open val userId: UserId)

class CreateUserCommand(
override val userId: UserId,
val name: String, @NotNull @Size(min = 3)
val username: String, @NotNull @Size(min = 3)
val password: String
) : UserCommand(userId)

data class AuthenticateUserCommand(
override val userId: UserId,
val userName: String,
@NotNull @Size(min = 3) val password: CharArray
) : UserCommand(userId) {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is AuthenticateUserCommand) return false

if (userId != other.userId) return false
if (userName != other.userName) return false
if (!Arrays.equals(password, other.password)) return false

return true
}

override fun hashCode(): Int {
var result = userId.hashCode()
result = 31 * result + userName.hashCode()
result = 31 * result + Arrays.hashCode(password)
return result
}

}
@@ -0,0 +1,12 @@
package org.axonframework.samples.trader.api.users

abstract class UserEvent(open val userId: UserId)

data class UserCreatedEvent(
override val userId: UserId,
val name: String,
val username: String,
val password: String
) : UserEvent(userId)

data class UserAuthenticatedEvent(override val userId: UserId) : UserEvent(userId)
@@ -0,0 +1,12 @@
package org.axonframework.samples.trader.api.users

import org.axonframework.common.IdentifierFactory
import java.io.Serializable

data class UserId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable {

companion object {
private const val serialVersionUID = -4860092244272266543L
}

}
Expand Up @@ -41,8 +41,8 @@ public class PortfolioManagementUserListener {
@EventHandler
public void createNewPortfolioWhenUserIsCreated(UserCreatedEvent event) {
logger.debug("About to dispatch a new command to create a Portfolio for the new user {}",
event.getUserIdentifier());
CreatePortfolioCommand command = new CreatePortfolioCommand(new PortfolioId(), event.getUserIdentifier());
event.getUserId());
CreatePortfolioCommand command = new CreatePortfolioCommand(new PortfolioId(), event.getUserId());
commandBus.dispatch(new GenericCommandMessage<>(command));
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ public class UserListener {
@EventHandler
public void handleUserCreated(UserCreatedEvent event) {
UserEntry userEntry = new UserEntry();
userEntry.setIdentifier(event.getUserIdentifier().toString());
userEntry.setIdentifier(event.getUserId().toString());
userEntry.setName(event.getName());
userEntry.setUsername(event.getUsername());
userEntry.setPassword(event.getPassword());
Expand Down
Expand Up @@ -53,7 +53,7 @@ public boolean authenticate(char[] password) {

@EventHandler
public void onUserCreated(UserCreatedEvent event) {
this.userId = event.getUserIdentifier();
this.userId = event.getUserId();
this.passwordHash = event.getPassword();
}

Expand Down

0 comments on commit 1f03f05

Please sign in to comment.