From 20999f4cd59c666a8ba5d12e96d2caa46fe00a56 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Thu, 18 May 2017 10:54:54 +0530 Subject: [PATCH 1/3] Fixing wso2/product-iots##467 --- .../resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json index 94966cc9f4..4e303190d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json @@ -41,7 +41,7 @@ "id": "device_cloud", "url": "https://docs.wso2.com/display/DeviceCloud/WSO2+Device+Cloud+Documentation", "icon": "fw fw-mobile", - "target": "_self" + "target": "_blank" } } } From 1a265954728f094cc5b8007be46612d17f874989 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Fri, 26 May 2017 14:54:04 +0530 Subject: [PATCH 2/3] Fix issue with using enrollment id for device id --- .../core/operation/mgt/OperationManagerImpl.java | 2 +- .../mgt/core/operation/mgt/OperationMapping.java | 9 +++++++++ .../mgt/dao/impl/GenericOperationDAOImpl.java | 15 +++++++++------ .../mgt/dao/impl/OperationMappingDAOImpl.java | 4 ++-- .../impl/operation/OracleOperationDAOImpl.java | 15 +++++++++------ .../impl/operation/SQLServerOperationDAOImpl.java | 13 ++++++++----- .../mgt/task/PushNotificationSchedulerTask.java | 2 +- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 41530bfb48..a8cc331787 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -151,7 +151,7 @@ public class OperationManagerImpl implements OperationManager { // check whether device list is greater than batch size notification strategy has enable to send push // notification using scheduler task if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). - getPushNotificationConfiguration().getSchedulerBatchSize() < authorizedDeviceList.size() && + getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceList.size() && notificationStrategy != null) { isScheduled = notificationStrategy.getConfig().isScheduled(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMapping.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMapping.java index 6f42a78d15..d85fe5ea89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMapping.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMapping.java @@ -27,6 +27,7 @@ public class OperationMapping { private DeviceIdentifier deviceIdentifier; private int operationId; + private int enrollmentId; private int tenantId; private Operation.Status status; private Operation.PushNotificationStatus pushNotificationStatus; @@ -39,6 +40,14 @@ public class OperationMapping { this.operationId = operationId; } + public int getEnrollmentId() { + return enrollmentId; + } + + public void setEnrollmentId(int enrollmentId) { + this.enrollmentId = enrollmentId; + } + public int getTenantId() { return tenantId; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 3e50f49800..9b0c6cb2cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -1104,10 +1104,10 @@ public class GenericOperationDAOImpl implements OperationDAO { Map> operationMappingsTenantMap = new HashMap<>(); try { conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " + - "DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? AND " + - "op.PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID ORDER BY " + - "op.OPERATION_ID LIMIT ?"; + String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, d.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE, " + + "d.TENANT_ID FROM DM_DEVICE d, DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ?" + + " AND op.PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID ORDER" + + " BY op.OPERATION_ID LIMIT ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, opStatus.toString()); stmt.setString(2, pushNotificationStatus.toString()); @@ -1122,8 +1122,11 @@ public class GenericOperationDAOImpl implements OperationDAO { } operationMapping = new OperationMapping(); operationMapping.setOperationId(rs.getInt("OPERATION_ID")); - operationMapping.setDeviceIdentifier(new DeviceIdentifier(String.valueOf(rs.getInt("ENROLMENT_ID")), - rs.getString("NAME"))); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + operationMapping.setDeviceIdentifier(deviceIdentifier); + operationMapping.setEnrollmentId(rs.getInt("ENROLMENT_ID")); operationMapping.setTenantId(tenantID); operationMappings.add(operationMapping); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java index 0846813fdf..c1fb5bd8f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java @@ -109,7 +109,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { if (conn.getMetaData().supportsBatchUpdates()) { for (OperationMapping operationMapping : operationMappingList) { stmt.setString(1, operationMapping.getPushNotificationStatus().toString()); - stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId())); + stmt.setInt(2, operationMapping.getEnrollmentId()); stmt.setInt(3, operationMapping.getOperationId()); stmt.addBatch(); } @@ -117,7 +117,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { } else { for (OperationMapping operationMapping : operationMappingList) { stmt.setString(1, operationMapping.getPushNotificationStatus().toString()); - stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId())); + stmt.setInt(2, operationMapping.getEnrollmentId()); stmt.setInt(3, operationMapping.getOperationId()); stmt.executeUpdate(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/OracleOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/OracleOperationDAOImpl.java index 321a13e46c..dd810cab2d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/OracleOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/OracleOperationDAOImpl.java @@ -376,10 +376,10 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl { Map> operationMappingsTenantMap = new HashMap<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " + - "DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? AND op" + - ".PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID AND ROWNUM" + - " <= ? ORDER BY op.OPERATION_ID"; + String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, d.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE, d" + + ".TENANT_ID FROM DM_DEVICE d, DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? " + + "AND op.PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID AND " + + "ROWNUM <= ? ORDER BY op.OPERATION_ID"; stmt = conn.prepareStatement(sql); stmt.setString(1, opStatus.toString()); @@ -395,8 +395,11 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl { } operationMapping = new OperationMapping(); operationMapping.setOperationId(rs.getInt("OPERATION_ID")); - operationMapping.setDeviceIdentifier(new DeviceIdentifier(String.valueOf(rs.getInt("ENROLMENT_ID")), - rs.getString("NAME"))); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + operationMapping.setDeviceIdentifier(deviceIdentifier); + operationMapping.setEnrollmentId(rs.getInt("ENROLMENT_ID")); operationMapping.setTenantId(tenantID); operationMappings.add(operationMapping); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java index d19a5b151b..60015a9095 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java @@ -277,9 +277,9 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl { Map> operationMappingsTenantMap = new HashMap<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " + - "DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? AND op" + - ".PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID " + + String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, d.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE, d" + + ".TENANT_ID FROM DM_DEVICE d, DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? " + + "AND op.PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID " + "AND d.ID=op.ENROLMENT_ID ORDER BY op.OPERATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); stmt.setString(1, opStatus.toString()); @@ -295,8 +295,11 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl { } operationMapping = new OperationMapping(); operationMapping.setOperationId(rs.getInt("OPERATION_ID")); - operationMapping.setDeviceIdentifier(new DeviceIdentifier(String.valueOf(rs.getInt("ENROLMENT_ID")), - rs.getString("NAME"))); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + operationMapping.setDeviceIdentifier(deviceIdentifier); + operationMapping.setEnrollmentId(rs.getInt("ENROLMENT_ID")); operationMapping.setTenantId(tenantID); operationMappings.add(operationMapping); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java index 3ac4126f30..133ba08cb0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java @@ -77,7 +77,7 @@ public class PushNotificationSchedulerTask implements Runnable { try { if (log.isDebugEnabled()) { log.debug("Sending push notification for operationId :" + operationMapping.getOperationId() + - "to deviceId : " + operationMapping.getDeviceIdentifier().getId()); + " to deviceId : " + operationMapping.getDeviceIdentifier().getId()); } // Set tenant id and domain PrivilegedCarbonContext.startTenantFlow(); From c4d433a1a0e53549240c100823478f209af30475 Mon Sep 17 00:00:00 2001 From: madhawap Date: Mon, 29 May 2017 20:13:51 +0530 Subject: [PATCH 3/3] Fix for disabling reboot and upgrade-firmware operations on UI and Code formatting In order to execute these two operations the enrolled device needs to have the system app installed. Therefore, in order to stop users from trying these two operations on cloud, the icons related to these two operations, on operation bar are disabled. In addition change a c-style for loop to a foreach loop in PolicyManagementServiceImpl.java --- .../jaxrs/service/impl/PolicyManagementServiceImpl.java | 8 ++++---- .../app/modules/business-controllers/operation.js | 8 ++++++++ .../units/cdmf.unit.ui.theme/public/css/custom-common.css | 7 ++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 7c1fe8e407..f51ebfd928 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -345,11 +345,11 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { public Response updatePolicyPriorities(List priorityUpdatedPolicies) { PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); List policiesToUpdate = new ArrayList<>(priorityUpdatedPolicies.size()); - int i; - for (i = 0; i < priorityUpdatedPolicies.size(); i++) { + + for (PriorityUpdatedPolicyWrapper priorityUpdatedPolicy : priorityUpdatedPolicies) { Policy policyObj = new Policy(); - policyObj.setId(priorityUpdatedPolicies.get(i).getId()); - policyObj.setPriorityId(priorityUpdatedPolicies.get(i).getPriority()); + policyObj.setId(priorityUpdatedPolicy.getId()); + policyObj.setPriorityId(priorityUpdatedPolicy.getPriority()); policiesToUpdate.add(policyObj); } boolean policiesUpdated; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index 666b1b571d..3451c66cb3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -86,6 +86,14 @@ var operationModule = function () { var iconIdentifier = operations[op].operation; if (features && features[iconIdentifier]) { var icon = features[iconIdentifier].icon; + var isCloud = devicemgtProps["isCloud"]; + //TODO: remove isCloud check once able to verify features from the device agent + var isDisabled = features[iconIdentifier].isDisabled; + if (isDisabled && isCloud) { + operations[op]["isDisabled"] = isDisabled; + } else { + operations[op]["isDisabled"] = false; + } if (icon) { operations[op]["iconFont"] = icon; } else if (iconPath) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css index 1fa92bf549..82a5f91859 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css @@ -265,4 +265,9 @@ header .username { .add-padding-top-3x { padding-top: 15px !important; -} \ No newline at end of file +} + +.op-disabled, .op-disabled i, .op-disabled span { + cursor: not-allowed; ++ color: #d2d2d2; +}