diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index ff3012e10e..891db9900b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.annotations - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT bundle WSO2 Carbon - API Management Annotations WSO2 Carbon - API Management Custom Annotation Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index 74aa6fd76b..1e15acaa0e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,12 +21,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml 4.0.0 - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT org.wso2.carbon.apimgt.application.extension.api war WSO2 Carbon - API Application Management API diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index 1bf3bf678d..e7fbb7361b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,12 +22,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml 4.0.0 - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT org.wso2.carbon.apimgt.application.extension bundle WSO2 Carbon - API Application Management diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml index e8e3b15821..66e97a2da9 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml @@ -21,13 +21,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.handlers - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT bundle WSO2 Carbon - API Security Handler Component WSO2 Carbon - API Management Security Handler Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index f94e8bad15..164e283e5e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.webapp.publisher - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT bundle WSO2 Carbon - API Management Webapp Publisher WSO2 Carbon - API Management Webapp Publisher diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 023096f28b..0d5a64053f 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../../pom.xml 4.0.0 apimgt-extensions - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT pom WSO2 Carbon - API Management Extensions Component http://wso2.org diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 7dd00860b1..f2804b019f 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index 72d3e072b5..0244bfd77a 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java index a2b90633ea..6fed010f65 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java @@ -35,7 +35,7 @@ import javax.ws.rs.core.Response; } ), tags = { - @Tag(name = "devicemgt_admin", description = "") + @Tag(name = "device_management", description = "") } ) @Api(value = "Certificate Management", description = "This API includes all the certificate management related operations") diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index fb889349a7..3cc9f11c9f 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt certificate-mgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.certificate.mgt.core - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT bundle WSO2 Carbon - Certificate Management Core WSO2 Carbon - Certificate Management Core diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 9877f9bcc3..10dd730b53 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt certificate-mgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT pom WSO2 Carbon - Certificate Management Component http://wso2.org diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 26be512777..8c4023418d 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml index 654c79e72f..bdd9a5b424 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index 703f3ba348..1a6b579afa 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml @@ -144,6 +144,7 @@ org.wso2.carbon.event.output.adapter.core, org.wso2.carbon.event.output.adapter.core.exception, org.osgi.framework, + org.wso2.carbon.device.mgt.core.operation.mgt, org.wso2.carbon.core diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index 03f2d8f9d3..93be818999 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -22,17 +22,21 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants; import org.wso2.carbon.event.output.adapter.core.MessageType; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; +import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -57,7 +61,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, @@ -79,23 +83,48 @@ public class MQTTNotificationStrategy implements NotificationStrategy { @Override public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { - Map dynamicProperties = new HashMap<>(); + Operation operation = ctx.getOperation(); Properties properties = operation.getProperties(); if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) { + Map dynamicProperties = new HashMap<>(); dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC)); + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + operation.getPayLoad()); } else { - String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" - + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType() - .toString().toLowerCase() + "/" + operation.getCode(); - dynamicProperties.put("topic", topic); - if (operation.getPayLoad() == null) { - operation.setPayLoad(""); + if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) { + PolicyOperation policyOperation = (PolicyOperation) operation; + List profileOperations = policyOperation.getProfileOperations(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + String deviceType = ctx.getDeviceId().getType(); + String deviceId = ctx.getDeviceId().getId(); + for (ProfileOperation profileOperation : profileOperations) { + Map dynamicProperties = new HashMap<>(); + String topic = tenantDomain + "/" + + deviceType + "/" + deviceId + "/" + profileOperation.getType() + .toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase(); + dynamicProperties.put("topic", topic); + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + profileOperation.getPayLoad()); + } + + } else { + Map dynamicProperties = new HashMap<>(); + String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" + + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType() + .toString().toLowerCase() + "/" + operation.getCode(); + dynamicProperties.put("topic", topic); + if (operation.getPayLoad() == null) { + operation.setPayLoad(""); + } + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + operation.getPayLoad()); + } + } - MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, - operation.getPayLoad()); + } @Override @@ -109,3 +138,4 @@ public class MQTTNotificationStrategy implements NotificationStrategy { } } + diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 3b8675d30b..3d7e306be4 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 258484e69a..0d12d3afdd 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml index b10784a845..b95a6476fd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt device-mgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml index 4f75e85d25..a06eb822e0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index d93d23221d..41525c7b8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index c6c7130926..b909ff609b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -72,7 +72,7 @@ import javax.ws.rs.core.Response; "Further, this is strictly restricted to admin users only ") public interface UserManagementAdminService { - @PUT + @POST @Path("/{username}/credentials") @ApiOperation( consumes = MediaType.APPLICATION_JSON, 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 0390e5b13d..2b5a2e8d45 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 @@ -77,6 +77,9 @@ public class UserManagementServiceImpl implements UserManagementService { private static final String API_BASE_PATH = "/users"; private static final Log log = LogFactory.getLog(UserManagementServiceImpl.class); + private static final String DEFAULT_DEVICE_USER = "Internal/devicemgt-user"; + private static final String DEFAULT_DEVICE_ADMIN = "Internal/devicemgt-admin"; + @POST @Override public Response addUser(UserInfo userInfo) { @@ -100,8 +103,17 @@ public class UserManagementServiceImpl implements UserManagementService { this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), userInfo.getEmailAddress()); // calling addUser method of carbon user api + List tmpRoles = new ArrayList<>(); + String[] userInfoRoles = userInfo.getRoles(); + tmpRoles.add(DEFAULT_DEVICE_USER); + if (userInfoRoles != null) { + tmpRoles.addAll(Arrays.asList(userInfoRoles)); + } + String[] roles = new String[tmpRoles.size()]; + tmpRoles.toArray(roles); + userStoreManager.addUser(userInfo.getUsername(), initialUserPassword, - userInfo.getRoles(), defaultUserClaims, null); + roles, defaultUserClaims, null); // Outputting debug message upon successful addition of user if (log.isDebugEnabled()) { log.debug("User '" + userInfo.getUsername() + "' has successfully been added."); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml index aa49482557..b23f60be4c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -89,7 +89,7 @@ org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter patterns - "text/html*","application/json*","text/plain*" + text/html" ,application/json" ,text/plain filterAction diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 344b5ec25a..732a2da4e0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index fcf80d13a2..ba0d3d59ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -90,4 +90,5 @@ public final class DeviceManagementConstants { public static final String DB_TYPE_H2 = "H2"; public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 3f5f30c892..d244169d26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java index c3e912fcb8..6e3803f2d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java @@ -26,18 +26,18 @@ import java.util.Map; public interface QueryBuilder { - Map> buildQueries(List conditions) throws InvalidOperatorException; + Map> buildQueries(List conditions) throws InvalidOperatorException; - String processAND(List conditions) throws InvalidOperatorException; + String processAND(List conditions, ValueType[] valueType, Integer intArr[]) throws InvalidOperatorException; - String processOR(List conditions) throws InvalidOperatorException; + String processOR(List conditions, ValueType[] valueType, Integer intArr[]) throws InvalidOperatorException; - List processLocation(Condition condition) throws InvalidOperatorException; + List processLocation(Condition condition) throws InvalidOperatorException; - List processANDProperties(List conditions) throws InvalidOperatorException; + List processANDProperties(List conditions) throws InvalidOperatorException; - List processORProperties(List conditions) throws InvalidOperatorException; + List processORProperties(List conditions) throws InvalidOperatorException; - String processUpdatedDevices(long epochTime) throws InvalidOperatorException; + QueryHolder processUpdatedDevices(long epochTime) throws InvalidOperatorException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryHolder.java new file mode 100644 index 0000000000..6bc6b1190d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryHolder.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, 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.search.mgt; + +public class QueryHolder { + + private String query; + private ValueType[] types; + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public ValueType[] getTypes() { + return types; + } + + public void setTypes(ValueType[] types) { + this.types = types; + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/ValueType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/ValueType.java new file mode 100644 index 0000000000..ea432068ec --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/ValueType.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017, 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.search.mgt; + +public class ValueType { + + public enum columnType { + STRING, + INTEGER, + DOUBLE, + LONG + } + + private String stringValue; + private int intValue; + private Double doubleValue; + private long longValue; + + private columnType columnType; + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + + public int getIntValue() { + return intValue; + } + + public void setIntValue(int intValue) { + this.intValue = intValue; + } + + public Double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(Double doubleValue) { + this.doubleValue = doubleValue; + } + + public ValueType.columnType getColumnType() { + return columnType; + } + + public void setColumnType(ValueType.columnType columnType) { + this.columnType = columnType; + } + + public long getLongValue() { + return longValue; + } + + public void setLongValue(long longValue) { + this.longValue = longValue; + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java index 7fe10ba8c4..b2c779c037 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java @@ -62,27 +62,32 @@ public class ProcessorImpl implements Processor { @Override public List execute(SearchContext searchContext) throws SearchMgtException { + if(!Utils.validateOperators(searchContext.getConditions())){ + throw new SearchMgtException("Invalid validator is provided."); + } + QueryBuilder queryBuilder = new QueryBuilderImpl(); List generalDevices = new ArrayList<>(); List> allANDDevices = new ArrayList<>(); List> allORDevices = new ArrayList<>(); List locationDevices = new ArrayList<>(); try { - Map> queries = queryBuilder.buildQueries(searchContext.getConditions()); DeviceManagementDAOFactory.openConnection(); + Map> queries = queryBuilder.buildQueries(searchContext.getConditions()); + if (queries.containsKey(Constants.GENERAL)) { generalDevices = searchDeviceDetailsTable(queries.get(Constants.GENERAL).get(0)); } if (queries.containsKey(Constants.PROP_AND)) { - for (String query : queries.get(Constants.PROP_AND)) { - List andDevices = searchDeviceDetailsTable(query); + for (QueryHolder queryHolder : queries.get(Constants.PROP_AND)) { + List andDevices = searchDeviceDetailsTable(queryHolder); allANDDevices.add(andDevices); } } if (queries.containsKey(Constants.PROP_OR)) { - for (String query : queries.get(Constants.PROP_OR)) { - List orDevices = searchDeviceDetailsTable(query); + for (QueryHolder queryHolder : queries.get(Constants.PROP_OR)) { + List orDevices = searchDeviceDetailsTable(queryHolder); allORDevices.add(orDevices); } } @@ -141,12 +146,12 @@ public class ProcessorImpl implements Processor { @Override public List getUpdatedDevices(long epochTime) throws SearchMgtException { - if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) { + if ((1 + (int) Math.floor(Math.log10(epochTime))) <= 10) { epochTime = epochTime * 1000; } QueryBuilder queryBuilder = new QueryBuilderImpl(); try { - String query = queryBuilder.processUpdatedDevices(epochTime); + QueryHolder query = queryBuilder.processUpdatedDevices(epochTime); DeviceManagementDAOFactory.openConnection(); return searchDeviceDetailsTable(query); } catch (InvalidOperatorException e) { @@ -218,7 +223,7 @@ public class ProcessorImpl implements Processor { for (List devices : deLists) { Map deviceMap = new HashMap<>(); - for (Device device: devices) { + for (Device device : devices) { deviceMap.put(device.getId(), device); } maps.add(deviceMap); @@ -241,9 +246,9 @@ public class ProcessorImpl implements Processor { } } - private List searchDeviceDetailsTable(String query) throws SearchDAOException { + private List searchDeviceDetailsTable(QueryHolder queryHolder) throws SearchDAOException { if (log.isDebugEnabled()) { - log.debug("Query : " + query); + log.debug("Query : " + queryHolder.getQuery()); } Connection conn; PreparedStatement stmt = null; @@ -252,7 +257,26 @@ public class ProcessorImpl implements Processor { Map devs = new HashMap<>(); try { conn = this.getConnection(); - stmt = conn.prepareStatement(query); + stmt = conn.prepareStatement(queryHolder.getQuery()); + + int x = 1; + ValueType[] types = queryHolder.getTypes(); + for (ValueType type : types) { + if (type.getColumnType().equals(ValueType.columnType.STRING)) { + stmt.setString(x, type.getStringValue()); + x++; + } else if (type.getColumnType().equals(ValueType.columnType.INTEGER)) { + stmt.setInt(x, type.getIntValue()); + x++; + } else if (type.getColumnType().equals(ValueType.columnType.LONG)){ + stmt.setLong(x, type.getLongValue()); + x++; + } else if(type.getColumnType().equals(ValueType.columnType.DOUBLE)){ + stmt.setDouble(x, type.getDoubleValue()); + x++; + } + } + rs = stmt.executeQuery(); while (rs.next()) { if (!devs.containsKey(rs.getInt("ID"))) { @@ -362,8 +386,8 @@ public class ProcessorImpl implements Processor { } } catch (SQLException e) { throw new SearchDAOException("Error occurred while retrieving the device properties.", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt,rs); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); } return devices; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java index 251b773123..6291f9cb16 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java @@ -23,9 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.search.Condition; -import org.wso2.carbon.device.mgt.core.search.mgt.Constants; -import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException; -import org.wso2.carbon.device.mgt.core.search.mgt.QueryBuilder; +import org.wso2.carbon.device.mgt.core.search.mgt.*; import java.util.ArrayList; import java.util.HashMap; @@ -41,7 +39,7 @@ public class QueryBuilderImpl implements QueryBuilder { private boolean isDeviceAdminUser; @Override - public Map> buildQueries(List conditions) throws InvalidOperatorException { + public Map> buildQueries(List conditions) throws InvalidOperatorException { List andColumns = new ArrayList<>(); List orColumns = new ArrayList<>(); List otherANDColumns = new ArrayList<>(); @@ -82,10 +80,27 @@ public class QueryBuilderImpl implements QueryBuilder { } } - Map> queries = new HashMap<>(); + Map> queries = new HashMap<>(); if ((!andColumns.isEmpty()) || (!orColumns.isEmpty())) { - queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) + - this.processOR(orColumns))); + // Size is taken as the sum of both columns and for tenant id. + ValueType valueTypeArray[] = new ValueType[andColumns.size() + orColumns.size() + 1]; + +// String query =Utils.convertStringToList( + + // passing the integer value to the x so that array is correctly passed. + Integer intArr[] = new Integer[1]; + intArr[0] = 1; + //int x = 1; + String query = this.getGenericQueryPart(valueTypeArray) + + this.processAND(andColumns, valueTypeArray, intArr) + + this.processOR(orColumns, valueTypeArray, intArr); + List queryHolders = new ArrayList<>(); + QueryHolder queryHolder = new QueryHolder(); + queryHolder.setQuery(query); + queryHolder.setTypes(valueTypeArray); + queryHolders.add(queryHolder); + + queries.put(Constants.GENERAL, queryHolders); } if (!otherANDColumns.isEmpty()) { queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns)); @@ -108,124 +123,262 @@ public class QueryBuilderImpl implements QueryBuilder { } @Override - public String processAND(List conditions) throws InvalidOperatorException { + public String processAND(List conditions, ValueType[] valueType, Integer intArr[]) throws InvalidOperatorException { String querySuffix = ""; - for (Condition con : conditions) { - if (Utils.checkDeviceDetailsColumns(con.getKey())) { - if (con.operator.equals(WILDCARD_OPERATOR)){ - querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) - + " LIKE \'%" + con.getValue() + "%\'"; - } else { - querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con - .getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); + try { + // TODO: find upto what address location of the array has filled. + int x = intArr[0]; + for (Condition con : conditions) { + if (Utils.checkDeviceDetailsColumns(con.getKey())) { + if (con.operator.equals(WILDCARD_OPERATOR)) { + querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + + " LIKE ? "; + ValueType type = new ValueType(); + type.setColumnType(ValueType.columnType.STRING); + type.setStringValue("%"+con.getValue()+"%"); + valueType[x] = type; + x++; + } else { + querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con + .getOperator() + " ? "; + ValueType type = new ValueType(); + if (Utils.checkColumnType(con.getKey())) { + type.setColumnType(ValueType.columnType.STRING); + type.setStringValue(Utils.getConvertedValue(con.getKey(), con.getValue())); + } else { + type.setColumnType(ValueType.columnType.INTEGER); + type.setIntValue(Integer.parseInt(Utils.getConvertedValue(con.getKey(), con.getValue()))); + } + valueType[x] = type; + x++; + } + } else if (Utils.checkDeviceLocationColumns(con.getKey().toLowerCase())) { + querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey().toLowerCase()) + + con.getOperator() + " ? "; + ValueType type = new ValueType(); + type.setColumnType(ValueType.columnType.STRING); + type.setStringValue(con.getValue()); + valueType[x] = type; + x++; } - } else if (Utils.checkDeviceLocationColumns(con.getKey().toLowerCase())) { - querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey().toLowerCase()) + - con.getOperator() + con.getValue(); } + intArr[0] = x; + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the sql", e); } return querySuffix; } @Override - public String processOR(List conditions) throws InvalidOperatorException { + public String processOR(List conditions, ValueType[] valueType, Integer intArr[]) throws InvalidOperatorException { String querySuffix = ""; - for (Condition con : conditions) { - if (Utils.checkDeviceDetailsColumns(con.getKey())) { - if (con.operator.equals(WILDCARD_OPERATOR)) { - querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) - + " LIKE \'%" + con.getValue() + "%\'"; - } else { - querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con - .getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); + // TODO: find upto what address location of the array has filled. + try { + int x = intArr[0]; + for (Condition con : conditions) { + if (Utils.checkDeviceDetailsColumns(con.getKey())) { + if (con.operator.equals(WILDCARD_OPERATOR)) { + querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + + " LIKE ? "; + ValueType type = new ValueType(); + type.setColumnType(ValueType.columnType.STRING); + type.setStringValue("%"+con.getValue()+"%"); + valueType[x] = type; + x++; + } else { + querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con + .getOperator() + " ? "; + + ValueType type = new ValueType(); + if (Utils.checkColumnType(con.getKey())) { + type.setColumnType(ValueType.columnType.STRING); + type.setStringValue(Utils.getConvertedValue(con.getKey(), con.getValue())); + } else { + type.setColumnType(ValueType.columnType.INTEGER); + type.setIntValue(Integer.parseInt(Utils.getConvertedValue(con.getKey(), con.getValue()))); + } + valueType[x] = type; + x++; + } + } else if (Utils.checkDeviceLocationColumns(con.getKey().toLowerCase())) { + querySuffix = + querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey().toLowerCase()) + + con.getOperator() + " ? "; + ValueType type = new ValueType(); + type.setColumnType(ValueType.columnType.STRING); + type.setStringValue(con.getValue()); + valueType[x] = type; + x++; } - } else if (Utils.checkDeviceLocationColumns(con.getKey().toLowerCase())) { - querySuffix = - querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey().toLowerCase()) - + con.getOperator() + con.getValue(); } + intArr[0] = x; + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the sql", e); } return querySuffix; } @Override - public List processLocation(Condition condition) throws InvalidOperatorException { - List queryList = new ArrayList<>(); - queryList.add(this.buildLocationQuery(condition.getValue())); - return queryList; + public List processLocation(Condition condition) throws InvalidOperatorException { + List queryHolders = new ArrayList<>(); + queryHolders.add(this.buildLocationQuery(condition.getValue())); + return queryHolders; } @Override - public List processANDProperties(List conditions) throws InvalidOperatorException { + public List processANDProperties(List conditions) throws InvalidOperatorException { return this.getQueryList(conditions); } @Override - public List processORProperties(List conditions) throws InvalidOperatorException { + public List processORProperties(List conditions) throws InvalidOperatorException { return this.getQueryList(conditions); } @Override - public String processUpdatedDevices(long epochTime) throws InvalidOperatorException { - return this.getGenericQueryPart() + " AND ( DD.UPDATE_TIMESTAMP > " + epochTime + - " OR DL.UPDATE_TIMESTAMP > " + epochTime + " )"; + public QueryHolder processUpdatedDevices(long epochTime) throws InvalidOperatorException { + try { + ValueType valueTypeArray[] = new ValueType[3]; + String query = this.getGenericQueryPart(valueTypeArray) + " AND ( DD.UPDATE_TIMESTAMP > ? " + + "OR DL.UPDATE_TIMESTAMP > ? )"; + + ValueType val1 = new ValueType(); + val1.setColumnType(ValueType.columnType.LONG); + val1.setLongValue(epochTime); + valueTypeArray[1] = val1; + + ValueType val2 = new ValueType(); + val2.setColumnType(ValueType.columnType.LONG); + val2.setLongValue(epochTime); + valueTypeArray[2] = val2; + + QueryHolder queryHolder = new QueryHolder(); + queryHolder.setQuery(query); + queryHolder.setTypes(valueTypeArray); + + return queryHolder; + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the for the updated devices.", e); + } } - private List getQueryList(List conditions) { - List queryList = new ArrayList<>(); - for (Condition con : conditions) { + private List getQueryList(List conditions) throws InvalidOperatorException { + try { + List queryHolders = new ArrayList<>(); + for (Condition con : conditions) { + + QueryHolder query = new QueryHolder(); + ValueType valueTypeArray[] = new ValueType[3]; + + String querySuffix = this.getPropertyQueryPart(valueTypeArray) + " AND DI.KEY_FIELD = " + " ? " + + " AND DI.VALUE_FIELD " + con.getOperator() + " ? "; + ValueType key = new ValueType(); + key.setColumnType(ValueType.columnType.STRING); + key.setStringValue(con.getKey()); + valueTypeArray[1] = key; + + ValueType value = new ValueType(); + value.setColumnType(ValueType.columnType.STRING); + value.setStringValue(con.getValue()); + valueTypeArray[2] = value; - String querySuffix = this.getPropertyQueryPart() + " AND DI.KEY_FIELD = " + "\'" + con.getKey() + "\'" + - " AND DI.VALUE_FIELD " + con.getOperator() + "\'" + con.getValue() + "\'"; - queryList.add(querySuffix); + query.setQuery(querySuffix); + query.setTypes(valueTypeArray); + + queryHolders.add(query); + } + return queryHolders; + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the sql", e); } - return queryList; } - private String buildLocationQuery(String location) { + private QueryHolder buildLocationQuery(String location) throws InvalidOperatorException { + try { + ValueType valueTypeArray[] = new ValueType[7]; + String query = this.getGenericQueryPart(valueTypeArray); + query = query + " AND (DL.STREET1 LIKE ? "; + query = query + " OR DL.STREET2 LIKE ? "; + query = query + " OR DL.CITY LIKE ? "; + query = query + " OR DL.STATE LIKE ? "; + query = query + " OR DL.COUNTRY LIKE ? "; + query = query + " OR DL.ZIP LIKE ? )"; + + ValueType value = new ValueType(); + value.setColumnType(ValueType.columnType.STRING); + value.setStringValue("%" + location + "%"); + + // Same location is passed to each place + valueTypeArray[1] = value; + valueTypeArray[2] = value; + valueTypeArray[3] = value; + valueTypeArray[4] = value; + valueTypeArray[5] = value; + valueTypeArray[6] = value; - String query = this.getGenericQueryPart(); - query = query + " AND (DL.STREET1 LIKE \'%" + location + "%\'"; - query = query + " OR DL.STREET2 LIKE \'%" + location + "%\'"; - query = query + " OR DL.CITY LIKE \'%" + location + "%\'"; - query = query + " OR DL.STATE LIKE \'%" + location + "%\'"; - query = query + " OR DL.COUNTRY LIKE \'%" + location + "%\'"; - query = query + " OR DL.ZIP LIKE \'%" + location + "%\')"; - return query; + QueryHolder queryHolder = new QueryHolder(); + queryHolder.setQuery(query); + queryHolder.setTypes(valueTypeArray); + + return queryHolder; + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the sql for location.", e); + } } - private String getGenericQueryPart() { - return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + - "D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" + - "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" + - "DD.OS_VERSION, DD.OS_BUILD_DATE, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + - "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + - "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + - "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + - "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, DE.OWNER, DE.OWNERSHIP, DE.STATUS " + - "AS DE_STATUS FROM DM_DEVICE_DETAIL AS DD INNER JOIN DM_DEVICE AS D ON D.ID=DD.DEVICE_ID\n" + - "LEFT JOIN DM_DEVICE_LOCATION AS DL ON DL.DEVICE_ID=D.ID \n" + - "INNER JOIN DM_DEVICE_TYPE AS DT ON DT.ID=D.DEVICE_TYPE_ID\n" + - "INNER JOIN DM_ENROLMENT AS DE ON D.ID=DE.DEVICE_ID\n" + - "WHERE D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + private String getGenericQueryPart(ValueType[] valueTypeArray) throws InvalidOperatorException { + try { + String query = "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + + "D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" + + "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" + + "DD.OS_VERSION, DD.OS_BUILD_DATE, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, DE.OWNER, DE.OWNERSHIP, DE.STATUS " + + "AS DE_STATUS FROM DM_DEVICE_DETAIL AS DD INNER JOIN DM_DEVICE AS D ON D.ID=DD.DEVICE_ID\n" + + "LEFT JOIN DM_DEVICE_LOCATION AS DL ON DL.DEVICE_ID=D.ID \n" + + "INNER JOIN DM_DEVICE_TYPE AS DT ON DT.ID=D.DEVICE_TYPE_ID\n" + + "INNER JOIN DM_ENROLMENT AS DE ON D.ID=DE.DEVICE_ID\n" + + "WHERE D.TENANT_ID = ? "; + + ValueType type = new ValueType(); + type.setIntValue(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + type.setColumnType(ValueType.columnType.INTEGER); + valueTypeArray[0] = type; + return query; + + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the sql", e); + } } - private String getPropertyQueryPart() { - return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + - "D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" + - "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" + - "DD.OS_VERSION, DD.OS_BUILD_DATE, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + - "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + - "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + - "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + - "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, DI.KEY_FIELD, DI.VALUE_FIELD, \n" + - "DE.OWNER, DE.OWNERSHIP, DE.STATUS AS DE_STATUS " + - "FROM DM_DEVICE_DETAIL AS DD INNER JOIN DM_DEVICE AS D ON D.ID=DD.DEVICE_ID\n" + - "LEFT JOIN DM_DEVICE_LOCATION AS DL ON DL.DEVICE_ID=D.ID \n" + - "INNER JOIN DM_DEVICE_TYPE AS DT ON DT.ID=D.DEVICE_TYPE_ID\n" + - "INNER JOIN DM_ENROLMENT AS DE ON D.ID=DE.DEVICE_ID\n" + - "LEFT JOIN DM_DEVICE_INFO AS DI ON DI.DEVICE_ID=D.ID\n" + - "WHERE D.TENANT_ID = " + - PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + private String getPropertyQueryPart(ValueType[] valueTypeArray) throws InvalidOperatorException { + try { + String query = "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + + "D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" + + "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" + + "DD.OS_VERSION, DD.OS_BUILD_DATE, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, DI.KEY_FIELD, DI.VALUE_FIELD, \n" + + "DE.OWNER, DE.OWNERSHIP, DE.STATUS AS DE_STATUS " + + "FROM DM_DEVICE_DETAIL AS DD INNER JOIN DM_DEVICE AS D ON D.ID=DD.DEVICE_ID\n" + + "LEFT JOIN DM_DEVICE_LOCATION AS DL ON DL.DEVICE_ID=D.ID \n" + + "INNER JOIN DM_DEVICE_TYPE AS DT ON DT.ID=D.DEVICE_TYPE_ID\n" + + "INNER JOIN DM_ENROLMENT AS DE ON D.ID=DE.DEVICE_ID\n" + + "LEFT JOIN DM_DEVICE_INFO AS DI ON DI.DEVICE_ID=D.ID\n" + + "WHERE D.TENANT_ID = ? "; + + ValueType type = new ValueType(); + type.setIntValue(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + type.setColumnType(ValueType.columnType.INTEGER); + valueTypeArray[0] = type; + return query; + + } catch (Exception e) { + throw new InvalidOperatorException("Error occurred while building the sql", e); + } } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java index d28666ba88..10e12f24ce 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.search.mgt.impl; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.search.Condition; import java.util.ArrayList; import java.util.HashMap; @@ -31,6 +32,8 @@ public class Utils { private static Map genericColumnsMap = new HashMap<>(); private static Map locationColumnsMap = new HashMap<>(); + private static Map operators = new HashMap<>(); + static { genericColumnsMap.put("deviceModel", "DEVICE_MODEL"); genericColumnsMap.put("vendor", "VENDOR"); @@ -58,6 +61,18 @@ public class Utils { locationColumnsMap.put("zip", "STATE"); locationColumnsMap.put("country", "COUNTRY"); + //=, >, <, >=, <=, <>, !=, !>, !< + operators.put("=", "="); + operators.put(">", ">"); + operators.put("<", "<"); + operators.put(">=", ">="); + operators.put("<=", "<="); + operators.put("<>", "<>"); + operators.put("!=", "!="); + operators.put("!>", "!>"); + operators.put("!<", "!<"); + operators.put("%", "%"); + } public static boolean checkColumnType(String column) { @@ -142,5 +157,15 @@ public class Utils { return str.substring(0, str.length() - 1); } + + public static boolean validateOperators(List conditions) { + for (Condition con : conditions) { + if (!operators.containsKey(con.getOperator())) { + return false; + } + } + return true; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 381405847b..cbb0891bd0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml index 1fb0b5eac7..5a7fbaddc5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.8-SNAPSHOT + 2.0.11-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag index 0fb2945cf4..f8cfa13520 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag @@ -24,6 +24,7 @@ var uriMatcher = new URIMatcher(String(uri)); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; +var utility = require("/app/modules/utility.js")["utility"]; function appendQueryParam (url, queryParam , value) { if (url.indexOf("?") > 0) { @@ -60,7 +61,7 @@ if (uriMatcher.match("/{context}/api/data-tables/invoker")) { // response callback function (backendResponse) { response["status"] = backendResponse["status"]; - response["content"] = backendResponse["responseText"]; + response["content"] = utility.encodeJson(backendResponse["responseText"]); } ); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json index ddce0b0204..7087cdb976 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json @@ -30,8 +30,8 @@ "enabled": true, "issuer" : "devicemgt", "appName" : "devicemgt", - "identityProviderUrl" : "https://localhost:9443/samlsso", - "acs": "https://localhost:9443/devicemgt/uuf/sso/acs", + "identityProviderUrl" : "https://%iot.keymanager.host%:%iot.keymanager.https.port%/samlsso", + "acs": "https://%iot.keymanager.host%:%iot.keymanager.https.port%/devicemgt/uuf/sso/acs", "identityAlias": "wso2carbon", "responseSigningEnabled" : true, "validateAssertionValidityPeriod": true, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index c850c11db9..a43bb34bce 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -1,9 +1,9 @@ { "appContext": "/devicemgt/", - "httpsURL" : "https://%server.ip%:8243", - "httpURL" : "http://%server.ip%:8280", - "wssURL" : "https://localhost:9445", - "portalURL": "https://%server.ip%:9445", + "httpsURL" : "https://%iot.gateway.host%:%iot.gateway.https.port%", + "httpURL" : "http://%iot.gateway.host%:%iot.gateway.http.port", + "wssURL" : "https://%iot.analytics.host%:%iot.analytics.https.port%", + "portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", "dashboardServerURL" : "%https.ip%", "androidEnrollmentDir": "/android-web-agent/enrollment", "windowsEnrollmentDir": "/windows-web-agent/enrollment", @@ -18,12 +18,12 @@ "clientName": "emm", "owner": "admin@carbon.super", "dynamicClientAppRegistrationServiceURL": "%https.ip%/dynamic-client-web/register", - "apiManagerClientAppRegistrationServiceURL": "https://%server.ip%:8243/api-application-registration/register/tenants", - "grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-carbon urn:ietf:params:oauth:grant-type:jwt-bearer", + "apiManagerClientAppRegistrationServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/api-application-registration/register/tenants", + "grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer urn:ietf:params:oauth:grant-type:jwt-bearer", "tokenScope": "admin", "callbackUrl": "%https.ip%/api/device-mgt/v1.0" }, - "tokenServiceURL": "https://%server.ip%:8243/token" + "tokenServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/token" }, "adminUser":"admin@carbon.super", "adminUserTenantId":"-1234", @@ -140,6 +140,39 @@ "perm:admin:certificates:view", "perm:admin:certificates:add", "perm:admin:certificates:verify", + "perm:ios:enroll", + "perm:ios:view-device", + "perm:ios:apn", + "perm:ios:ldap", + "perm:ios:enterprise-app", + "perm:ios:store-application", + "perm:ios:remove-application", + "perm:ios:app-list", + "perm:ios:profile-list", + "perm:ios:lock", + "perm:ios:enterprise-wipe", + "perm:ios:device-info", + "perm:ios:restriction", + "perm:ios:email", + "perm:ios:cellular", + "perm:ios:applications", + "perm:ios:wifi", + "perm:ios:ring", + "perm:ios:location", + "perm:ios:notification", + "perm:ios:airplay", + "perm:ios:caldav", + "perm:ios:cal-subscription", + "perm:ios:passcode-policy", + "perm:ios:webclip", + "perm:ios:vpn", + "perm:ios:per-app-vpn", + "perm:ios:app-to-per-app-vpn", + "perm:ios:app-lock", + "perm:ios:clear-passcode", + "perm:ios:remove-profile", + "perm:ios:get-restrictions", + "perm:ios:wipe-data", "perm:admin" ], "isOAuthEnabled" : true, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/batch-provider-api.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/batch-provider-api.js new file mode 100644 index 0000000000..78d026bf1a --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/batch-provider-api.js @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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. + */ +var batchProviders; + +batchProviders = function () { + var operations = {}; + var CONTENT_TYPE_JSON = "application/json"; + var JS_MAX_VALUE = "9007199254740992"; + var JS_MIN_VALUE = "-9007199254740992"; + + var TABLENAME_ANDROID = "ORG_WSO2_GEO_FUSEDSPATIALEVENT"; + var TABLENAME_ANDROID_SENSE = "ORG_WSO2_IOT_ANDROID_LOCATION"; + + var tableName = function (deviceType) { + switch (deviceType) { + case "android" : + return TABLENAME_ANDROID; + break; + case "android_sense" : + return TABLENAME_ANDROID_SENSE; + break; + default: + return null; + + } + }; + + var typeMap = { + "bool": "string", + "boolean": "string", + "string": "string", + "int": "number", + "integer": "number", + "long": "number", + "double": "number", + "float": "number", + "time": "time" + }; + + var log = new Log(); + var carbon = require('carbon'); + var JSUtils = Packages.org.wso2.carbon.analytics.jsservice.Utils; + var AnalyticsCachedJSServiceConnector = Packages.org.wso2.carbon.analytics.jsservice.AnalyticsCachedJSServiceConnector; + var AnalyticsCache = Packages.org.wso2.carbon.analytics.jsservice.AnalyticsCachedJSServiceConnector.AnalyticsCache; + var cacheTimeoutSeconds = 5; + + var cacheSizeBytes = 1024 * 1024 * 1024; // 1GB + response.contentType = CONTENT_TYPE_JSON; + + + var cache = application.get("AnalyticsWebServiceCache"); + if (cache == null) { + cache = new AnalyticsCache(cacheTimeoutSeconds, cacheSizeBytes); + application.put("AnalyticsWebServiceCache", cache); + } + var connector = new AnalyticsCachedJSServiceConnector(cache); + + + /** + * returns an array of column names & types + * @param providerConfig + */ + operations.getSchema = function (loggedInUser) { + var tablename = tableName(deviceType); + if (tablename == null) { + return []; + } + var schema = []; + var result = connector.getTableSchema(loggedInUser, tablename).getMessage(); + result = JSON.parse(result); + + var columns = result.columns; + Object.getOwnPropertyNames(columns).forEach(function (name, idx, array) { + var type = "ordinal"; + if (columns[name]['type']) { + type = columns[name]['type']; + } + schema.push({ + fieldName: name, + fieldType: typeMap[type.toLowerCase()] + }); + }); + // log.info(schema); + return schema; + }; + + /** + * returns the actual data + * @param providerConfig + * @param limit + */ + operations.getData = function (loggedInUser, deviceId, deviceType) { + var luceneQuery = ""; + var limit = 100; + var result; + var tablename = tableName(deviceType); + if (tablename == null) { + return []; + } + //if there's a filter present, we should perform a Lucene search instead of reading the table + if (luceneQuery) { + luceneQuery = 'id:"' + deviceId + '" AND type:"' + deviceType + '"'; + var filter = { + "query": luceneQuery, + "start": 0, + "count": limit + }; + result = connector.search(loggedInUser, tablename, stringify(filter)).getMessage(); + } else { + var from = JS_MIN_VALUE; + var to = JS_MAX_VALUE; + result = connector.getRecordsByRange(loggedInUser, tablename, from, to, 0, limit, null).getMessage(); + + } + result = JSON.parse(result); + var data = []; + for (var i = 0; i < result.length; i++) { + var values = result[i].values; + data.push(values); + } + return data; + }; + + + + return operations; +}(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index bec644d249..56939377cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -24,6 +24,7 @@ deviceModule = function () { 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 batchProvider = require("/app/modules/batch-provider-api.js")["batchProviders"]; var publicMethods = {}; var privateMethods = {}; @@ -67,6 +68,36 @@ deviceModule = function () { log.error("User object was not found in the session"); throw constants["ERRORS"]["USER_NOT_FOUND"]; } + var userName = carbonUser.username + "@" + carbonUser.domain; + + var locationDataSet = []; + switch(deviceType) { + case 'android': + locationDataSet = batchProvider.getData(userName, deviceId, deviceType); + break; + case 'android_sense': + locationDataSet = batchProvider.getData(userName, deviceId, deviceType); + break; + + } + + + var locationData = []; + var locationTimeData = []; + for (var i = 0 ; i < locationDataSet.length; i++) { + var gpsReading = {}; + var gpsReadingTimes = {}; + gpsReading.lat = locationDataSet[i].latitude; + gpsReading.lng = locationDataSet[i].longitude; + if (deviceType == "android") { + gpsReadingTimes.time = locationDataSet[i].timeStamp; + } else { + gpsReadingTimes.time = locationDataSet[i].meta_timestamp; + } + locationData.push(gpsReading); + locationTimeData.push(gpsReadingTimes); + } + var utility = require('/app/modules/utility.js')["utility"]; try { utility.startTenantFlow(carbonUser); @@ -144,6 +175,10 @@ deviceModule = function () { if (device["deviceInfo"]) { filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"]; } + var locationHistory = {}; + locationHistory.locations = locationData; + locationHistory.times = locationTimeData; + filteredDeviceData["locationHistory"] = locationHistory; response["content"] = filteredDeviceData; response["status"] = "success"; return response; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index de20da586d..a7727ccea5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -39,7 +39,11 @@ var groupModule = {}; } else if (permissions.LIST_GROUPS) { endPoint = deviceServiceEndpoint + "/groups/count"; } else { - log.error("Access denied for user: " + carbonUser.username); + if (!user) { + log.error("User object was not found in the session"); + throw constants["ERRORS"]["USER_NOT_FOUND"]; + } + log.error("Access denied for user: " + user.username); return -1; } return serviceInvokers.XMLHttp.get( @@ -116,7 +120,7 @@ var groupModule = {}; } ); }; - + groupModule.getRolesOfGroup = function (groupId) { return serviceInvokers.XMLHttp.get( deviceServiceEndpoint + "/groups/id/" + groupId + "/roles", function (responsePayload) { 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 8e02b70ff3..ce57a85980 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 @@ -22,6 +22,7 @@ var conf = function () { conf = require("/app/conf/config.json"); var pinch = require("/app/modules/conf-reader/pinch.min.js")["pinch"]; var server = require("carbon")["server"]; + var process = require("process"); pinch(conf, /^/, function (path, key, value) { if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) { @@ -36,8 +37,23 @@ var conf = function () { } else if ((typeof value === "string") && value.indexOf("%server.ip%") > -1) { var getProperty = require("process").getProperty; return value.replace("%server.ip%", getProperty("carbon.local.ip")); + } else { + var paramPattern = new RegExp("%(.*?)%", "g"); + var out = value; + while ((matches = paramPattern.exec(value)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (matches.index === paramPattern.lastIndex) { + paramPattern.lastIndex++; + } + if (matches.length == 2) { + var property = process.getProperty(matches[1]); + if (property) { + out = out.replace(new RegExp("%" + matches[1] + "%", "g"), property); + } + } + } + return out; } - return value; } ); application.put("CONF", conf); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index 4815edd59d..50cbba4dca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -29,7 +29,8 @@ var carbonServer = new carbonModule.server.Server({ application.put("carbonServer", carbonServer); var permissions = { - "/permission/admin/Login": ["ui.execute"] + "/permission/admin/Login": ["ui.execute"], + "/permission/admin/manage/api/subscribe": ["ui.execute"] }; var adminPermissions = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index d29498a318..ed40ee7de8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -117,15 +117,44 @@ var invokers = function () { log.debug("Response status : " + xmlHttpRequest.status); log.debug("Response payload if any : " + xmlHttpRequest.responseText); - if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || - xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { - tokenUtil.refreshTokenPair(); - return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); - } else { + if (xmlHttpRequest.status == 401) { + if ((xmlHttpRequest.responseText == TOKEN_EXPIRED || + xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { + tokenUtil.refreshTokenPair(); + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); + } else if (privateMethods.isInvalidCredential(xmlHttpRequest.responseText)) { + tokenUtil.refreshTokenPair(); + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); + } + } else { return responseCallback(xmlHttpRequest); - } + } }; + + /** + * This method verify whether the access token is expired using response payload. + * This is required when using API gateway. + * @param responsePayload response payload. + * return true if it is invalid otherwise false. + */ + privateMethods["isInvalidCredential"] = + function (responsePayload) { + if (responsePayload) { + try { + payload = parse(responsePayload); + if (payload["fault"]["code"] == 900901) { + log.debug("Access token is invalid: " + payload["fault"]["code"]); + log.debug(payload["fault"]["description"]); + return true; + } + } catch (err) { + // do nothing + } + } + return false; + }; + /** * This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled. * @param httpMethod HTTP request type. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index 49b1a0d5b1..d1658872b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -153,5 +153,24 @@ utility = function () { return scopesList; }; + + /** + * Escapes special characters such as <,>,',",...etc + * This will prevent XSS attacks upon JSON. + * @param text + * @returns {*} + */ + publicMethods.encodeJson = function (text) { + return text + .replace(/\\u003c/g, "<") + .replace(//g, ">") + .replace(/\\u0027/g, "'") + .replace(/'/g, "'") + .replace(/\\"/g, """) + .replace(/\\u0022/g, """) + }; + return publicMethods; }(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js index c885566db8..68a4292ea8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js @@ -47,7 +47,7 @@ var dynamicForm = '
' + + 'Internal Available Memory ' + ' '; } else { return ''; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs index 3a80726bc2..0bb38a9492 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs @@ -50,9 +50,9 @@

