diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index 82e3fb57d4..b3a594a95c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.common; public class EnrolmentInfo { public enum Status { - CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED + CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED } public enum OwnerShip { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index ad87c15096..75cddd8141 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -60,5 +60,7 @@ public interface DeviceDAO { EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException; + + List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 55d19152ff..fdb18454f7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -442,4 +442,33 @@ public class DeviceDAOImpl implements DeviceDAO { return enrolmentInfo; } + public List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + List devices = new ArrayList(); + try { + conn = this.getConnection(); + stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + + "AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " + + "AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"); + stmt.setInt(1, tenantId); + stmt.setString(2, status.toString()); + stmt.setInt(3, tenantId); + ResultSet rs = stmt.executeQuery(); + + while (rs.next()) { + Device device = this.loadDevice(rs); + devices.add(device); + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + + "'" + status + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return devices; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 9c72e0323c..345838a1e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -79,4 +79,13 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM List getDevicesByName(String deviceName) throws DeviceManagementException; void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; + + /** + * This method is used to retrieve list of devices based on the device status + * + * @param status Device status + * @return List of devices + * @throws DeviceManagementException + */ + List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 98ce6549f0..0538923cdf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -716,6 +716,45 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } + + public List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException { + List devices = new ArrayList(); + List allDevices; + try { + DeviceManagementDAOFactory.getConnection(); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + allDevices = deviceDAO.getDevicesByStatus(status, tenantId); + + } catch (DeviceManagementDAOException e) { + String errorMsg = "Error occurred while fetching the list of devices that matches to status: '" + + status + "'"; + log.error(errorMsg, e); + throw new DeviceManagementException(errorMsg, e); + } finally { + + try { + DeviceManagementDAOFactory.closeConnection(); + } catch (DeviceManagementDAOException e) { + log.warn("Error occurred while closing the connection", e); + } + } + + for (Device device : allDevices) { + Device dmsDevice = + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( + new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } + devices.add(device); + } + return devices; + } + + + private int getTenantId() { ThreadLocal tenantId = new ThreadLocal(); @@ -728,4 +767,5 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } return tenant; } + } diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml new file mode 100644 index 0000000000..a20ebb17c6 --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml @@ -0,0 +1,154 @@ + + + + + + + + org.wso2.carbon.devicemgt + oauth-extentions-feature + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.oauth.extensions.server.feature + pom + 0.9.2-SNAPSHOT + WSO2 Carbon - Oauth Extensions Server Feature + http://wso2.org + This feature contains oauth functionality + + + + + + + + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + copy + package + + copy + + + + + org.wso2.mdm + dynamic-client-manager + ${project.version} + war + true + ${basedir}/src/main/resources/ + dynamic-client-manager.war + + + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.oauth.extensions.server + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + + + + + + + + + + + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + + + + + + + + + + + diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..3143c5e9df --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf @@ -0,0 +1,2 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.oauth.extensions.server_${feature.version}/dynamic-client-manager.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-manager.war,overwrite:true);\ \ No newline at end of file diff --git a/features/oauth-extensions/pom.xml b/features/oauth-extensions/pom.xml new file mode 100644 index 0000000000..87ed9a7ef0 --- /dev/null +++ b/features/oauth-extensions/pom.xml @@ -0,0 +1,42 @@ + + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 0.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt + oauth-extentions-feature + 0.9.2-SNAPSHOT + pom + WSO2 Carbon - Policy Management Feature + http://wso2.org + + + org.wso2.carbon.oauth.extensions.server.feature + + + diff --git a/pom.xml b/pom.xml index f31068a457..ffd4eda2eb 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ features/device-mgt features/policy-mgt features/webapp-authenticator-framework + features/oauth-extensions