Skip to content

Commit

Permalink
Merge pull request #93 from TAMULib/issue-92
Browse files Browse the repository at this point in the history
Generate resource identifiers using UUID v3 from URL
  • Loading branch information
wwelling authored Oct 7, 2020
2 parents 1eb31e4 + f339959 commit 3591648
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>edu.tamu</groupId>
<artifactId>ir-iiif-service</artifactId>
<version>0.5.2</version>
<version>0.5.3</version>
<packaging>war</packaging>

<name>IR IIIF Service</name>
Expand Down
25 changes: 5 additions & 20 deletions src/main/java/edu/tamu/iiif/model/RedisResource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.tamu.iiif.model;

import java.util.UUID;

import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.index.Indexed;
Expand All @@ -8,39 +10,22 @@
public class RedisResource {

@Id
private String id;
private final String id;

@Indexed
private String url;

public RedisResource() {
super();
}
private final String url;

public RedisResource(String url) {
this();
this.id = UUID.nameUUIDFromBytes(url.getBytes()).toString();
this.url = url;
}

public RedisResource(String id, String url) {
this(url);
this.id = id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public class ResourceControllerTest {
@MockBean
private ResourceResolver resourceResolver;

private final RedisResource mockResource = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fd1", "http://localhost:9000/fcrepo/rest/image01");
private final RedisResource mockResource = new RedisResource("http://localhost:9000/fcrepo/rest/image01");

private final RedisResource mockResourceNotExist = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fd9", "http://localhost:9000/fcrepo/rest/image02");
private final RedisResource mockResourceNotExist = new RedisResource("http://localhost:9000/fcrepo/rest/image02");

private final RedisResource mockResourceNotExistYet = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fe3", "http://localhost:9000/fcrepo/rest/image03");
private final RedisResource mockResourceNotExistYet = new RedisResource("http://localhost:9000/fcrepo/rest/image03");

private final String resourceWithIdNotFound = String.format("Resource with id %s not found!", mockResourceNotExist.getId());

Expand Down
34 changes: 5 additions & 29 deletions src/test/java/edu/tamu/iiif/model/RedisResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,12 @@
public class RedisResourceTest {

@Test
public void testCreateDefault() {
RedisResource redisResource = new RedisResource();
public void testCreate() {
String url = "http://localhost:900/fcrepo/rest/image02";
RedisResource redisResource = new RedisResource(url);
Assert.assertNotNull(redisResource);
}

@Test
public void testCreateWithUrl() {
RedisResource redisResource = new RedisResource("http://localhost:900/fcrepo/rest/image01");
Assert.assertNotNull(redisResource);
Assert.assertEquals("http://localhost:900/fcrepo/rest/image01", redisResource.getUrl());
}

@Test
public void testCreateComplete() {
String id = UUID.randomUUID().toString();
RedisResource redisResource = new RedisResource(id, "http://localhost:900/fcrepo/rest/image02");
Assert.assertNotNull(redisResource);
Assert.assertEquals(id, redisResource.getId());
Assert.assertEquals("http://localhost:900/fcrepo/rest/image02", redisResource.getUrl());
}

@Test
public void testUpdate() {
RedisResource redisResource = new RedisResource(UUID.randomUUID().toString(), "http://localhost:900/fcrepo/rest/image02");
String id = UUID.randomUUID().toString();
redisResource.setId(id);
redisResource.setUrl("http://localhost:900/fcrepo/rest/image03");
Assert.assertNotNull(redisResource);
Assert.assertEquals(id, redisResource.getId());
Assert.assertEquals("http://localhost:900/fcrepo/rest/image03", redisResource.getUrl());
Assert.assertEquals(UUID.nameUUIDFromBytes(redisResource.getUrl().getBytes()).toString(), redisResource.getId());
Assert.assertEquals(url, redisResource.getUrl());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class RedisResourceResolverTest {

private RedisResourceResolver redisResourceResolver = new RedisResourceResolver();

private final RedisResource mockResource = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fd1", "http://localhost:9000/fcrepo/rest/image01");
private final RedisResource mockResource = new RedisResource("http://localhost:9000/fcrepo/rest/image01");

private final RedisResource mockResourceNotExist = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fd9", "http://localhost:9000/fcrepo/rest/image02");
private final RedisResource mockResourceNotExist = new RedisResource("http://localhost:9000/fcrepo/rest/image02");

@Before
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class RemoteResourceResolverTest {

private RemoteResourceResolver remoteResourceResolver = new RemoteResourceResolver();

private final RedisResource mockResource = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fd1", "http://localhost:9000/fcrepo/rest/image01");
private final RedisResource mockResource = new RedisResource("http://localhost:9000/fcrepo/rest/image01");

private final RedisResource mockResourceNotExist = new RedisResource("26f9b338-f744-11e8-8eb2-f2801f1b9fd9", "http://localhost:9000/fcrepo/rest/image02");
private final RedisResource mockResourceNotExist = new RedisResource("http://localhost:9000/fcrepo/rest/image02");

private final ResolverConfig resolver = new ResolverConfig();

Expand Down

0 comments on commit 3591648

Please sign in to comment.