diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java
index 208d009326..5ee72f4daa 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java
@@ -22,6 +22,8 @@ public class Device {
private int id;
+ private String type;
+
private String description;
private String name;
@@ -130,4 +132,12 @@ public class Device {
this.features = features;
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java
index 44952cd566..eab1b03e17 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java
@@ -80,10 +80,11 @@ public interface DeviceManagerService {
* Method to set the status indicating whether a particular device registered within CDM is enabled at a given
* moment.
*
+ * @param deviceId Fully qualified device identifier
* @param status Indicates whether the device is active
* @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device
*/
- void setActive(boolean status) throws DeviceManagementException;
+ void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException;
/**
* Method to retrieve metadata of all devices registered within CDM corresponding to a particular device type.
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 0490197ae0..c8d5f99e73 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
@@ -80,10 +80,6 @@
org.eclipse.equinox
org.eclipse.equinox.common
-
- org.wso2.carbon
- org.wso2.carbon.logging
-
org.wso2.carbon
org.wso2.carbon.device.mgt.common
@@ -95,29 +91,26 @@
org.wso2.carbon
org.wso2.carbon.utils
- ${carbon.platform.version}
-
+
+ org.wso2.carbon
+ org.wso2.carbon.core
+
org.wso2.carbon
org.wso2.carbon.ndatasource.core
- ${carbon.platform.version}
org.wso2.carbon
org.wso2.carbon.ndatasource.rdbms
- ${carbon.platform.version}
org.wso2.carbon
org.wso2.carbon.transaction.manager
- ${carbon.platform.version}
-
org.jboss.spec.javax.transaction
jboss-transaction-api_1.1_spec
- ${jboss-transaction-api.version}
org.testng
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java
index fb7e0a32e9..5f8cc91120 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java
@@ -15,8 +15,20 @@
*/
package org.wso2.carbon.device.mgt.core;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
+
+import java.util.Map;
+
public class DeviceManagementRepository {
+ private Map providers;
+
+ public void addDeviceManagementProvider(DeviceManagerService provider) {
+ providers.put(provider.getProviderType(), provider);
+ }
+ public DeviceManagerService getDeviceManagementProvider(String type) {
+ return providers.get(type);
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java
index 59144523f0..586a649a58 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java
@@ -15,14 +15,11 @@
package org.wso2.carbon.device.mgt.core.config;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
-import org.wso2.carbon.device.mgt.core.dao.exception.DeviceMgtDAOFactory;
+import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
-import org.wso2.carbon.device.mgt.core.util.DeviceMgtDbCreator;
import org.wso2.carbon.utils.CarbonUtils;
import javax.sql.DataSource;
import javax.xml.bind.JAXBContext;
@@ -34,16 +31,12 @@ import java.io.File;
*/
public class DeviceConfigurationManager {
- private DeviceMgtConfig currentDeviceConfig;
+ private DeviceManagementConfig currentDeviceConfig;
private static DeviceConfigurationManager deviceConfigManager;
- private static final Log log = LogFactory.getLog(DeviceConfigurationManager.class);
private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
- private final String cdmSetupSql = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
- "conf" + File.separator + "dbscripts";
-
public static DeviceConfigurationManager getInstance() {
if (deviceConfigManager == null) {
synchronized (DeviceConfigurationManager.class) {
@@ -55,33 +48,26 @@ public class DeviceConfigurationManager {
return deviceConfigManager;
}
-
public synchronized void initConfig() throws DeviceManagementException {
try {
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
-/* Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
- //rss-config supports secure vault as it needs to be resolve when parsing
- DeviceManagerUtil.secureResolveDocument(doc);*/
- /* Un-marshaling RSS configuration */
- JAXBContext rssContext = JAXBContext.newInstance(DeviceMgtConfig.class);
- Unmarshaller unmarshaller = rssContext.createUnmarshaller();
- this.currentDeviceConfig = (DeviceMgtConfig) unmarshaller.unmarshal(doc);
- //set jndi data source name for future use
- DeviceManagerUtil.setJndiDataSourceName(currentDeviceConfig.getDeviceMgtRepository().getDataSourceConfig().
- getJndiLookupDefintion().getJndiName());
- DataSource dataSource = DeviceMgtDAOFactory.resolveDataSource(this.currentDeviceConfig.getDeviceMgtRepository()
- .getDataSourceConfig());
- DeviceManagerUtil.setDataSource(dataSource);
+ /* Un-marshaling Device Management configuration */
+ JAXBContext rssContext = JAXBContext.newInstance(DeviceManagementConfig.class);
+ Unmarshaller unmarshaller = rssContext.createUnmarshaller();
+ this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
} catch (Exception e) {
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
}
}
-
-
- public DeviceMgtConfig getCurrentDeviceConfig() {
+ public DeviceManagementConfig getDeviceManagementConfig() {
return currentDeviceConfig;
}
+
+ public DataSourceConfig getDataSourceConfig() {
+ return currentDeviceConfig.getDeviceMgtRepository().getDataSourceConfig();
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceMgtConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
similarity index 96%
rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceMgtConfig.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
index 0a10dfc8a9..29077c2814 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceMgtConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
@@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* Represents Device Mgt configuration.
*/
@XmlRootElement(name = "DeviceMgtConfiguration")
-public final class DeviceMgtConfig {
+public final class DeviceManagementConfig {
private String deviceMgtProvider;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java
index 94d86102d1..6737e73ae1 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java
@@ -37,4 +37,5 @@ public class DeviceManagementRepository {
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
this.dataSourceConfig = dataSourceConfig;
}
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
index d7de35a6ba..503138d987 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
@@ -15,16 +15,21 @@
package org.wso2.carbon.device.mgt.core.dao;
-import org.wso2.carbon.device.mgt.core.dao.util.DeviceDAOUtil;
+import org.wso2.carbon.device.mgt.core.dto.Device;
+import org.wso2.carbon.device.mgt.core.dto.Status;
-import javax.sql.DataSource;
+import java.util.List;
-public class DeviceDAO {
+public interface DeviceDAO {
- private DataSource dataSource;
+ void addDevice(Device device) throws DeviceManagementDAOException;
- public DeviceDAO(DataSource dataSource) {
- this.dataSource = dataSource;
- }
+ void updateDevice(Device device) throws DeviceManagementDAOException;
+
+ void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException;
+
+ void deleteDevice(Long deviceId) throws DeviceManagementDAOException;
+
+ List getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/DeviceDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java
similarity index 83%
rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/DeviceDAOException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java
index 7d59beddce..cb48c3320c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/DeviceDAOException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java
@@ -16,12 +16,12 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.core.dao.exception;
+package org.wso2.carbon.device.mgt.core.dao;
/**
* Custom exception class for data access related exceptions
*/
-public class DeviceDAOException extends Exception {
+public class DeviceManagementDAOException extends Exception {
private String message;
private static final long serialVersionUID = 2021891706072918864L;
@@ -32,7 +32,7 @@ public class DeviceDAOException extends Exception {
* @param message error message
* @param nestedException exception
*/
- public DeviceDAOException(String message, Exception nestedException) {
+ public DeviceManagementDAOException(String message, Exception nestedException) {
super(message, nestedException);
setErrorMessage(message);
}
@@ -43,7 +43,7 @@ public class DeviceDAOException extends Exception {
* @param message the detail message.
* @param cause the cause of this exception.
*/
- public DeviceDAOException(String message, Throwable cause) {
+ public DeviceManagementDAOException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
@@ -53,7 +53,7 @@ public class DeviceDAOException extends Exception {
*
* @param message the detail message.
*/
- public DeviceDAOException(String message) {
+ public DeviceManagementDAOException(String message) {
super(message);
setErrorMessage(message);
}
@@ -63,7 +63,7 @@ public class DeviceDAOException extends Exception {
*
* @param cause the cause of this exception.
*/
- public DeviceDAOException(Throwable cause) {
+ public DeviceManagementDAOException(Throwable cause) {
super(cause);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java
new file mode 100644
index 0000000000..9788bbf121
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2014, 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.
+ */
+package org.wso2.carbon.device.mgt.core.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.DeviceDAOImpl;
+import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
+import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
+
+import javax.sql.DataSource;
+import java.util.Hashtable;
+import java.util.List;
+
+public class DeviceManagementDAOFactory {
+
+ private static DataSource dataSource;
+ private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class);
+
+ public static DeviceDAO getDeviceDAO() {
+ return new DeviceDAOImpl(dataSource);
+ }
+
+ public static DeviceTypeDAO getDeviceTypeDAO() {
+ return new DeviceTypeDAOImpl(dataSource);
+ }
+
+ public static void init(DataSourceConfig config) {
+ dataSource = resolveDataSource(config);
+ }
+
+ /**
+ * Resolve data source from the data source definition
+ *
+ * @param config data source configuration
+ * @return data source resolved from the data source definition
+ */
+ public static DataSource resolveDataSource(DataSourceConfig config) {
+ DataSource dataSource = null;
+ if (config == null) {
+ throw new RuntimeException("Device Management Repository data source configuration " +
+ "is null and thus, is not initialized");
+ }
+ JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
+ if (jndiConfig != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing Device Management Repository data source using the JNDI " +
+ "Lookup Definition");
+ }
+ List jndiPropertyList =
+ jndiConfig.getJndiProperties();
+ if (jndiPropertyList != null) {
+ Hashtable
-
-
-
org.testng
testng
${testng.version}
-
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+ ${carbon.platform.version}
+
+
+ org.wso2.carbon
+ org.wso2.carbon.core
+ ${carbon.platform.version}
+
+
+ org.wso2.carbon
+ org.wso2.carbon.ndatasource.core
+ ${carbon.platform.version}
+
+
+ org.wso2.carbon
+ org.wso2.carbon.ndatasource.rdbms
+ ${carbon.platform.version}
+
+
+ org.wso2.carbon
+ org.wso2.carbon.transaction.manager
+ ${carbon.platform.version}
+
+
+ org.jboss.spec.javax.transaction
+ jboss-transaction-api_1.1_spec
+ ${jboss-transaction-api.version}
+