Fixed EMM-1146 issue

revert-70aa11f8
harshanl 9 years ago
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_MYSQL = "MySQL";
public static final String DB_TYPE_ORACLE = "Oracle"; 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_DB2 = "DB2";
public static final String DB_TYPE_H2 = "H2"; public static final String DB_TYPE_H2 = "H2";
public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; 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.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; 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.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.impl.*; 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 final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class);
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>(); private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
public static DeviceDAO getDeviceDAO() { public static DeviceDAO getDeviceDAO() {
if(databaseEngine != null) { if(databaseEngine != null) {
switch (databaseEngine) { switch (databaseEngine) {
@ -103,12 +103,12 @@ public class DeviceManagementDAOFactory {
return new PostgreSQLDeviceDAOImpl(); return new PostgreSQLDeviceDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
default:
return new GenericDeviceDAOImpl(); return new GenericDeviceDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
} }
} else {
return new GenericDeviceDAOImpl();
} }
throw new RuntimeException("Database engine has not initialized properly.");
} }
public static DeviceTypeDAO getDeviceTypeDAO() { public static DeviceTypeDAO getDeviceTypeDAO() {

@ -123,10 +123,9 @@ public class DeviceManagementServiceComponent {
DeviceManagementDAOFactory.init(dsConfig); DeviceManagementDAOFactory.init(dsConfig);
NotificationManagementDAOFactory.init(dsConfig); NotificationManagementDAOFactory.init(dsConfig);
OperationManagementDAOFactory.init(dsConfig);
/*Initialize Operation Manager*/ /*Initialize Operation Manager*/
this.initOperationsManager(); this.initOperationsManager();
OperationManagementDAOFactory.init(dsConfig);
/* If -Dsetup option enabled then create device management database schema */ /* If -Dsetup option enabled then create device management database schema */
String setupOption = String setupOption =
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);

@ -128,12 +128,10 @@ public class NotificationDAOImpl implements NotificationDAO {
try { try {
conn = NotificationManagementDAOFactory.getConnection(); conn = NotificationManagementDAOFactory.getConnection();
String sql = String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," + "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " + " d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " + "NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"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 = ?";
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -144,8 +142,7 @@ public class NotificationDAOImpl implements NotificationDAO {
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
"Error occurred while retrieving information of all " + "Error occurred while retrieving information of all notifications", e);
"notifications", e);
} finally { } finally {
NotificationDAOUtil.cleanupResources(stmt, rs); 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.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; 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.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -75,12 +76,12 @@ public class OperationManagementDAOFactory {
return new PostgreSQLOperationDAOImpl(); return new PostgreSQLOperationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
default:
return new GenericOperationDAOImpl(); return new GenericOperationDAOImpl();
default:
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) { public static void init(DataSource dtSource) {

@ -50,12 +50,12 @@ public abstract class BaseDeviceManagementTest {
@BeforeSuite @BeforeSuite
public void setupDataSource() throws Exception { public void setupDataSource() throws Exception {
this.initDatSource(); this.initDataSource();
this.initSQLScript(); this.initSQLScript();
this.initializeCarbonContext(); this.initializeCarbonContext();
} }
public void initDatSource() throws Exception { public void initDataSource() throws Exception {
this.dataSource = this.getDataSource(this.readDataSourceConfig()); this.dataSource = this.getDataSource(this.readDataSourceConfig());
DeviceManagementDAOFactory.init(dataSource); DeviceManagementDAOFactory.init(dataSource);
} }

@ -77,7 +77,7 @@ public class ApplicationPersistenceTests extends BaseDeviceManagementTest {
@BeforeClass @BeforeClass
@Override @Override
public void init() throws Exception { public void init() throws Exception {
this.initDatSource(); this.initDataSource();
} }
} }

@ -36,15 +36,17 @@ import java.sql.*;
public class DevicePersistTests extends BaseDeviceManagementTest { public class DevicePersistTests extends BaseDeviceManagementTest {
DeviceDAO deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); DeviceDAO deviceDAO;
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO;
private static final Log log = LogFactory.getLog(DevicePersistTests.class); private static final Log log = LogFactory.getLog(DevicePersistTests.class);
@BeforeClass @BeforeClass
@Override @Override
public void init() throws Exception { public void init() throws Exception {
initDatSource(); initDataSource();
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
} }
@Test @Test

@ -83,7 +83,7 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
@BeforeClass @BeforeClass
@Override @Override
public void init() throws Exception { 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.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; 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.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.FeatureManager; 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.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 { public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
@ -42,7 +36,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@BeforeClass @BeforeClass
@Override @Override
public void init() throws Exception { public void init() throws Exception {
this.initDatSource(); this.initDataSource();
this.providerService = new DeviceManagementProviderServiceImpl(); 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; 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.OAuthApplicationInfo;
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; 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.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.DynamicClientWebAppRegistrationConstants;
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil; import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil;
import javax.servlet.ServletContext; 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. * This class contains the logic to handle the OAuth application creation process.

Loading…
Cancel
Save