Skip to content

Commit

Permalink
Bugfix: Timestamp as Instant
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Dec 29, 2023
1 parent 9aa3bb2 commit e871017
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/samply/db/model/BridgeheadOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.time.LocalDate;
import java.time.Instant;

@Entity
@Table(name = "bridgehead_operation", schema = "samply")
Expand All @@ -28,7 +28,7 @@ public class BridgeheadOperation {
private String userEmail;

@Column(name = "timestamp", nullable = false)
private LocalDate timestamp;
private Instant timestamp;

@Column(name = "http_status", nullable = false)
@Enumerated(EnumType.STRING)
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/de/samply/db/model/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;
import java.time.LocalDate;

@Entity
Expand All @@ -31,13 +32,16 @@ public class Project {
private String creatorEmail;

@Column(name = "created_at", nullable = false)
private LocalDate createdAt;
private Instant createdAt;

@Column(name = "expires_at")
private LocalDate expiresAt;

@Column(name = "archived_at")
private LocalDate archivedAt;
private Instant archivedAt;

@Column(name = "modified_at")
private Instant modifiedAt;

@Column(name = "state", nullable = false)
@Enumerated(EnumType.STRING)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/samply/db/model/ProjectBridgehead.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

@Entity
@Table(name = "project_bridgehead", schema = "samply")
@Data
Expand All @@ -30,4 +32,7 @@ public class ProjectBridgehead {
@Enumerated(EnumType.STRING)
private ProjectBridgeheadState state;

@Column(name = "modified_at")
private Instant modifiedAt;

}
4 changes: 2 additions & 2 deletions src/main/java/de/samply/db/model/ProjectDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.Instant;

@Entity
@Table(name = "project_document", schema = "samply")
Expand Down Expand Up @@ -34,7 +34,7 @@ public class ProjectDocument {
private String url;

@Column(name = "created_at", nullable = false)
private LocalDate createdAt;
private Instant createdAt;

@Column(name = "bridgehead")
private String bridgehead;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/samply/db/model/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.Instant;

@Entity
@Table(name = "query", schema = "samply")
Expand All @@ -25,7 +25,7 @@ public class Query {
private String code;

@Column(name = "created_at", nullable = false)
private LocalDate createdAt;
private Instant createdAt;

@Column(name = "query", nullable = false)
private String query;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/samply/document/DocumentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -101,7 +102,7 @@ private void addDocument(String projectCode,
}
labelOptional.ifPresent(label -> projectDocument.setLabel(label));
projectDocument.setDocumentType(documentType);
projectDocument.setCreatedAt(LocalDate.now());
projectDocument.setCreatedAt(Instant.now());
projectDocument.setCreatorEmail(sessionUser.getEmail());
documentSetter.accept(projectDocument);
this.projectDocumentRepository.save(projectDocument);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/samply/exporter/ExporterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import reactor.util.retry.Retry;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
Expand Down Expand Up @@ -148,7 +149,7 @@ private void createBridgeheadOperation(
BridgeheadOperation bridgeheadOperation = new BridgeheadOperation();
bridgeheadOperation.setBridgehead(bridgehead);
bridgeheadOperation.setProject(projectRepository.findByCode(projectCode).get());
bridgeheadOperation.setTimestamp(LocalDate.now());
bridgeheadOperation.setTimestamp(Instant.now());
bridgeheadOperation.setType(fetchBridgeheadOperationType(restService));
bridgeheadOperation.setHttpStatus(status);
bridgeheadOperation.setError(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.time.Instant;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Optional;
Expand Down Expand Up @@ -100,6 +101,7 @@ private void changeEventWithoutExceptionHandling(String projectCode, ProjectEven
Optional<Project> project = this.projectRepository.findByCode(projectCode);
if (project.isPresent()) {
project.get().setState(stateMachine.getState().getId());
project.get().setModifiedAt(Instant.now());
this.projectRepository.save(project.get());
}
});
Expand Down Expand Up @@ -138,8 +140,9 @@ private void createProjectAsDraft(String projectCode, Consumer<Project> projectC
Project project = new Project();
project.setCode(projectCode);
project.setCreatorEmail(sessionUser.getEmail());
project.setCreatedAt(LocalDate.now());
project.setCreatedAt(Instant.now());
project.setExpiresAt(createExpirationDate());
project.setModifiedAt(Instant.now());
project.setStateMachineKey(UUID.randomUUID().toString().replace("-", ""));
project.setQuery(query);
project.setType(projectType);
Expand All @@ -160,6 +163,7 @@ private ProjectBridgehead createProjectBridgehead(String bridgehead, Project pro
projectBridgehead.setBridgehead(bridgehead.toLowerCase());
projectBridgehead.setProject(project);
projectBridgehead.setState(ProjectBridgeheadState.CREATED); // TODO: Replace with state machine
projectBridgehead.setModifiedAt(Instant.now());
return this.projectBridgeheadRepository.save(projectBridgehead);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/samply/query/QueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.samply.db.repository.QueryRepository;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.time.LocalDate;
import java.util.UUID;

Expand All @@ -24,7 +25,7 @@ public String createQuery(
tempQuery.setCode(generateQueryCode());
tempQuery.setQuery(query);
tempQuery.setQueryFormat(queryFormat);
tempQuery.setCreatedAt(LocalDate.now());
tempQuery.setCreatedAt(Instant.now());
tempQuery.setLabel(label);
tempQuery.setDescription(description);
tempQuery.setOutputFormat(outputFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CREATE TABLE samply.query
query_format TEXT NOT NULL,
created_at TIMESTAMP NOT NULL,
human_readable TEXT,
explorer_url TEXT,
explorer_url TEXT,
output_format TEXT,
template_id TEXT,
label TEXT,
Expand All @@ -28,16 +28,18 @@ CREATE TABLE samply.project
created_at TIMESTAMP NOT NULL,
expires_at DATE,
archived_at TIMESTAMP,
modified_at TIMESTAMP NOT NULL,
query_id BIGINT,
type TEXT
);

CREATE TABLE samply.project_bridgehead
(
id SERIAL NOT NULL PRIMARY KEY,
project_id BIGINT NOT NULL,
bridgehead TEXT NOT NULL,
state TEXT NOT NULL
id SERIAL NOT NULL PRIMARY KEY,
project_id BIGINT NOT NULL,
bridgehead TEXT NOT NULL,
modified_at TIMESTAMP NOT NULL,
state TEXT NOT NULL
);

CREATE TABLE samply.project_bridgehead_user
Expand Down

0 comments on commit e871017

Please sign in to comment.