Fórum

Liferay 6.1 How to programmatically create a team?

thumbnail
Elijah Mangason, modificado 11 Anos atrás.

Liferay 6.1 How to programmatically create a team?

Junior Member Postagens: 65 Data de Entrada: 14/05/12 Postagens Recentes
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
Sachin Mane, modificado 11 Anos atrás.

RE: Liferay 6.1 How to programmatically create a team?

Junior Member Postagens: 76 Data de Entrada: 10/04/12 Postagens Recentes
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
Jignesh Vachhani, modificado 11 Anos atrás.

RE: Liferay 6.1 How to programmatically create a team?

Liferay Master Postagens: 803 Data de Entrada: 10/03/08 Postagens Recentes
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
Elijah Mangason, modificado 11 Anos atrás.

RE: Liferay 6.1 How to programmatically create a team?

Junior Member Postagens: 65 Data de Entrada: 14/05/12 Postagens Recentes
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
Elijah Mangason, modificado 11 Anos atrás.

RE: Liferay 6.1 How to programmatically create a team?

Junior Member Postagens: 65 Data de Entrada: 14/05/12 Postagens Recentes
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
Elijah Mangason, modificado 11 Anos atrás.

RE: Liferay 6.1 How to programmatically create a team?

Junior Member Postagens: 65 Data de Entrada: 14/05/12 Postagens Recentes
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?