diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index 444854e1e46..b80889f41b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -81,7 +81,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService long timestamp = 0; boolean isIfModifiedSinceSet = false; boolean isSinceSet = false; - + RequestValidationUtil.validatePaginationParameters(offset, limit); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { Date ifSinceDate; SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 2266f51d4a8..2fafc9b1290 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -74,7 +74,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("limit") int limit) { try { // RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status); - + RequestValidationUtil.validatePaginationParameters(offset, limit); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; @@ -154,6 +154,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { public Response getDeviceByUser(@QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; DeviceList devices = new DeviceList(); @@ -292,6 +293,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("offset") int offset, @QueryParam("limit") int limit) { OperationList operationsList = new OperationList(); + RequestValidationUtil.validatePaginationParameters(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; DeviceManagementProviderService dms; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java index c504da33d1b..acfe66f043c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java @@ -50,6 +50,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; 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 487cdc1517d..a47e85e5c1d 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 @@ -140,6 +140,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); List policies; List filteredPolicies; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index 9c56351d35c..37fe8b214e4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -63,6 +63,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { @QueryParam("user-store") String userStore, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); List filteredRoles; RoleList targetRoles = new RoleList(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index ffad2e8d81a..eda434e2f8a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.*; import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService; +import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; @@ -264,6 +265,7 @@ public class UserManagementServiceImpl implements UserManagementService { log.debug("Getting the list of users with all user-related information"); } List userList, offsetList; + RequestValidationUtil.validatePaginationParameters(offset, limit); String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); int appliedLimit = (limit <= 0) ? -1 : (limit + offset); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 4956583627f..26ac8dd8d2c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; +import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.*; @@ -50,6 +51,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); try { int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java index a3b503640f5..bf9a9e8246b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.util; import org.wso2.carbon.device.mgt.jaxrs.beans.Scope; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.jaxrs.beans.*; @@ -313,11 +314,16 @@ public class RequestValidationUtil { } } - public static void validateScopes(List scopes) { - if (scopes == null || scopes.isEmpty()) { + public static void validatePaginationParameters(int offset, int limit) { + if (offset < 0) { throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Scope details of the request body" + - " is incorrect or empty").build()); + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter offset is s " + + "negative value.").build()); + } + if (limit < 0) { + throw new InputValidationException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter limit is a " + + "negative value.").build()); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java index 1eb5e28e46f..1849a97c0d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java @@ -29,12 +29,12 @@ public class DeviceTypeIdentifier implements Serializable { private static final int DEFAULT_SHARE_WITH_ALL_TENANTS_ID = -1; public DeviceTypeIdentifier(String deviceType, int tenantId) { - this.deviceType = deviceType; + this.deviceType = deviceType.toLowerCase(); this.tenantId = tenantId; } public DeviceTypeIdentifier(String deviceType) { - this.deviceType = deviceType; + this.deviceType = deviceType.toLowerCase(); this.tenantId = DEFAULT_SHARE_WITH_ALL_TENANTS_ID; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index d55f553920b..504d29d5f18 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -52,7 +52,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis } public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceType = provider.getType(); + String deviceType = provider.getType().toLowerCase(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); String tenantDomain = provisioningConfig.getProviderTenantDomain(); @@ -87,7 +87,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis } public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceTypeName = provider.getType(); + String deviceTypeName = provider.getType().toLowerCase(); DeviceTypeIdentifier deviceTypeIdentifier; ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); if (provisioningConfig.isSharedWithAllTenants()) { @@ -103,10 +103,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public DeviceManagementService getDeviceManagementService(String type, int tenantId) { //Priority need to be given to the tenant before public. - DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(type, tenantId); + DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase(), tenantId); DeviceManagementService provider = providers.get(deviceTypeIdentifier); if (provider == null) { - deviceTypeIdentifier = new DeviceTypeIdentifier(type); + deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase()); provider = providers.get(deviceTypeIdentifier); } return provider; @@ -153,10 +153,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public OperationManager getOperationManager(String deviceType, int tenantId) { //Priority need to be given to the tenant before public. - DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId); + DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase(), tenantId); OperationManager operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier); if (operationManager == null) { - deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType); + deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase()); operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier); } return operationManager; @@ -164,14 +164,15 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis @Override public void notifyObserver() { + String deviceTypeName; synchronized (providers) { for (DeviceManagementService provider : providers.values()) { try { provider.init(); - + deviceTypeName = provider.getType().toLowerCase(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); - DeviceManagerUtil.registerDeviceType(provider.getType(), tenantId, provisioningConfig.isSharedWithAllTenants()); + DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId, provisioningConfig.isSharedWithAllTenants()); registerPushNotificationStrategy(provider); //TODO: //This is a temporory fix. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index 0891164cb06..20e4eba5c22 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; +import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration; import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration; @@ -37,6 +38,7 @@ public final class DeviceManagementConfig { private TaskConfiguration taskConfiguration; private IdentityConfigurations identityConfigurations; private PolicyConfiguration policyConfiguration; + private PaginationConfiguration paginationConfiguration; private List pushNotificationProviders; @@ -87,5 +89,14 @@ public final class DeviceManagementConfig { this.pushNotificationProviders = pushNotificationProviders; } + @XmlElement(name = "PaginationConfiguration", required = true) + public PaginationConfiguration getPaginationConfiguration() { + return paginationConfiguration; + } + + public void setPaginationConfiguration(PaginationConfiguration paginationConfiguration) { + this.paginationConfiguration = paginationConfiguration; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java new file mode 100644 index 00000000000..f60f33d98f6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.core.config.pagination; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This class represents the information related to Pagination configuration. + */ +@XmlRootElement(name = "PaginationConfiguration") +public class PaginationConfiguration { + + private int deviceListPageSize; + private int operationListPageSize; + private int notificationListPageSize; + private int activityListPageSize; + + public int getDeviceListPageSize() { + return deviceListPageSize; + } + + @XmlElement(name = "DeviceListPageSize", required = true) + public void setDeviceListPageSize(int deviceListPageSize) { + this.deviceListPageSize = deviceListPageSize; + } + + public int getOperationListPageSize() { + return operationListPageSize; + } + + @XmlElement(name = "OperationListPageSize", required = true) + public void setOperationListPageSize(int operationListPageSize) { + this.operationListPageSize = operationListPageSize; + } + + public int getNotificationListPageSize() { + return notificationListPageSize; + } + + @XmlElement(name = "NotificationListPageSize", required = true) + public void setNotificationListPageSize(int notificationListPageSize) { + this.notificationListPageSize = notificationListPageSize; + } + + public int getActivityListPageSize() { + return activityListPageSize; + } + + @XmlElement(name = "ActivityListPageSize", required = true) + public void setActivityListPageSize(int activityListPageSize) { + this.activityListPageSize = activityListPageSize; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java index 0021c0dc969..45a4b881c43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java @@ -102,7 +102,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { Connection conn; PreparedStatement stmt = null; try { - String sql = "DELETE DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + + String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + "APPLICATION_ID = ? AND TENANT_ID = ?"; conn = this.getConnection(); @@ -114,7 +114,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { stmt.execute(); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while adding device application mapping", e); + throw new DeviceManagementDAOException("Error occurred while removing device application mapping", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java index 1998907b9d0..abb9b1f87c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java @@ -129,7 +129,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { int status = -1; try { conn = this.getConnection(); - String sql = "DELETE DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; + String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql, new String[] {"id"}); stmt.setInt(1, deviceId); stmt.setString(2, currentOwner); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 59692da94db..88883a4e261 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationDAO; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.sql.SQLException; import java.util.ArrayList; @@ -177,6 +178,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException { PaginationResult paginationResult = new PaginationResult(); List notifications = new ArrayList<>(); + request = DeviceManagerUtil.validateNotificationListPageSize(request); int count =0; try { NotificationManagementDAOFactory.openConnection(); @@ -199,6 +201,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement PaginationRequest request) throws NotificationManagementException{ PaginationResult paginationResult = new PaginationResult(); List notifications = new ArrayList<>(); + request = DeviceManagerUtil.validateNotificationListPageSize(request); int count =0; try { NotificationManagementDAOFactory.openConnection(); 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 314a26c3924..73533f36fd4 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 @@ -508,6 +508,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int count = 0; int tenantId = this.getTenantId(); String deviceType = request.getDeviceType(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevices(request, tenantId); @@ -569,6 +570,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List allDevices = new ArrayList<>(); int count = 0; int tenantId = this.getTenantId(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevices(request, tenantId); @@ -1031,6 +1033,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request) throws OperationManagementException { + request = DeviceManagerUtil.validateOperationListPageSize(request); return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId()) .getOperations(deviceId, request); } @@ -1091,6 +1094,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException { + limit = DeviceManagerUtil.validateActivityListPageSize(limit); return DeviceManagementDataHolder.getInstance().getOperationManager().getActivitiesUpdatedAfter(timestamp, limit, offset); } @@ -1176,6 +1180,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv String username = request.getOwner(); List devices = new ArrayList<>(); List userDevices = new ArrayList<>(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); userDevices = deviceDAO.getDevicesOfUser(request, tenantId); @@ -1253,6 +1258,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int deviceCount = 0; int tenantId = this.getTenantId(); String ownerShip = request.getOwnership(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByOwnership(request, tenantId); @@ -1412,6 +1418,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv public List getDevicesByNameAndType(String deviceName, String type, int offset, int limit) throws DeviceManagementException { List devices = new ArrayList<>(); List allDevices; + limit = DeviceManagerUtil.validateDeviceListPageSize(limit); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByNameAndType(deviceName, type, this.getTenantId(), offset, limit); @@ -1474,6 +1481,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List devices = new ArrayList<>(); List allDevices = new ArrayList<>(); String deviceName = request.getDeviceName(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByName(request, tenantId); @@ -1636,6 +1644,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List allDevices = new ArrayList<>(); int tenantId = this.getTenantId(); String status = request.getStatus(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByStatus(request, tenantId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index a9d472d4985..2e338943b85 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -21,10 +21,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.wso2.carbon.base.MultitenantConstants; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; @@ -241,4 +242,79 @@ public final class DeviceManagerUtil { } } + public static int validateActivityListPageSize(int limit) throws OperationManagementException { + if (limit == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + return deviceManagementConfig.getPaginationConfiguration().getActivityListPageSize(); + } else { + throw new OperationManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return limit; + } + + public static PaginationRequest validateOperationListPageSize(PaginationRequest paginationRequest) throws + OperationManagementException { + if (paginationRequest.getRowCount() == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration(). + getOperationListPageSize()); + } else { + throw new OperationManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } + + public static PaginationRequest validateNotificationListPageSize(PaginationRequest paginationRequest) throws + NotificationManagementException { + if (paginationRequest.getRowCount() == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration(). + getNotificationListPageSize()); + } else { + throw new NotificationManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } + + public static PaginationRequest validateDeviceListPageSize(PaginationRequest paginationRequest) throws + DeviceManagementException { + if (paginationRequest.getRowCount() == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration(). + getDeviceListPageSize()); + } else { + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } + + public static int validateDeviceListPageSize(int limit) throws DeviceManagementException { + if (limit == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + return deviceManagementConfig.getPaginationConfiguration().getDeviceListPageSize(); + } else { + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return limit; + } } 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 1e479286a90..e96ffcdec19 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 @@ -16,123 +16,119 @@ * under the License. */ -/* - @Deprecated New - */ +var operationModule = function () { + var log = new Log("/app/modules/business-controllers/operation.js"); + var utility = require('/app/modules/utility.js').utility; + var constants = require('/app/modules/constants.js'); + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; + + var publicMethods = {}; + var privateMethods = {}; + + /** + * This method reads the token from the Token client and return the access token. + * If the token pair s not set in the session this will send a redirect to the login page. + */ + function getAccessToken(deviceType, owner, deviceId) { + var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; + var accessTokenClient = new TokenClient(deviceType); + var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); + return accessTokenInfo.getAccess_token(); + } + + privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { + var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; + var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { + var features = responsePayload; + var featureList = []; + var feature; + for (var i = 0; i < features.length; i++) { + feature = {}; + var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; + if (analyticStreams) { + for (var stream in analyticStreams) { + if (analyticStreams[stream].name == features[i].name) { + feature.ui_unit = analyticStreams[stream].ui_unit; + break; + } + } + } + + feature["operation"] = features[i].code; + feature["name"] = features[i].name; + feature["description"] = features[i].description; + feature["deviceType"] = deviceType; + feature["params"] = []; + var metaData = features[i].metadataEntries; + if (metaData) { + for (var j = 0; j < metaData.length; j++) { + feature["params"].push(metaData[j].value); + } + featureList.push(feature); + } + } + return featureList; + }, function (responsePayload) { + var response = {}; + response["status"] = "error"; + return response; + } + ); + return featuresList; + }; + + publicMethods.getControlOperations = function (deviceType) { + var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); + for (var op in operations) { + var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); + if (iconPath) { + operations[op]["icon"] = iconPath; + } + } + return operations; + }; + + publicMethods.getMonitorOperations = function (deviceType) { + return privateMethods.getOperationsFromFeatures(deviceType, "monitor"); + }; + + publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) { + var user = session.get(constants.USER_SESSION_KEY); + var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; + var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + + '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + + constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + + getAccessToken(deviceType, user.username, deviceId) + '"}'; + return post(endPoint, params, JSON.parse(header), "json"); + }; + + publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) { + var user = session.get(constants.USER_SESSION_KEY); + var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; + var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + + '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + + constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + + '"}'; + var result = get(endPoint, {}, JSON.parse(header), "json"); + if (result.data) { + var values = result.data.sensorValue.split(','); + if (operationName == 'gps') { + result.data.map = { + lat: parseFloat(values[0]), + lng: parseFloat(values[1]) + } + } else { + var sqSum = 0; + for (var v in values) { + sqSum += Math.pow(values[v], 2); + } + result.data[operationName] = Math.sqrt(sqSum); + } + delete result.data['sensorValue']; + } + return result; + }; -//var operationModule = function () { -// var log = new Log("/app/modules/business-controllers/operation.js"); -// var utility = require('/app/modules/utility.js').utility; -// var constants = require('/app/modules/constants.js'); -// var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; -// var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; -// -// var publicMethods = {}; -// var privateMethods = {}; -// -// /** -// * This method reads the token from the Token client and return the access token. -// * If the token pair s not set in the session this will send a redirect to the login page. -// */ -// function getAccessToken(deviceType, owner, deviceId) { -// var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; -// var accessTokenClient = new TokenClient(deviceType); -// var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); -// return accessTokenInfo.getAccess_token(); -// } -// -// privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { -// var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; -// var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { -// var features = responsePayload; -// var featureList = []; -// var feature; -// for (var i = 0; i < features.length; i++) { -// feature = {}; -// var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; -// if (analyticStreams) { -// for (var stream in analyticStreams) { -// if (analyticStreams[stream].name == features[i].name) { -// feature.ui_unit = analyticStreams[stream].ui_unit; -// break; -// } -// } -// } -// -// feature["operation"] = features[i].code; -// feature["name"] = features[i].name; -// feature["description"] = features[i].description; -// feature["deviceType"] = deviceType; -// feature["params"] = []; -// var metaData = features[i].metadataEntries; -// if (metaData) { -// for (var j = 0; j < metaData.length; j++) { -// feature["params"].push(metaData[j].value); -// } -// featureList.push(feature); -// } -// } -// return featureList; -// }, function (responsePayload) { -// var response = {}; -// response["status"] = "error"; -// return response; -// } -// ); -// return featuresList; -// }; -// -// publicMethods.getControlOperations = function (deviceType) { -// var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); -// for (var op in operations) { -// var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); -// if (iconPath) { -// operations[op]["icon"] = iconPath; -// } -// } -// return operations; -// }; -// -// publicMethods.getMonitorOperations = function (deviceType) { -// return privateMethods.getOperationsFromFeatures(deviceType, "monitor"); -// }; -// -// publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) { -// var user = session.get(constants.USER_SESSION_KEY); -// var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; -// var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + -// '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + -// constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + -// getAccessToken(deviceType, user.username, deviceId) + '"}'; -// return post(endPoint, params, JSON.parse(header), "json"); -// }; -// -// publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) { -// var user = session.get(constants.USER_SESSION_KEY); -// var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; -// var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + -// '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + -// constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + -// '"}'; -// var result = get(endPoint, {}, JSON.parse(header), "json"); -// if (result.data) { -// var values = result.data.sensorValue.split(','); -// if (operationName == 'gps') { -// result.data.map = { -// lat: parseFloat(values[0]), -// lng: parseFloat(values[1]) -// } -// } else { -// var sqSum = 0; -// for (var v in values) { -// sqSum += Math.pow(values[v], 2); -// } -// result.data[operationName] = Math.sqrt(sqSum); -// } -// delete result.data['sensorValue']; -// } -// return result; -// }; -// -// return publicMethods; -//}(); \ No newline at end of file + return publicMethods; +}(); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js index 6cc38a9bfe5..f569accf612 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js @@ -1,24 +1,21 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ -/* - @Refactored - */ var policyModule; policyModule = function () { var log = new Log("/app/modules/business-controllers/policy.js"); @@ -31,118 +28,90 @@ policyModule = function () { var publicMethods = {}; var privateMethods = {}; - privateMethods.handleGetAllPoliciesError = function (responsePayload) { + privateMethods.handleGetAllPoliciesResponse = function (backendResponse) { var response = {}; - response.status = "error"; - /* responsePayload == "Scope validation failed" - Here the response.context("Scope validation failed") is used other then response.status(401). - Reason for this is IDP return 401 as the status in 4 different situations such as, - 1. UnAuthorized. - 2. Scope Validation Failed. - 3. Permission Denied. - 4. Access Token Expired. - 5. Access Token Invalid. - In these cases in order to identify the correct situation we have to compare the unique value from status and - context which is context. - */ - if (responsePayload == "Scope validation failed") { - response.content = "Permission Denied"; - } else { - response.content = responsePayload; - } - return response; - }; + if (backendResponse.status == 200 && backendResponse.responseText) { + var isUpdated = false; + var policyListFromRestEndpoint = parse(backendResponse.responseText)["policies"]; + + var policyListToView = []; + var i, policyObjectFromRestEndpoint, policyObjectToView; + for (i = 0; i < policyListFromRestEndpoint.length; i++) { + // get list object + policyObjectFromRestEndpoint = policyListFromRestEndpoint[i]; + // populate list object values to view-object + policyObjectToView = {}; + policyObjectToView["id"] = policyObjectFromRestEndpoint["id"]; + policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"]; + policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; + policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]; + policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"]; + + var assignedRoleCount = policyObjectFromRestEndpoint["roles"].length; + var assignedUserCount = policyObjectFromRestEndpoint["users"].length; + + if (assignedRoleCount == 0) { + policyObjectToView["roles"] = "None"; + } else if (assignedRoleCount == 1) { + policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0]; + } else if (assignedRoleCount > 1) { + policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0] + ", ..."; + } - privateMethods.handleGetAllPoliciesSuccess = function (responsePayload) { - var isUpdated = false; - var policyListFromRestEndpoint = responsePayload["responseContent"]; - var policyListToView = []; - var i, policyObjectFromRestEndpoint, policyObjectToView; - for (i = 0; i < policyListFromRestEndpoint.length; i++) { - // get list object - policyObjectFromRestEndpoint = policyListFromRestEndpoint[i]; - // populate list object values to view-object - policyObjectToView = {}; - policyObjectToView["id"] = policyObjectFromRestEndpoint["id"]; - policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"]; - policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; - policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]["name"]; - policyObjectToView["icon"] = utility.getDeviceThumb(policyObjectToView["platform"]); - policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"]; - policyObjectToView["roles"] = privateMethods. - getElementsInAString(policyObjectFromRestEndpoint["roles"]); - policyObjectToView["users"] = privateMethods. - getElementsInAString(policyObjectFromRestEndpoint["users"]); - policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"]; + if (assignedUserCount == 0) { + policyObjectToView["users"] = "None"; + } else if (assignedUserCount == 1) { + policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0]; + } else if (assignedUserCount > 1) { + policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0] + ", ..."; + } - if (policyObjectFromRestEndpoint["active"] == true && policyObjectFromRestEndpoint["updated"] == true) { - policyObjectToView["status"] = "Active/Updated"; - isUpdated = true; - } else if (policyObjectFromRestEndpoint["active"] == true && - policyObjectFromRestEndpoint["updated"] == false) { - policyObjectToView["status"] = "Active"; - } else if (policyObjectFromRestEndpoint["active"] == false && - policyObjectFromRestEndpoint["updated"] == true) { - policyObjectToView["status"] = "Inactive/Updated"; - isUpdated = true; - } else if (policyObjectFromRestEndpoint["active"] == false && - policyObjectFromRestEndpoint["updated"] == false) { - policyObjectToView["status"] = "Inactive"; + policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"]; + + if (policyObjectFromRestEndpoint["active"] == true && + policyObjectFromRestEndpoint["updated"] == true) { + policyObjectToView["status"] = "Active/Updated"; + isUpdated = true; + } else if (policyObjectFromRestEndpoint["active"] == true && + policyObjectFromRestEndpoint["updated"] == false) { + policyObjectToView["status"] = "Active"; + } else if (policyObjectFromRestEndpoint["active"] == false && + policyObjectFromRestEndpoint["updated"] == true) { + policyObjectToView["status"] = "Inactive/Updated"; + isUpdated = true; + } else if (policyObjectFromRestEndpoint["active"] == false && + policyObjectFromRestEndpoint["updated"] == false) { + policyObjectToView["status"] = "Inactive"; + } + // push view-objects to list + policyListToView.push(policyObjectToView); } - // push view-objects to list - policyListToView.push(policyObjectToView); - } - // generate response - var response = {}; - response.updated = isUpdated; - response.status = "success"; - response.content = policyListToView; - return response; - }; + // generate response + response.updated = isUpdated; + response.status = "success"; + response.content = policyListToView; - publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription, - deviceId) { - var carbonUser = session.get(constants["USER_SESSION_KEY"]); - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants["ERRORS"]["USER_NOT_FOUND"]; - } - if (policyName && deviceType) { - var queName = "WSO2IoTServer/" + carbonUser.username + "/" + deviceType; - var deviceQueName; - if (deviceId) { - deviceQueName = queName + "/" + deviceId; - privateMethods.publish(deviceQueName, policyName, deviceType, policyDefinition); + return response; + } else { + response.status = "error"; + /* backendResponse.responseText == "Scope validation failed" + Here the response.context("Scope validation failed") is used other then response.status(401). + Reason for this is IDP return 401 as the status in 4 different situations such as, + 1. UnAuthorized. + 2. Scope Validation Failed. + 3. Permission Denied. + 4. Access Token Expired. + 5. Access Token Invalid. + In these cases in order to identify the correct situation we have to compare the unique value from status and + context which is context. + */ + if (backendResponse.responseText == "Scope validation failed") { + response.content = "Permission Denied"; } else { - var deviceManagementService = utility.getDeviceManagementService(); - var devices = deviceManagementService.getDevicesOfUser(carbonUser.username); - var device; - for (var i = 0; i < devices.size(); i++) { - device = devices.get(i); - deviceId = device.getDeviceIdentifier(); - deviceQueName = queName + "/" + deviceId; - privateMethods.publish(deviceQueName, policyName, deviceType, policyDefinition); - } + response.content = backendResponse.responseText; } - return true; + return response; } - return false; - }; - - privateMethods.publish = function (queName, policyName, deviceType, policyDefinition) { - var configurationService = utility.getConfigurationService(); - var mqttEndPointDeviceConfig = configurationService.getControlQueue(constants.MQTT_QUEUE_CONFIG_NAME); - var mqttBrokerURL = mqttEndPointDeviceConfig.getServerURL(); - var mqttBrokerPort = mqttEndPointDeviceConfig.getPort(); - var mqttQueueEndpoint = mqttBrokerURL + ":" + mqttBrokerPort; - - var mqttsenderClass = Packages.org.wso2.carbon.device.mgt.iot.mqtt.PolicyPush; - var mqttsender = new mqttsenderClass(); - - var policyPayload = "POLICY:" + policyDefinition; - var result = mqttsender.pushToMQTT(queName, policyPayload, mqttQueueEndpoint, "MQTT_Agent"); - mqttsender = null; - return result; }; /* @@ -155,9 +124,9 @@ policyModule = function () { throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/policies"; - return serviceInvokers.XMLHttp. - get(url, privateMethods.handleGetAllPoliciesSuccess, privateMethods.handleGetAllPoliciesError); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/policies?offset=0&limit=100"; + return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse); } catch (e) { throw e; } @@ -178,97 +147,5 @@ policyModule = function () { return elementsInAString; }; - /* - @Deprecated - */ - publicMethods.getProfiles = function () { - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var policyManagementService = utility.getPolicyManagementService(); - var policyAdminPoint = policyManagementService.getPAP(); - var profiles = policyAdminPoint.getProfiles(); - var profileList = []; - var i, profile, profileObject; - for (i = 0; i < profiles.size(); i++) { - profile = profiles.get(i); - profileObject = {}; - profileObject.name = profile.getProfileName(); - profileObject.id = profile.getProfileId(); - profileList.push(profileObject); - } - return profileList; - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - - /* - @Deprecated - */ - publicMethods.updatePolicyPriorities = function (payload) { - var carbonUser = session.get(constants.USER_SESSION_KEY); - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var policyManagementService = utility.getPolicyManagementService(); - var policyAdminPoint = policyManagementService.getPAP(); - var policyCount = payload.length; - var policyList = new java.util.ArrayList(); - var i, policyObject; - for (i = 0; i < policyCount; i++) { - policyObject = new Policy(); - policyObject.setId(payload[i].id); - policyObject.setPriorityId(payload[i].priority); - policyList.add(policyObject); - } - policyAdminPoint.updatePolicyPriorities(policyList); - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - - /* - @Deprecated - */ - publicMethods.deletePolicy = function (policyId) { - var isDeleted; - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var policyManagementService = utility.getPolicyManagementService(); - var policyAdminPoint = policyManagementService.getPAP(); - isDeleted = policyAdminPoint.deletePolicy(policyId); - if (isDeleted) { - // http status code 200 refers to - success. - return 200; - } else { - // http status code 409 refers to - conflict. - return 409; - } - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - return publicMethods; -}(); +}(); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js index f81849fe3bd..6731dbd23a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js @@ -37,6 +37,12 @@ var conf = function () { return value; } ); + if (conf.generalConfig.host) { + //TODO: Move enrollment URL into app-conf.json + var enrollmentHost = conf.generalConfig.host.replace(/https:\/\/localhost(:\d+)?/, conf.httpsURL).replace( + /http:\/\/localhost(:\d+)?/, conf.httpURL); + conf.enrollmentUrl = enrollmentHost + conf.enrollmentDir; + } application.put("CONF", conf); } return conf; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js index cf46e20def5..28142c13eb2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js @@ -28,7 +28,9 @@ function onRequest(context) { var typesListResponse = userModule.getPlatforms(); if (typesListResponse["status"] == "success") { for (var type in typesListResponse["content"]) { - var deviceType = typesListResponse["content"][type]["name"]; + var content = {}; + var deviceType = typesListResponse["content"]["deviceTypes"][type]; + content["name"] = deviceType; var configs = utility.getDeviceTypeConfig(deviceType); var deviceTypeLabel = deviceType; if (configs && configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY]) { @@ -36,9 +38,9 @@ function onRequest(context) { } var policyWizard = new File("/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-wizard")); if(policyWizard.isExists()){ - typesListResponse["content"][type]["icon"] = utility.getDeviceThumb(deviceType); - typesListResponse["content"][type]["label"] = deviceTypeLabel; - types["types"].push(typesListResponse["content"][type]); + content["icon"] = utility.getDeviceThumb(deviceType); + content["label"] = deviceTypeLabel; + types["types"].push(content); } } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 416495b0614..bf6e3787b1e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -27,8 +27,8 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.GCMBasedPushNotificationProvider - org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider - org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider + + https://localhost:9443 @@ -37,14 +37,14 @@ org.wso2.carbon.policy.mgt - false + true 60000 5 8 20 - false + true 600000 org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask @@ -62,5 +62,11 @@ + + 20 + 20 + 20 + 20 + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index f3f3735e50e..82c2eba5366 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -134,7 +134,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID INT NOT NULL AUTO_INCREMENT , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INT NOT NULL , - DEVICE_TYPE VARCHAR(20) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME NOT NULL , UPDATED_TIME DATETIME NOT NULL , PRIMARY KEY (ID) , @@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ID INT(11) NOT NULL , - DEVICE_TYPE VARCHAR(20) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INT(11) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -218,7 +218,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID INT(11) NOT NULL AUTO_INCREMENT, PROFILE_ID INT(11) NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE VARCHAR(20) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INT(11) NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), @@ -339,7 +339,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, - DEVICE_TYPE VARCHAR(20) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INT(11) NOT NULL, PRIMARY KEY (ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 66ce12dc875..385ac2a135f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -135,13 +135,13 @@ CREATE TABLE DM_PROFILE ( ID INTEGER NOT NULL IDENTITY , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INTEGER NOT NULL , - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME2(0) NOT NULL , UPDATED_TIME DATETIME2(0) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -196,7 +196,7 @@ CREATE TABLE DM_DEVICE_POLICY ( CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL , - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INTEGER NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -205,8 +205,8 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -219,7 +219,7 @@ CREATE TABLE DM_PROFILE_FEATURES ( ID INTEGER NOT NULL IDENTITY, PROFILE_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INTEGER NOT NULL , CONTENT VARBINARY(max) NULL DEFAULT NULL, PRIMARY KEY (ID), @@ -340,7 +340,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE DM_POLICY_CHANGE_MGT ( ID INTEGER NOT NULL IDENTITY, POLICY_ID INTEGER NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 1d2013cbc42..098ebc5d98e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID) )ENGINE = InnoDB; +CREATE INDEX device_type_name ON DM_DEVICE_TYPE (NAME); CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER AUTO_INCREMENT NOT NULL, @@ -117,13 +118,13 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID INT NOT NULL AUTO_INCREMENT , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INT NOT NULL , - DEVICE_TYPE_ID INT NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME NOT NULL , UPDATED_TIME DATETIME NOT NULL , PRIMARY KEY (ID) , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE) + REFERENCES DM_DEVICE_TYPE (NAME) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -171,7 +172,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ID INT(11) NOT NULL , - DEVICE_TYPE_ID INT(11) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INT(11) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -180,8 +181,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -191,7 +192,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID INT(11) NOT NULL AUTO_INCREMENT, PROFILE_ID INT(11) NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INT(11) NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), @@ -308,7 +309,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, - DEVICE_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INT(11) NOT NULL, PRIMARY KEY (ID) )ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 18ed9c2abe4..0b1256d5ee4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -250,13 +250,13 @@ CREATE TABLE DM_PROFILE ( ID NUMBER(10) NOT NULL , PROFILE_NAME VARCHAR2(45) NOT NULL , TENANT_ID NUMBER(10) NOT NULL , - DEVICE_TYPE_ID NUMBER(10) NOT NULL , + DEVICE_TYPE VARCHAR2(300) NOT NULL , CREATED_TIME TIMESTAMP(0) NOT NULL , UPDATED_TIME TIMESTAMP(0) NOT NULL , CONSTRAINT PK_DM_PROFILE PRIMARY KEY (ID) , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ) / -- Generate ID using sequence and trigger @@ -338,15 +338,15 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID NUMBER(10) NOT NULL , - DEVICE_TYPE_ID NUMBER(10) NOT NULL , + DEVICE_TYPE VARCHAR2(300) NOT NULL , POLICY_ID NUMBER(10) NOT NULL , CONSTRAINT PK_DEV_TYPE_POLICY PRIMARY KEY (ID) , CONSTRAINT FK_DEV_TYPE_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ), CONSTRAINT FK_DEV_TYPE_POLICY_DEV_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ) / @@ -355,7 +355,7 @@ CREATE TABLE DM_PROFILE_FEATURES ( ID NUMBER(10) NOT NULL, PROFILE_ID NUMBER(10) NOT NULL, FEATURE_CODE VARCHAR2(100) NOT NULL, - DEVICE_TYPE_ID NUMBER(10) NOT NULL, + DEVICE_TYPE VARCHAR2(300) NOT NULL , TENANT_ID NUMBER(10) NOT NULL , CONTENT BLOB DEFAULT NULL NULL, CONSTRAINT PK_DM_PROF_DM_POLICY_FEATURES PRIMARY KEY (ID), @@ -566,7 +566,7 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_POLICY_CHANGE_MGT ( ID NUMBER(10) NOT NULL, POLICY_ID NUMBER(10) NOT NULL, - DEVICE_TYPE_ID NUMBER(10) NOT NULL, + DEVICE_TYPE VARCHAR2(300) NOT NULL, TENANT_ID NUMBER(10) NOT NULL, CONSTRAINT PK_DM_POLICY_CHANGE_MGT PRIMARY KEY (ID) ) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 2da059d3a77..dc3c6229f22 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -103,12 +103,12 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INTEGER NOT NULL , - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME TIMESTAMP NOT NULL , UPDATED_TIME TIMESTAMP NOT NULL , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -151,7 +151,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INTEGER NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -160,8 +160,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -170,7 +170,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INTEGER NOT NULL , CONTENT BYTEA NULL DEFAULT NULL, CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES @@ -272,7 +272,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INTEGER NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INTEGER NOT NULL );