Navigation Menu

Skip to content

Commit

Permalink
wire in an import action (and makke the whole repository exportable too)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 21, 2013
1 parent c5dc19f commit 35e3ae7
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 16 deletions.
@@ -0,0 +1,24 @@

package org.fcrepo.api.repository;

import javax.jcr.Session;
import javax.ws.rs.Path;
import org.fcrepo.api.FedoraImport;
import org.fcrepo.session.InjectedSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
* This stub is a hack to mount the functionality of FedoraImport at
* the root of this webapp. Without it, the globbing from FedoraNodes would
* own this path instead.
*/
@Component
@Scope("prototype")
@Path("/fcr:export")
public class FedoraRepositoryExport extends FedoraImport {

@InjectedSession
protected Session session;

}
26 changes: 13 additions & 13 deletions fcrepo-http-api/src/main/java/org/fcrepo/url/HttpApiResources.java
Expand Up @@ -22,10 +22,10 @@
import org.fcrepo.api.FedoraFieldSearch;
import org.fcrepo.api.FedoraFixity;
import org.fcrepo.api.FedoraSitemap;
import org.fcrepo.api.FedoraTransactions;
import org.fcrepo.api.FedoraVersions;
import org.fcrepo.api.rdf.UriAwareResourceModelFactory;
import org.fcrepo.api.repository.FedoraRepositoryNamespaces;
import org.fcrepo.api.repository.FedoraRepositoryTransactions;
import org.fcrepo.rdf.GraphSubjects;
import org.fcrepo.serialization.SerializerUtil;
import org.fcrepo.utils.FedoraJcrTypes;
Expand Down Expand Up @@ -61,6 +61,17 @@ public Model createModelForResource(final FedoraResource resource,
addContentStatements(resource, uriInfo, model, s);
}

// fcr:export?format=xyz
for (final String key : serializers.keySet()) {
final Map<String, String> pathMap =
of("path", resource.getPath().substring(1));
final Resource format = model.createResource(uriInfo
.getBaseUriBuilder().path(FedoraExport.class).queryParam("format", key)
.buildFromMap(pathMap).toASCIIString());
model.add(s, HAS_SERIALIZATION, format);
model.add(format, RDFS_LABEL, key);
}

return model;
}

Expand All @@ -75,17 +86,6 @@ private void addContentStatements(FedoraResource resource, UriInfo uriInfo, Mode

private void addNodeStatements(FedoraResource resource, UriInfo uriInfo, Model model, Resource s) throws RepositoryException {

// fcr:export?format=xyz
for (final String key : serializers.keySet()) {
final Map<String, String> pathMap =
of("path", resource.getPath().substring(1));
final Resource format = model.createResource(uriInfo
.getBaseUriBuilder().path(FedoraExport.class).queryParam("format", key)
.buildFromMap(pathMap).toASCIIString());
model.add(s, HAS_SERIALIZATION, format);
model.add(format, RDFS_LABEL, key);
}

// fcr:versions
final Map<String, String> pathMap =
of("path", resource.getPath().substring(1));
Expand All @@ -107,7 +107,7 @@ private void addRepositoryStatements(UriInfo uriInfo, Model model, Resource s) {

// fcr:tx
model.add(s, HAS_TRANSACTION_SERVICE, model.createResource(uriInfo
.getBaseUriBuilder().path(FedoraTransactions.class).build()
.getBaseUriBuilder().path(FedoraRepositoryTransactions.class).build()
.toASCIIString()));

// fcr:namespaces
Expand Down
26 changes: 23 additions & 3 deletions fcrepo-http-api/src/main/resources/views/common-node-actions.vsl
Expand Up @@ -20,9 +20,9 @@
<input type="file" id="update_file"/>
</label>
<button type="submit" class="btn btn-primary">Add</button>
<hr />
</form>

<hr />

<form id="action_sparql_update">
<h3>Update Properties</h3>
Expand All @@ -33,16 +33,16 @@ INSERT { }
WHERE { }
</textarea>
<button type="submit" class="btn btn-primary">Update</button>
<hr />
</form>

<hr />

<form id="action_delete" action="javascript:deleteItem()">
<h3>Delete Object</h3>
<button type="submit" class="btn btn-danger">Delete</button>
<hr />
</form>

<hr />

#set ($serializations = $rdf.find($nodeany, $topic, $helpers.asNode($rdfLexicon.HAS_SERIALIZATION), $nodeany))

Expand All @@ -59,4 +59,24 @@ WHERE { }
#end
</ul>
</div>
<hr />
#end


#set ($serializations = $rdf.find($nodeany, $topic, $helpers.asNode($rdfLexicon.HAS_SERIALIZATION), $nodeany))

#if($serializations.hasNext())
<form id="action_import">
<h3>Import</h3>

<input type="file" id="import_file"/>

<select id="import_format" name="format">
#foreach($quad in $helpers.getSortedTriples($model, $serializations))
<option>$helpers.getObjectTitle($rdf, $quad.getObject())</option>
#end
</select>
<button type="submit" class="btn">Import</button>
</form>

#end
4 changes: 4 additions & 0 deletions fcrepo-http-api/src/main/resources/views/common.css
Expand Up @@ -9,6 +9,10 @@ body { padding-top: 40px; }
display: none;
}

.nt_file #action_import, .nt_resource #action_import {
display: none;
}

.well {
text-indent: -35px;
padding-left: 54px;
Expand Down
31 changes: 31 additions & 0 deletions fcrepo-http-api/src/main/resources/views/common.js
Expand Up @@ -61,6 +61,36 @@ function addChild()
return false;
}

function sendImport() {
var mixin = $("#import_format").val();
var postURI = $('#main').attr('resource') + "/fcr:import?format=" + mixin;

var update_file = document.getElementById("import_file").files[0];
var reader = new FileReader();
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
window.location.reload();
}
}

xhr.open( "POST", postURI );

xhr.setRequestHeader("Content-type", update_file.type || "application/octet-stream");
reader.onload = function(e) {
var result = e.target.result;
var data = new Uint8Array(result.length);
for (var i = 0; i < result.length; i++) {
data[i] = (result.charCodeAt(i) & 0xff);
}
xhr.send(data.buffer);
};
reader.readAsBinaryString(update_file);

return false;

}

$(function() {
$('#new_mixin').change(function() {
if($('#new_mixin').val() == "fedora:datastream") {
Expand All @@ -77,6 +107,7 @@ $(function() {
$('#action_create_transaction').submit(submitAndFollowLocation);
$('#action_rollback_transaction').submit(submitAndRedirectToBase);
$('#action_commit_transaction').submit(submitAndRedirectToBase);
$('#action_import').submit(sendImport);

});

Expand Down
Expand Up @@ -86,5 +86,29 @@ public void shouldMoveObjectToTheRootLevelUsingTheRepositoryWideApi() throws IOE

}



@Test
public void shouldExportUsingTheRepositoryWideApi() throws IOException {
final String objName = "JcrXmlSerializerIT2";

// set up the object
client.execute(postObjMethod(objName));
client.execute(postDSMethod(objName, "testDS", "stuff"));

// export it
logger.debug("Attempting to export: " + objName);
final HttpGet getObjMethod =
new HttpGet(serverAddress + "objects/JcrXmlSerializerIT2" + "/fcr:export");
HttpResponse response = client.execute(getObjMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
logger.debug("Successfully exported: " + objName);
final String content = EntityUtils.toString(response.getEntity());
logger.debug("Found exported object: " + content);



}

}

0 comments on commit 35e3ae7

Please sign in to comment.