Some bugfixes for the category model
parent
e228dc98ec
commit
5089929d00
|
|
@ -66,7 +66,6 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.PathSegment;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
|
|
@ -247,7 +246,7 @@ public class PagesController {
|
|||
final Versions versions = generateFromPreviewParam(preview);
|
||||
final String language = determineLanguage(category, versions);
|
||||
|
||||
initPageUrlModel(uriInfo);
|
||||
pageUrlModel.init(uriInfo);
|
||||
|
||||
final String indexPage = String.format(
|
||||
"/index.%s.html%s",
|
||||
|
|
@ -278,7 +277,7 @@ public class PagesController {
|
|||
final Versions versions = generateFromPreviewParam(preview);
|
||||
final String language = determineLanguage(category, versions);
|
||||
|
||||
initPageUrlModel(uriInfo);
|
||||
pageUrlModel.init(uriInfo);
|
||||
|
||||
final String itemPage = String.format(
|
||||
"/%s.%s.html%s",
|
||||
|
|
@ -310,7 +309,7 @@ public class PagesController {
|
|||
final Versions versions = generateFromPreviewParam(preview);
|
||||
final String language = determineLanguage(category, itemName, versions);
|
||||
|
||||
initPageUrlModel(uriInfo);
|
||||
pageUrlModel.init(uriInfo);
|
||||
|
||||
final String itemPage = String.format(
|
||||
"/%s.%s.html", itemName, language
|
||||
|
|
@ -418,7 +417,7 @@ public class PagesController {
|
|||
final Versions versions = generateFromPreviewParam(preview);
|
||||
final String language = determineLanguage(category, versions);
|
||||
|
||||
initPageUrlModel(uriInfo);
|
||||
pageUrlModel.init(uriInfo);
|
||||
|
||||
final String redirectTo;
|
||||
if (uriInfo.getPath().endsWith("/")) {
|
||||
|
|
@ -474,7 +473,7 @@ public class PagesController {
|
|||
final Versions versions = generateFromPreviewParam(preview);
|
||||
final String language = determineLanguage(category, versions);
|
||||
|
||||
initPageUrlModel(uriInfo);
|
||||
pageUrlModel.init(uriInfo);
|
||||
|
||||
final String redirectTo;
|
||||
if (uriInfo.getPath().endsWith("/")) {
|
||||
|
|
@ -550,7 +549,7 @@ public class PagesController {
|
|||
.sorted()
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
initPageUrlModel(uriInfo);
|
||||
pageUrlModel.init(uriInfo);
|
||||
siteInfoModel.setDomain(site.getDomainOfSite());
|
||||
siteInfoModel.setHost(domain);
|
||||
siteInfoModel.setName(
|
||||
|
|
@ -835,62 +834,60 @@ public class PagesController {
|
|||
}
|
||||
}
|
||||
|
||||
private void initPageUrlModel(final UriInfo uriInfo) {
|
||||
pageUrlModel.setBasePath(uriInfo.getBaseUri().toString());
|
||||
pageUrlModel.setBaseUri(uriInfo.getBaseUri());
|
||||
pageUrlModel.setHost(uriInfo.getRequestUri().getHost());
|
||||
|
||||
final List<PathSegment> pathSegments = uriInfo.getPathSegments();
|
||||
if (pathSegments.isEmpty()) {
|
||||
throw new IllegalArgumentException("No page segements available.");
|
||||
}
|
||||
pageUrlModel.setPath(
|
||||
pathSegments
|
||||
.subList(0, pathSegments.size())
|
||||
.stream()
|
||||
.map(PathSegment::getPath)
|
||||
.collect(Collectors.joining("/"))
|
||||
);
|
||||
final String pageSegment = pathSegments
|
||||
.get(pathSegments.size() - 1)
|
||||
.getPath();
|
||||
final String[] pageTokens = pageSegment.split("\\.");
|
||||
if (pageTokens.length != 3) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Unexpected number of tokens for page segement of path."
|
||||
+ "Expected 3 tokens, separated by '.', but got %d "
|
||||
+ "tokens.",
|
||||
pageTokens.length
|
||||
)
|
||||
);
|
||||
}
|
||||
final String pageName = pageTokens[0];
|
||||
final String pageLocale = pageTokens[1];
|
||||
final String pageFormat = pageTokens[2];
|
||||
|
||||
pageUrlModel.setPageName(pageName);
|
||||
pageUrlModel.setPageLocale(pageLocale);
|
||||
pageUrlModel.setPageFormat(pageFormat);
|
||||
|
||||
|
||||
pageUrlModel.setPath(uriInfo.getPath());
|
||||
pageUrlModel.setPort(uriInfo.getRequestUri().getPort());
|
||||
pageUrlModel.setProtocol(uriInfo.getRequestUri().getScheme());
|
||||
pageUrlModel.setQueryParameters(
|
||||
uriInfo
|
||||
.getQueryParameters()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
entry -> entry.getKey(),
|
||||
entry -> entry.getValue().get(0)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// private void pageUrlModel.init(final UriInfo uriInfo) {
|
||||
// pageUrlModel.setBasePath(uriInfo.getBaseUri().toString());
|
||||
// pageUrlModel.setBaseUri(uriInfo.getBaseUri());
|
||||
// pageUrlModel.setHost(uriInfo.getRequestUri().getHost());
|
||||
//
|
||||
// final List<PathSegment> pathSegments = uriInfo.getPathSegments();
|
||||
// if (pathSegments.isEmpty()) {
|
||||
// throw new IllegalArgumentException("No page segements available.");
|
||||
// }
|
||||
// pageUrlModel.setPath(
|
||||
// pathSegments
|
||||
// .subList(0, pathSegments.size())
|
||||
// .stream()
|
||||
// .map(PathSegment::getPath)
|
||||
// .collect(Collectors.joining("/"))
|
||||
// );
|
||||
// final String pageSegment = pathSegments
|
||||
// .get(pathSegments.size() - 1)
|
||||
// .getPath();
|
||||
// final String[] pageTokens = pageSegment.split("\\.");
|
||||
// if (pageTokens.length != 3) {
|
||||
// throw new IllegalArgumentException(
|
||||
// String.format(
|
||||
// "Unexpected number of tokens for page segement of path."
|
||||
// + "Expected 3 tokens, separated by '.', but got %d "
|
||||
// + "tokens.",
|
||||
// pageTokens.length
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// final String pageName = pageTokens[0];
|
||||
// final String pageLocale = pageTokens[1];
|
||||
// final String pageFormat = pageTokens[2];
|
||||
//
|
||||
// pageUrlModel.setPageName(pageName);
|
||||
// pageUrlModel.setPageLocale(pageLocale);
|
||||
// pageUrlModel.setPageFormat(pageFormat);
|
||||
//
|
||||
// pageUrlModel.setPath(uriInfo.getPath());
|
||||
// pageUrlModel.setPort(uriInfo.getRequestUri().getPort());
|
||||
// pageUrlModel.setProtocol(uriInfo.getRequestUri().getScheme());
|
||||
// pageUrlModel.setQueryParameters(
|
||||
// uriInfo
|
||||
// .getQueryParameters()
|
||||
// .entrySet()
|
||||
// .stream()
|
||||
// .collect(
|
||||
// Collectors.toMap(
|
||||
// entry -> entry.getKey(),
|
||||
// entry -> entry.getValue().get(0)
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
/**
|
||||
* Encapsulate the result of converting the value of the {@code preview}
|
||||
* query parameter.
|
||||
|
|
|
|||
|
|
@ -153,12 +153,14 @@ public class CategoryModel implements Serializable {
|
|||
fromCategory.getDescription())
|
||||
);
|
||||
node.setName(fromCategory.getName());
|
||||
node.setVisible(fromCategory.isVisible());
|
||||
node.setSelected(fromCategory.getUuid().equals(category.getUuid()));
|
||||
node.setParentCategory(parent);
|
||||
node.setSubCategories(
|
||||
fromCategory
|
||||
.getSubCategories()
|
||||
.stream()
|
||||
.filter(cat -> !cat.isAbstractCategory())
|
||||
.sorted(Comparator.comparing(Category::getCategoryOrder))
|
||||
.map(cat -> buildTreeNode(cat, node))
|
||||
.collect(Collectors.toList())
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public class CategoryTreeNode {
|
|||
|
||||
private String categoryPath;
|
||||
|
||||
private boolean visible;
|
||||
|
||||
private boolean selected;
|
||||
|
||||
private boolean subCategorySelected;
|
||||
|
|
@ -96,6 +98,14 @@ public class CategoryTreeNode {
|
|||
this.subCategories = new ArrayList<>(subCategories);
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
|
@ -104,7 +114,6 @@ public class CategoryTreeNode {
|
|||
this.selected = selected;
|
||||
}
|
||||
|
||||
|
||||
public CategoryTreeNode getParentCategory() {
|
||||
return parentCategory;
|
||||
}
|
||||
|
|
@ -112,12 +121,11 @@ public class CategoryTreeNode {
|
|||
protected void setParentCategory(final CategoryTreeNode parentCategory) {
|
||||
this.parentCategory = parentCategory;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSubCategorySelected() {
|
||||
return subCategorySelected;
|
||||
}
|
||||
|
||||
|
||||
protected void setSubCategorySelected(final boolean subCategorySelected) {
|
||||
this.subCategorySelected = subCategorySelected;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,12 +21,15 @@ package org.librecms.pages.models;
|
|||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.core.PathSegment;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
/**
|
||||
* Model initialized by the Pages application containing information about the
|
||||
|
|
@ -43,7 +46,7 @@ public class PageUrlModel {
|
|||
private String host;
|
||||
|
||||
private int port;
|
||||
|
||||
|
||||
private URI baseUri;
|
||||
|
||||
private String basePath;
|
||||
|
|
@ -62,78 +65,91 @@ public class PageUrlModel {
|
|||
queryParameters = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
public void init(final UriInfo uriInfo) {
|
||||
basePath = uriInfo.getBaseUri().toString();
|
||||
baseUri = uriInfo.getBaseUri();
|
||||
host = uriInfo.getRequestUri().getHost();
|
||||
|
||||
final List<PathSegment> pathSegments = uriInfo.getPathSegments();
|
||||
if (pathSegments.isEmpty()) {
|
||||
throw new IllegalArgumentException("No page segements available.");
|
||||
}
|
||||
path = pathSegments
|
||||
.subList(0, pathSegments.size())
|
||||
.stream()
|
||||
.map(PathSegment::getPath)
|
||||
.collect(Collectors.joining("/"));
|
||||
final String pageSegment = pathSegments
|
||||
.get(pathSegments.size() - 1)
|
||||
.getPath();
|
||||
final String[] pageTokens = pageSegment.split("\\.");
|
||||
if (pageTokens.length != 3) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Unexpected number of tokens for page segement of path."
|
||||
+ "Expected 3 tokens, separated by '.', but got %d "
|
||||
+ "tokens.",
|
||||
pageTokens.length
|
||||
)
|
||||
);
|
||||
}
|
||||
pageName = pageTokens[0];
|
||||
pageLocale = pageTokens[1];
|
||||
pageFormat = pageTokens[2];
|
||||
|
||||
path = uriInfo.getPath();
|
||||
port = uriInfo.getRequestUri().getPort();
|
||||
protocol = uriInfo.getRequestUri().getScheme();
|
||||
queryParameters.putAll(
|
||||
uriInfo
|
||||
.getQueryParameters()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
entry -> entry.getKey(),
|
||||
entry -> entry.getValue().get(0)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void setProtocol(final String protocol) {
|
||||
this.protocol = protocol;
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(final String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(final int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public URI getBaseUri() {
|
||||
return baseUri;
|
||||
}
|
||||
|
||||
public void setBaseUri(final URI baseUri) {
|
||||
this.baseUri = baseUri;
|
||||
}
|
||||
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(final String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(final String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPageName() {
|
||||
return pageName;
|
||||
}
|
||||
|
||||
public void setPageName(String pageName) {
|
||||
this.pageName = pageName;
|
||||
}
|
||||
|
||||
public String getPageLocale() {
|
||||
return pageLocale;
|
||||
}
|
||||
|
||||
public void setPageLocale(String pageLocale) {
|
||||
this.pageLocale = pageLocale;
|
||||
}
|
||||
|
||||
public String getPageFormat() {
|
||||
return pageFormat;
|
||||
}
|
||||
|
||||
public void setPageFormat(String pageFormat) {
|
||||
this.pageFormat = pageFormat;
|
||||
}
|
||||
|
||||
public Map<String, String> getQueryParameters() {
|
||||
return Collections.unmodifiableMap(queryParameters);
|
||||
}
|
||||
|
|
@ -145,36 +161,36 @@ public class PageUrlModel {
|
|||
public void setQueryParameters(final Map<String, String> queryParameters) {
|
||||
this.queryParameters = new HashMap<>(queryParameters);
|
||||
}
|
||||
|
||||
|
||||
public String getPageUrl() {
|
||||
final UriBuilder uriBuilder = UriBuilder
|
||||
.fromUri(baseUri)
|
||||
.path(path)
|
||||
.path(String.format("%s.%s.%s", pageName, pageLocale, pageFormat));
|
||||
|
||||
for(Map.Entry<String, String> parameter : queryParameters.entrySet()) {
|
||||
|
||||
for (Map.Entry<String, String> parameter : queryParameters.entrySet()) {
|
||||
uriBuilder.queryParam(
|
||||
parameter.getKey(),
|
||||
parameter.getKey(),
|
||||
parameter.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return uriBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
public String getPageUrl(final String locale) {
|
||||
final UriBuilder uriBuilder = UriBuilder
|
||||
.fromUri(baseUri)
|
||||
.path(path)
|
||||
.path(String.format("%s.%s.%s", pageName, locale, pageFormat));
|
||||
|
||||
for(Map.Entry<String, String> parameter : queryParameters.entrySet()) {
|
||||
|
||||
for (Map.Entry<String, String> parameter : queryParameters.entrySet()) {
|
||||
uriBuilder.queryParam(
|
||||
parameter.getKey(),
|
||||
parameter.getKey(),
|
||||
parameter.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return uriBuilder.build().toString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class LoginController {
|
|||
models.put("loginFailed", true);
|
||||
return getLoginForm(uriInfo, returnUrl);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
return Response.seeOther(
|
||||
new URI(
|
||||
|
|
|
|||
Loading…
Reference in New Issue