protected void importResourcePermissions( PortletDataContext portletDataContext, Role importedRole, Permission permission) throws PortalException, SystemException { int scope = permission.getScope(); if (scope == ResourceConstants.SCOPE_COMPANY) { ResourcePermissionServiceUtil.addResourcePermission( portletDataContext.getCompanyGroupId(), portletDataContext.getCompanyId(), permission.getName(), scope, String.valueOf(portletDataContext.getCompanyGroupId()), importedRole.getRoleId(), permission.getActionId()); } else if (scope == ResourceConstants.SCOPE_GROUP) { long groupId = portletDataContext.getCompanyGroupId(); long sourceGroupId = GetterUtil.getLong(permission.getPrimKey()); if (sourceGroupId == portletDataContext.getSourceUserPersonalSiteGroupId()) { groupId = portletDataContext.getUserPersonalSiteGroupId(); } ResourcePermissionServiceUtil.addResourcePermission( groupId, portletDataContext.getCompanyId(), permission.getName(), ResourceConstants.SCOPE_GROUP, String.valueOf(groupId), importedRole.getRoleId(), permission.getActionId()); } else if (scope == ResourceConstants.SCOPE_GROUP_TEMPLATE) { ResourcePermissionServiceUtil.addResourcePermission( GroupConstants.DEFAULT_PARENT_GROUP_ID, portletDataContext.getCompanyId(), permission.getName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), importedRole.getRoleId(), permission.getActionId()); } else { if (_log.isDebugEnabled()) { _log.debug("Individually scoped permissions are not imported"); } } }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, Role role) throws Exception { long userId = portletDataContext.getUserId(role.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(role); Role existingRole = RoleLocalServiceUtil.fetchRoleByUuidAndCompanyId( role.getUuid(), portletDataContext.getCompanyId()); if (existingRole == null) { existingRole = RoleLocalServiceUtil.fetchRole(portletDataContext.getCompanyId(), role.getName()); } Role importedRole = null; if (existingRole == null) { serviceContext.setUuid(role.getUuid()); importedRole = RoleLocalServiceUtil.addRole( userId, null, 0, role.getName(), role.getTitleMap(), role.getDescriptionMap(), role.getType(), role.getSubtype(), serviceContext); } else { importedRole = RoleLocalServiceUtil.updateRole( existingRole.getRoleId(), role.getName(), role.getTitleMap(), role.getDescriptionMap(), role.getSubtype(), serviceContext); deleteRolePermissions(portletDataContext, importedRole); } String permissionsPath = ExportImportPathUtil.getModelPath(role, "permissions.xml"); List<Permission> permissions = (List<Permission>) portletDataContext.getZipEntryAsObject(permissionsPath); for (Permission permission : permissions) { if (ResourceBlockLocalServiceUtil.isSupported(permission.getName())) { importResourceBlock(portletDataContext, importedRole, permission); } else { importResourcePermissions(portletDataContext, importedRole, permission); } } portletDataContext.importClassedModel(role, importedRole); }