Advanced Device Search


- diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index e58df263dd..b5f0f93954 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -89,7 +89,7 @@
-
+
@@ -277,7 +277,7 @@ - + Device Grouping diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index bae88512d5..a65de8a6da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -375,15 +375,15 @@ function loadDevices(searchType, searchParam) { var fnCreatedRow = function (row, data, dataIndex) { $(row).attr('data-type', 'selectable'); - $(row).attr('data-deviceid', data.deviceIdentifier); - $(row).attr('data-devicetype', data.deviceType); - $(row).attr('data-url', context + '/device/' + data.deviceType + '?id=' + data.deviceIdentifier); - var model = getPropertyValue(data.properties, 'DEVICE_MODEL'); - var vendor = getPropertyValue(data.properties, 'VENDOR'); - var owner = data.user; - var status = data.status; - var ownership = data.ownership; - var deviceType = data.deviceType; + $(row).attr('data-deviceid', htmlspecialchars(data.deviceIdentifier)); + $(row).attr('data-devicetype', htmlspecialchars(data.deviceType)); + $(row).attr('data-url', context + '/device/' + htmlspecialchars(data.deviceType) + '?id=' + htmlspecialchars(data.deviceIdentifier)); + var model = htmlspecialchars(getPropertyValue(data.properties, 'DEVICE_MODEL')); + var vendor = htmlspecialchars(getPropertyValue(data.properties, 'VENDOR')); + var owner = htmlspecialchars(data.user); + var status = htmlspecialchars(data.status); + var ownership = htmlspecialchars(data.ownership); + var deviceType = htmlspecialchars(data.deviceType); var category = getDeviceTypeCategory(deviceType); $.each($('td', row), function (colIndex) { switch (colIndex) { @@ -417,6 +417,10 @@ function loadDevices(searchType, searchParam) { }); }; + function htmlspecialchars(text){ + return jQuery('
').text(text).html(); + } + var dataFilter = function (data) { data = JSON.parse(data); var objects = []; @@ -455,6 +459,13 @@ function loadDevices(searchType, searchParam) { $('#device-grid').removeClass('hidden'); $("#loading-content").remove(); attachDeviceEvents(); + + if($('.advance-search').length < 1){ + $(this).closest('.dataTables_wrapper').find('div[id$=_filter] input') + .after('Advance Search'); + } + }, { "placeholder": "Search By Device Name", "searchKey": "name" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 212bec7521..6566078bf9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -112,6 +112,10 @@ function toTitleCase(str) { }); } +function htmlspecialchars(text){ + return jQuery('
').text(text).html(); +} + function loadGroups() { var groupListing = $("#group-listing"); var currentUser = groupListing.data("currentUser"); @@ -134,10 +138,10 @@ function loadGroups() { var objects = []; $(data.deviceGroups).each(function (index) { objects.push({ - groupId: data.deviceGroups[index].id, - name: data.deviceGroups[index].name, - description: data.deviceGroups[index].description, - owner: data.deviceGroups[index].owner + groupId: htmlspecialchars(data.deviceGroups[index].id), + name: htmlspecialchars(data.deviceGroups[index].name), + description: htmlspecialchars(data.deviceGroups[index].description), + owner: htmlspecialchars(data.deviceGroups[index].owner) }) }); var json = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js index 8e31e39ecc..0d94332844 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js @@ -109,6 +109,7 @@ function getSelectedPolicies() { return policyList; } + $(document).ready(function () { /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index 5b5b835d5b..d673e72929 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -86,6 +86,10 @@ function InitiateViewOption() { // $(location).attr('href', $(this).data("url")); } +function htmlspecialchars(text){ + return jQuery('
').text(text).html(); +} + function loadRoles() { var loadingContent = $("#loading-content"); loadingContent.show(); @@ -98,8 +102,8 @@ function loadRoles() { $(data.roles).each(function (index) { objects.push( { - name: data.roles[index], - DT_RowId: "role-" + data.roles[index] + name: htmlspecialchars(data.roles[index]), + DT_RowId: "role-" + htmlspecialchars(data.roles[index]) } ) }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 95c8b9bbc3..ce89b335f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -258,6 +258,10 @@ function InitiateViewOption() { } } +function htmlspecialchars(text){ + return jQuery('
').text(text).html(); +} + function loadUsers() { var loadingContentView = "#loading-content"; $(loadingContentView).show(); @@ -269,11 +273,11 @@ function loadUsers() { $(data.users).each(function (index) { objects.push({ - filter: data.users[index].username, - firstname: data.users[index].firstname ? data.users[index].firstname : "", - lastname: data.users[index].lastname ? data.users[index].lastname : "", - emailAddress: data.users[index].emailAddress ? data.users[index].emailAddress : "", - DT_RowId: "user-" + data.users[index].username + filter: htmlspecialchars(data.users[index].username), + firstname: htmlspecialchars(data.users[index].firstname) ? htmlspecialchars(data.users[index].firstname) : "", + lastname: htmlspecialchars(data.users[index].lastname) ? htmlspecialchars(data.users[index].lastname) : "", + emailAddress: htmlspecialchars(data.users[index].emailAddress) ? htmlspecialchars(data.users[index].emailAddress) : "", + DT_RowId: "user-" + htmlspecialchars(data.users[index].username) }) }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 243df02a4d..9ca788dc43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -273,6 +273,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter thisTable.removeClass("table-selectable"); $(button).addClass("active").html('Select'); $(button).parent().next().children().addClass("disabled"); + $('.DTTT_selected.selected').removeClass(rowSelectedClass); // EMM related function $(document).on('click', '.viewEnabledIcon', InitiateViewOption); //--- End of EMM related codes diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js index ba9a4be94a..c68cfbe1f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js @@ -41,22 +41,22 @@ $(document).ready(function () { /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover({ - html : true, - content : function () { - return $("#content-filter-types").html(); - } - }); + html: true, + content: function () { + return $("#content-filter-types").html(); + } + }); - $(".ast-container").on("click", ".claim-btn", function(e){ + $(".ast-container").on("click", ".claim-btn", function (e) { e.stopPropagation(); var deviceId = $(this).data("deviceid"); var deviceListing = $("#device-listing"); var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; - invokerUtil.put(serviceURL, deviceIdentifier, function(message){ + invokerUtil.put(serviceURL, deviceIdentifier, function (message) { console.log(message); - }, function(message){ + }, function (message) { console.log(message); }); }); @@ -68,15 +68,15 @@ $(document).ready(function () { * @param button: Select All Device button */ function selectAllDevices(button) { - if(!$(button).data('select')){ - $(deviceCheckbox).each(function(index){ + if (!$(button).data('select')) { + $(deviceCheckbox).each(function (index) { $(this).prop('checked', true); addDeviceSelectedClass(this); }); $(button).data('select', true); $(button).html('Deselect All Devices'); - }else{ - $(deviceCheckbox).each(function(index){ + } else { + $(deviceCheckbox).each(function (index) { $(this).prop('checked', false); addDeviceSelectedClass(this); }); @@ -92,7 +92,7 @@ function selectAllDevices(button) { * @param selection: Selection button */ function changeDeviceView(view, selection) { - $(".view-toggle").each(function() { + $(".view-toggle").each(function () { $(this).removeClass("selected"); }); $(selection).addClass("selected"); @@ -117,27 +117,33 @@ function addDeviceSelectedClass(checkbox) { } function toTitleCase(str) { - return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); + return str.replace(/\w\S*/g, function (txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); } var deviceTypeCount, compiledDeviceTypesCount = 0; -function loadDevices(searchType, searchParam){ +function htmlspecialchars(text) { + return jQuery('
').text(text).html(); +} + +function loadDevices(searchType, searchParam) { var deviceListing = $("#device-listing"); var deviceListingSrc = deviceListing.attr("src"); var currentUser = deviceListing.data("currentUser"); $('#ast-container').html(""); deviceTypeCount = deviceTypesList.length; - if(deviceTypesList.length > 0){ + if (deviceTypesList.length > 0) { for (var i = 0; i < deviceTypesList.length; i++) { var viewModel = {}; viewModel.thumb = deviceTypesList[i].thumb; viewModel.appContext = clientJsAppContext; - viewModel.deviceTypeName = deviceTypesList[i].deviceTypeName; - viewModel.deviceTypeId = deviceTypesList[i].deviceTypeId; - viewModel.deviceCategory = deviceTypesList[i].deviceCategory; - viewModel.deviceTypeLabel = deviceTypesList[i].deviceTypeLabel; + viewModel.deviceTypeName = htmlspecialchars(deviceTypesList[i].deviceTypeName); + viewModel.deviceTypeId = htmlspecialchars(deviceTypesList[i].deviceTypeId); + viewModel.deviceCategory = htmlspecialchars(deviceTypesList[i].deviceCategory); + viewModel.deviceTypeLabel = htmlspecialchars(deviceTypesList[i].deviceTypeLabel); compileTemplate(viewModel, deviceListingSrc); } } else { @@ -155,12 +161,12 @@ function loadDevices(searchType, searchParam){ } -function compileTemplate(viewModel, templateSrc){ +function compileTemplate(viewModel, templateSrc) { $.template("device-listing", templateSrc, function (template) { $("#ast-container").html($("#ast-container").html() + template(viewModel)); compiledDeviceTypesCount++; - if(deviceTypeCount == compiledDeviceTypesCount){ - $('#device-type-grid').datatables_extended({"bFilter": false, "order": [[ 1, "asc" ]]}); + if (deviceTypeCount == compiledDeviceTypesCount) { + $('#device-type-grid').datatables_extended({"bFilter": false, "order": [[1, "asc"]]}); } }); } @@ -171,17 +177,16 @@ function compileTemplate(viewModel, templateSrc){ var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var assetContainer = "#ast-container"; -function openCollapsedNav(){ +function openCollapsedNav() { $('.wr-hidden-nav-toggle-btn').addClass('active'); - $('#hiddenNav').slideToggle('slideDown', function(){ - if($(this).css('display') == 'none'){ + $('#hiddenNav').slideToggle('slideDown', function () { + if ($(this).css('display') == 'none') { $('.wr-hidden-nav-toggle-btn').removeClass('active'); } }); } - /* * DOM ready functions. */ @@ -196,22 +201,22 @@ $(document).ready(function () { /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover({ - html : true, - content : function () { - return $("#content-filter-types").html(); - } - }); + html: true, + content: function () { + return $("#content-filter-types").html(); + } + }); - $(".ast-container").on("click", ".claim-btn", function(e){ + $(".ast-container").on("click", ".claim-btn", function (e) { e.stopPropagation(); var deviceId = $(this).data("deviceid"); var deviceListing = $("#device-listing"); var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; - invokerUtil.put(serviceURL, deviceIdentifier, function(message){ + invokerUtil.put(serviceURL, deviceIdentifier, function (message) { console.log(message); - }, function(message){ + }, function (message) { console.log(message); }); }); @@ -222,20 +227,20 @@ $(document).ready(function () { $("[data-toggle=popover]").popover(); $(".ctrl-filter-type-switcher").popover({ - html : true, - content: function() { - return $('#content-filter-types').html(); - } - }); + html: true, + content: function () { + return $('#content-filter-types').html(); + } + }); $('#nav').affix({ - offset: { - top: $('header').height() - } - }); + offset: { + top: $('header').height() + } + }); - $(document).on("click", "tr.clickable-row", function(){ - window.document.location = $(this).data('href'); + $(document).on("click", "tr.clickable-row", function () { + window.document.location = $(this).data('href'); }) }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs index d63ee90965..07ee1b4801 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs @@ -67,11 +67,4 @@ }); } - {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js index 0e97b964b7..29c29bf7a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js @@ -20,15 +20,15 @@ var modalDialog = (function () { var publicMethoads = {}; publicMethoads.header = function (headerText) { - $("#modal-title-text").html(headerText); + $("#basic-modal-view #modal-title-text").html(headerText); }; publicMethoads.content = function (contentText) { - $("#modal-content-text").html(contentText); + $("#basic-modal-view #modal-content-text").html(contentText); }; publicMethoads.footer = function (footerContent) { - $("#modal-footer-content").html(footerContent); + $("#basic-modal-view #modal-footer-content").html(footerContent); }; publicMethoads.footerButtons = function (buttonList) { @@ -37,7 +37,7 @@ var modalDialog = (function () { footerContent = footerContent + ''; } - $("#modal-footer-content").html(footerContent); + $("#basic-modal-view #modal-footer-content").html(footerContent); }; publicMethoads.show = function () { @@ -62,11 +62,21 @@ var modalDialog = (function () { publicMethoads.hide = function () { $("#basic-modal-view").addClass('hidden'); $("#basic-modal-view").modal('hide'); - $("#modal-title-text").html(""); - $("#modal-content-text").html(""); - $("#modal-footer-content").html(""); - $('body').removeClass('modal-open').css('padding-right', '0px'); $('.modal-backdrop').remove(); }; + + $("#basic-modal-view").on('hidden.bs.modal', function () { + $('#basic-modal-view .modal-dialog').html(''); + $('body').removeClass('modal-open').css('padding-right', '0px'); + }); + return publicMethoads; }(modalDialog)); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 51d087ca34..61655a5f44 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -80,9 +80,9 @@ @@ -90,9 +90,8 @@ {{/zone}} {{#zone "sidePanes"}} -