Example usage for com.liferay.portal.kernel.service TeamLocalServiceUtil getTeam

List of usage examples for com.liferay.portal.kernel.service TeamLocalServiceUtil getTeam

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service TeamLocalServiceUtil getTeam.

Prototype

public static com.liferay.portal.kernel.model.Team getTeam(long groupId, String name)
            throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Usage

From source file:com.liferay.exportimport.lar.PermissionImporter.java

License:Open Source License

protected Role checkRole(LayoutCache layoutCache, long companyId, long groupId, long userId,
        Element roleElement) throws Exception {

    String name = roleElement.attributeValue("name");

    Role role = null;//  w  ww . j  a va 2 s .co  m

    if (ExportImportPermissionUtil.isTeamRoleName(name)) {
        name = name.substring(ExportImportPermissionUtil.ROLE_TEAM_PREFIX.length());

        String description = roleElement.attributeValue("description");

        Team team = null;

        try {
            team = TeamLocalServiceUtil.getTeam(groupId, name);
        } catch (NoSuchTeamException nste) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nste, nste);
            }

            team = TeamLocalServiceUtil.addTeam(userId, groupId, name, description, new ServiceContext());
        }

        role = RoleLocalServiceUtil.getTeamRole(companyId, team.getTeamId());

        return role;
    }

    String uuid = roleElement.attributeValue("uuid");

    role = layoutCache.getUuidRole(companyId, uuid);

    if (role == null) {
        role = layoutCache.getNameRole(companyId, name);
    }

    if ((role != null) || MergeLayoutPrototypesThreadLocal.isInProgress()) {
        return role;
    }

    String title = roleElement.attributeValue("title");

    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(title);

    String description = roleElement.attributeValue("description");

    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(description);

    int type = GetterUtil.getInteger(roleElement.attributeValue("type"));
    String subtype = roleElement.attributeValue("subtype");

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setUuid(uuid);

    role = RoleLocalServiceUtil.addRole(userId, null, 0, name, titleMap, descriptionMap, type, subtype,
            serviceContext);

    return role;
}

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

@Override
public void importPermissions(String resourceName, long resourcePK, long newResourcePK) throws PortalException {

    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

        return;//from  w  w w  .jav  a 2  s . com
    }

    List<KeyValuePair> permissions = _permissionsMap.get(getPrimaryKeyString(resourceName, resourcePK));

    if (permissions == null) {
        return;
    }

    Map<Long, Set<String>> existingRoleIdsToActionIds = ExportImportPermissionUtil
            .getRoleIdsToActionIds(_companyId, resourceName, newResourcePK);

    Map<Long, String[]> importedRoleIdsToActionIds = new HashMap<>();

    for (KeyValuePair permission : permissions) {
        String roleName = permission.getKey();

        Role role = null;

        Team team = null;

        if (ExportImportPermissionUtil.isTeamRoleName(roleName)) {
            roleName = roleName.substring(ExportImportPermissionUtil.ROLE_TEAM_PREFIX.length());

            try {
                team = TeamLocalServiceUtil.getTeam(_groupId, roleName);
            } catch (NoSuchTeamException nste) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Team " + roleName + " does not exist", nste);
                }

                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", nsre);
            }

            continue;
        }

        if (isPrivateLayout() && resourceName.equals(Layout.class.getName())
                && roleName.equals(RoleConstants.GUEST)) {

            continue;
        }

        String[] actionIds = StringUtil.split(permission.getValue());

        importedRoleIdsToActionIds.put(role.getRoleId(), actionIds);
    }

    Map<Long, String[]> roleIdsToActionIds = ExportImportPermissionUtil
            .mergeImportedPermissionsWithExistingPermissions(existingRoleIdsToActionIds,
                    importedRoleIdsToActionIds);

    ExportImportPermissionUtil.updateResourcePermissions(_companyId, _groupId, resourceName, newResourcePK,
            roleIdsToActionIds);
}