mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixed EMM-1146 issue
This commit is contained in:
parent
ed2fa14952
commit
9a7093a0f7
@ -85,7 +85,7 @@ public final class DeviceManagementConstants {
|
||||
}
|
||||
public static final String DB_TYPE_MYSQL = "MySQL";
|
||||
public static final String DB_TYPE_ORACLE = "Oracle";
|
||||
public static final String DB_TYPE_MSSQL = "MSSQL";
|
||||
public static final String DB_TYPE_MSSQL = "Microsoft SQL Server";
|
||||
public static final String DB_TYPE_DB2 = "DB2";
|
||||
public static final String DB_TYPE_H2 = "H2";
|
||||
public static final String DB_TYPE_POSTGRESQL = "PostgreSQL";
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.common;
|
||||
|
||||
/**
|
||||
* This runtime exception will be thrown if the server has configured with unsupported DB engine.
|
||||
*/
|
||||
public class UnsupportedDatabaseEngineException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070297L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.*;
|
||||
@ -91,7 +92,6 @@ public class DeviceManagementDAOFactory {
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class);
|
||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||
|
||||
|
||||
public static DeviceDAO getDeviceDAO() {
|
||||
if(databaseEngine != null) {
|
||||
switch (databaseEngine) {
|
||||
@ -103,12 +103,12 @@ public class DeviceManagementDAOFactory {
|
||||
return new PostgreSQLDeviceDAOImpl();
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||
return new GenericDeviceDAOImpl();
|
||||
default:
|
||||
return new GenericDeviceDAOImpl();
|
||||
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||
}
|
||||
} else {
|
||||
return new GenericDeviceDAOImpl();
|
||||
}
|
||||
throw new RuntimeException("Database engine has not initialized properly.");
|
||||
}
|
||||
|
||||
public static DeviceTypeDAO getDeviceTypeDAO() {
|
||||
|
||||
@ -123,10 +123,9 @@ public class DeviceManagementServiceComponent {
|
||||
DeviceManagementDAOFactory.init(dsConfig);
|
||||
NotificationManagementDAOFactory.init(dsConfig);
|
||||
|
||||
OperationManagementDAOFactory.init(dsConfig);
|
||||
/*Initialize Operation Manager*/
|
||||
this.initOperationsManager();
|
||||
|
||||
OperationManagementDAOFactory.init(dsConfig);
|
||||
/* If -Dsetup option enabled then create device management database schema */
|
||||
String setupOption =
|
||||
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
||||
|
||||
@ -128,12 +128,10 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
@ -144,8 +142,7 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all " +
|
||||
"notifications", e);
|
||||
"Error occurred while retrieving information of all notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
@ -75,12 +76,12 @@ public class OperationManagementDAOFactory {
|
||||
return new PostgreSQLOperationDAOImpl();
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||
return new GenericOperationDAOImpl();
|
||||
default:
|
||||
return new GenericOperationDAOImpl();
|
||||
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||
}
|
||||
} else {
|
||||
return new GenericOperationDAOImpl();
|
||||
}
|
||||
throw new RuntimeException("Database engine has not initialized properly.");
|
||||
}
|
||||
|
||||
public static void init(DataSource dtSource) {
|
||||
|
||||
@ -50,12 +50,12 @@ public abstract class BaseDeviceManagementTest {
|
||||
|
||||
@BeforeSuite
|
||||
public void setupDataSource() throws Exception {
|
||||
this.initDatSource();
|
||||
this.initDataSource();
|
||||
this.initSQLScript();
|
||||
this.initializeCarbonContext();
|
||||
}
|
||||
|
||||
public void initDatSource() throws Exception {
|
||||
public void initDataSource() throws Exception {
|
||||
this.dataSource = this.getDataSource(this.readDataSourceConfig());
|
||||
DeviceManagementDAOFactory.init(dataSource);
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ public class ApplicationPersistenceTests extends BaseDeviceManagementTest {
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
this.initDatSource();
|
||||
this.initDataSource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,15 +36,17 @@ import java.sql.*;
|
||||
|
||||
public class DevicePersistTests extends BaseDeviceManagementTest {
|
||||
|
||||
DeviceDAO deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
DeviceDAO deviceDAO;
|
||||
DeviceTypeDAO deviceTypeDAO;
|
||||
|
||||
private static final Log log = LogFactory.getLog(DevicePersistTests.class);
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
initDatSource();
|
||||
initDataSource();
|
||||
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -83,7 +83,7 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
this.initDatSource();
|
||||
this.initDataSource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,15 +21,9 @@ import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
||||
|
||||
@ -42,7 +36,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
this.initDatSource();
|
||||
this.initDataSource();
|
||||
this.providerService = new DeviceManagementProviderServiceImpl();
|
||||
}
|
||||
|
||||
|
||||
@ -23,17 +23,17 @@ import org.apache.commons.collections.iterators.IteratorEnumeration;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
|
||||
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService;
|
||||
import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo;
|
||||
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
||||
import org.wso2.carbon.dynamic.client.web.app.registration.dto.OAuthAppDetails;
|
||||
import org.wso2.carbon.dynamic.client.web.app.registration.dto.JaggeryOAuthConfigurationSettings;
|
||||
import org.wso2.carbon.dynamic.client.web.app.registration.internal.DynamicClientWebAppRegistrationDataHolder;
|
||||
import org.wso2.carbon.dynamic.client.web.app.registration.dto.OAuthAppDetails;
|
||||
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationConstants;
|
||||
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.util.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class contains the logic to handle the OAuth application creation process.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user