Skip to content

Commit

Permalink
Removing mix:versionable from fedora:resource definition, which disab…
Browse files Browse the repository at this point in the history
…les automatic versioning by default
  • Loading branch information
escowles committed Mar 18, 2014
1 parent cd363f9 commit 01790aa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
Expand Up @@ -19,11 +19,13 @@
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import static org.fcrepo.http.commons.test.util.TestHelpers.parseTriples;
import static org.junit.Assert.assertEquals;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

Expand All @@ -35,6 +37,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -180,4 +183,20 @@ protected HttpResponse setProperty(final String pid, final String txId,
return dcResp;
}

protected static void addMixin(final String pid, final String mixinUrl) throws IOException {
final HttpPatch updateObjectGraphMethod =
new HttpPatch(serverAddress + pid);
updateObjectGraphMethod.addHeader("Content-Type",
"application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();

e.setContent(new ByteArrayInputStream(
("INSERT DATA { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + mixinUrl + "> . } ")
.getBytes()));
updateObjectGraphMethod.setEntity(e);
final HttpResponse response = client.execute(updateObjectGraphMethod);
assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine()
.getStatusCode());
}

}
Expand Up @@ -372,6 +372,7 @@ public void verifyFullSetOfRdfTypes() throws Exception {
logger.debug("Entering verifyFullSetOfRdfTypes()...");
final String pid = "FedoraGraphWithRdfTypes";
createObject(pid);
addMixin( "FedoraGraphWithRdfTypes", "http://www.jcp.org/jcr/mix/1.0versionable");

final HttpGet getObjMethod =
new HttpGet(serverAddress + pid);
Expand Down Expand Up @@ -984,4 +985,33 @@ public String getMethod() {
}

}

/**
* I should be able to upload a file to a read/write federated filesystem.
**/
@Test
public void testUploadToProjection() throws IOException {
// upload file to federated filesystem using rest api
final String uploadLocation = serverAddress + "files/upload/ds1/fcr:content";
final String uploadContent = "abc123";
logger.debug("Uploading to federated filesystem via rest api: " + uploadLocation);
final HttpPost post = postDSMethod("files/upload", "ds1", uploadContent);
final HttpResponse response = client.execute(post);
assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode());
final String actualLocation = response.getFirstHeader("Location").getValue();
assertEquals("Wrong URI in Location header", uploadLocation, actualLocation);

// validate content
final HttpGet get = new HttpGet(uploadLocation);
final HttpResponse getResponse = client.execute(get);
final String actualContent = EntityUtils.toString( getResponse.getEntity() );
assertEquals(OK.getStatusCode(), getResponse.getStatusLine().getStatusCode());
assertEquals("Content doesn't match", actualContent, uploadContent);

