0.1 #1
7 changed files with 30 additions and 29 deletions
|
@ -26,10 +26,9 @@ public class ArtifactDto {
|
||||||
@NotNull
|
@NotNull
|
||||||
private Path path;
|
private Path path;
|
||||||
|
|
||||||
@Schema(type = "integer", format = "int64",
|
@Schema(type = "integer", format = "int64", accessMode = AccessMode.READ_ONLY,
|
||||||
description = "Upload time in milliseconds since the unix epoch 01.01.1970 00:00:00 UTC")
|
description = "Creation time in milliseconds since the unix epoch 01.01.1970 00:00:00 UTC")
|
||||||
@Builder.Default
|
private Instant creationTime;
|
||||||
private Instant uploadTime = Instant.now();
|
|
||||||
|
|
||||||
@Schema(accessMode = AccessMode.READ_ONLY, type = "boolean",
|
@Schema(accessMode = AccessMode.READ_ONLY, type = "boolean",
|
||||||
description = "Whether the artifact was successfully persisted in the archive.")
|
description = "Whether the artifact was successfully persisted in the archive.")
|
||||||
|
|
|
@ -24,11 +24,10 @@ public class FlingDto {
|
||||||
@NotNull
|
@NotNull
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(type = "integer", format = "int64",
|
@Schema(type = "integer", format = "int64", accessMode = AccessMode.READ_ONLY,
|
||||||
description = "Creation time in milliseconds since the unix epoch 01.01.1970 00:00:00 UTC")
|
description = "Creation time in milliseconds since the unix epoch 01.01.1970 00:00:00 UTC")
|
||||||
@NotNull
|
@NotNull
|
||||||
@Builder.Default
|
private Instant creationTime;
|
||||||
private Instant creationTime = Instant.now();
|
|
||||||
|
|
||||||
@Schema(description = "Share id of the fling. Used in the share link.")
|
@Schema(description = "Share id of the fling. Used in the share link.")
|
||||||
private String shareId;
|
private String shareId;
|
||||||
|
|
|
@ -9,6 +9,9 @@ import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Version;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@ -24,9 +27,6 @@ public class ArtifactEntity {
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Path path;
|
private Path path;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
private Instant uploadTime = Instant.now();
|
|
||||||
|
|
||||||
@Column(unique = true, nullable = true)
|
@Column(unique = true, nullable = true)
|
||||||
private String archiveId;
|
private String archiveId;
|
||||||
|
|
||||||
|
@ -35,4 +35,13 @@ public class ArtifactEntity {
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
private FlingEntity fling;
|
private FlingEntity fling;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private Instant creationTime;
|
||||||
|
|
||||||
|
@UpdateTimestamp
|
||||||
|
private Instant updateTime;
|
||||||
|
|
||||||
|
@Version
|
||||||
|
private Long version;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.friedl.fling.persistence.entities;
|
package net.friedl.fling.persistence.entities;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
@ -10,6 +11,9 @@ import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Version;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@ -24,8 +28,6 @@ public class FlingEntity {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private Instant creationTime = Instant.now();
|
|
||||||
|
|
||||||
private Instant expirationTime;
|
private Instant expirationTime;
|
||||||
|
|
||||||
private Integer expirationClicks;
|
private Integer expirationClicks;
|
||||||
|
@ -46,4 +48,13 @@ public class FlingEntity {
|
||||||
|
|
||||||
@OneToMany(mappedBy = "fling", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "fling", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private Set<ArtifactEntity> artifacts;
|
private Set<ArtifactEntity> artifacts;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private Date creationTime;
|
||||||
|
|
||||||
|
@UpdateTimestamp
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Version
|
||||||
|
private Long version;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@ import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -71,18 +69,15 @@ public class ArtifactServiceTest {
|
||||||
public void beforeEach() {
|
public void beforeEach() {
|
||||||
this.artifactEntity1 = new ArtifactEntity();
|
this.artifactEntity1 = new ArtifactEntity();
|
||||||
artifactEntity1.setId(UUID.randomUUID());
|
artifactEntity1.setId(UUID.randomUUID());
|
||||||
artifactEntity1.setUploadTime(Instant.EPOCH);
|
|
||||||
artifactEntity1.setPath(Path.of("artifact1"));
|
artifactEntity1.setPath(Path.of("artifact1"));
|
||||||
|
|
||||||
this.artifactEntity2 = new ArtifactEntity();
|
this.artifactEntity2 = new ArtifactEntity();
|
||||||
artifactEntity2.setId(UUID.randomUUID());
|
artifactEntity2.setId(UUID.randomUUID());
|
||||||
artifactEntity2.setUploadTime(Instant.EPOCH.plus(12000, ChronoUnit.DAYS));
|
|
||||||
artifactEntity2.setPath(Path.of("/", "/sub", "artifact2"));
|
artifactEntity2.setPath(Path.of("/", "/sub", "artifact2"));
|
||||||
|
|
||||||
this.flingEntity = new FlingEntity();
|
this.flingEntity = new FlingEntity();
|
||||||
flingEntity.setId(UUID.randomUUID());
|
flingEntity.setId(UUID.randomUUID());
|
||||||
flingEntity.setName("fling");
|
flingEntity.setName("fling");
|
||||||
flingEntity.setCreationTime(Instant.now());
|
|
||||||
|
|
||||||
when(flingRepository.save(any())).then(new Answer<FlingEntity>() {
|
when(flingRepository.save(any())).then(new Answer<FlingEntity>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,19 +106,16 @@ public class ArtifactServiceTest {
|
||||||
ArtifactDto artifactDto = artifactService.getById(artifactEntity1.getId());
|
ArtifactDto artifactDto = artifactService.getById(artifactEntity1.getId());
|
||||||
assertThat(artifactDto.getId(), equalTo(artifactEntity1.getId()));
|
assertThat(artifactDto.getId(), equalTo(artifactEntity1.getId()));
|
||||||
assertThat(artifactDto.getPath(), equalTo(artifactEntity1.getPath()));
|
assertThat(artifactDto.getPath(), equalTo(artifactEntity1.getPath()));
|
||||||
assertThat(artifactDto.getUploadTime(), equalTo(artifactEntity1.getUploadTime()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create_createsArtifact_ok() {
|
public void create_createsArtifact_ok() {
|
||||||
ArtifactDto artifactToCreate = ArtifactDto.builder()
|
ArtifactDto artifactToCreate = ArtifactDto.builder()
|
||||||
.uploadTime(Instant.now())
|
|
||||||
.path(Path.of("new", "artifacts"))
|
.path(Path.of("new", "artifacts"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ArtifactDto createdArtifact = artifactService.create(flingEntity.getId(), artifactToCreate);
|
ArtifactDto createdArtifact = artifactService.create(flingEntity.getId(), artifactToCreate);
|
||||||
|
|
||||||
assertThat(createdArtifact.getUploadTime(), equalTo(artifactToCreate.getUploadTime()));
|
|
||||||
assertThat(createdArtifact.getPath(), equalTo(artifactToCreate.getPath()));
|
assertThat(createdArtifact.getPath(), equalTo(artifactToCreate.getPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -88,13 +87,11 @@ public class FlingServiceTest {
|
||||||
flingEntity1.setId(UUID.randomUUID());
|
flingEntity1.setId(UUID.randomUUID());
|
||||||
flingEntity1.setName("fling1");
|
flingEntity1.setName("fling1");
|
||||||
flingEntity1.setAuthCode("testhash");
|
flingEntity1.setAuthCode("testhash");
|
||||||
flingEntity1.setCreationTime(Instant.now());
|
|
||||||
|
|
||||||
this.flingEntity2 = new FlingEntity();
|
this.flingEntity2 = new FlingEntity();
|
||||||
flingEntity2.setId(UUID.randomUUID());
|
flingEntity2.setId(UUID.randomUUID());
|
||||||
flingEntity2.setName("fling2");
|
flingEntity2.setName("fling2");
|
||||||
flingEntity2.setShareId("shareId2");
|
flingEntity2.setShareId("shareId2");
|
||||||
flingEntity2.setCreationTime(Instant.now());
|
|
||||||
|
|
||||||
when(flingRepository.save(any())).then(new Answer<FlingEntity>() {
|
when(flingRepository.save(any())).then(new Answer<FlingEntity>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,8 +18,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -273,14 +271,12 @@ public class FileSystemArchiveTest {
|
||||||
// Fling1/Artifact1
|
// Fling1/Artifact1
|
||||||
this.artifactEntity1 = new ArtifactEntity();
|
this.artifactEntity1 = new ArtifactEntity();
|
||||||
artifactEntity1.setId(UUID.randomUUID());
|
artifactEntity1.setId(UUID.randomUUID());
|
||||||
artifactEntity1.setUploadTime(Instant.EPOCH);
|
|
||||||
artifactEntity1.setPath(Path.of("artifact1"));
|
artifactEntity1.setPath(Path.of("artifact1"));
|
||||||
artifactEntity1.setArchived(true);
|
artifactEntity1.setArchived(true);
|
||||||
|
|
||||||
this.flingEntity1 = new FlingEntity();
|
this.flingEntity1 = new FlingEntity();
|
||||||
flingEntity1.setId(new UUID(0, 0));
|
flingEntity1.setId(new UUID(0, 0));
|
||||||
flingEntity1.setName("fling1");
|
flingEntity1.setName("fling1");
|
||||||
flingEntity1.setCreationTime(Instant.now());
|
|
||||||
|
|
||||||
artifactEntity1.setFling(flingEntity1);
|
artifactEntity1.setFling(flingEntity1);
|
||||||
|
|
||||||
|
@ -288,14 +284,12 @@ public class FileSystemArchiveTest {
|
||||||
// Fling2/Artifact2
|
// Fling2/Artifact2
|
||||||
this.artifactEntity2 = new ArtifactEntity();
|
this.artifactEntity2 = new ArtifactEntity();
|
||||||
artifactEntity2.setId(UUID.randomUUID());
|
artifactEntity2.setId(UUID.randomUUID());
|
||||||
artifactEntity2.setUploadTime(Instant.EPOCH.plus(12000, ChronoUnit.DAYS));
|
|
||||||
artifactEntity2.setPath(Path.of("/", "/sub", "artifact2"));
|
artifactEntity2.setPath(Path.of("/", "/sub", "artifact2"));
|
||||||
artifactEntity2.setArchived(false);
|
artifactEntity2.setArchived(false);
|
||||||
|
|
||||||
this.flingEntity2 = new FlingEntity();
|
this.flingEntity2 = new FlingEntity();
|
||||||
flingEntity2.setId(new UUID(1, 0));
|
flingEntity2.setId(new UUID(1, 0));
|
||||||
flingEntity2.setName("fling2");
|
flingEntity2.setName("fling2");
|
||||||
flingEntity2.setCreationTime(Instant.EPOCH);
|
|
||||||
|
|
||||||
artifactEntity2.setFling(flingEntity2);
|
artifactEntity2.setFling(flingEntity2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue