-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set Timezone to UTC (and Log) first implementation of command-bus, api and database
- Loading branch information
Showing
17 changed files
with
416 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'https://plantuml.com/de/sequence-diagram | ||
|
||
@startuml | ||
'header Command Poll Flow | ||
title Command Poll Flow | ||
|
||
participant CLIENT | ||
participant SERVER | ||
database DB | ||
|
||
CLIENT -> SERVER: authenticate | ||
SERVER --> CLIENT: send JWT Token | ||
|
||
|
||
CLIENT -> SERVER: Poll for Commands | ||
SERVER --> DB: Query for latest Commands | ||
DB --> SERVER: Send Commands | ||
|
||
CLIENT <-- SERVER: give Commands | ||
CLIENT --> CLIENT: execute Commands | ||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@startuml | ||
'https://plantuml.com/state-diagram | ||
'https://github.com/pnavais/state-machine | ||
|
||
'https://www.baeldung.com/spring-state-machine | ||
' https://github.com/64ink/spring-statemachine-chart-exporter | ||
' https://plantuml.com/de/api | ||
' https://plantuml.com/de/download | ||
|
||
'scale 500 width | ||
|
||
|
||
[*] --> INIT_NewGame : start game | ||
INIT_NewGame: generate basic commands (if not present) | ||
INIT_NewGame --> RUN : initialized | ||
RUN --> STOPPED : stop | ||
RUN --> PAUSE : pause | ||
PAUSE --> RUN : resume | ||
STOPPED --> [*] : end | ||
|
||
@enduml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/recom/api/commandbus/CommandBusController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.recom.api.commandbus; | ||
|
||
import com.recom.api.commons.HttpCommons; | ||
import com.recom.dto.command.CommandDto; | ||
import com.recom.persistence.command.CommandPersistenceLayer; | ||
import com.recom.service.AssertionService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Validated | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Tag(name = "CommandBus") | ||
@RequestMapping("/api/v1/command-bus") | ||
public class CommandBusController { | ||
|
||
@NonNull | ||
private final AssertionService assertionService; | ||
@NonNull | ||
private final CommandPersistenceLayer commandPersistenceLayer; | ||
|
||
|
||
@Operation( | ||
summary = "Get a list of commands", | ||
description = "Gets all map specific, latest commands 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()) | ||
}) | ||
@GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<List<CommandDto>> getCommands( | ||
@RequestParam(required = true) | ||
@NonNull final String mapName | ||
) { | ||
log.debug("Requested GET /api/v1/map/command-bus"); | ||
|
||
// @TODO: re-enable after development | ||
// assertionService.assertMapExists(mapName); | ||
|
||
final List<CommandDto> allMapSpecificCommands = commandPersistenceLayer.findAllMapSpecificCommands(mapName); | ||
|
||
if (allMapSpecificCommands.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND) | ||
.cacheControl(CacheControl.noCache()) | ||
.build(); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.cacheControl(CacheControl.noCache()) | ||
.body(allMapSpecificCommands); | ||
} | ||
|
||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/recom/configuration/LocaleLoggerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.recom.configuration; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
|
||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class LocaleLoggerConfiguration implements AsyncConfigurer { | ||
|
||
@PostConstruct | ||
public void init() { | ||
log.info("Locale initialized with '{}'", Locale.getDefault()); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/recom/configuration/TimezoneLoggerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.recom.configuration; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
|
||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class TimezoneLoggerConfiguration implements AsyncConfigurer { | ||
|
||
@PostConstruct | ||
public void init() { | ||
log.info("Timezone initialized with '{}'", TimeZone.getDefault().getDisplayName()); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.recom.dto.command; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.recom.model.command.CommandType; | ||
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 | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class CommandDto { | ||
|
||
@Schema | ||
@JsonProperty() | ||
private Long id; | ||
|
||
@Schema | ||
@JsonProperty() | ||
private String mapName; | ||
|
||
@Schema | ||
@JsonProperty() | ||
private CommandType commandType; | ||
|
||
@Schema(description = "Unix timestamp in milliseconds", example = "1691941419964") | ||
@JsonProperty() | ||
private Long timestampEpochMilliseconds; | ||
|
||
@Schema | ||
@JsonProperty() | ||
private String payload; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.recom.entity; | ||
|
||
import com.recom.model.command.CommandType; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.annotations.Cache; | ||
import org.hibernate.annotations.CacheConcurrencyStrategy; | ||
import org.hibernate.annotations.Nationalized; | ||
import org.springframework.data.domain.Persistable; | ||
|
||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Builder | ||
@NoArgsConstructor | ||
@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_timestamp", columnList = "mapName, timestamp", unique = false), | ||
}) | ||
@Cacheable | ||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) | ||
public class Command implements Persistable<Long>, Serializable { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(insertable = true, updatable = false, nullable = false) | ||
private Long id; | ||
|
||
@Nationalized | ||
@Column(insertable = true, updatable = false, nullable = false, length = 255) | ||
private String mapName; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(insertable = true, updatable = false, nullable = false, length = 255) | ||
private CommandType commandType; | ||
|
||
@Column(insertable = true, updatable = false, nullable = false, columnDefinition="DATETIME(6) DEFAULT NOW(6)") | ||
private LocalDateTime timestamp; | ||
|
||
@Lob | ||
@Column(insertable = true, updatable = true, nullable = true, columnDefinition = "LONGTEXT") | ||
private String payload; | ||
|
||
@Override | ||
public int hashCode() { | ||
return Command.class.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} else if (obj == null) { | ||
return false; | ||
} else if (getClass() != obj.getClass()) { | ||
return false; | ||
} else { | ||
final Command other = (Command) obj; | ||
if (getId() == null) { | ||
return false; | ||
} else return getId().equals(other.getId()); | ||
} | ||
} | ||
|
||
@Override | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public boolean isNew() { | ||
return getId() == null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.