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 ee5024a94..9220c079a 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 @@ -17,12 +17,6 @@ package org.wso2.carbon.device.mgt.common; public final class DeviceManagementConstants { - /*DEVICE Manager operations*/ - public static final String ADD_DEVICE_ENTRY = "Add device entry"; - public static final String STANDARD_TRANSACTION_MANAGER_JNDI_NAME = "java:comp/TransactionManager"; - public static final String STANDARD_USER_TRANSACTION_JNDI_NAME = "java:comp/UserTransaction"; - /*Data Source Configurations */ - public static final class DataSourceProperties { private DataSourceProperties() { throw new AssertionError(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index b196bf802..95d2ef67e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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. @@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import java.util.List; @@ -52,7 +53,8 @@ public class DeviceManager implements DeviceManagerService { this.getPluginRepository().getDeviceManagementProvider(device.getType()); dms.enrollDevice(device); try { - this.getDeviceDAO().addDevice(device); + this.getDeviceTypeDAO().getDeviceType(); + this.getDeviceDAO().addDevice(DeviceManagementDAOUtil.convertDevice(device)); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", e); @@ -65,7 +67,7 @@ public class DeviceManager implements DeviceManagerService { this.getPluginRepository().getDeviceManagementProvider(device.getType()); dms.modifyEnrollment(device); try { - this.getDeviceDAO().updateDevice(device); + this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", e); 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 6c17a7d7c..5bf4335db 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,7 +15,7 @@ package org.wso2.carbon.device.mgt.core.dao; -import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.dto.Status; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java index 668f0db11..1947922f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.dao; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.List; @@ -33,4 +34,6 @@ public interface DeviceTypeDAO { List getDeviceTypes() throws DeviceManagementDAOException; + DeviceIdentifier getDeviceType() throws DeviceManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index ece6a3ea9..94bdc0604 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -38,6 +38,7 @@ public class DeviceDAOImpl implements DeviceDAO { private DataSource dataSource; private static final Log log = LogFactory.getLog(DeviceDAOImpl.class); + public DeviceDAOImpl(DataSource dataSource) { this.dataSource = dataSource; } @@ -60,13 +61,13 @@ public class DeviceDAOImpl implements DeviceDAO { stmt.setLong(4, new Date().getTime()); stmt.setString(5, device.getOwnerShip()); stmt.setString(6, device.getStatus().toString()); - stmt.setLong(7, device.getDeviceType().getId()); - stmt.setLong(8, device.getDeviceIdentificationId()); + stmt.setString(7, device.getDeviceType()); + stmt.setString(8, device.getDeviceIdentificationId()); stmt.setString(9, device.getOwnerId()); stmt.setInt(10, DeviceManagementDAOUtil.getTenantId()); stmt.executeUpdate(); } catch (SQLException e) { - String msg = "Failed to enroll device '" + device.getName() + "'"; + String msg = "Error occurred while enrolling device '" + device.getName() + "'"; log.error(msg, e); throw new DeviceManagementDAOException(msg, e); } finally { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index 6a0ee2368..aa1386c86 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -15,6 +15,7 @@ */ package org.wso2.carbon.device.mgt.core.dao.impl; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; @@ -60,6 +61,11 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { return null; } + @Override + public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException { + return new DeviceIdentifier(); + } + private Connection getConnection() throws DeviceManagementDAOException { try { return dataSource.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 354487812..e9fdd98fb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -19,6 +19,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.dto.Status; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.tenant.TenantManager; @@ -99,4 +102,19 @@ public final class DeviceManagementDAOUtil { } } + public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device + device) throws DeviceManagementDAOException { + Device deviceBO = new Device(); + deviceBO.setDescription(device.getDescription()); + deviceBO.setName(device.getName()); + deviceBO.setDateOfEnrolment(device.getDateOfEnrolment()); + deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); + deviceBO.setStatus(Status.valueOf(String.valueOf(device.isStatus()))); + deviceBO.setOwnerId(device.getOwner()); + deviceBO.setOwnerShip(device.getOwnership()); + deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId()); + deviceBO.setDeviceType(device.getType()); + return deviceBO; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java index c988968ce..325a4322a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java @@ -19,35 +19,36 @@ package org.wso2.carbon.device.mgt.core.dto; import java.io.Serializable; +import java.util.Date; public class Device implements Serializable { private static final long serialVersionUID = -8101106997837486245L; - private Long id; + private int id; private String description; private String name; - private Long dateOfEnrolment; - private Long dateOfLastUpdate; - private Long deviceIdentificationId; + private Date dateOfEnrolment; + private Date dateOfLastUpdate; + private String deviceIdentificationId; private Status status; private String ownerId; private String ownerShip; - private Long tenantId; - private DeviceType deviceType; + private int tenantId; + private String deviceType; - public DeviceType getDeviceType() { + public String getDeviceType() { return deviceType; } - public void setDeviceType(DeviceType deviceType) { + public void setDeviceType(String deviceType) { this.deviceType = deviceType; } - public Long getId() { + public int getId() { return id; } - public void setId(Long id) { + public void setId(int id) { this.id = id; } @@ -67,27 +68,27 @@ public class Device implements Serializable { this.name = name; } - public Long getDateOfEnrolment() { + public Date getDateOfEnrolment() { return dateOfEnrolment; } - public void setDateOfEnrolment(Long dateOfEnrolment) { + public void setDateOfEnrolment(Date dateOfEnrolment) { this.dateOfEnrolment = dateOfEnrolment; } - public Long getDateOfLastUpdate() { + public Date getDateOfLastUpdate() { return dateOfLastUpdate; } - public void setDateOfLastUpdate(Long dateOfLastUpdate) { + public void setDateOfLastUpdate(Date dateOfLastUpdate) { this.dateOfLastUpdate = dateOfLastUpdate; } - public Long getDeviceIdentificationId() { + public String getDeviceIdentificationId() { return deviceIdentificationId; } - public void setDeviceIdentificationId(Long deviceIdentificationId) { + public void setDeviceIdentificationId(String deviceIdentificationId) { this.deviceIdentificationId = deviceIdentificationId; } @@ -115,11 +116,11 @@ public class Device implements Serializable { this.ownerId = ownerId; } - public Long getTenantId() { + public int getTenantId() { return tenantId; } - public void setTenantId(Long tenantId) { + public void setTenantId(int tenantId) { this.tenantId = tenantId; } }