Skip to content

Commit

Permalink
Formatter / Cache & landing pages / Add possibility to use a formatte…
Browse files Browse the repository at this point in the history
…r with custom parameters.
  • Loading branch information
fxprunayre committed Jan 8, 2020
1 parent 6e7f7ac commit 44b1650
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public void getRecordFormattedBy(
if (refreshCache) {
cache.remove(key);
}
bytes = cache.get(key, validator, formatMetadata, false);
bytes = cache.get(key, validator, formatMetadata, refreshCache ? true : false);
}
if (bytes != null) {
if (!skipPopularity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class FormatterCache {

private final HashMap<String, String> cacheProperties = new HashMap<String, String>();
private String landingPageFormatter;
private Map<String, String> landingPageFormatterParameters = new HashMap<>();
private String landingPageLanguage = Geonet.DEFAULT_LANGUAGE;
private ServiceContext _context;

Expand Down Expand Up @@ -337,7 +338,22 @@ public void clear() throws IOException, SQLException {
}

public void setLandingPageFormatter(String landingPageFormatter) {
this.landingPageFormatter = landingPageFormatter;
if (landingPageFormatter.contains("?")) {
final String[] strings = landingPageFormatter.split("\\?");
this.landingPageFormatter = strings[0];
if (strings.length > 1) {
for (String param : strings[1].split("&")) {
if(param.contains("=")) {
final String[] paramAndValue = param.split("=");
this.landingPageFormatterParameters.put(paramAndValue[0], paramAndValue[1]);
} else {
this.landingPageFormatterParameters.put(param, "");
}
}
}
} else {
this.landingPageFormatter = landingPageFormatter;
}
}

public void setContext(ServiceContext context) {
Expand Down Expand Up @@ -432,6 +448,7 @@ public void run() {
servletSession.setAttribute(Jeeves.Elem.SESSION, context.getUserSession());
final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext);
servletRequest.setSession(servletSession);
servletRequest.setParameters(landingPageFormatterParameters);
final MockHttpServletResponse response = new MockHttpServletResponse();

allPublicRecordIds.stream().forEach(r -> {
Expand Down Expand Up @@ -480,6 +497,7 @@ public void buildLandingPage(int metadataId) {
servletSession.setAttribute(Jeeves.Elem.SESSION, _context.getUserSession());
final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext);
servletRequest.setSession(servletSession);
servletRequest.setParameters(landingPageFormatterParameters);
final MockHttpServletResponse response = new MockHttpServletResponse();

final OperationAllowed publicRecord = operationAllowedRepo.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(ReservedGroup.all.getId(), metadataId, ReservedOperation.view.getId());
Expand Down

0 comments on commit 44b1650

Please sign in to comment.