// validate object profile
final HttpGet objGet = new HttpGet(serverAddress + "files/upload");
final HttpResponse objResponse = client.execute(objGet);
assertEquals(OK.getStatusCode(), objResponse.getStatusLine().getStatusCode());
}

}
Expand Up @@ -61,6 +61,7 @@ public void testGetObjectVersionProfile() throws Exception {
final String pid = UUID.randomUUID().toString();

createObject(pid);
addMixin( pid, "http://www.jcp.org/jcr/mix/1.0versionable");
final HttpGet getVersion =
new HttpGet(serverAddress + pid + "/fcr:versions");
logger.debug("Retrieved version profile:");
Expand All @@ -74,6 +75,7 @@ public void testGetObjectVersionProfile() throws Exception {
public void testAddAndRetrieveVersion() throws Exception {
final String pid = UUID.randomUUID().toString();
createObject(pid);
addMixin( pid, "http://www.jcp.org/jcr/mix/1.0versionable");

logger.info("Setting a title");
patchLiteralProperty(serverAddress + pid, "http://purl.org/dc/elements/1.1/title", "First Title");
Expand Down Expand Up @@ -102,6 +104,7 @@ public void testAddAndRetrieveVersion() throws Exception {
public void testVersioningANodeWithAVersionableChild() throws Exception {
final String pid = UUID.randomUUID().toString();
createObject(pid);
addMixin( pid, "http://www.jcp.org/jcr/mix/1.0versionable");

logger.info("Adding a child");
createDatastream(pid, "ds", "This DS will not be versioned");
Expand Down Expand Up @@ -132,6 +135,7 @@ public void testCreateUnlabeledVersion() throws Exception {
logger.info("Creating an object");
final String objId = UUID.randomUUID().toString();
createObject(objId);
addMixin( objId, "http://www.jcp.org/jcr/mix/1.0versionable");

logger.info("Setting a title");
patchLiteralProperty(serverAddress + objId, "http://purl.org/dc/elements/1.1/title", "Example Title");
Expand All @@ -145,6 +149,7 @@ public void testCreateTwoVersionsWithSameLabel() throws Exception {
logger.info("creating an object");
final String objId = UUID.randomUUID().toString();
createObject(objId);
addMixin( objId, "http://www.jcp.org/jcr/mix/1.0versionable");

logger.info("Setting a title");
patchLiteralProperty(serverAddress + objId, "http://purl.org/dc/elements/1.1/title", "First title");
Expand Down Expand Up @@ -174,7 +179,9 @@ public void testGetDatastreamVersionNotFound() throws Exception {
final String pid = randomUUID().toString();

createObject(pid);
addMixin( pid, "http://www.jcp.org/jcr/mix/1.0versionable");
createDatastream(pid, "ds1", "foo");
addMixin( pid + "/ds1", "http://www.jcp.org/jcr/mix/1.0versionable");

final HttpGet getVersion =
new HttpGet(serverAddress
Expand Down Expand Up @@ -205,6 +212,7 @@ public void isAutoVersionedContentStillAccessible() throws Exception {

createObject(objName);
createDatastream(objName, dsName, firstVersionText);
addMixin( objName + "/" + dsName, "http://www.jcp.org/jcr/mix/1.0versionable");

setAutoVersioning(serverAddress + objName + "/" + dsName);

Expand Down Expand Up @@ -238,7 +246,7 @@ public void testAddMixinAutoVersioning() throws IOException {
final String objName = UUID.randomUUID().toString();

createObject(objName);
addMixin(serverAddress + objName, "http://fedora.info/definitions/v4/rest-api#autoVersioned");
addMixin(objName, "http://fedora.info/definitions/v4/rest-api#autoVersioned");

final GraphStore initialVersion = getContent(serverAddress + objName);
assertTrue("Should find auto-created versioning policy", initialVersion
Expand Down Expand Up @@ -349,22 +357,6 @@ private static void patchLiteralProperty(final String url, final String predicat
.getStatusCode());
}

private static void addMixin(final String url, final String mixinUrl) throws IOException {
final HttpPatch updateObjectGraphMethod =
new HttpPatch(url);
updateObjectGraphMethod.addHeader("Content-Type",
"application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();

e.setContent(new ByteArrayInputStream(
("INSERT DATA { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + mixinUrl + "> . } ")
.getBytes()));
updateObjectGraphMethod.setEntity(e);
final HttpResponse response = client.execute(updateObjectGraphMethod);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatusLine()
.getStatusCode());
}

private GraphStore getContent(final String url) throws IOException {
final HttpGet getVersion = new HttpGet(url);
return getGraphStore(getVersion);
Expand Down
2 changes: 1 addition & 1 deletion fcrepo-kernel/src/main/resources/fedora-node-types.cnd
Expand Up @@ -88,7 +88,7 @@
/*
* Any Fedora resource.
*/
[fedora:resource] > fedora:relations, mix:created, mix:lastModified, mix:lockable, mix:versionable, dc:describable mixin
[fedora:resource] > fedora:relations, mix:created, mix:lastModified, mix:lockable, mix:referenceable, dc:describable mixin
- rdf:type (URI) multiple
- * (undefined) multiple
- * (undefined)
Expand Down
Expand Up @@ -422,6 +422,8 @@ public void testAddVersionLabel() throws RepositoryException {
final FedoraResource object =
objectService.createObject(session, "/testObjectVersionLabel");

object.getNode().addMixin("mix:versionable");

session.save();

object.addVersionLabel("v0.0.1");
Expand All @@ -439,6 +441,8 @@ public void testGetObjectVersionGraph() throws RepositoryException {
final FedoraResource object =
objectService.createObject(session, "/testObjectVersionGraph");

object.getNode().addMixin("mix:versionable");

session.save();

object.addVersionLabel("v0.0.1");
Expand Down

0 comments on commit 01790aa

Please sign in to comment.