revert-70aa11f8
charitha 8 years ago
commit a0050d8f4d

@ -48,8 +48,6 @@ public class ActivityList extends BasePaginatedResult {
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" devices: [").append(activities).append("\n"); sb.append(" devices: [").append(activities).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -39,34 +39,4 @@ public class BasePaginatedResult {
public void setCount(int count) { public void setCount(int count) {
this.count = count; this.count = count;
} }
}
/**
* Link to the next subset of resources qualified. \nEmpty if no more resources are to be returned.
*/
@ApiModelProperty(value = "Link to the next subset of resources qualified. \n " +
"Empty if no more resources are to be returned.")
@JsonProperty("next")
public String getNext() {
return next;
}
public void setNext(String next) {
this.next = next;
}
/**
* Link to the previous subset of resources qualified. \nEmpty if current subset is the first subset returned.
*/
@ApiModelProperty(value = "Link to the previous subset of resources qualified. \n" +
"Empty if current subset is the first subset returned.")
@JsonProperty("previous")
public String getPrevious() {
return previous;
}
public void setPrevious(String previous) {
this.previous = previous;
}
}

@ -24,8 +24,8 @@ import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "BasicUserInfo", description = "Basic user information and the roles of the user.") @ApiModel(value = "BasicUserInfo", description = "Basic user information and the roles of the user.")
public class BasicUserInfo { public class BasicUserInfo {
@ApiModelProperty(name = "username", value = "The login name of the user.", required = true )
private String username; private String username;
@ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true ) @ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true )
private String firstname; private String firstname;
@ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true ) @ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true )

