Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Use raw compaction for embedded resource preference
Browse files Browse the repository at this point in the history
This is purely to make the Ember adapter happy
  • Loading branch information
birkland committed May 2, 2018
1 parent 66189c4 commit b6d8b01
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.dataconservancy.fcrepo.jsonld.compact;

import static org.dataconservancy.fcrepo.jsonld.ConfigUtil.JSONLD_MINIMAL_CONTEXT;
import static org.dataconservancy.fcrepo.jsonld.ConfigUtil.JSONLD_PERSIST_CONTEXT;
import static org.dataconservancy.fcrepo.jsonld.ConfigUtil.JSONLD_STRICT;
import static org.dataconservancy.fcrepo.jsonld.ConfigUtil.getValue;
import static org.dataconservancy.fcrepo.jsonld.JsonldUtil.loadContexts;

Expand Down Expand Up @@ -58,6 +58,8 @@ public class CompactionFilter implements Filter {

private Compactor compactor;

private Compactor rawCompactor;

Logger LOG = LoggerFactory.getLogger(CompactionFilter.class);

@Override
Expand All @@ -84,7 +86,7 @@ public void init(FilterConfig filterConfig) throws ServletException {
loadContexts(options);

boolean limitContexts = false;
if (getValue(JSONLD_STRICT) != null && !getValue(JSONLD_STRICT).equals("false")) {
if (getValue(JSONLD_MINIMAL_CONTEXT) != null && !getValue(JSONLD_MINIMAL_CONTEXT).equals("false")) {
limitContexts = true;
}

Expand All @@ -94,6 +96,7 @@ public void init(FilterConfig filterConfig) throws ServletException {
}

compactor = new Compactor(options, limitContexts, usePersistedContext);
rawCompactor = new Compactor(options, false, false);
}

@Override
Expand All @@ -114,12 +117,23 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
accept = String.join(",", Collections.list(req.getHeaders("accept")));
}

// Hack to allow ember adapter to be happy for findAll
boolean useRawCompaction = false;
if (Optional.ofNullable(req.getHeader("Prefer")).orElse("").contains("embed")) {
useRawCompaction = true;
}

if (method.equalsIgnoreCase("GET") && (accept.contains("application/ld+json") || accept.equals(""))) {

LOG.debug("Compaction filter is compacting");
final CompactionWrapper compactionWrapper = new CompactionWrapper(resp,
compactor,
defaultContext);
final CompactionWrapper compactionWrapper;
if (useRawCompaction) {
compactionWrapper = new CompactionWrapper(resp, rawCompactor, defaultContext);
} else {
compactionWrapper = new CompactionWrapper(resp,
compactor,
defaultContext);
}
chain.doFilter(new CompactionRequestWrapper(req), compactionWrapper);
compactionWrapper.getOutputStream().close();
} else {
Expand Down

0 comments on commit b6d8b01

Please sign in to comment.