protected Session getSession() throws RepositoryException { return RequestContextProvider.get().getSession(); }
private static Session getSessionFromRequest(final HttpServletRequest request) throws RepositoryException { HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext != null) { try { final Session session = requestContext.getSession(); log.debug("Return HstRequestContext#getSession '{}' for Request pathInfo '{}'", session.getUserID(), request.getPathInfo()); return session; } catch (IllegalStateException e) { log.warn("HstRequestContext is already disposed for Request pathInfo '{}'. Return null for jcr session " + "from request.", request.getPathInfo()); } } return null; }
@Override public boolean isUserInRole(final String role) { try { return securityModel.isUserInRole(RequestContextProvider.get().getSession(), role); } catch (RepositoryException e) { throw new IllegalStateException("Exception while trying to find whether user is " + "in role.", e); } }
@Override public Principal getUserPrincipal() { try { return securityModel.getUserPrincipal(RequestContextProvider.get().getSession()); } catch (RepositoryException e) { throw new IllegalStateException("Exception while getting user principal.", e); } }
private Session getSession() throws RepositoryException { return getPageComposerContextService().getRequestContext().getSession(); }
@Override public void validate(HstRequestContext requestContext) throws RuntimeException { try { final Node prototypePageNode = getNodeByIdentifier(prototypePageUuid, requestContext.getSession()); if (!prototypePageNode.getPath().contains("/" + HstNodeTypes.NODENAME_HST_PROTOTYPEPAGES + "/")) { final String message = String.format("Not a prototype page since '%s' is not configured below .", prototypePageNode.getPath(), HstNodeTypes.NODENAME_HST_PROTOTYPEPAGES); throw new ClientException(message, ClientError.ITEM_NOT_CORRECT_LOCATION); } validatePrototypePage(prototypePageNode); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } }
public Node getScope(final HttpServletRequest request) throws RepositoryException { HstRequestContext requestContext = getRequestContext(request); Mount siteMount = requestContext.getResolvedMount().getMount(); if (siteMount == null) { log.error("Couldn't find site mount for rest service"); return null; } String contentPath = siteMount.getContentPath(); if (contentPath != null) { return requestContext.getSession().getRootNode().getNode(PathUtils.normalizePath(contentPath)); } return null; }
private Response publishChangesOfCurrentUser() { try { Session session = getPageComposerContextService().getRequestContext().getSession(); String currentUserId = session.getUserID(); return publishChangesOfUsers(Collections.singletonList(currentUserId)); } catch (RepositoryException e) { log.warn("Could not publish preview configuration of the current user : ", e); return error("Could not publish preview configuration of the current user: " + e); } }
protected List<Node> findLockedNodesForUsers(final String previewConfigurationPath, final List<String> userIds) throws RepositoryException { if (userIds.isEmpty()) { return Collections.emptyList(); } final Session session = pageComposerContextService.getRequestContext().getSession(); final String xpath = buildXPathQueryLockedNodesForUsers(previewConfigurationPath, userIds); final QueryResult result = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH).execute(); List<Node> lockedNodesForUsers = new ArrayList<>(); for (Node lockedNodeForUsers : new NodeIterable(result.getNodes())) { lockedNodesForUsers.add(lockedNodeForUsers); } return lockedNodesForUsers; }
public Node getRequestConfigNode(final String expectedNodeType) throws RepositoryException { final String id = getRequestConfigIdentifier(); return getRequestConfigNodeById(id, expectedNodeType, getRequestContext().getSession()); }
private void deleteBranches(final HstRequestContext requestContext, final Channel master) throws RepositoryException, HstConfigurationException { VirtualHost virtualHost = requestContext.getResolvedMount().getMount().getVirtualHost(); String hostGroupName = virtualHost.getHostGroupName(); Map<String, Channel> channels = virtualHost.getVirtualHosts().getChannels(hostGroupName); List<Channel> branches = channels.values().stream() // only the live channels since #delete(session, channel) will also delete the preview .filter(channel -> !channel.isPreview() && master.getId().equals(channel.getBranchOf())) .collect(Collectors.toList()); // remove the branches as well for (Channel branch : branches) { delete(requestContext.getSession(), branch.getHstConfigPath()); } }
@Override public void delete(final HstRequestContext requestContext, final Channel channel) throws RepositoryException, HstConfigurationException { try { delete(requestContext.getSession(), channel.getHstConfigPath()); deleteBranches(requestContext, channel); } catch (HstConfigurationException e) { deleteBranches(requestContext, channel); throw e; } }
public ObjectBeanManager getObjectBeanManager(HstRequest request) { try { HstRequestContext requestContext = request.getRequestContext(); return new ObjectBeanManagerImpl(requestContext.getSession(), this.objectConverter); } catch (UnsupportedRepositoryOperationException e) { throw new HstComponentException(e); } catch (RepositoryException e) { throw new HstComponentException(e); } }
private SiteMapPageRepresentation createSiteMapPageRepresentation(final Mount target, final String siteMapItemUUID, final String parentId) throws RepositoryException { SiteMapPageRepresentation siteMapPageRepresentation = new SiteMapPageRepresentation(); siteMapPageRepresentation.setId(siteMapItemUUID); // siteMapPathInfo without starting / Node siteMapItem = getPageComposerContextService().getRequestContext().getSession().getNodeByIdentifier(siteMapItemUUID); String siteMapPathInfo = StringUtils.substringAfter(siteMapItem.getPath(), NODENAME_HST_WORKSPACE + "/" + NODENAME_HST_SITEMAP ); siteMapPageRepresentation.setPathInfo(siteMapPathInfo.substring(1)); siteMapPageRepresentation.setRenderPathInfo(target.getMountPath() + siteMapPathInfo); siteMapPageRepresentation.setParentId(parentId); return siteMapPageRepresentation; }
@Override public void validate(HstRequestContext requestContext) throws RuntimeException { try { final Session session = requestContext.getSession(); final Node parent = getNodeByIdentifier(parentId, session); final Node child = getNodeByIdentifier(childId, session); if (!parent.isSame(child.getParent())) { final String message = String.format("Node '%s' is not a child of '%s", child, parent); throw new ClientException(message, ClientError.ITEM_NOT_CHILD_OF_PARENT); } } catch (RepositoryException e) { throw new RuntimeRepositoryException("RepositoryException during pre-validate", e); } }
private void createMandatoryWorkspaceNodesIfMissing() throws RepositoryException { final String liveConfigPath = getPageComposerContextService().getEditingLiveConfigurationPath(); final String previewConfigPath = getPageComposerContextService().getEditingPreviewConfigurationPath(); HstConfigurationUtils.createMandatoryWorkspaceNodesIfMissing(liveConfigPath, getPageComposerContextService().getRequestContext().getSession()); HstConfigurationUtils.createMandatoryWorkspaceNodesIfMissing(previewConfigPath, getPageComposerContextService().getRequestContext().getSession()); }
public void delete(final String id) throws RepositoryException { HstRequestContext requestContext = pageComposerContextService.getRequestContext(); final Session session = requestContext.getSession(); Node sitemapItemNodeToDelete = session.getNodeByIdentifier(id); lockHelper.acquireLock(sitemapItemNodeToDelete, 0); pagesHelper.delete(sitemapItemNodeToDelete); deleteOrMarkDeletedIfLiveExists(sitemapItemNodeToDelete); }
@Override public void validate(final HstRequestContext requestContext) throws RuntimeException { Mount mount = requestContext.getVirtualHost().getVirtualHosts().getMountByIdentifier(mountId); try { if (!requestContext.getSession().nodeExists(mount.getHstSite().getConfigurationPath() + "/" + NODENAME_HST_WORKSPACE)) { final String message = String.format("There is no workspace configuration for '%s'", mount.getHstSite().getConfigurationPath()); throw new ClientException("There is no workspace configuration", ClientError.NO_PREVIEW_CONFIGURATION, Collections.singletonMap("errorReason", message)); } } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } } }
@DELETE @Path("/{menuItemId}") public Response delete(final @PathParam("menuItemId") String menuItemId) { final Validator preValidator = ValidatorBuilder.builder() .add(getDefaultMenuModificationValidator()) .add(validatorFactory.getHasPreviewConfigurationValidator(getPageComposerContextService())) .add(validatorFactory.getNodePathPrefixValidator(getPreviewConfigurationWorkspacePath(), menuItemId, null)) .build(); return tryExecute(() -> { final Session session = getPageComposerContextService().getRequestContext().getSession(); siteMenuItemHelper.delete(session.getNodeByIdentifier(menuItemId)); return ok("Item deleted successfully", menuItemId); }, preValidator); }
private boolean workspaceFiltered(final Channel channel, final boolean required) throws RuntimeRepositoryException { if (!required) { return true; } final Mount mount = getAllVirtualHosts().getMountByIdentifier(channel.getMountId()); final String workspacePath = mount.getHstSite().getConfigurationPath() + "/" + HstNodeTypes.NODENAME_HST_WORKSPACE; try { return RequestContextProvider.get().getSession().nodeExists(workspacePath); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } }