@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); Team newTeam = _persistence.create(pk); newTeam.setMvccVersion(RandomTestUtil.nextLong()); newTeam.setCompanyId(RandomTestUtil.nextLong()); newTeam.setUserId(RandomTestUtil.nextLong()); newTeam.setUserName(RandomTestUtil.randomString()); newTeam.setCreateDate(RandomTestUtil.nextDate()); newTeam.setModifiedDate(RandomTestUtil.nextDate()); newTeam.setGroupId(RandomTestUtil.nextLong()); newTeam.setName(RandomTestUtil.randomString()); newTeam.setDescription(RandomTestUtil.randomString()); _teams.add(_persistence.update(newTeam)); Team existingTeam = _persistence.findByPrimaryKey(newTeam.getPrimaryKey()); Assert.assertEquals(existingTeam.getMvccVersion(), newTeam.getMvccVersion()); Assert.assertEquals(existingTeam.getTeamId(), newTeam.getTeamId()); Assert.assertEquals(existingTeam.getCompanyId(), newTeam.getCompanyId()); Assert.assertEquals(existingTeam.getUserId(), newTeam.getUserId()); Assert.assertEquals(existingTeam.getUserName(), newTeam.getUserName()); Assert.assertEquals( Time.getShortTimestamp(existingTeam.getCreateDate()), Time.getShortTimestamp(newTeam.getCreateDate())); Assert.assertEquals( Time.getShortTimestamp(existingTeam.getModifiedDate()), Time.getShortTimestamp(newTeam.getModifiedDate())); Assert.assertEquals(existingTeam.getGroupId(), newTeam.getGroupId()); Assert.assertEquals(existingTeam.getName(), newTeam.getName()); Assert.assertEquals(existingTeam.getDescription(), newTeam.getDescription()); }
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()])); }