Commit 15e0c445 authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Constraint added to component ID. Added query parameter for prefetching...

Constraint added to component ID. Added query parameter for prefetching binaries on standard content read calls
parent 0389255a
Pipeline #332 failed with stage
in 9 seconds
......@@ -49,7 +49,7 @@ class App extends Component {
render() {
return (
<Switch>
<Route exact path='/' render={(props) => {return <Auth {...props} handleSuccess={this.handleSuccess} handleError={this.handleError} />}} />
<Route exact path='/' render={(props) => {return < {...props} handleSuccess={this.handleSuccess} handleError={this.handleError} />}} />
<Route exact path='/logout' render={() => window.location.href = oauthSettings.logoutUri} />
<Route exact path='/login' component={Login} />
<PrivateRoute state={this.state} path='/home' component={Home} />
......
......@@ -67,14 +67,15 @@ public class ContentController {
@GetMapping("**")
@PreAuthorize("#oauth2.hasScope('read')")
public ResponseEntity<com.jeff_cms.jeff.model.Node> getNode(@RequestParam(defaultValue = "false") final Boolean withChildren,
@RequestParam(defaultValue = "false") final Boolean preFetchBinaries,
final ServletRequest servletRequest, final Principal principal) throws Exception {
final String requestedUri = getRequestedUri(servletRequest);
final Node result = withChildren
?
contentService.getNodeWithChildren(requestedUri, principal)
contentService.getNodeWithChildren(requestedUri, preFetchBinaries, principal)
:
contentService.getNode(requestedUri, principal);
contentService.getNode(requestedUri, preFetchBinaries, principal);
/* Remove namespace identifiers */
result.getProperties().forEach(np -> {
......
......@@ -66,13 +66,14 @@ public class ContentService {
* Retrieves a jeff node from the repository.
*
* @param path Path to the content node.
* @param prefetchBinaries If true binaries will be part of the response, otherwise a reference to them is created.
* @param principal Principal trying to access the node.
* @return Jeff Node.
* @throws UnauthorisedException In case the user does not have access.
* @throws NotFoundException In case the node is not found.
*/
@Cacheable(key = "#path + #principal.name")
public Node getNode(final String path, final Principal principal) throws UnauthorisedException, NotFoundException {
public Node getNode(final String path, final boolean prefetchBinaries, final Principal principal) throws UnauthorisedException, NotFoundException {
final Session session = jcrSessionFactory.getSession();
try {
......@@ -85,13 +86,18 @@ public class ContentService {
final com.jeff_cms.jeff.model.Node resultNode = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
resultNode.getProperties().stream()
.filter(p -> p.getType().equals(PropertyType.TYPENAME_BINARY))
.forEach(p -> p.setValues(Collections.singletonList(
ServletUriComponentsBuilder.fromCurrentRequestUri()
.replacePath("/binary/" + resultNode.getPath() + "/" + p.getName().replaceAll("^" + Constants.NS_JEFF, ""))
.build().toString())));
if (prefetchBinaries) {
resultNode.getProperties().stream()
.filter(p -> p.getType().equals(PropertyType.TYPENAME_BINARY))
.forEach(p -> p.setValues(Collections.singletonList(jcrUtils.getBinaryAsBase64String(node, p.getName()))));
} else {
resultNode.getProperties().stream()
.filter(p -> p.getType().equals(PropertyType.TYPENAME_BINARY))
.forEach(p -> p.setValues(Collections.singletonList(
ServletUriComponentsBuilder.fromCurrentRequestUri()
.replacePath("/binary/" + resultNode.getPath() + "/" + p.getName().replaceAll("^" + Constants.NS_JEFF, ""))
.build().toString())));
}
return resultNode;
} catch (RepositoryException e) {
LOGGER.error("Error requesting node at path: {}", path);
......@@ -104,13 +110,15 @@ public class ContentService {
/**
* Returns a node with all of its children.
* @param path Path to the node.
* @param prefetchBinaries If true binaries will be part of the response, otherwise a reference to them is created.
* @param principal Principal trying to access the node.
* @return Node
*/
public Node getNodeWithChildren(final String path, final Principal principal) throws UnauthorisedException, NotFoundException {
final Node node = getNode(path, principal);
public Node getNodeWithChildren(final String path, final boolean prefetchBinaries,
final Principal principal) throws UnauthorisedException, NotFoundException {
final Node node = getNode(path, prefetchBinaries, principal);
for (String child : node.getChildren()) {
node.getChildNodes().add(getNode(path + "/" + child, principal));
node.getChildNodes().add(getNode(path + "/" + child, prefetchBinaries, principal));
}
return node;
......
......@@ -141,7 +141,7 @@ public class ContentServiceTest {
public void readNode() throws Exception {
saveNode();
final Node node = contentService.getNode("/test", principal);
final Node node = contentService.getNode("/test", false, principal);
Assert.assertNotNull(node);
Assert.assertEquals("/test", node.getPath());
......@@ -165,7 +165,7 @@ public class ContentServiceTest {
contentService.updateNode("/test", node, principal);
final Node readBack = contentService.getNode("/test", principal);
final Node readBack = contentService.getNode("/test", false, principal);
Assert.assertNotNull(readBack);
Assert.assertEquals("/test", readBack.getPath());
......@@ -180,7 +180,7 @@ public class ContentServiceTest {
contentService.deleteNode("/test", principal);
final Node nonExistentNode = contentService.getNode("/test", principal);
final Node nonExistentNode = contentService.getNode("/test", false, principal);
}
@Test
......@@ -199,7 +199,7 @@ public class ContentServiceTest {
contentService.saveNode("/test/node2", newNode, principal);
final Node node = contentService.getNodeWithChildren("/test", principal);
final Node node = contentService.getNodeWithChildren("/test", false, principal);
Assert.assertNotNull(node);
Assert.assertEquals("/test", node.getPath());
......
......@@ -26,6 +26,7 @@ package com.jeff_cms.jeff.web.model;
import lombok.Data;
import javax.validation.constraints.Pattern;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -35,6 +36,7 @@ import java.util.Set;
*/
@Data
public class Component {
@Pattern(regexp = "^[0-9a-z\\-]+$")
private String id;
private String name;
private Map<String, List<String>> data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment