Added getAllDevicesOfUser and getAllDevicesOfRole methods with user feature

revert-70aa11f8
harshanl 10 years ago
parent fc0dc162ef
commit db2065435b

@ -82,7 +82,9 @@
org.wso2.carbon.apimgt.impl,
org.wso2.carbon.identity.oauth.stub,
org.wso2.carbon.identity.oauth.stub.dto,
org.wso2.carbon.ndatasource.core
org.wso2.carbon.ndatasource.core,
org.wso2.carbon.device.mgt.user.core,
org.wso2.carbon.device.mgt.user.common,
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.core.internal,
@ -122,6 +124,14 @@
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.user.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.user.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>

@ -21,6 +21,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -52,4 +53,8 @@ public class DeviceManagementRepository {
return providers.get(type);
}
public Collection<DeviceMgtService> getDeviceManagementProviders(){
return providers.values();
}
}

@ -471,4 +471,104 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsForStatus(status);
}
}
@Override
public List<Device> getAllDevicesOfUser(String userName)
throws DeviceManagementException {
List<Device> devicesOfUser = new ArrayList<Device>();
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList;
Device convertedDevice;
DeviceIdentifier deviceIdentifier;
DeviceManager dms;
Device dmsDevice;
org.wso2.carbon.device.mgt.core.dto.Device device;
int tenantId = DeviceManagerUtil.getTenantId();
//Fetch the DeviceList from Core
try {
devicesList = this.getDeviceDAO().getDeviceListOfUser(userName, tenantId);
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the devices of user '"
+ userName + "'", e);
}
//Fetch the DeviceList from device plugin dbs & append the properties
for (int x = 0; x < devicesList.size(); x++) {
device = devicesList.get(x);
try {
//TODO : Possible improvement if DeviceTypes have been cached
device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId()));
dms = this.getPluginRepository().getDeviceManagementProvider(device.getDeviceType().getName());
convertedDevice = DeviceManagementDAOUtil.convertDevice(device, device.getDeviceType());
deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentificationId());
deviceIdentifier.setType(device.getDeviceType().getName());
dmsDevice = dms.getDevice(deviceIdentifier);
if (dmsDevice != null) {
convertedDevice.setProperties(dmsDevice.getProperties());
convertedDevice.setFeatures(dmsDevice.getFeatures());
}
devicesOfUser.add(convertedDevice);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while obtaining the device type of DeviceTypeId '"+
device.getDeviceTypeId() + "'",e);
}
}
return devicesOfUser;
}
@Override
public List<Device> getAllDevicesOfRole(String roleName)
throws DeviceManagementException {
List<Device> devicesOfRole = new ArrayList<Device>();
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList;
List<org.wso2.carbon.device.mgt.user.common.User> users;
Device convertedDevice;
DeviceIdentifier deviceIdentifier;
DeviceManager dms;
Device dmsDevice;
org.wso2.carbon.device.mgt.core.dto.Device device;
String userName = "";
int tenantId = DeviceManagerUtil.getTenantId();
//Obtaining the list of users of role
try {
users = DeviceManagementDataHolder.getInstance().getUserManager().getUsersForTenantAndRole(
tenantId, roleName);
} catch (org.wso2.carbon.device.mgt.user.common.UserManagementException e) {
throw new DeviceManagementException("Error occurred while obtaining the users of role '"
+ roleName + "'", e);
}
//Obtaining the devices per user
for(org.wso2.carbon.device.mgt.user.common.User user:users){
try {
userName = user.getUserName();
devicesList = this.getDeviceDAO().getDeviceListOfUser(userName, tenantId);
for (int x = 0; x < devicesList.size(); x++) {
device = devicesList.get(x);
try {
//TODO : Possible improvement if DeviceTypes have been cached
device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId()));
dms = this.getPluginRepository().getDeviceManagementProvider(device.getDeviceType().getName());
convertedDevice = DeviceManagementDAOUtil.convertDevice(device, device.getDeviceType());
deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentificationId());
deviceIdentifier.setType(device.getDeviceType().getName());
dmsDevice = dms.getDevice(deviceIdentifier);
if (dmsDevice != null) {
convertedDevice.setProperties(dmsDevice.getProperties());
convertedDevice.setFeatures(dmsDevice.getFeatures());
}
devicesOfRole.add(convertedDevice);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while obtaining the device type of DeviceTypeId '"+
device.getDeviceTypeId() + "'",e);
}
}
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while obtaining the devices of user '"
+ userName + "'", e);
}
}
return devicesOfRole;
}
}

