Skip to content

Commit

Permalink
commandBus -> messageBus
Browse files Browse the repository at this point in the history
  • Loading branch information
svencc committed Sep 22, 2023
1 parent 40ce38e commit 1c3cb09
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 89 deletions.
12 changes: 8 additions & 4 deletions docs/concept/Command-Bus.puml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@startuml
'https://plantuml.com/sequence-diagram

header Message Bus
title Message Bus Sequence Diagram

autonumber

Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
REFORGER -> RECOM: Authentication Request
REFORGER -> RECOM: Authentication Response
REFORGER -> RECOM: Another authentication Request
REFORGER <-- RECOM: another authentication Response


Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
3 changes: 2 additions & 1 deletion runConfigurations/RECOM GraalVM.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="RECOM GraalVM" type="Application" factoryName="Application">
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-ce-19" />
<option name="ALTERNATIVE_JRE_PATH" value="graalvm-jdk-21" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="com.recom.Application" />
<module name="recom-backend" />
<option name="VM_PARAMETERS" value="-Xms256m -Xmx16384m -Dspring.profiles.active=local" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.recom.api.commandbus;
package com.recom.api.messagebus;

import com.recom.api.commons.HttpCommons;
import com.recom.dto.command.CommandBusRequestDto;
import com.recom.dto.command.CommandBusResponseDto;
import com.recom.persistence.command.CommandPersistenceLayer;
import com.recom.dto.message.MessageBusRequestDto;
import com.recom.dto.message.MessageBusResponseDto;
import com.recom.persistence.message.MessagePersistenceLayer;
import com.recom.service.AssertionService;
import com.recom.service.ReforgerPayloadParserService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -29,59 +29,59 @@
@Validated
@RestController
@RequiredArgsConstructor
@Tag(name = "CommandBus")
@RequestMapping("/api/v1/command-bus")
public class CommandBusController {
@Tag(name = "MessageBus")
@RequestMapping("/api/v1/message-bus")
public class MessageBusController {

@NonNull
private final AssertionService assertionService;
@NonNull
private final ReforgerPayloadParserService payloadParser;
@NonNull
private final CommandPersistenceLayer commandPersistenceLayer;
private final MessagePersistenceLayer messagePersistenceLayer;

@Operation(
summary = "Get a list of commands",
description = "Gets all map specific, latest commands of a type.",
summary = "Get a list of messages",
description = "Gets all map specific, latest message of a type.",
security = @SecurityRequirement(name = HttpCommons.BEARER_AUTHENTICATION_REQUIREMENT)
)
@ApiResponses(value = {
@ApiResponse(responseCode = HttpCommons.OK_CODE, description = HttpCommons.OK),
@ApiResponse(responseCode = HttpCommons.UNAUTHORIZED_CODE, description = HttpCommons.UNAUTHORIZED, content = @Content())
})
@PostMapping(path = "/form", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<CommandBusResponseDto> getCommandsForm(
public ResponseEntity<MessageBusResponseDto> getMessagesForm(
@RequestParam(required = true)
@NonNull final Map<String, String> payload
) {
log.debug("Requested POST /api/v1/map/renderer/form (FORM)");

return getCommandsJSON(payloadParser.parseValidated(payload, CommandBusRequestDto.class));
return getMessagesJSON(payloadParser.parseValidated(payload, MessageBusRequestDto.class));
}

@Operation(
summary = "Get a list of commands",
description = "Gets all map specific, latest commands of a type.",
summary = "Get a list of messages",
description = "Gets all map specific, latest message of a type.",
security = @SecurityRequirement(name = HttpCommons.BEARER_AUTHENTICATION_REQUIREMENT)
)
@ApiResponses(value = {
@ApiResponse(responseCode = HttpCommons.OK_CODE, description = HttpCommons.OK),
@ApiResponse(responseCode = HttpCommons.UNAUTHORIZED_CODE, description = HttpCommons.UNAUTHORIZED, content = @Content())
})
@PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CommandBusResponseDto> getCommandsJSON(
public ResponseEntity<MessageBusResponseDto> getMessagesJSON(
@RequestBody(required = true)
@NonNull @Valid final CommandBusRequestDto mapRendererRequestDto
@NonNull @Valid final MessageBusRequestDto mapRendererRequestDto
) {
log.debug("Requested POST /api/v1/map/command-bus (JSON)");
log.debug("Requested POST /api/v1/map/message-bus (JSON)");

// assertionService.assertMapExists(mapRendererRequestDto.getMapName());

return ResponseEntity.status(HttpStatus.OK)
.cacheControl(CacheControl.noCache())
.body(
CommandBusResponseDto.builder()
.commands(commandPersistenceLayer.findAllMapSpecificCommands(mapRendererRequestDto.getMapName()))
MessageBusResponseDto.builder()
.messages(messagePersistenceLayer.findAllMapSpecificMessages(mapRendererRequestDto.getMapName()))
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.recom.dto.command;
package com.recom.dto.message;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.recom.model.command.CommandType;
import com.recom.model.message.MessageType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Nationalized;

@Data
@Schema
Expand All @@ -28,7 +23,7 @@ public class CommandDto {

@Schema
@JsonProperty()
private CommandType commandType;
private MessageType messageType;

@Schema(description = "Unix timestamp in milliseconds", example = "1691941419964")
@JsonProperty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.recom.dto.command;
package com.recom.dto.message;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -17,7 +17,7 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommandBusRequestDto implements Serializable {
public class MessageBusRequestDto implements Serializable {

@NotBlank
@Schema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.recom.dto.command;
package com.recom.dto.message;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -18,11 +17,11 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommandBusResponseDto implements Serializable {
public class MessageBusResponseDto implements Serializable {

@Schema
@JsonProperty()
private List<CommandDto> commands;
private List<CommandDto> messages;

}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.recom.entity;

import com.recom.model.command.CommandType;
import com.recom.model.message.MessageType;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.Cache;
Expand All @@ -19,13 +19,13 @@
@AllArgsConstructor
@Table(indexes = {
@Index(name = "IDX_mapName", columnList = "mapName", unique = false),
@Index(name = "IDX_mapName_commandType", columnList = "mapName, commandType", unique = false),
@Index(name = "IDX_mapName_commandType_timestamp", columnList = "mapName, commandType, timestamp", unique = true),
@Index(name = "IDX_mapName_messageType", columnList = "mapName, messageType", unique = false),
@Index(name = "IDX_mapName_messageType_timestamp", columnList = "mapName, messageType, timestamp", unique = true),
@Index(name = "IDX_mapName_timestamp", columnList = "mapName, timestamp", unique = false),
})
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Command implements Persistable<Long>, Serializable {
public class Message implements Persistable<Long>, Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Expand All @@ -38,7 +38,7 @@ public class Command implements Persistable<Long>, Serializable {

@Enumerated(EnumType.STRING)
@Column(insertable = true, updatable = false, nullable = false, length = 255)
private CommandType commandType;
private MessageType messageType;

@Column(insertable = true, updatable = false, nullable = false, columnDefinition="DATETIME(6) DEFAULT NOW(6)")
private LocalDateTime timestamp;
Expand All @@ -49,7 +49,7 @@ public class Command implements Persistable<Long>, Serializable {

@Override
public int hashCode() {
return Command.class.hashCode();
return Message.class.hashCode();
}

@Override
Expand All @@ -61,7 +61,7 @@ public boolean equals(Object obj) {
} else if (getClass() != obj.getClass()) {
return false;
} else {
final Command other = (Command) obj;
final Message other = (Message) obj;
if (getId() == null) {
return false;
} else return getId().equals(other.getId());
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/recom/mapper/CommandMapper.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.recom.mapper;

import com.recom.dto.command.CommandDto;
import com.recom.entity.Command;
import com.recom.dto.message.CommandDto;
import com.recom.entity.Message;
import lombok.NonNull;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;

import java.time.LocalDateTime;
Expand All @@ -26,6 +24,6 @@ static long timestampToTimestampEpochMilliseconds(@Nullable final LocalDateTime
}

@Mapping(source = "timestamp", target = "timestampEpochMilliseconds", qualifiedByName = "timestampToTimestampEpochMilliseconds")
CommandDto toDto(final Command entity);
CommandDto toDto(final Message entity);

}
7 changes: 0 additions & 7 deletions src/main/java/com/recom/model/command/CommandType.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/com/recom/model/message/MessageType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.recom.model.message;

public enum MessageType {

FETCH_MAP_RENDER_DATA

}
19 changes: 0 additions & 19 deletions src/main/java/com/recom/persistence/command/CommandRepository.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.recom.persistence.command;
package com.recom.persistence.message;

import com.recom.dto.command.CommandDto;
import com.recom.entity.Command;
import com.recom.dto.message.CommandDto;
import com.recom.entity.Message;
import com.recom.mapper.CommandMapper;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
Expand All @@ -12,33 +12,33 @@

@Service
@RequiredArgsConstructor
public class CommandPersistenceLayer {
public class MessagePersistenceLayer {

@NonNull
private final CommandRepository commandRepository;
private final MessageRepository messageRepository;
@NonNull
private final ConversionService conversionService;

@NonNull
// @Cacheable(cacheNames = "CommandPersistenceLayer.findAllMapSpecificCommands") // @TODO there is some work to do, to cache the commands ...
public List<CommandDto> findAllMapSpecificCommands(@NonNull final String mapName) {
return commandRepository.findAllByMapName(mapName).stream()
public List<CommandDto> findAllMapSpecificMessages(@NonNull final String mapName) {
return messageRepository.findAllByMapName(mapName).stream()
.map(CommandMapper.INSTANCE::toDto)
.toList();
}

@NonNull
public List<Command> saveAll(@NonNull final List<Command> entities) {
return commandRepository.saveAll(entities);
public List<Message> saveAll(@NonNull final List<Message> entities) {
return messageRepository.saveAll(entities);
}

@NonNull
public Command save(@NonNull final Command entity) {
return commandRepository.save(entity);
public Message save(@NonNull final Message entity) {
return messageRepository.save(entity);
}

public void deleteAll(@NonNull final List<Command> entities) {
commandRepository.deleteAll(entities);
public void deleteAll(@NonNull final List<Message> entities) {
messageRepository.deleteAll(entities);
}

}
16 changes: 16 additions & 0 deletions src/main/java/com/recom/persistence/message/MessageRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.recom.persistence.message;

import com.recom.entity.Message;
import lombok.NonNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
interface MessageRepository extends JpaRepository<Message, Long> {

@NonNull
List<Message> findAllByMapName(@NonNull final String mapName);

}

0 comments on commit 1c3cb09

Please sign in to comment.