Skip to content

Commit

Permalink
Remove datastream references from HTML UI controls
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Oct 28, 2014
1 parent feb74ec commit 7880667
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 66 deletions.
61 changes: 25 additions & 36 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraLdp.java
Expand Up @@ -69,7 +69,6 @@
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.Status.UNSUPPORTED_MEDIA_TYPE;
import static javax.ws.rs.core.Response.created;
Expand All @@ -85,7 +84,7 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_DATASTREAM;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_BINARY;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.kernel.impl.services.TransactionServiceImpl.getCurrentTransactionId;
import static org.slf4j.LoggerFactory.getLogger;
Expand Down Expand Up @@ -243,7 +242,7 @@ public Response createOrReplaceObjectRdf(
} else {
final MediaType effectiveContentType
= requestBodyStream == null || requestContentType == null ? null : contentType;
resource = createFedoraResource(null, effectiveContentType, path, contentDisposition);
resource = createFedoraResource(path, effectiveContentType, contentDisposition);

final URI location = getUri(resource);

Expand Down Expand Up @@ -366,8 +365,7 @@ public Response updateSparql(@ContentLocation final InputStream requestBodyStrea
@POST
@Consumes({MediaType.APPLICATION_OCTET_STREAM + ";qs=1001", MediaType.WILDCARD})
@Timed
public Response createObject(@QueryParam("mixin") final String mixin,
@QueryParam("checksum") final String checksum,
public Response createObject(@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Disposition") final ContentDisposition contentDisposition,
@HeaderParam("Content-Type") final MediaType requestContentType,
@HeaderParam("Slug") final String slug,
Expand All @@ -388,9 +386,10 @@ public Response createObject(@QueryParam("mixin") final String mixin,

final MediaType effectiveContentType
= requestBodyStream == null || requestContentType == null ? null : contentType;
final FedoraResource result = createFedoraResource(mixin,
final FedoraResource result = createFedoraResource(
newObjectPath,
effectiveContentType,
newObjectPath, contentDisposition);
contentDisposition);

final RdfStream resourceTriples;

Expand All @@ -405,7 +404,7 @@ public Response createObject(@QueryParam("mixin") final String mixin,
} else {
LOGGER.trace("Received createObject with a request body and content type \"{}\"", contentTypeString);

if ((result instanceof FedoraObject || result instanceof Datastream)
if ((result instanceof FedoraObject)
&& isRdfContentType(contentTypeString)) {
replaceResourceWithStream(result, requestBodyStream, contentType, resourceTriples);
} else if (result instanceof FedoraBinary) {
Expand All @@ -430,7 +429,7 @@ && isRdfContentType(contentTypeString)) {
throw new RepositoryRuntimeException(e);
}

LOGGER.debug("Finished creating {} with path: {}", mixin, newObjectPath);
LOGGER.debug("Finished creating resource with path: {}", newObjectPath);

addCacheControlHeaders(servletResponse, result, session);

Expand Down Expand Up @@ -514,46 +513,36 @@ private void addResourceLinkHeaders(final FedoraResource resource, final boolean

}

private String getRequestedObjectType(final String mixin,
final MediaType requestContentType,
private String getRequestedObjectType(final MediaType requestContentType,
final ContentDisposition contentDisposition) {
String objectType = FEDORA_OBJECT;

if (mixin != null) {
objectType = mixin;
} else {
if (requestContentType != null) {
final String s = requestContentType.toString();
if (!s.equals(contentTypeSPARQLUpdate) && !isRdfContentType(s) || s.equals(TEXT_PLAIN)) {
objectType = FEDORA_DATASTREAM;
}
if (requestContentType != null) {
final String s = requestContentType.toString();
if (!s.equals(contentTypeSPARQLUpdate) && !isRdfContentType(s) || s.equals(TEXT_PLAIN)) {
return FEDORA_BINARY;
}
}

if (contentDisposition != null && contentDisposition.getType().equals("attachment")) {
objectType = FEDORA_DATASTREAM;
}
if (contentDisposition != null && contentDisposition.getType().equals("attachment")) {
return FEDORA_BINARY;
}
return objectType;

return FEDORA_OBJECT;
}

private FedoraResource createFedoraResource(final String requestMixin,
private FedoraResource createFedoraResource(final String path,
final MediaType requestContentType,
final String path,
final ContentDisposition contentDisposition) {
final String objectType = getRequestedObjectType(requestMixin, requestContentType, contentDisposition);
final String objectType = getRequestedObjectType(requestContentType, contentDisposition);

final FedoraResource result;

switch (objectType) {
case FEDORA_OBJECT:
result = objectService.findOrCreateObject(session, path);
break;
case FEDORA_DATASTREAM:
result = binaryService.findOrCreateBinary(session, path);
break;
default:
throw new ClientErrorException("Unknown object type " + objectType, BAD_REQUEST);
if (objectType.equals(FEDORA_BINARY)) {
result = binaryService.findOrCreateBinary(session, path);
} else {
result = objectService.findOrCreateObject(session, path);
}

return result;
}

Expand Down
12 changes: 6 additions & 6 deletions fcrepo-http-api/src/main/resources/views/common-node-actions.vsl
Expand Up @@ -38,9 +38,9 @@
<label for="new_mixin" class="control-label">
Type
</label>
<select id="new_mixin" name="mixin" class="form-control">
<option value="fedora:object">object</option>
<option value="fedora:datastream">datastream</option>
<select id="new_mixin" class="form-control">
<option value="object">object</option>
<option value="binary">binary</option>
</select>
</div>

Expand All @@ -52,11 +52,11 @@
</div>


<div id="datastream_payload_container" class="form-group">
<label for="datastream_payload" class="control-label">
<div id="binary_payload_container" class="form-group">
<label for="binary_payload" class="control-label">
File
</label>
<input type="file" name="file" id="datastream_payload"/>
<input type="file" name="file" id="binary_payload"/>
</div>
<button type="submit" class="btn btn-primary">Add</button>
<hr />
Expand Down
2 changes: 1 addition & 1 deletion fcrepo-http-api/src/main/resources/views/common.css
Expand Up @@ -37,7 +37,7 @@ dd {
padding-left: 35px;
}

#datastream_payload_container {
#binary_payload_container {
display: none;
}

Expand Down
20 changes: 8 additions & 12 deletions fcrepo-http-api/src/main/resources/views/common.js
Expand Up @@ -12,12 +12,8 @@ function addChild()

var postURI = newURI;

if ( mixin != '' ) {
postURI = postURI + "?mixin=" + mixin;
}

if (mixin == "fedora:datastream") {
var update_file = document.getElementById("datastream_payload").files[0];
if (mixin == "binary") {
var update_file = document.getElementById("binary_payload").files[0];
var reader = new FileReader();
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
Expand All @@ -34,7 +30,7 @@ function addChild()
window.location.reload();
}
} else {
ajaxErrorHandler(xhr, "", "Error creating datastream");
ajaxErrorHandler(xhr, "", "Error creating binary");
}
}
};
Expand Down Expand Up @@ -103,10 +99,10 @@ function sendImport() {

$(function() {
$('#new_mixin').change(function() {
if($('#new_mixin').val() == "fedora:datastream") {
$('#datastream_payload_container').show();
if($('#new_mixin').val() == "binary") {
$('#binary_payload_container').show();
} else {
$('#datastream_payload_container').hide();
$('#binary_payload_container').hide();
}
});

Expand Down Expand Up @@ -288,7 +284,7 @@ function updateFile()
if (xhr.status == 204 || xhr.status == 201) {
window.location.reload(true);
} else {
ajaxErrorHandler(xhr, "", "Error creating datastream");
ajaxErrorHandler(xhr, "", "Error updating binary");
}
}
}
Expand All @@ -315,7 +311,7 @@ function updateAccessRoles()
if (xhr.status == 204 || xhr.status == 201) {
window.location.reload(true);
} else {
ajaxErrorHandler(xhr, "", "Error creating datastream");
ajaxErrorHandler(xhr, "", "Error");
}
}
}
Expand Down
Expand Up @@ -716,7 +716,7 @@ public void testCreateNewObject() throws Exception {

when(mockObjectService.findOrCreateObject(mockSession, "/b")).thenReturn(mockObject);

final Response actual = testObj.createObject(null, null, null, null, "b", null);
final Response actual = testObj.createObject(null, null, null, "b", null);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
}
Expand All @@ -728,7 +728,7 @@ public void testCreateNewObjectWithSparql() throws Exception {

when(mockObjectService.findOrCreateObject(mockSession, "/b")).thenReturn(mockObject);

final Response actual = testObj.createObject(null, null, null,
final Response actual = testObj.createObject(null, null,
MediaType.valueOf(contentTypeSPARQLUpdate), "b", toInputStream("x"));

assertEquals(CREATED.getStatusCode(), actual.getStatus());
Expand All @@ -742,7 +742,7 @@ public void testCreateNewObjectWithRdf() throws Exception {

when(mockObjectService.findOrCreateObject(mockSession, "/b")).thenReturn(mockObject);

final Response actual = testObj.createObject(null, null, null, NTRIPLES_TYPE, "b",
final Response actual = testObj.createObject(null, null, NTRIPLES_TYPE, "b",
toInputStream("_:a <info:b> _:c ."));

assertEquals(CREATED.getStatusCode(), actual.getStatus());
Expand All @@ -758,7 +758,7 @@ public void testCreateNewBinary() throws Exception {
when(mockBinaryService.findOrCreateBinary(mockSession, "/b")).thenReturn(mockBinary);

try (final InputStream content = toInputStream("x")) {
final Response actual = testObj.createObject(null, null, null, APPLICATION_OCTET_STREAM_TYPE, "b",
final Response actual = testObj.createObject(null, null, APPLICATION_OCTET_STREAM_TYPE, "b",
content);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
Expand All @@ -771,7 +771,7 @@ public void testPostToBinary() throws Exception {
final FedoraBinary mockObject = (FedoraBinary)setResource(FedoraBinary.class);
doReturn(mockObject).when(testObj).resource();

testObj.createObject(null, null, null, null, null, null);
testObj.createObject(null, null, null, null, null);

}

Expand Down
Expand Up @@ -98,8 +98,8 @@ public void testCreateNewNodeWithProvidedId() throws IOException {
private HtmlPage createAndVerifyObjectWithIdFromRootPage(final String pid) throws IOException {
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlSelect type = form.getSelectByName("mixin");
type.getOptionByValue("fedora:object").setSelected(true);
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("object").setSelected(true);

final HtmlInput new_id = (HtmlInput)page.getElementById("new_id");
new_id.setValueAttribute(pid);
Expand All @@ -122,8 +122,8 @@ public void testCreateNewNodeWithGeneratedId() throws IOException {

final HtmlPage page = javascriptlessWebClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlSelect type = form.getSelectByName("mixin");
type.getOptionByValue("fedora:object").setSelected(true);
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("object").setSelected(true);
final HtmlButton button = form.getFirstByXPath("button");
button.click();

Expand All @@ -144,8 +144,8 @@ public void testCreateNewDatastream() throws IOException {
final HtmlInput slug = form.getInputByName("slug");
slug.setValueAttribute(pid);

final HtmlSelect type = form.getSelectByName("mixin");
type.getOptionByValue("fedora:datastream").setSelected(true);
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("binary").setSelected(true);

final HtmlFileInput fileInput = (HtmlFileInput)page.getElementById("datastream_payload");
fileInput.setData("abcdef".getBytes());
Expand Down

0 comments on commit 7880667

Please sign in to comment.