Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class StatementEntity {
@Column(columnDefinition = "BLOB")
private JsonNode statement;

@Column
@Column(nullable = false)
private Instant stored;

/**
Expand All @@ -41,6 +41,7 @@ public StatementEntity() {}
*
* @param id the statement id
* @param statement the statement as JSON
* @param stored the stored timestamp
*/
public StatementEntity(UUID id, JsonNode statement, Instant stored) {

Expand Down Expand Up @@ -86,10 +87,20 @@ public void setStatement(JsonNode statement) {
this.statement = statement;
}

/**
* Gets the stored timestamp.
*
* @return the stored timestamp
*/
public Instant getStored() {
return stored;
}

/**
* Sets the stored timestamp.
*
* @param stored the stored timestamp to set
*/
public void setStored(Instant stored) {
this.stored = stored;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*
* @author Thomas Turrell-Croft
*/
public interface StatementRepository extends PagingAndSortingRepository<StatementEntity, UUID> {
public interface StatementRepository extends PagingAndSortingRepository<StatementEntity, UUID>,
CrudRepository<StatementEntity, UUID> {

Slice<StatementEntity> findAllByOrderByStoredAscIdAsc(Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
Expand Down Expand Up @@ -119,8 +118,7 @@ public StatementResult getStatementsMore(String moreToken) {

private StatementResult buildStatementResult(int page, Instant since) {

final Pageable pageable = PageRequest.of(page, PAGE_SIZE,
Sort.by(Sort.Direction.ASC, "stored").and(Sort.by("id")));
final Pageable pageable = PageRequest.of(page, PAGE_SIZE);

final Slice<StatementEntity> slice;
if (since == null) {
Expand Down Expand Up @@ -171,11 +169,11 @@ public Collection<UUID> processStatements(List<Statement> statements) {

final List<Statement> processedStatements = new ArrayList<>();

final Instant stored = Instant.now();

for (final Statement statement : statements) {
log.info("processing statement: {}", statement);

final Instant stored = Instant.now();

if (statement.getId() == null) {
processedStatements.add(statement.withId(UUID.randomUUID()).withStored(stored));
} else {
Expand Down Expand Up @@ -206,6 +204,10 @@ private MoreToken decodeMoreToken(String token) {
final var decoded = new String(Base64.getUrlDecoder().decode(token), StandardCharsets.UTF_8);
final var parts = decoded.split("\\|", -1);

if (parts[0].isBlank()) {
throw new IllegalArgumentException("Invalid more token format: missing page number");
}

final var page = Integer.parseInt(parts[0]);
final Instant since;

Expand All @@ -216,8 +218,6 @@ private MoreToken decodeMoreToken(String token) {
}

return new MoreToken(page, since);
} catch (IllegalArgumentException ex) {
throw ex;
} catch (Exception ex) {
throw new IllegalArgumentException("Invalid more token", ex);
}
Expand Down