Skip to content

Commit

Permalink
Adding FedoraResource.setURIProperty method
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Apr 23, 2015
1 parent 48610ce commit 0a7b1d4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Expand Up @@ -37,6 +37,7 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand All @@ -48,6 +49,7 @@
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
Expand Down Expand Up @@ -261,6 +263,15 @@ public Property getProperty(final String relPath) {
}
}

@Override
public void setURIProperty(final String relPath, final URI value) {
try {
getNode().setProperty(relPath, value.toString(), PropertyType.URI);
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}

@Override
public void delete() {
try {
Expand Down
Expand Up @@ -41,6 +41,8 @@
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -669,6 +671,23 @@ public void testGetChildrenHidesHashUris() {
assertFalse(container.getChildren().hasNext());
}

@Test
public void testSetURIProperty() throws URISyntaxException, RepositoryException {
final String pid1 = getRandomPid();
final String pid2 = getRandomPid();
final String prop = "premis:hasEventRelatedObject";
final FedoraResource resource1 = containerService.findOrCreate(session, "/" + pid1);
final FedoraResource resource2 = containerService.findOrCreate(session, "/" + pid2);
final String uri = createGraphSubjectNode(resource2).getURI();
resource1.setURIProperty(prop, new URI(uri));
resource2.delete();
session.save();

// URI property should survive the linked resource being deleted
assertTrue(resource1.hasProperty(prop));
assertEquals(resource1.getProperty(prop).getString(), uri);
}

@Test
public void testGetUnfrozenResource() throws RepositoryException {
final String pid = getRandomPid();
Expand Down
Expand Up @@ -38,13 +38,16 @@
import static org.mockito.MockitoAnnotations.initMocks;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
Expand Down Expand Up @@ -394,6 +397,14 @@ public void testGetProperty() throws RepositoryException {
assertEquals(mockProp, actual);
}

@Test
public void testSetURIProperty() throws URISyntaxException, RepositoryException {
final String prop = "premis:hasEventRelatedObject";
final String uri = "http://localhost:8080/rest/1";
testObj.setURIProperty(prop, new URI(uri));
verify(mockNode).setProperty(prop, uri, PropertyType.URI);
}

@Test
public void testEquals() {
assertEquals(new FedoraResourceImpl(mockNode), new FedoraResourceImpl(mockNode));
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.fcrepo.kernel.models;

import java.net.URI;
import java.util.Date;
import java.util.Iterator;

Expand Down Expand Up @@ -83,6 +84,13 @@ public interface FedoraResource {
*/
Property getProperty(String relPath);

/**
* Set the given property value for this resource
* @param relPath the given path
* @param value the URI value
*/
void setURIProperty(String relPath, URI value);

/**
* Delete this resource, and any inbound references to it
*/
Expand Down

0 comments on commit 0a7b1d4

Please sign in to comment.