device org imports optimize

pull/238/head
Isuri Mendis 1 year ago
parent 0385f35dab
commit f6054795bc

@ -142,7 +142,6 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
DeviceOrganizationService deviceOrganizationService = DeviceOrgAPIUtils.getDeviceOrganizationService();
boolean exists;
if (parentDeviceId.equals("null")) {
log.info("inside if");
exists = deviceOrganizationService.isDeviceOrganizationExist(deviceId, null);
} else {
exists = deviceOrganizationService.isDeviceOrganizationExist(deviceId, Integer.valueOf(parentDeviceId));

@ -1,75 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
@XmlRootElement
@JsonIgnoreProperties(ignoreUnknown = true)
public class DeviceOrganizationRequest {
@XmlElement
private int organizationId;
@XmlElement
private int deviceId;
@XmlElement
private Integer parentDeviceId;
@XmlElement
private Date updateTime;
public int getOrganizationId() {
return organizationId;
}
public void setOrganizationId(int organizationId) {
this.organizationId = organizationId;
}
public int getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}
public Integer getParentDeviceId() {
return parentDeviceId;
}
public void setParentDeviceId(Integer parentDeviceId) {
this.parentDeviceId = parentDeviceId;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

@ -31,8 +31,8 @@ public interface DeviceOrganizationDAO {
/**
* Retrieves child devices per particular device ID
*
* @param node The device node for which child devices are retrieved.
* @param maxDepth The maximum depth to traverse when fetching child devices.
* @param node The device node for which child devices are retrieved.
* @param maxDepth The maximum depth to traverse when fetching child devices.
* @param includeDevice Flag to indicate whether to include the parent device in the result.
* @return A list of child device nodes.
* @throws DeviceOrganizationMgtDAOException If an error occurs while retrieving child devices.
@ -42,8 +42,8 @@ public interface DeviceOrganizationDAO {
/**
* Retrieves parent devices for a given device node.
*
* @param node The device node for which parent devices are retrieved.
* @param maxDepth The maximum depth to traverse when fetching parent devices.
* @param node The device node for which parent devices are retrieved.
* @param maxDepth The maximum depth to traverse when fetching parent devices.
* @param includeDevice Flag to indicate whether to include the current device node in the result.
* @return A list of parent device nodes.
* @throws DeviceOrganizationMgtDAOException If an error occurs while retrieving parent devices.
@ -80,7 +80,7 @@ public interface DeviceOrganizationDAO {
/**
* Get a device organization by the CHILD_PARENT_COMP_KEY unique key.
*
* @param deviceId The ID of the child device.
* @param deviceId The ID of the child device.
* @param parentDeviceId The ID of the parent device.
* @return The DeviceOrganization object if found, null otherwise.
* @throws DeviceOrganizationMgtDAOException if an error occurs while accessing the database.

@ -50,6 +50,7 @@ public class DeviceOrganizationDAOFactory {
public static final class DataBaseTypes {
private DataBaseTypes() {
}
public static final String DB_TYPE_MYSQL = "MySQL";
public static final String DB_TYPE_ORACLE = "Oracle";
public static final String DB_TYPE_MSSQL = "Microsoft SQL Server";

@ -31,7 +31,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
@ -300,10 +299,8 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
Connection conn = ConnectionManagerUtil.getDBConnection();
if (parentDeviceId != null) {
// If parentDeviceId is not null, use it in the query.
sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID = ?";
} else {
// If parentDeviceId is null, use a query that checks for null values.
sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID IS NULL";
}
@ -340,10 +337,8 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
Connection conn = ConnectionManagerUtil.getDBConnection();
if (parentDeviceId != null) {
// If parentDeviceId is not null, use it in the query.
sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID = ?";
} else {
// If parentDeviceId is null, use a query that checks for null values.
sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID IS NULL";
}

@ -100,7 +100,7 @@ public class ConnectionManagerUtil {
/**
* Ends the current database transaction by setting auto-commit mode to true.
*
* @throws DBConnectionException If an error occurs while ending the transaction.
* @throws DBConnectionException If an error occurs while ending the transaction.
* @throws IllegalTransactionStateException If there is no active transaction to end.
*/
public static void endDBTransaction() throws DBConnectionException {
@ -248,8 +248,8 @@ public class ConnectionManagerUtil {
/**
* Lookup a data source using the given data source name and JNDI properties.
*
* @param dataSourceName The JNDI name of the data source to lookup.
* @param jndiProperties Optional JNDI properties used for the lookup.
* @param dataSourceName The JNDI name of the data source to lookup.
* @param jndiProperties Optional JNDI properties used for the lookup.
* @return A data source object representing the looked-up data source.
* @throws RuntimeException If an error occurs during the lookup process.
*/
@ -273,7 +273,7 @@ public class ConnectionManagerUtil {
* Get the name of the database product to which the current connection belongs.
*
* @return A string representing the name of the database product.
* Returns null if an error occurs during the retrieval process.
* Returns null if an error occurs during the retrieval process.
*/
public static String getDatabaseType() {
try {

@ -19,6 +19,7 @@ public class DeviceOrganizationDaoUtil {
/**
* Helper method to create a Device Organization object from a ResultSet
*
* @param rs The ResultSet containing the organization data.
* @return A DeviceOrganization object.
* @throws SQLException If there's an issue reading data from the ResultSet.
@ -39,6 +40,7 @@ public class DeviceOrganizationDaoUtil {
/**
* Helper method to create a DeviceNode object from a ResultSet
*
* @param rs The ResultSet containing device data.
* @return A DeviceNode object.
* @throws SQLException If there's an issue reading data from the ResultSet.

@ -1,47 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception;
/**
* Represents the exception thrown during application management.
*/
public class ApplicationManagementException extends Exception {
private String message;
public ApplicationManagementException(String message, Throwable throwable) {
super(message, throwable);
setMessage(message);
}
public ApplicationManagementException(String message) {
super(message);
setMessage(message);
}
public ApplicationManagementException() {
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -4,7 +4,7 @@ package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exce
* This exception is thrown when a bad request is encountered in the Device Organization Management DAO layer.
* It typically indicates issues with the input parameters or data during DAO operations.
*/
public class BadRequestDaoException extends DeviceOrganizationMgtDAOException{
public class BadRequestDaoException extends DeviceOrganizationMgtDAOException {
private static final long serialVersionUID = -6275360486437601206L;

@ -47,8 +47,8 @@ public class DeviceOrganizationMgtDAOException extends Exception {
/**
* Constructs a new `DeviceOrganizationMgtDAOException` with a specified detail message and a nested exception.
*
* @param msg The detail message that describes the exception.
* @param nestedEx The nested exception.
* @param msg The detail message that describes the exception.
* @param nestedEx The nested exception.
*/
public DeviceOrganizationMgtDAOException(String msg, Exception nestedEx) {
super(msg, nestedEx);

@ -48,8 +48,8 @@ public class DeviceOrganizationMgtPluginException extends Exception {
/**
* Constructs a new `DeviceOrganizationMgtPluginException` with a specified detail message and a nested exception.
*
* @param msg The detail message that describes the exception.
* @param nestedEx The nested exception.
* @param msg The detail message that describes the exception.
* @param nestedEx The nested exception.
*/
public DeviceOrganizationMgtPluginException(String msg, Exception nestedEx) {
super(msg, nestedEx);

@ -1,39 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception;
/**
* Exception thrown due to an issue in database transactions.
*/
public class IllegalTransactionStateException extends RuntimeException {
private static final long serialVersionUID = -3151279331929070297L;
public IllegalTransactionStateException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public IllegalTransactionStateException(String message, Throwable cause) {
super(message, cause);
}
public IllegalTransactionStateException(String msg) {
super(msg);
}
}

@ -1,39 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception;
/**
* Exception thrown due to an issue in TransactionManagement of Database.
*/
public class TransactionManagementException extends ApplicationManagementException {
private static final long serialVersionUID = -3151279321929070297L;
public TransactionManagementException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public TransactionManagementException(String message, Throwable cause) {
super(message, cause);
}
public TransactionManagementException(String msg) {
super(msg);
}
}

@ -113,8 +113,6 @@ public class DeviceOrganizationMgtServiceComponent {
* @param dataSourceService
*/
protected void setDataSourceService(DataSourceService dataSourceService) {
/* This is to avoid mobile device management component getting initialized before the underlying datasources
are registered */
if (log.isDebugEnabled()) {
log.debug("Data source service set to Device Organization Mgt component");
}

@ -2,15 +2,10 @@ package io.entgra.device.mgt.core.device.mgt.extensions.device.organization;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.DeviceOrganizationDAO;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.DeviceOrganizationDAOFactory;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.util.ConnectionManagerUtil;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtDAOException;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.mock.BaseDeviceOrganizationTest;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DBConnectionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class DAONegativeTest extends BaseDeviceOrganizationTest {

Loading…
Cancel
Save