@ -47,8 +47,6 @@ public class BasicUserInfoList extends BasePaginatedResult {
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" users: [").append(users).append("\n"); sb.append(" users: [").append(users).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -45,8 +45,6 @@ public class DeviceList extends BasePaginatedResult {
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" devices: [").append(devices).append("\n"); sb.append(" devices: [").append(devices).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -90,8 +90,6 @@ public class DeviceTypeList {
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" deviceTypes: [").append(deviceTypes).append("\n"); sb.append(" deviceTypes: [").append(deviceTypes).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -46,8 +46,6 @@ public class NotificationList extends BasePaginatedResult {
sb.append("{"); sb.append("{");
sb.append(" count: ").append(getCount()).append(","); sb.append(" count: ").append(getCount()).append(",");
sb.append(" next: ").append(getNext()).append(",");
sb.append(" previous: ").append(getPrevious()).append(",");
sb.append(" notifications: [").append(notifications).append(""); sb.append(" notifications: [").append(notifications).append("");
sb.append("]}"); sb.append("]}");
return sb.toString(); return sb.toString();

@ -42,8 +42,6 @@ public class OperationList extends BasePaginatedResult {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" operations: [").append(operations).append("\n"); sb.append(" operations: [").append(operations).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -45,8 +45,6 @@ public class PolicyList extends BasePaginatedResult {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" policies: [").append(policies).append("\n"); sb.append(" policies: [").append(policies).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -44,8 +44,6 @@ public class RoleList extends BasePaginatedResult {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" roles: [").append(roles).append("\n"); sb.append(" roles: [").append(roles).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -46,8 +46,6 @@ public class UserInfoList extends BasePaginatedResult {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" users: [").append(users).append("\n"); sb.append(" users: [").append(users).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();

@ -440,7 +440,7 @@ public interface UserManagementService {
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@PUT @PUT
@Path("/{username}/credentials") @Path("/credentials")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -472,11 +472,6 @@ public interface UserManagementService {
}) })
@Permission(name = "Reset user password", permission = "/login") @Permission(name = "Reset user password", permission = "/login")
Response resetPassword( Response resetPassword(
@ApiParam(
name = "username",
value = "Username of the user.",
required = true)
@PathParam("username") String username,
@ApiParam( @ApiParam(
name = "credentials", name = "credentials",
value = "Credential.", value = "Credential.",

@ -373,10 +373,10 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
@PUT @PUT
@Path("/{username}/credentials") @Path("/credentials")
@Override @Override
public Response resetPassword(@PathParam("username") String username, OldPasswordResetWrapper credentials) { public Response resetPassword(OldPasswordResetWrapper credentials) {
return CredentialManagementResponseBuilder.buildChangePasswordResponse(username, credentials); return CredentialManagementResponseBuilder.buildChangePasswordResponse(credentials);
} }
/** /**

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
@ -43,26 +44,23 @@ public class CredentialManagementResponseBuilder {
/** /**
* Builds the response to change the password of a user * Builds the response to change the password of a user
* *
* @param username - Username of the user.
* @param credentials - User credentials * @param credentials - User credentials
* @return Response Object * @return Response Object
*/ */
public static Response buildChangePasswordResponse(String username, OldPasswordResetWrapper credentials) { public static Response buildChangePasswordResponse(OldPasswordResetWrapper credentials) {
String username = "";
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No user found with the username '"
+ username + "'").build()).build();
}
RequestValidationUtil.validateCredentials(credentials); RequestValidationUtil.validateCredentials(credentials);
if (!validateCredential(credentials.getNewPassword())) { if (!validateCredential(credentials.getNewPassword())) {
String errorMsg = DeviceMgtAPIUtils.getRealmService().getBootstrapRealmConfiguration() String errorMsg = DeviceMgtAPIUtils.getRealmService().getBootstrapRealmConfiguration()
.getUserStoreProperty(PASSWORD_VALIDATION_ERROR_MSG_TAG); .getUserStoreProperty(PASSWORD_VALIDATION_ERROR_MSG_TAG);
return Response.status(Response.Status.BAD_REQUEST).entity( return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMsg).build()).build(); new ErrorResponse.ErrorResponseBuilder().setMessage(errorMsg).build()).build();
} }
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
// this is the user who initiates the request
username = CarbonContext.getThreadLocalCarbonContext().getUsername();
userStoreManager.updateCredential(username, credentials.getNewPassword(), userStoreManager.updateCredential(username, credentials.getNewPassword(),
credentials.getOldPassword()); credentials.getOldPassword());
return Response.status(Response.Status.OK).entity("UserImpl password by username: " + return Response.status(Response.Status.OK).entity("UserImpl password by username: " +

@ -431,6 +431,18 @@ public class OperationManagerImpl implements OperationManager {
"Identifier:" + deviceId.getId() + " and given type" + "Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType()); deviceId.getType());
} }
int enrolmentId = enrolmentInfo.getId();
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
switch (enrolmentInfo.getStatus()) {
case ACTIVE:
this.resetAttemptCount(enrolmentId);
break;
case INACTIVE:
case UNREACHABLE:
this.resetAttemptCount(enrolmentId);
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
break;
}
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();

@ -61,7 +61,7 @@
"roleNameHelpMsg" : "should be in minimum 3 characters long and do not include any whitespaces." "roleNameHelpMsg" : "should be in minimum 3 characters long and do not include any whitespaces."
}, },
"generalConfig" : { "generalConfig" : {
"host" : "https://localhost:9443", "host" : "%http.ip%",
"companyName" : "WSO2 Carbon Device Manager", "companyName" : "WSO2 Carbon Device Manager",
"browserTitle" : "WSO2 Device Manager", "browserTitle" : "WSO2 Device Manager",
"copyrightPrefix" : "\u00A9 %date-year%, ", "copyrightPrefix" : "\u00A9 %date-year%, ",

@ -26,14 +26,16 @@ var onFail;
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"]; var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"];
if (context.input.samlToken) { if (context.input.samlToken) {
apiWrapperUtil.setupTokenPairBySamlGrantType(context.input.username, context.input.samlToken); apiWrapperUtil.setupTokenPairBySamlGrantType(context.user.username + '@' + context.user.domain, context.input.samlToken);
} else { } else {
apiWrapperUtil.setupTokenPairByPasswordGrantType(context.input.username, context.input.password); apiWrapperUtil.setupTokenPairByPasswordGrantType(context.input.username, context.input.password);
} }
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var carbonServer = require("carbon").server; var carbonServer = require("carbon").server;
(new carbonServer.Server({url: devicemgtProps["adminService"]})) if (!context.input.samlToken) {
.login(context.input.username, context.input.password); (new carbonServer.Server({url: devicemgtProps["adminService"]}))
.login(context.input.username, context.input.password);
}
}; };
onFail = function (error) { onFail = function (error) {

@ -1,5 +1,5 @@
<tr data-type="selectable" data-deviceid="{{deviceTypeId}}" data-devicetype="{{deviceTypeName}}" <tr data-type="selectable" data-deviceid="{{deviceTypeId}}" data-devicetype="{{deviceTypeName}}"
data-href="{{@app.context}}/device/{{deviceTypeName}}/enroll" class="clickable-row"> data-href="{{appContext}}/device/{{deviceTypeName}}/enroll" class="clickable-row">
<td class="remove-padding icon-only content-fill" data-search="{{deviceCategory}}" data-display="{{deviceCategory}}"> <td class="remove-padding icon-only content-fill" data-search="{{deviceCategory}}" data-display="{{deviceCategory}}">
<div class="thumbnail icon"> <div class="thumbnail icon">
<!--<i class="square-element text fw fw-mobile"></i>--> <!--<i class="square-element text fw fw-mobile"></i>-->
@ -9,7 +9,7 @@
<td class="remove-padding-top" data-search="{{deviceTypeLabel}}" data-display="{{deviceTypeLabel}}"> <td class="remove-padding-top" data-search="{{deviceTypeLabel}}" data-display="{{deviceTypeLabel}}">
{{deviceTypeLabel}}</td> {{deviceTypeLabel}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap"> <td class="text-right content-fill text-left-on-grid-view no-wrap">
<a href="{{@app.context}}/device/{{deviceTypeName}}/enroll" <a href="{{appContext}}/device/{{deviceTypeName}}/enroll"
data-click-event="remove-form" class="btn col-md-12"> data-click-event="remove-form" class="btn col-md-12">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>

@ -105,7 +105,7 @@ var constants = {
CACHE_KEY_APP_CONF_FILE_LMD: "_UUF_APP_CONF_FILE_LMD", CACHE_KEY_APP_CONF_FILE_LMD: "_UUF_APP_CONF_FILE_LMD",
CACHE_KEY_LOOKUP_TABLE: "_UUF_LOOKUP_TABLE", CACHE_KEY_LOOKUP_TABLE: "_UUF_LOOKUP_TABLE",
CACHE_KEY_USER: "_UUF_USER", CACHE_KEY_USER: "_UUF_USER",
CACHE_KEY_SSO_SESSIONS: "_UUF_SSO_SESSIONS", CACHE_KEY_SSO_SESSIONS: "sso_sessions",
CACHE_KEY_HANDLEBARS_ROOT: "_UUF_HANDLEBARS_ROOT", CACHE_KEY_HANDLEBARS_ROOT: "_UUF_HANDLEBARS_ROOT",
// URL Query Params // URL Query Params
URL_PARAM_REFERER: "referer" URL_PARAM_REFERER: "referer"

@ -364,10 +364,10 @@ var module = {};
* samlToken: string}>} SSO sessions * samlToken: string}>} SSO sessions
*/ */
function getSsoSessions() { function getSsoSessions() {
var ssoSessions = session.get(constants.CACHE_KEY_SSO_SESSIONS); var ssoSessions = application.get(constants.CACHE_KEY_SSO_SESSIONS);
if (!ssoSessions) { if (!ssoSessions) {
ssoSessions = {}; ssoSessions = {};
session.put(constants.CACHE_KEY_SSO_SESSIONS, ssoSessions); application.put(constants.CACHE_KEY_SSO_SESSIONS, ssoSessions);
} }
return ssoSessions; return ssoSessions;
} }
@ -486,67 +486,75 @@ var module = {};
*/ */
module.ssoAcs = function (request, response) { module.ssoAcs = function (request, response) {
var samlResponse = request.getParameter("SAMLResponse"); var samlResponse = request.getParameter("SAMLResponse");
if (!samlResponse) { var samlRequest = request.getParameter('SAMLRequest');
var msg = "SAML response is not found in request parameters.";
log.error(msg);
response.sendError(400, msg);
return;
}
var ssoClient = require("sso").client; var ssoClient = require("sso").client;
var samlResponseObj; var samlResponseObj;
try {
samlResponseObj = ssoClient.getSamlObject(samlResponse); if (samlResponse) {
} catch (e) { try {
log.error(e.message, e); samlResponseObj = ssoClient.getSamlObject(samlResponse);
response.sendError(500, e.message); } catch (e) {
return; log.error(e.message, e);
} response.sendError(500, e.message);
if (ssoClient.isLogoutResponse(samlResponseObj)) { return;
// This is a logout response. }
module.logout(response); if (ssoClient.isLogoutResponse(samlResponseObj)) {
} else { // This is a logout response.
// This is a login response. module.logout(response);
var ssoConfigs = getSsoConfigurations(); } else {
var rsEnabled = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_RESPONSE_SIGNING_ENABLED]; // This is a login response.
if (utils.parseBoolean(rsEnabled)) { var ssoConfigs = getSsoConfigurations();
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils; var rsEnabled = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_RESPONSE_SIGNING_ENABLED];
var keyStorePassword = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Password"); if (utils.parseBoolean(rsEnabled)) {
var keyStoreName = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Location"); var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
var identityAlias = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_ALIAS]; var keyStorePassword = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Password");
var keyStoreParams = { var keyStoreName = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Location");
KEY_STORE_NAME: keyStoreName, var identityAlias = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_ALIAS];
KEY_STORE_PASSWORD: keyStorePassword, var keyStoreParams = {
IDP_ALIAS: identityAlias, KEY_STORE_NAME: keyStoreName,
USE_ST_KEY: !ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_USE_ST_KEY] KEY_STORE_PASSWORD: keyStorePassword,
}; IDP_ALIAS: identityAlias,
if (!ssoClient.validateSignature(samlResponseObj, keyStoreParams)) { USE_ST_KEY: !ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_USE_ST_KEY]
var msg = "Invalid signature found in the SAML response."; };
if (!ssoClient.validateSignature(samlResponseObj, keyStoreParams)) {
var msg = "Invalid signature found in the SAML response.";
log.error(msg);
response.sendError(500, msg);
return;
}
}
/**
* @type {{sessionId: string, loggedInUser: string, sessionIndex: string, samlToken:
* string}}
*/
var ssoSession = ssoClient.decodeSAMLLoginResponse(samlResponseObj, samlResponse,
session.getId());
if (ssoSession.sessionId) {
var ssoSessions = getSsoSessions();
ssoSessions[ssoSession.sessionId] = ssoSession;
if (ssoSession.sessionIndex != null || ssoSession.sessionIndex != 'undefined') {
module.loadTenant(ssoSession.loggedInUser);
var carbonUser = (require("carbon")).server.tenantUser(ssoSession.loggedInUser);
utils.setCurrentUser(carbonUser.username, carbonUser.domain, carbonUser.tenantId);
var scriptArgument = {input: {samlToken: ssoSession.samlToken}, user: module.getCurrentUser()};
handleEvent(OPERATION_LOGIN, EVENT_SUCCESS, scriptArgument);
}
} else {
var msg = "Cannot decode SAML login response.";
log.error(msg); log.error(msg);
response.sendError(500, msg); response.sendError(500, msg);
return;
} }
} }
/** }
* @type {{sessionId: string, loggedInUser: string, sessionIndex: string, samlToken: // If it is a logout request
* string}} if (samlRequest) {
*/ var index = ssoClient.decodeSAMLLogoutRequest(ssoClient.getSamlObject(samlRequest));
var ssoSession = ssoClient.decodeSAMLLoginResponse(samlResponseObj, samlResponse, if (log.isDebugEnabled()) {
session.getId()); log.debug("Back end log out request received for the session Id : " + index);
if (ssoSession.sessionId) {
var ssoSessions = getSsoSessions();
ssoSessions[ssoSession.sessionId] = ssoSession;
if (ssoSessions.sessionIndex != null || ssoSessions.sessionIndex != 'undefined') {
module.loadTenant(ssoSessions.loggedInUser);
var carbonUser = (require("carbon")).server.tenantUser(ssoSession.loggedInUser);
utils.setCurrentUser(carbonUser.username, carbonUser.domain, carbonUser.tenantId);
var scriptArgument = {input: {samlToken: ssoSession.samlToken}, user: module.getCurrentUser()};
handleEvent(OPERATION_LOGIN, EVENT_SUCCESS, scriptArgument);
}
} else {
var msg = "Cannot decode SAML login response.";
log.error(msg);
response.sendError(500, msg);
} }
var jSessionId = getSsoSessions()[index];
delete getSsoSessions()[index];
session.invalidate();
} }
}; };

