Skip to content

Commit

Permalink
Merge pull request #8 from TAMULib/tamu-june-dame-sprint-b03507-mime-…
Browse files Browse the repository at this point in the history
…types

allow/disallow by mime type
  • Loading branch information
jcreel committed Jun 8, 2018
2 parents 9fc5bd3 + 8c95dea commit cadd8b1
Show file tree
Hide file tree
Showing 63 changed files with 726 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public abstract class AbstractManifestController<S extends ManifestService> {
@Autowired
private S manifestService;

protected void sendManifest(HttpServletResponse response, String path, Boolean update) throws IOException, URISyntaxException {
setResponseFile(response, getFileName(path));
sendJsonFile(response, manifestService.getManifest(path, update));
protected void sendManifest(ManifestBuilder builder) throws IOException, URISyntaxException {
setResponseFile(builder.getResponse(), getFileName(builder.getRequest().getContext()));
sendJsonFile(builder.getResponse(), manifestService.getManifest(builder.getRequest()));
}

private void setResponseFile(HttpServletResponse response, String filename) {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/edu/tamu/iiif/controller/ManifestBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.tamu.iiif.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

public class ManifestBuilder {

private final HttpServletResponse response;

private final ManifestRequest request;

public ManifestBuilder(HttpServletResponse response, ManifestRequest request) {
this.response = response;
this.request = request;
}

public HttpServletResponse getResponse() {
return response;
}

public ManifestRequest getRequest() {
return request;
}

public static ManifestBuilder of(HttpServletResponse response, String path, boolean update, List<String> allowed, List<String> disallowed) {
return new ManifestBuilder(response, ManifestRequest.of(path, update, allowed, disallowed));
}

}
47 changes: 47 additions & 0 deletions src/main/java/edu/tamu/iiif/controller/ManifestRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package edu.tamu.iiif.controller;

import java.util.ArrayList;
import java.util.List;

public class ManifestRequest {

private final String context;

private final boolean update;

private final List<String> allowed;

private final List<String> disallowed;

public ManifestRequest(String context, boolean update, List<String> allowed, List<String> disallowed) {
this.context = context;
this.update = update;
this.allowed = allowed;
this.disallowed = disallowed;
}

public String getContext() {
return context;
}

public boolean isUpdate() {
return update;
}

public String getAllowed() {
return String.join(",", allowed);
}

public String getDisallowed() {
return String.join(",", disallowed);
}

public static ManifestRequest of(String path, boolean update, List<String> allowed, List<String> disallowed) {
return new ManifestRequest(path, update, allowed, disallowed);
}

public static ManifestRequest of(String path, boolean update) {
return new ManifestRequest(path, update, new ArrayList<String>(), new ArrayList<String>());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.dspace.DSpaceCanvasManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class DSpaceCanvasManifestController extends AbstractManifestController<DSpaceCanvasManifestService> {

@RequestMapping("/" + CANVAS_IDENTIFIER)
public void image(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void image(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.dspace.DSpaceCollectionManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class DSpaceCollectionManifestController extends AbstractManifestController<DSpaceCollectionManifestService> {

@RequestMapping("/" + COLLECECTION_IDENTIFIER)
public void collection(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void collection(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.dspace.DSpaceImageManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class DSpaceImageManifestController extends AbstractManifestController<DSpaceImageManifestService> {

@RequestMapping("/" + IMAGE_IDENTIFIER)
public void image(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void image(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.dspace.DSpacePresentationManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class DSpacePresentationManifestController extends AbstractManifestController<DSpacePresentationManifestService> {

@RequestMapping("/" + PRESENTATION_IDENTIFIER)
public void presentation(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void presentation(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.dspace.DSpaceSequenceManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class DSpaceSequenceManifestController extends AbstractManifestController<DSpaceSequenceManifestService> {

@RequestMapping("/" + SEQUENCE_IDENTIFIER)
public void image(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void image(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.fedora.FedoraCanvasManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class FedoraCanvasManifestController extends AbstractManifestController<FedoraCanvasManifestService> {

@RequestMapping("/" + CANVAS_IDENTIFIER)
public void image(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void image(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.fedora.FedoraCollectionManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class FedoraCollectionManifestController extends AbstractManifestController<FedoraCollectionManifestService> {

@RequestMapping("/" + COLLECECTION_IDENTIFIER)
public void collection(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void collection(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.iiif.controller.AbstractManifestController;
import edu.tamu.iiif.controller.ManifestBuilder;
import edu.tamu.iiif.service.fedora.FedoraImageManifestService;

@RestController
Expand All @@ -23,8 +25,16 @@
public class FedoraImageManifestController extends AbstractManifestController<FedoraImageManifestService> {

@RequestMapping("/" + IMAGE_IDENTIFIER)
public void image(HttpServletResponse response, @RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path, @RequestParam(value = "update", required = false, defaultValue = "false") boolean update) throws IOException, URISyntaxException {
sendManifest(response, path, update);
public void image(
// @formatter:off
HttpServletResponse response,
@RequestParam(value = CONTEXT_IDENTIFIER, required = true) String path,
@RequestParam(value = "update", required = false, defaultValue = "false") boolean update,
@RequestParam(value = "allow", required = false, defaultValue = "") List<String> allowed,
@RequestParam(value = "disallow", required = false, defaultValue = "") List<String> disallowed
// @formatter:on
) throws IOException, URISyntaxException {
sendManifest(ManifestBuilder.of(response, path, update, allowed, disallowed));
}

}
Loading

0 comments on commit cadd8b1

Please sign in to comment.