From 22bf18666f2bc266ea6dd7a0e19c5fd8c6fda5cb Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 4 Dec 2014 11:18:18 +0530 Subject: [PATCH 1/3] DAO Layer implementation --- .../device/mgt/core/dao/DeviceTypeMgtDAO.java | 34 +++++ .../core/dao/exception/CDMDAOException.java | 78 ++++++++++++ .../CDMDatabaseConnectionException.java | 72 +++++++++++ .../mgt/core/dao/impl/DeviceMgtDAOImpl.java | 61 +++++++++ .../carbon/device/mgt/core/dto/Device.java | 116 ++++++++++++++++++ .../device/mgt/core/dto/DeviceType.java | 45 +++++++ .../carbon/device/mgt/core/dto/Status.java | 23 ++++ 7 files changed, 429 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeMgtDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDAOException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDatabaseConnectionException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Status.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeMgtDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeMgtDAO.java new file mode 100644 index 000000000..4d076e3e6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeMgtDAO.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014, 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.core.dao; + +import org.wso2.carbon.device.mgt.core.dao.exception.CDMDAOException; +import org.wso2.carbon.device.mgt.core.dao.exception.CDMDatabaseConnectionException; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; + +import java.util.List; + +public interface DeviceTypeMgtDAO { + + void addDeviceType(DeviceType deviceType) throws CDMDAOException, CDMDatabaseConnectionException; + + void updateDeviceType(DeviceType deviceType) throws CDMDAOException, CDMDatabaseConnectionException; + + List getDeviceTypes() throws CDMDAOException, CDMDatabaseConnectionException; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDAOException.java new file mode 100644 index 000000000..dd5ca1eba --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDAOException.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014, 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.core.dao.exception; + +/** + * Custom exception class for data access related exceptions + */ +public class CDMDAOException extends Exception { + + private String message; + private static final long serialVersionUID = 2021891706072918864L; + + /** + * Constructs a new exception with the specified detail message and nested exception. + * + * @param message error message + * @param nestedException exception + */ + public CDMDAOException(String message, Exception nestedException) { + super(message, nestedException); + setErrorMessage(message); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message the detail message. + * @param cause the cause of this exception. + */ + public CDMDAOException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + /** + * Constructs a new exception with the specified detail message + * + * @param message the detail message. + */ + public CDMDAOException(String message) { + super(message); + setErrorMessage(message); + } + + /** + * Constructs a new exception with the specified and cause. + * + * @param cause the cause of this exception. + */ + public CDMDAOException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + + public void setErrorMessage(String errorMessage) { + this.message = errorMessage; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDatabaseConnectionException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDatabaseConnectionException.java new file mode 100644 index 000000000..85028fafe --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/exception/CDMDatabaseConnectionException.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014, 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.core.dao.exception; + +public class CDMDatabaseConnectionException extends Exception { + + private String message; + + /** + * Constructs a new exception with the specified detail message and nested exception. + * + * @param message error message + * @param nestedException exception + */ + public CDMDatabaseConnectionException(String message, Exception nestedException) { + super(message, nestedException); + setErrorMessage(message); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message the detail message. + * @param cause the cause of this exception. + */ + public CDMDatabaseConnectionException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + /** + * Constructs a new exception with the specified detail message + * + * @param message the detail message. + */ + public CDMDatabaseConnectionException(String message) { + super(message); + setErrorMessage(message); + } + + /** + * Constructs a new exception with the specified and cause. + * + * @param cause the cause of this exception. + */ + public CDMDatabaseConnectionException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + + public void setErrorMessage(String errorMessage) { + this.message = errorMessage; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java new file mode 100644 index 000000000..54e008a20 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014, 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.core.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.dao.DeviceMgtDAO; +import org.wso2.carbon.device.mgt.core.dao.exception.CDMDAOException; +import org.wso2.carbon.device.mgt.core.dao.exception.CDMDatabaseConnectionException; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.Status; + +import java.util.List; + +public class DeviceMgtDAOImpl implements DeviceMgtDAO { + + private static final Log log = LogFactory.getLog(DeviceMgtDAOImpl.class); + + @Override + public void addDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException { + + } + + @Override + public void updateDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException { + + } + + @Override + public void updateDeviceStatus(Long deviceId, Status status) + throws CDMDAOException, CDMDatabaseConnectionException { + + } + + @Override + public void deleteDevice(Long deviceId) throws CDMDAOException, CDMDatabaseConnectionException { + + } + + @Override + public List getDeviceByDeviceId(Long deviceId) + throws CDMDAOException, CDMDatabaseConnectionException { + return null; + } +} 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 new file mode 100644 index 000000000..36a52a45c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014, 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.core.dto; + +import java.io.Serializable; + +public class Device implements Serializable{ + + private static final long serialVersionUID = -8101106997837486245L; + private Long id; + private String description; + private String name; + private Long dateOfEnrolment; + private Long dateOfLastUpdate; + private Long deviceIdentificationId; + private Status status; + private String ownerId; + private String ownerShip; + private Long tenantId; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getDateOfEnrolment() { + return dateOfEnrolment; + } + + public void setDateOfEnrolment(Long dateOfEnrolment) { + this.dateOfEnrolment = dateOfEnrolment; + } + + public Long getDateOfLastUpdate() { + return dateOfLastUpdate; + } + + public void setDateOfLastUpdate(Long dateOfLastUpdate) { + this.dateOfLastUpdate = dateOfLastUpdate; + } + + public Long getDeviceIdentificationId() { + return deviceIdentificationId; + } + + public void setDeviceIdentificationId(Long deviceIdentificationId) { + this.deviceIdentificationId = deviceIdentificationId; + } + + public void setOwnerShip(String ownerShip) { + this.ownerShip = ownerShip; + } + + public String getOwnerShip() { + return ownerShip; + } + + public Status getStatus() { + return status; + } + + public String getOwnerId() { + return ownerId; + } + + public void setStatus(Status status) { + this.status = status; + } + + public void setOwnerId(String ownerId) { + this.ownerId = ownerId; + } + + public Long getTenantId() { + return tenantId; + } + + public void setTenantId(Long tenantId) { + this.tenantId = tenantId; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java new file mode 100644 index 000000000..cd2349820 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2014, 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.core.dto; + +import java.io.Serializable; + +public class DeviceType implements Serializable { + + private static final long serialVersionUID = 7927802716452548282L; + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Status.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Status.java new file mode 100644 index 000000000..f315a2402 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Status.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2014, 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.core.dto; + +public enum Status { + ACTIVE, INACTIVE +} From 2ad0e441e87e5887bd932ef3676c0e3553dff4ca Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 4 Dec 2014 11:19:17 +0530 Subject: [PATCH 2/3] DAO Layer Implementation --- .../org.wso2.carbon.device.mgt.core/pom.xml | 5 +++ .../device/mgt/core/dao/DeviceMgtDAO.java | 44 ++++++++++++++----- pom.xml | 1 + 3 files changed, 38 insertions(+), 12 deletions(-) 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 4b01db648..c25fe103c 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 @@ -87,6 +87,11 @@ org.wso2.carbon org.wso2.carbon.device.mgt.common + + org.wso2.carbon + logging + ${carbon.platform.version} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAO.java index bcee7df2e..ba9a49fdd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAO.java @@ -1,20 +1,40 @@ -/** - * Copyright (c) 2014, 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. - * You may obtain a copy of the License at + * 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 + * 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. + * 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; -public class DeviceMgtDAO { +import org.wso2.carbon.device.mgt.core.dao.exception.CDMDAOException; +import org.wso2.carbon.device.mgt.core.dao.exception.CDMDatabaseConnectionException; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.Status; + +import java.util.List; + +public interface DeviceMgtDAO { + + void addDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException; + + void updateDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException; + + void updateDeviceStatus(Long deviceId, Status status) throws CDMDAOException, CDMDatabaseConnectionException; + + void deleteDevice(Long deviceId) throws CDMDAOException, CDMDatabaseConnectionException; + + List getDeviceByDeviceId(Long deviceId) throws CDMDAOException, CDMDatabaseConnectionException; } diff --git a/pom.xml b/pom.xml index 81923e069..3259cec23 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ 4.3.0-SNAPSHOT + 4.3.0-SNAPSHOT 1.5.4 1.3 [1.6.1.wso2v11, 1.7.0) From 19d4d1f62d14489239bdea613d389318847fe7aa Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 4 Dec 2014 11:38:19 +0530 Subject: [PATCH 3/3] DAO Layer Implementation --- components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 4 ++-- .../carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java | 2 +- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 c25fe103c..aa5f4e9a5 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 @@ -89,8 +89,8 @@ org.wso2.carbon - logging - ${carbon.platform.version} + org.wso2.carbon.logging + ${carbon.kernel.version} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java index 54e008a20..426266cca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceMgtDAOImpl.java @@ -34,7 +34,7 @@ public class DeviceMgtDAOImpl implements DeviceMgtDAO { @Override public void addDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException { - + } @Override diff --git a/pom.xml b/pom.xml index 3259cec23..d0b77c184 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ 4.3.0-SNAPSHOT - 4.3.0-SNAPSHOT + 4.2.0-SNAPSHOT 1.5.4 1.3 [1.6.1.wso2v11, 1.7.0)