@ -1,3 +1,4 @@
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_CERTIFICATE]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_CERTIFICATE ( CREATE TABLE DM_DEVICE_CERTIFICATE (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,

@ -1,3 +1,4 @@
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_TYPE]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_TYPE ( CREATE TABLE DM_DEVICE_TYPE (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
NAME VARCHAR(300) DEFAULT NULL, NAME VARCHAR(300) DEFAULT NULL,
@ -7,8 +8,10 @@ CREATE TABLE DM_DEVICE_TYPE (
CONSTRAINT DEVICE_TYPE_NAME UNIQUE(NAME) CONSTRAINT DEVICE_TYPE_NAME UNIQUE(NAME)
); );
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DEVICE_TYPE' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_TYPE'))
CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME); CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE ( CREATE TABLE DM_DEVICE (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DESCRIPTION VARCHAR(MAX) DEFAULT NULL, DESCRIPTION VARCHAR(MAX) DEFAULT NULL,
@ -22,8 +25,10 @@ CREATE TABLE DM_DEVICE (
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_DEVICE' AND OBJECT_ID = OBJECT_ID('DM_DEVICE'))
CREATE INDEX IDX_DM_DEVICE ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID); CREATE INDEX IDX_DM_DEVICE ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_OPERATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_OPERATION ( CREATE TABLE DM_OPERATION (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
TYPE VARCHAR(20) NOT NULL, TYPE VARCHAR(20) NOT NULL,
@ -33,6 +38,7 @@ CREATE TABLE DM_OPERATION (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_CONFIG_OPERATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_CONFIG_OPERATION ( CREATE TABLE DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG VARBINARY(MAX) DEFAULT NULL, OPERATION_CONFIG VARBINARY(MAX) DEFAULT NULL,
@ -41,6 +47,7 @@ CREATE TABLE DM_CONFIG_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_COMMAND_OPERATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_COMMAND_OPERATION ( CREATE TABLE DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
ENABLED BIT NOT NULL DEFAULT 0, ENABLED BIT NOT NULL DEFAULT 0,
@ -49,6 +56,7 @@ CREATE TABLE DM_COMMAND_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_OPERATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY_OPERATION ( CREATE TABLE DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0, ENABLED INTEGER NOT NULL DEFAULT 0,
@ -58,6 +66,7 @@ CREATE TABLE DM_POLICY_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_PROFILE_OPERATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_PROFILE_OPERATION ( CREATE TABLE DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0, ENABLED INTEGER NOT NULL DEFAULT 0,
@ -67,6 +76,7 @@ CREATE TABLE DM_PROFILE_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ENROLMENT]') AND TYPE IN (N'U'))
CREATE TABLE DM_ENROLMENT ( CREATE TABLE DM_ENROLMENT (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -81,9 +91,12 @@ CREATE TABLE DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_FK_DEVICE_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT'))
CREATE INDEX IDX_ENROLMENT_FK_DEVICE_ID ON DM_ENROLMENT(DEVICE_ID); CREATE INDEX IDX_ENROLMENT_FK_DEVICE_ID ON DM_ENROLMENT(DEVICE_ID);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_DEVICE_ID_TENANT_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT'))
CREATE INDEX IDX_ENROLMENT_DEVICE_ID_TENANT_ID ON DM_ENROLMENT(DEVICE_ID, TENANT_ID); CREATE INDEX IDX_ENROLMENT_DEVICE_ID_TENANT_ID ON DM_ENROLMENT(DEVICE_ID, TENANT_ID);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ENROLMENT_OP_MAPPING]') AND TYPE IN (N'U'))
CREATE TABLE DM_ENROLMENT_OP_MAPPING ( CREATE TABLE DM_ENROLMENT_OP_MAPPING (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
@ -98,10 +111,14 @@ CREATE TABLE DM_ENROLMENT_OP_MAPPING (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_OP_MAPPING' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT_OP_MAPPING'))
CREATE INDEX IDX_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING (UPDATED_TIMESTAMP); CREATE INDEX IDX_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING (UPDATED_TIMESTAMP);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_EN_OP_MAPPING_EN_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT_OP_MAPPING'))
CREATE INDEX IDX_EN_OP_MAPPING_EN_ID ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID); CREATE INDEX IDX_EN_OP_MAPPING_EN_ID ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_EN_OP_MAPPING_OP_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT_OP_MAPPING'))
CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID); CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_OPERATION_RESPONSE]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
@ -115,10 +132,12 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENID_OPID' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE'))
CREATE INDEX IDX_ENID_OPID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID); CREATE INDEX IDX_ENID_OPID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID);
-- POLICY RELATED TABLES -- -- POLICY RELATED TABLES --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_PROFILE]') AND TYPE IN (N'U'))
CREATE TABLE DM_PROFILE ( CREATE TABLE DM_PROFILE (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
PROFILE_NAME VARCHAR(45) NOT NULL , PROFILE_NAME VARCHAR(45) NOT NULL ,
@ -131,6 +150,7 @@ CREATE TABLE DM_PROFILE (
DM_DEVICE_TYPE (NAME) ON DELETE NO ACTION ON UPDATE NO ACTION DM_DEVICE_TYPE (NAME) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY ( CREATE TABLE DM_POLICY (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
NAME VARCHAR(45) DEFAULT NULL , NAME VARCHAR(45) DEFAULT NULL ,
@ -147,6 +167,7 @@ CREATE TABLE DM_POLICY (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_POLICY ( CREATE TABLE DM_DEVICE_POLICY (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL , DEVICE_ID INTEGER NOT NULL ,
@ -160,6 +181,7 @@ CREATE TABLE DM_DEVICE_POLICY (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_TYPE_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_TYPE_POLICY ( CREATE TABLE DM_DEVICE_TYPE_POLICY (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_TYPE_ID INTEGER NOT NULL , DEVICE_TYPE_ID INTEGER NOT NULL ,
@ -171,6 +193,7 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_PROFILE_FEATURES]') AND TYPE IN (N'U'))
CREATE TABLE DM_PROFILE_FEATURES ( CREATE TABLE DM_PROFILE_FEATURES (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
PROFILE_ID INTEGER NOT NULL, PROFILE_ID INTEGER NOT NULL,
@ -183,6 +206,7 @@ CREATE TABLE DM_PROFILE_FEATURES (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ROLE_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_ROLE_POLICY ( CREATE TABLE DM_ROLE_POLICY (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
ROLE_NAME VARCHAR(45) NOT NULL , ROLE_NAME VARCHAR(45) NOT NULL ,
@ -192,6 +216,7 @@ CREATE TABLE DM_ROLE_POLICY (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_USER_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_USER_POLICY ( CREATE TABLE DM_USER_POLICY (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
POLICY_ID INTEGER NOT NULL , POLICY_ID INTEGER NOT NULL ,
@ -201,6 +226,7 @@ CREATE TABLE DM_USER_POLICY (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_POLICY_APPLIED]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_POLICY_APPLIED ( CREATE TABLE DM_DEVICE_POLICY_APPLIED (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL , DEVICE_ID INTEGER NOT NULL ,
@ -217,6 +243,7 @@ CREATE TABLE DM_USER_POLICY (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_CRITERIA]') AND TYPE IN (N'U'))
CREATE TABLE DM_CRITERIA ( CREATE TABLE DM_CRITERIA (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
@ -224,6 +251,7 @@ CREATE TABLE DM_CRITERIA (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_CRITERIA]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY_CRITERIA ( CREATE TABLE DM_POLICY_CRITERIA (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
CRITERIA_ID INTEGER NOT NULL, CRITERIA_ID INTEGER NOT NULL,
@ -235,6 +263,7 @@ CREATE TABLE DM_POLICY_CRITERIA (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_CRITERIA_PROPERTIES]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES ( CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
POLICY_CRITERION_ID INTEGER NOT NULL, POLICY_CRITERION_ID INTEGER NOT NULL,
@ -246,6 +275,7 @@ CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
ON DELETE CASCADE ON UPDATE NO ACTION ON DELETE CASCADE ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_COMPLIANCE_STATUS]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE DM_POLICY_COMPLIANCE_STATUS (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -260,6 +290,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_CHANGE_MGT]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY_CHANGE_MGT ( CREATE TABLE DM_POLICY_CHANGE_MGT (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
POLICY_ID INTEGER NOT NULL, POLICY_ID INTEGER NOT NULL,
@ -268,6 +299,7 @@ CREATE TABLE DM_POLICY_CHANGE_MGT (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_COMPLIANCE_FEATURES]') AND TYPE IN (N'U'))
CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
COMPLIANCE_STATUS_ID INTEGER NOT NULL, COMPLIANCE_STATUS_ID INTEGER NOT NULL,
@ -279,6 +311,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_APPLICATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_APPLICATION ( CREATE TABLE DM_APPLICATION (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
NAME VARCHAR(150) NOT NULL, NAME VARCHAR(150) NOT NULL,
@ -296,6 +329,7 @@ CREATE TABLE DM_APPLICATION (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_APPLICATION_MAPPING]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_APPLICATION_MAPPING ( CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -312,7 +346,7 @@ CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
-- DEVICE GROUP TABLES -- -- DEVICE GROUP TABLES --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_GROUP]') AND TYPE IN (N'U'))
CREATE TABLE DM_GROUP ( CREATE TABLE DM_GROUP (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
GROUP_NAME VARCHAR(100) DEFAULT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL,
@ -324,6 +358,7 @@ CREATE TABLE DM_GROUP (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_GROUP_MAP]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_GROUP_MAP ( CREATE TABLE DM_DEVICE_GROUP_MAP (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER DEFAULT NULL, DEVICE_ID INTEGER DEFAULT NULL,
@ -339,7 +374,7 @@ CREATE TABLE DM_DEVICE_GROUP_MAP (
-- END OF DEVICE GROUP TABLES -- -- END OF DEVICE GROUP TABLES --
-- POLICY AND DEVICE GROUP MAPPING -- -- POLICY AND DEVICE GROUP MAPPING --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_GROUP_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_GROUP_POLICY ( CREATE TABLE DM_DEVICE_GROUP_POLICY (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_GROUP_ID INTEGER NOT NULL, DEVICE_GROUP_ID INTEGER NOT NULL,
@ -361,6 +396,7 @@ CREATE TABLE DM_DEVICE_GROUP_POLICY (
-- END OF POLICY AND DEVICE GROUP MAPPING -- -- END OF POLICY AND DEVICE GROUP MAPPING --
-- NOTIFICATION TABLE -- -- NOTIFICATION TABLE --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_NOTIFICATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_NOTIFICATION ( CREATE TABLE DM_NOTIFICATION (
NOTIFICATION_ID INTEGER IDENTITY(1,1) NOT NULL, NOTIFICATION_ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -376,6 +412,7 @@ CREATE TABLE DM_NOTIFICATION (
); );
-- NOTIFICATION TABLE END -- -- NOTIFICATION TABLE END --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_INFO]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_INFO ( CREATE TABLE DM_DEVICE_INFO (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NULL, DEVICE_ID INTEGER NULL,
@ -387,6 +424,7 @@ CREATE TABLE DM_DEVICE_INFO (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_LOCATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_LOCATION ( CREATE TABLE DM_DEVICE_LOCATION (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NULL, DEVICE_ID INTEGER NULL,
@ -408,6 +446,7 @@ CREATE TABLE DM_DEVICE_LOCATION (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_DETAIL]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_DETAIL ( CREATE TABLE DM_DEVICE_DETAIL (
ID INTEGER IDENTITY(1,1) NOT NULL, ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -438,6 +477,7 @@ CREATE TABLE DM_DEVICE_DETAIL (
-- DASHBOARD RELATED VIEWS -- -- DASHBOARD RELATED VIEWS --
IF NOT EXISTS (SELECT * FROM SYS.VIEWS WHERE NAME = 'POLICY_COMPLIANCE_INFO')
exec('CREATE VIEW POLICY_COMPLIANCE_INFO AS exec('CREATE VIEW POLICY_COMPLIANCE_INFO AS
SELECT TOP 100 PERCENT SELECT TOP 100 PERCENT
DEVICE_INFO.DEVICE_ID, DEVICE_INFO.DEVICE_ID,
@ -469,6 +509,7 @@ DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
ORDER BY DEVICE_INFO.DEVICE_ID'); ORDER BY DEVICE_INFO.DEVICE_ID');
IF NOT EXISTS (SELECT * FROM SYS.VIEWS WHERE NAME = 'CREATE VIEW FEATURE_NON_COMPLIANCE_INFO')
exec('CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS exec('CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS
SELECT TOP 100 PERCENT SELECT TOP 100 PERCENT
DM_DEVICE.ID AS DEVICE_ID, DM_DEVICE.ID AS DEVICE_ID,

Loading…
Cancel
Save