public TeamActionableDynamicQuery() { setBaseLocalService(TeamLocalServiceUtil.getService()); setClass(Team.class); setClassLoader(PortalClassLoaderUtil.getClassLoader()); setPrimaryKeyPropertyName("teamId"); }
protected List<Team> getTeams(PortletRequest portletRequest) throws Exception { List<Team> teams = new UniqueList<Team>(); long[] teamsTeamIds = StringUtil.split(ParamUtil.getString(portletRequest, "teamsTeamIds"), 0L); for (long teamsTeamId : teamsTeamIds) { if (teamsTeamId == 0) { continue; } Team team = TeamLocalServiceUtil.getTeam(teamsTeamId); teams.add(team); } return teams; }
@Test public void testActionableDynamicQuery() throws Exception { final IntegerWrapper count = new IntegerWrapper(); ActionableDynamicQuery actionableDynamicQuery = TeamLocalServiceUtil.getActionableDynamicQuery(); actionableDynamicQuery.setPerformActionMethod( new ActionableDynamicQuery.PerformActionMethod() { @Override public void performAction(Object object) { Team team = (Team) object; Assert.assertNotNull(team); count.increment(); } }); actionableDynamicQuery.performActions(); Assert.assertEquals(count.getValue(), _persistence.countAll()); }
public void importPermissions(String resourceName, long resourcePK, long newResourcePK) throws PortalException, SystemException { if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { return; } List<KeyValuePair> permissions = _permissionsMap.get(getPrimaryKeyString(resourceName, resourcePK)); if (permissions == null) { return; } Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>(); for (KeyValuePair permission : permissions) { String roleName = permission.getKey(); Role role = null; Team team = null; if (roleName.startsWith(PermissionExporter.ROLE_TEAM_PREFIX)) { roleName = roleName.substring(PermissionExporter.ROLE_TEAM_PREFIX.length()); try { team = TeamLocalServiceUtil.getTeam(_groupId, roleName); } catch (NoSuchTeamException nste) { if (_log.isWarnEnabled()) { _log.warn("Team " + roleName + " does not exist"); } continue; } } try { if (team != null) { role = RoleLocalServiceUtil.getTeamRole(_companyId, team.getTeamId()); } else { role = RoleLocalServiceUtil.getRole(_companyId, roleName); } } catch (NoSuchRoleException nsre) { if (_log.isWarnEnabled()) { _log.warn("Role " + roleName + " does not exist"); } continue; } String[] actionIds = StringUtil.split(permission.getValue()); roleIdsToActionIds.put(role.getRoleId(), actionIds); } if (roleIdsToActionIds.isEmpty()) { return; } if (ResourceBlockLocalServiceUtil.isSupported(resourceName)) { ResourceBlockLocalServiceUtil.setIndividualScopePermissions( _companyId, _groupId, resourceName, newResourcePK, roleIdsToActionIds); } else { ResourcePermissionLocalServiceUtil.setResourcePermissions( _companyId, resourceName, ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(newResourcePK), roleIdsToActionIds); } }
public void addPermissions(String resourceName, long resourcePK) throws PortalException, SystemException { if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { return; } List<KeyValuePair> permissions = new ArrayList<KeyValuePair>(); Group group = GroupLocalServiceUtil.getGroup(_groupId); List<Role> roles = RoleLocalServiceUtil.getRoles(_companyId); PrimitiveLongList roleIds = new PrimitiveLongList(roles.size()); Map<Long, String> roleIdsToNames = new HashMap<Long, String>(); for (Role role : roles) { int type = role.getType(); if ((type == RoleConstants.TYPE_REGULAR) || ((type == RoleConstants.TYPE_ORGANIZATION) && group.isOrganization()) || ((type == RoleConstants.TYPE_SITE) && (group.isLayoutSetPrototype() || group.isSite()))) { String name = role.getName(); roleIds.add(role.getRoleId()); roleIdsToNames.put(role.getRoleId(), name); } else if ((type == RoleConstants.TYPE_PROVIDER) && role.isTeam()) { Team team = TeamLocalServiceUtil.getTeam(role.getClassPK()); if (team.getGroupId() == _groupId) { String name = PermissionExporter.ROLE_TEAM_PREFIX + team.getName(); roleIds.add(role.getRoleId()); roleIdsToNames.put(role.getRoleId(), name); } } } List<String> actionIds = ResourceActionsUtil.getModelResourceActions(resourceName); Map<Long, Set<String>> roleIdsToActionIds = getActionIds(_companyId, roleIds.getArray(), resourceName, resourcePK, actionIds); for (Map.Entry<Long, String> entry : roleIdsToNames.entrySet()) { long roleId = entry.getKey(); String name = entry.getValue(); Set<String> availableActionIds = roleIdsToActionIds.get(roleId); if ((availableActionIds == null) || availableActionIds.isEmpty()) { continue; } KeyValuePair permission = new KeyValuePair(name, StringUtil.merge(availableActionIds)); permissions.add(permission); } _permissionsMap.put(getPrimaryKeyString(resourceName, resourcePK), permissions); }
public List<Team> getTeams() throws SystemException { return TeamLocalServiceUtil.getUserTeams(getUserId()); }
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); try { log.debug(":: VIEW STUDENT SEARCH " + this.viewJSP); PortletPreferences preferences = renderRequest.getPreferences(); boolean showSearcher = GetterUtil.getBoolean(preferences.getValue("showSearcher", StringPool.TRUE)); boolean showScreenName = GetterUtil.getBoolean(preferences.getValue("showScreenName", StringPool.TRUE)); boolean showEmail = GetterUtil.getBoolean(preferences.getValue("showEmail", StringPool.FALSE)); long teamId = ParamUtil.getLong(renderRequest, "team", 0); List<Team> teams = TeamLocalServiceUtil.getGroupTeams(themeDisplay.getScopeGroupId()); renderRequest.setAttribute("showSearcher", showSearcher); renderRequest.setAttribute("showScreenName", showScreenName); renderRequest.setAttribute("showEmail", showEmail); PortletURL iteratorURL = renderResponse.createRenderURL(); iteratorURL.setParameter("team", String.valueOf(teamId)); /*iteratorURL.setParameter("showSearcher" , String.valueOf(showSearcher)); iteratorURL.setParameter("showScreenName" , String.valueOf(showScreenName)); iteratorURL.setParameter("showEmail" , String.valueOf(showEmail));*/ UserSearchContainer userSearchContainer = new UserSearchContainer(renderRequest, iteratorURL); UserDisplayTerms displayTerms = (UserDisplayTerms) userSearchContainer.getDisplayTerms(); LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("usersGroups", new Long(themeDisplay.getScopeGroupId())); Course course = CourseLocalServiceUtil.fetchByGroupCreatedId(themeDisplay.getScopeGroupId()); if (log.isDebugEnabled()) { log.debug("NAME " + displayTerms.getFirstName()); log.debug("SURNAME " + displayTerms.getLastName()); log.debug("SCREEN NAME " + displayTerms.getScreenName()); log.debug("EMAIL ADDRESS " + displayTerms.getEmailAddress()); log.debug("KEYWORDS " + displayTerms.getKeywords()); log.debug("START " + userSearchContainer.getStart()); log.debug("END " + userSearchContainer.getEnd()); log.debug("ADVANCED SEARCH " + displayTerms.isAdvancedSearch()); log.debug("AND OPERATOR " + displayTerms.isAndOperator()); log.debug("TEAM " + teamId); } if (log.isDebugEnabled()) { log.debug("NAME " + ParamUtil.getString(renderRequest, "firstName")); } if (course != null) { try { if (displayTerms.isAdvancedSearch()) { userSearchContainer.setResults( CourseLocalServiceUtil.getStudentsFromCourse( themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), userSearchContainer.getStart(), userSearchContainer.getEnd(), teamId, displayTerms.getFirstName(), displayTerms.getLastName(), displayTerms.getScreenName(), displayTerms.getEmailAddress(), displayTerms.isAndOperator())); userSearchContainer.setTotal( CourseLocalServiceUtil.getStudentsFromCourseCount( course.getCourseId(), teamId, displayTerms.getFirstName(), displayTerms.getLastName(), displayTerms.getScreenName(), displayTerms.getEmailAddress(), displayTerms.isAndOperator())); } else { userSearchContainer.setResults( CourseLocalServiceUtil.getStudentsFromCourse( themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), userSearchContainer.getStart(), userSearchContainer.getEnd(), teamId, displayTerms.getKeywords(), displayTerms.getKeywords(), displayTerms.getKeywords(), displayTerms.getKeywords(), true)); userSearchContainer.setTotal( CourseLocalServiceUtil.getStudentsFromCourseCount( course.getCourseId(), teamId, displayTerms.getKeywords(), displayTerms.getKeywords(), displayTerms.getKeywords(), displayTerms.getKeywords(), true)); } } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (log.isDebugEnabled()) { log.debug(" -- TOTAL: " + userSearchContainer.getTotal()); log.debug(" -- SIZE: " + userSearchContainer.getResults().size()); } renderRequest.setAttribute("searchContainer", userSearchContainer); renderRequest.setAttribute("team", teamId); renderRequest.setAttribute("teams", teams); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PortalException e) { // TODO: handle exception e.printStackTrace(); } this.include(this.viewJSP, renderRequest, renderResponse); }
protected void doAddPermissionFields_6( long companyId, long groupId, String className, String classPK, Document doc) throws Exception { Group group = null; if (groupId > 0) { group = GroupLocalServiceUtil.getGroup(groupId); } List<Role> roles = ResourceActionsUtil.getRoles(companyId, group, className, null); if (groupId > 0) { List<Team> teams = TeamLocalServiceUtil.getGroupTeams(groupId); for (Team team : teams) { Role role = RoleLocalServiceUtil.getTeamRole(team.getCompanyId(), team.getTeamId()); roles.add(role); } } long[] roleIdsArray = new long[roles.size()]; for (int i = 0; i < roleIdsArray.length; i++) { Role role = roles.get(i); roleIdsArray[i] = role.getRoleId(); } boolean[] hasResourcePermissions = null; if (ResourceBlockLocalServiceUtil.isSupported(className)) { ResourceBlockIdsBag resourceBlockIdsBag = ResourceBlockLocalServiceUtil.getResourceBlockIdsBag( companyId, groupId, className, roleIdsArray); long actionId = ResourceBlockLocalServiceUtil.getActionId(className, ActionKeys.VIEW); List<Long> resourceBlockIds = resourceBlockIdsBag.getResourceBlockIds(actionId); hasResourcePermissions = new boolean[roleIdsArray.length]; for (long resourceBlockId : resourceBlockIds) { for (int i = 0; i < roleIdsArray.length; i++) { int count = ResourceBlockPermissionLocalServiceUtil.getResourceBlockPermissionsCount( resourceBlockId, roleIdsArray[i]); hasResourcePermissions[i] = (count > 0); } } } else { hasResourcePermissions = ResourcePermissionLocalServiceUtil.hasResourcePermissions( companyId, className, ResourceConstants.SCOPE_INDIVIDUAL, classPK, roleIdsArray, ActionKeys.VIEW); } List<Long> roleIds = new ArrayList<Long>(); List<String> groupRoleIds = new ArrayList<String>(); for (int i = 0; i < hasResourcePermissions.length; i++) { if (!hasResourcePermissions[i]) { continue; } Role role = roles.get(i); if ((role.getType() == RoleConstants.TYPE_ORGANIZATION) || (role.getType() == RoleConstants.TYPE_SITE)) { groupRoleIds.add(groupId + StringPool.DASH + role.getRoleId()); } else { roleIds.add(role.getRoleId()); } } doc.addKeyword(Field.ROLE_ID, roleIds.toArray(new Long[roleIds.size()])); doc.addKeyword(Field.GROUP_ROLE_ID, groupRoleIds.toArray(new String[groupRoleIds.size()])); }