掲示板

Liferay 6.1 How to programmatically create a team?

thumbnail
11年前 に Elijah Mangason によって更新されました。

Liferay 6.1 How to programmatically create a team?

Junior Member 投稿: 65 参加年月日: 12/05/14 最新の投稿
I'm doing a bulk import of new users while also updating existing users as part of a migration from Liferay 5.0.2. Some of the new users are on teams that aren't created in the database at time of upload. Is there a way to programmatically create new teams, then add members? I noticed that TeamLocalServiceUtil has the method createTeam(long teamId); where does the teamId come from? Not sure how to proceed... Any help appreciated!
thumbnail
11年前 に Sachin Mane によって更新されました。

RE: Liferay 6.1 How to programmatically create a team?

Junior Member 投稿: 76 参加年月日: 12/04/10 最新の投稿
You can use

TeamLocalServiceUtil.addTeam(long userId,
long groupId, java.lang.String name, java.lang.String description)

this method internally users counterLocalServiceUtil to generate a unique id for the team and use .createTeam (teamId)
thumbnail
11年前 に Jignesh Vachhani によって更新されました。

RE: Liferay 6.1 How to programmatically create a team?

Liferay Master 投稿: 803 参加年月日: 08/03/10 最新の投稿
You can check below implementation and apply it in your service layer of portlet :

public Team addTeam(
			long userId, long groupId, String name, String description)
		throws PortalException, SystemException {

		// Team

		User user = userPersistence.findByPrimaryKey(userId);
		Date now = new Date();

		validate(0, groupId, name);

		long teamId = counterLocalService.increment();

		Team team = teamPersistence.create(teamId);

		team.setUserId(userId);
		team.setCompanyId(user.getCompanyId());
		team.setUserName(user.getFullName());
		team.setCreateDate(now);
		team.setModifiedDate(now);
		team.setGroupId(groupId);
		team.setName(name);
		team.setDescription(description);

		teamPersistence.update(team, false);

		// Resources

		resourceLocalService.addResources(
			user.getCompanyId(), groupId, userId, Team.class.getName(),
			team.getTeamId(), false, true, true);

		// Role

		roleLocalService.addRole(
			userId, user.getCompanyId(), String.valueOf(teamId), null, null,
			RoleConstants.TYPE_PROVIDER, Team.class.getName(), teamId);

		return team;
	}
thumbnail
11年前 に Elijah Mangason によって更新されました。

RE: Liferay 6.1 How to programmatically create a team?

Junior Member 投稿: 65 参加年月日: 12/05/14 最新の投稿
Thank to both of you for the information. I tried using the TeamLocalServiceUtil.addTeam() method to create teams programmatically, then used UserLocalServiceUtil.addTeamUsers() to populate the teams. They work great and the teams and users are visible in the database. However, when logged in as administrator to the portal, neither teams nor users show up when clicking Search All Users or View Teams from the Control Panel. Have you seen this behaviour, and if so, do you know why it's happening and how to correct it?
thumbnail
11年前 に Elijah Mangason によって更新されました。

RE: Liferay 6.1 How to programmatically create a team?

Junior Member 投稿: 65 参加年月日: 12/05/14 最新の投稿
Hello again.

I'm still trying to create a team programmatically. In the code sample above, where are you getting the validate() method from? It doesn't appear to be part of Liferay.

validate(0, groupId, name);

Also, where does groupId come from? It doesn't seem to be automatically generated.....

Any help is much appreciated.
thumbnail
11年前 に Elijah Mangason によって更新されました。

RE: Liferay 6.1 How to programmatically create a team?

Junior Member 投稿: 65 参加年月日: 12/05/14 最新の投稿
OK, I created the teams programmatically and all is good. When logged in as the system administrator, I'm getting this error when trying to edit the team:

'Control Panel' -> 'User and Organizations' -> click on organization -> click on team -> click 'Actions: Edit'

ERROR [PortletRequestProcessor:468] Invalid path was requested /users_admin/edit_team_assignments

Any ideas?