Skip to content

Commit

Permalink
generate resource identifiers using UUID v3 from url
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Oct 7, 2020
1 parent 1eb31e4 commit c223802
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 49 deletions.
23 changes: 3 additions & 20 deletions src/main/java/edu/tamu/iiif/model/RedisResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,22 @@
public class RedisResource {

@Id
private String id;
private final String id;

@Indexed
private String url;

public RedisResource() {
super();
}

public RedisResource(String url) {
this();
this.url = url;
}
private final String url;

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

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 @@ -2,6 +2,7 @@

import java.net.URISyntaxException;
import java.util.Optional;
import java.util.UUID;

import org.apache.commons.validator.routines.UrlValidator;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -36,7 +37,7 @@ public String create(String url) throws URISyntaxException {
if (!URL_VALIDATOR.isValid(url)) {
throw new URISyntaxException(url, "Not a valid URL");
}
return redisResourceRepo.save(new RedisResource(url)).getId();
return redisResourceRepo.save(new RedisResource(UUID.nameUUIDFromBytes(url.getBytes()).toString(), url)).getId();
}

public String resolve(String id) throws NotFoundException {
Expand Down
33 changes: 5 additions & 28 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,13 @@
public class RedisResourceTest {

@Test
public void testCreateDefault() {
RedisResource redisResource = new RedisResource();
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");
public void testCreate() {
String url = "http://localhost:900/fcrepo/rest/image02";
String id = UUID.nameUUIDFromBytes(url.getBytes()).toString();
RedisResource redisResource = new RedisResource(id, url);
Assert.assertNotNull(redisResource);
Assert.assertEquals(id, redisResource.getId());
Assert.assertEquals("http://localhost:900/fcrepo/rest/image03", redisResource.getUrl());
Assert.assertEquals(url, redisResource.getUrl());
}

}

0 comments on commit c223802

Please sign in to comment.