0.1 #1

Merged
armin merged 30 commits from 0.1 into master 2020-07-26 00:51:55 +00:00
7 changed files with 30 additions and 29 deletions
Showing only changes of commit c663ec5e73 - Show all commits

View file

@ -26,10 +26,9 @@ public class ArtifactDto {
@NotNull
private Path path;
@Schema(type = "integer", format = "int64",
description = "Upload time in milliseconds since the unix epoch 01.01.1970 00:00:00 UTC")
@Builder.Default
private Instant uploadTime = Instant.now();
@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")
private Instant creationTime;
@Schema(accessMode = AccessMode.READ_ONLY, type = "boolean",
description = "Whether the artifact was successfully persisted in the archive.")

View file

@ -24,11 +24,10 @@ public class FlingDto {
@NotNull
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")
@NotNull
@Builder.Default
private Instant creationTime = Instant.now();
private Instant creationTime;
@Schema(description = "Share id of the fling. Used in the share link.")
private String shareId;

View file

@ -9,6 +9,9 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import lombok.Getter;
import lombok.Setter;
@ -24,9 +27,6 @@ public class ArtifactEntity {
@Column(nullable = false)
private Path path;
@Column(nullable = false)
private Instant uploadTime = Instant.now();
@Column(unique = true, nullable = true)
private String archiveId;
@ -35,4 +35,13 @@ public class ArtifactEntity {
@ManyToOne(optional = false)
private FlingEntity fling;
@CreationTimestamp
private Instant creationTime;
@UpdateTimestamp
private Instant updateTime;
@Version
private Long version;
}

View file

@ -1,6 +1,7 @@
package net.friedl.fling.persistence.entities;
import java.time.Instant;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
@ -10,6 +11,9 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import lombok.Getter;
import lombok.Setter;
@ -24,8 +28,6 @@ public class FlingEntity {
private String name;
private Instant creationTime = Instant.now();
private Instant expirationTime;
private Integer expirationClicks;
@ -46,4 +48,13 @@ public class FlingEntity {
@OneToMany(mappedBy = "fling", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<ArtifactEntity> artifacts;
@CreationTimestamp
private Date creationTime;
@UpdateTimestamp
private Date updateTime;
@Version
private Long version;
}

View file

@ -7,8 +7,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -71,18 +69,15 @@ public class ArtifactServiceTest {
public void beforeEach() {
this.artifactEntity1 = new ArtifactEntity();
artifactEntity1.setId(UUID.randomUUID());
artifactEntity1.setUploadTime(Instant.EPOCH);
artifactEntity1.setPath(Path.of("artifact1"));
this.artifactEntity2 = new ArtifactEntity();
artifactEntity2.setId(UUID.randomUUID());
artifactEntity2.setUploadTime(Instant.EPOCH.plus(12000, ChronoUnit.DAYS));
artifactEntity2.setPath(Path.of("/", "/sub", "artifact2"));
this.flingEntity = new FlingEntity();
flingEntity.setId(UUID.randomUUID());
flingEntity.setName("fling");
flingEntity.setCreationTime(Instant.now());
when(flingRepository.save(any())).then(new Answer<FlingEntity>() {
@Override
@ -111,19 +106,16 @@ public class ArtifactServiceTest {
ArtifactDto artifactDto = artifactService.getById(artifactEntity1.getId());
assertThat(artifactDto.getId(), equalTo(artifactEntity1.getId()));
assertThat(artifactDto.getPath(), equalTo(artifactEntity1.getPath()));
assertThat(artifactDto.getUploadTime(), equalTo(artifactEntity1.getUploadTime()));
}
@Test
public void create_createsArtifact_ok() {
ArtifactDto artifactToCreate = ArtifactDto.builder()
.uploadTime(Instant.now())
.path(Path.of("new", "artifacts"))
.build();
ArtifactDto createdArtifact = artifactService.create(flingEntity.getId(), artifactToCreate);
assertThat(createdArtifact.getUploadTime(), equalTo(artifactToCreate.getUploadTime()));
assertThat(createdArtifact.getPath(), equalTo(artifactToCreate.getPath()));
}

View file

@ -13,7 +13,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@ -88,13 +87,11 @@ public class FlingServiceTest {
flingEntity1.setId(UUID.randomUUID());
flingEntity1.setName("fling1");
flingEntity1.setAuthCode("testhash");
flingEntity1.setCreationTime(Instant.now());
this.flingEntity2 = new FlingEntity();
flingEntity2.setId(UUID.randomUUID());
flingEntity2.setName("fling2");
flingEntity2.setShareId("shareId2");
flingEntity2.setCreationTime(Instant.now());
when(flingRepository.save(any())).then(new Answer<FlingEntity>() {
@Override

View file

@ -18,8 +18,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@ -273,14 +271,12 @@ public class FileSystemArchiveTest {
// Fling1/Artifact1
this.artifactEntity1 = new ArtifactEntity();
artifactEntity1.setId(UUID.randomUUID());
artifactEntity1.setUploadTime(Instant.EPOCH);
artifactEntity1.setPath(Path.of("artifact1"));
artifactEntity1.setArchived(true);
this.flingEntity1 = new FlingEntity();
flingEntity1.setId(new UUID(0, 0));
flingEntity1.setName("fling1");
flingEntity1.setCreationTime(Instant.now());
artifactEntity1.setFling(flingEntity1);
@ -288,14 +284,12 @@ public class FileSystemArchiveTest {
// Fling2/Artifact2
this.artifactEntity2 = new ArtifactEntity();
artifactEntity2.setId(UUID.randomUUID());
artifactEntity2.setUploadTime(Instant.EPOCH.plus(12000, ChronoUnit.DAYS));
artifactEntity2.setPath(Path.of("/", "/sub", "artifact2"));
artifactEntity2.setArchived(false);
this.flingEntity2 = new FlingEntity();
flingEntity2.setId(new UUID(1, 0));
flingEntity2.setName("fling2");
flingEntity2.setCreationTime(Instant.EPOCH);
artifactEntity2.setFling(flingEntity2);
}