@GET @Path("join/{spaceName}") public Response join( @PathParam("spaceName") String spaceName, @Context SecurityContext sc, @Context UriInfo uriInfo) { try { String userId = getUserId(sc, uriInfo); if (userId == null) { return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build(); } SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); if (spaceService.getSpaceById(spaceName).getRegistration().equals("open")) spaceService.addMember(spaceService.getSpaceById(spaceName), userId); return Response.ok("{}", MediaType.APPLICATION_JSON).cacheControl(cacheControl).build(); } catch (Exception e) { log.error("Error in space deny rest service: " + e.getMessage(), e); return Response.ok("error").cacheControl(cacheControl).build(); } }
public void execute(Event<UISpaceInfo> event) throws Exception { UISpaceInfo uiSpaceInfo = event.getSource(); SpaceService spaceService = uiSpaceInfo.getSpaceService(); UIPortal uiPortal = Util.getUIPortal(); String id = uiSpaceInfo.getUIStringInput(SPACE_ID).getValue(); String name = uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).getValue(); Space space = spaceService.getSpaceById(id); String oldDisplayName = space.getDisplayName(); String existingDescription = space.getDescription(); if (space == null) { // redirect to spaces event.getRequestContext().sendRedirect(Utils.getURI("all-spaces")); return; } UserNode selectedNode = uiPortal.getSelectedUserNode(); UserNode renamedNode = null; boolean nameChanged = (!space.getDisplayName().equals(name)); UIPortletApplication uiApp = uiSpaceInfo.getAncestorOfType(UIPortletApplication.class); if (nameChanged) { String cleanedString = SpaceUtils.cleanString(name); if (spaceService.getSpaceByUrl(cleanedString) != null) { // reset to origin values uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).setValue(oldDisplayName); uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(existingDescription); // uiApp.addMessage( new ApplicationMessage( "UISpaceInfo.msg.current-name-exist", null, ApplicationMessage.INFO)); return; } renamedNode = uiSpaceInfo.renamePageNode(name, space); if (renamedNode == null) { return; } } uiSpaceInfo.invokeSetBindingBean(space); String spaceDescription = space.getDescription(); if (spaceDescription == null || spaceDescription.trim().length() == 0) { ResourceBundle resourceBundle = event.getRequestContext().getApplicationResourceBundle(); space.setDescription(resourceBundle.getString(MSG_DEFAULT_SPACE_DESCRIPTION)); uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(space.getDescription()); } else { space.setDescription(StringEscapeUtils.escapeHtml(space.getDescription())); if (!existingDescription.equals(spaceDescription)) { space.setField(UpdatedField.DESCRIPTION); } } space.setEditor(Utils.getViewerRemoteId()); if (nameChanged) { space.setDisplayName(oldDisplayName); String remoteId = Utils.getViewerRemoteId(); spaceService.renameSpace(remoteId, space, name); // rename group label OrganizationService organizationService = (OrganizationService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(OrganizationService.class); GroupHandler groupHandler = organizationService.getGroupHandler(); Group group = groupHandler.findGroupById(space.getGroupId()); group.setLabel(space.getDisplayName()); groupHandler.saveGroup(group, true); } else { spaceService.updateSpace(space); } if (nameChanged) { if (renamedNode != null) { // update space navigation (change name). selectedNode = renamedNode; PortalRequestContext prContext = Util.getPortalRequestContext(); prContext.createURL(NodeURL.TYPE).setNode(selectedNode); event.getRequestContext().sendRedirect(Utils.getSpaceURL(selectedNode)); return; } } else { uiApp.addMessage( new ApplicationMessage( "UISpaceInfo.msg.update-success", null, ApplicationMessage.INFO)); } }
/** * Gets image source url. * * @return image source url * @throws Exception */ protected String getImageSource() throws Exception { SpaceService spaceService = getSpaceService(); String id = getUIStringInput(SPACE_ID).getValue(); Space space = spaceService.getSpaceById(id); return space.getAvatarUrl(); }