@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;
import org.wso2.carbon.device.mgt.user.core.UserManager;
public class DeviceManagementDataHolder {
@ -42,6 +43,7 @@ public class DeviceManagementDataHolder {
private AppManagerConnector appManager;
private AppManagementConfig appManagerConfig;
private OperationManager operationManager;
private UserManager userManager;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
@ -135,4 +137,13 @@ public class DeviceManagementDataHolder {
public void setOperationManager(OperationManager operationManager) {
this.operationManager = operationManager;
}
public UserManager getUserManager() {
return userManager;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
}

@ -29,7 +29,6 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
@ -55,6 +54,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.device.mgt.user.core.UserManager;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService;
@ -93,6 +93,12 @@ import java.util.List;
* policy="dynamic"
* bind="setDataSourceService"
* unbind="unsetDataSourceService"
* @scr.reference name="org.wso2.carbon.device.mgt.usermanager.service"
* interface="org.wso2.carbon.device.mgt.user.core.UserManager"
* cardinality="1..1"
* policy="dynamic"
* bind="setUserManager"
* unbind="unsetUserManager"
*/
public class DeviceManagementServiceComponent {
@ -324,6 +330,30 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setRegistryService(null);
}
/**
* Sets UserManager Service.
*
* @param userMgtService An instance of UserManager
*/
protected void setUserManager(UserManager userMgtService) {
if (log.isDebugEnabled()) {
log.debug("Setting UserManager Service");
}
DeviceManagementDataHolder.getInstance().setUserManager(userMgtService);
}
/**
* Unsets UserManager Service.
*
* @param userMgtService An instance of UserManager
*/
protected void unsetUserManager(UserManager userMgtService) {
if (log.isDebugEnabled()) {
log.debug("Unsetting UserManager Service");
}
DeviceManagementDataHolder.getInstance().setUserManager(null);
}
private DeviceManagementRepository getPluginRepository() {
return pluginRepository;
}

@ -50,4 +50,24 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
*/
Device getCoreDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
/**
* Method to get the list of devices owned by an user.
*
* @param userName Username of the user
* @return List of devices owned by a particular user
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
List<Device> getAllDevicesOfUser(String userName) throws DeviceManagementException;
/**
* Method to get the list of devices owned by users of a particular user-role.
*
* @param roleName Role name of the users
* @return List of devices owned by users of a particular role
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
* device list
*/
List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException;
}

@ -189,4 +189,18 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendRegistrationEmail(emailMessageProperties);
}
@Override
public List<Device> getAllDevicesOfUser(String userName)
throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getAllDevicesOfUser(userName);
}
@Override
public List<Device> getAllDevicesOfRole(String roleName)
throws DeviceManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getAllDevicesOfRole(roleName);
}
}

@ -55,7 +55,7 @@ public class DeviceMgtUserServiceComponent {
}
/* Registering User Management service */
BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(UserManagementService.class.getName(),
bundleContext.registerService(UserManager.class,
new UserManagementService(), null);
if (log.isDebugEnabled()) {
log.debug("User management core bundle has been successfully initialized");

@ -32,7 +32,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.devicemgt.user.server.feature</artifactId>
<artifactId>org.wso2.carbon.device.mgt.user.server.feature</artifactId>
<packaging>pom</packaging>
<version>0.9.2-SNAPSHOT</version>
<name>WSO2 Carbon - User Management Server Feature</name>
@ -91,7 +91,7 @@
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>org.wso2.carbon.devicemgt.user.server</id>
<id>org.wso2.carbon.device.mgt.user.server</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile>
<properties>

@ -41,7 +41,7 @@
<modules>
<module>org.wso2.carbon.devicemgt.user.server.feature</module>
<module>org.wso2.carbon.device.mgt.user.server.feature</module>
</modules>
</project>
Loading…
Cancel
Save