refactored issues in codes

merge-requests/1/head
hasuniea 9 years ago
parent c064b32ff2
commit 716daee269

@ -1,13 +1,10 @@
/*
* 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
*
* 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

@ -1,21 +1,18 @@
/*
* 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.
*
* 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.mobile.impl.windows;
import org.apache.commons.logging.Log;
@ -101,16 +98,15 @@ public class WindowsDeviceManager implements DeviceManager {
public TenantConfiguration getConfiguration() throws DeviceManagementException {
Resource resource;
try {
String windowsRegPath =
String windowsTenantRegistryPath =
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
resource = MobileDeviceManagementUtil.getRegistryResource(windowsRegPath);
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath);
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (TenantConfiguration) unmarshaller.unmarshal(
new StringReader(new String((byte[]) resource.getContent(), Charset
.forName(MobilePluginConstants.CHARSET_UTF8))));
} catch (MobileDeviceMgtPluginException e) {
throw new DeviceManagementException(
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
@ -132,20 +128,12 @@ public class WindowsDeviceManager implements DeviceManager {
log.debug("Modifying the Windows device enrollment data");
}
WindowsDAOFactory.beginTransaction();
status = daoFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice);
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
WindowsDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
WindowsDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
log.warn(msg, mobileDAOEx);
}
String msg = "Error while updating the enrollment of the Windows device : " +
device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
WindowsDAOFactory.rollbackTransaction();
throw new DeviceManagementException("Error while updating the enrollment of the Windows device : " +
device.getDeviceIdentifier(), e);
}
return status;
}
@ -161,16 +149,8 @@ public class WindowsDeviceManager implements DeviceManager {
status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId());
WindowsDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
WindowsDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the device dis enrol transaction :" +
deviceId.toString();
log.warn(msg, mobileDAOEx);
}
String msg = "Error while removing the Windows device : " + deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
WindowsDAOFactory.rollbackTransaction();
throw new DeviceManagementException("Error while removing the Windows device : " + deviceId.getId(), e);
}
return status;
}

@ -1,13 +1,10 @@
/*
* 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
*
* 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
@ -16,7 +13,6 @@
* under the License.
*/
package org.wso2.carbon.device.mgt.mobile.impl.windows;
import org.wso2.carbon.device.mgt.common.Device;

@ -1,21 +1,18 @@
/*
* 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.
*
* 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.mobile.impl.windows.dao;
import org.apache.commons.logging.Log;
@ -41,10 +38,14 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
}
@Override
public MobileDeviceDAO getMobileDeviceDAO() {return new WindowsDeviceDAOImpl();}
public MobileDeviceDAO getMobileDeviceDAO() {
return new WindowsDeviceDAOImpl();
}
@Override
public MobileOperationDAO getMobileOperationDAO() {return null;}
public MobileOperationDAO getMobileOperationDAO() {
return null;
}
@Override
public MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
@ -88,7 +89,7 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
return currentConnection.get();
}
public static void commitTransaction() throws MobileDeviceManagementDAOException {
public static void commitTransaction() {
try {
Connection conn = currentConnection.get();
if (conn != null) {
@ -100,13 +101,13 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
}
}
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
log.error("Error occurred while committing the transaction", e);
} finally {
closeConnection();
}
}
public static void closeConnection() throws MobileDeviceManagementDAOException {
public static void closeConnection() {
Connection con = currentConnection.get();
try {
@ -117,7 +118,7 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
currentConnection.remove();
}
public static void rollbackTransaction() throws MobileDeviceManagementDAOException {
public static void rollbackTransaction() {
try {
Connection conn = currentConnection.get();
if (conn != null) {
@ -129,7 +130,8 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
}
}
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error occurred while rollback the transaction", e);
log.warn("Error occurred while roll-backing the transaction", e);
} finally {
closeConnection();
}

@ -1,4 +1,3 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
@ -28,9 +27,12 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Implements MobileDeviceDAO for Windows Devices.
@ -41,7 +43,49 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO {
@Override
public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
return null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
MobileDevice mobileDevice = null;
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
try {
conn = WindowsDAOFactory.getConnection();
String selectDBQuery =
"SELECT MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " +
"OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS, OS_VERSION, DEVICE_NAME " +
"FROM WINDOWS_DEVICE WHERE MOBILE_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, mblDeviceId);
rs = stmt.executeQuery();
while (rs.next()) {
mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.MOBILE_DEVICE_ID));
mobileDevice.setVendor(rs.getString(WindowsPluginConstants.IMEI));
mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.IMSI));
mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.OS_VERSION));
mobileDevice.setImei(rs.getString(WindowsPluginConstants.DEVICE_MODEL));
mobileDevice.setImsi(rs.getString(WindowsPluginConstants.VENDOR));
mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE));
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI));
propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO));
propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME));
mobileDevice.setDeviceProperties(propertyMap);
mobileDevices.add(mobileDevice);
}
if (log.isDebugEnabled()) {
log.debug("All Windows device details have fetched from Windows database.");
}
return mobileDevice;
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
WindowsDAOFactory.closeConnection();
}
}
@Override
@ -88,10 +132,8 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO {
}
}
} catch (SQLException e) {
String msg = "Error occurred while adding the Windows device '" +
mobileDevice.getMobileDeviceId() + "' to the Windows db.";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
throw new MobileDeviceManagementDAOException("Error occurred while adding the Windows device '" +
mobileDevice.getMobileDeviceId() + "' to the Windows db.", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
}
@ -124,7 +166,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO {
WindowsPluginConstants.DEVICE_INFO));
stmt.setString(3, mobileDevice.getImei());
stmt.setString(4, mobileDevice.getImsi());
stmt.setString(5, mobileDevice.getOsVersion() );
stmt.setString(5, mobileDevice.getOsVersion());
stmt.setString(6, mobileDevice.getModel());
stmt.setString(7, mobileDevice.getVendor());
stmt.setString(8, mobileDevice.getLatitude());
@ -144,10 +186,8 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO {
}
}
} catch (SQLException e) {
String msg = "Error occurred while modifying the Windows device '" +
mobileDevice.getMobileDeviceId() + "' data.";
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
throw new MobileDeviceManagementDAOException("Error occurred while modifying the Windows device '" +
mobileDevice.getMobileDeviceId() + "' data.", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
}
@ -184,6 +224,47 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO {
@Override
public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
return null;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
MobileDevice mobileDevice;
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
try {
conn = WindowsDAOFactory.getConnection();
String selectDBQuery =
"SELECT MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " +
"OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS, OS_VERSION, DEVICE_NAME " +
"FROM WINDOWS_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
rs = stmt.executeQuery();
while (rs.next()) {
mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.MOBILE_DEVICE_ID));
mobileDevice.setVendor(rs.getString(WindowsPluginConstants.IMEI));
mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.IMSI));
mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.OS_VERSION));
mobileDevice.setImei(rs.getString(WindowsPluginConstants.DEVICE_MODEL));
mobileDevice.setImsi(rs.getString(WindowsPluginConstants.VENDOR));
mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE));
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI));
propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO));
propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME));
mobileDevice.setDeviceProperties(propertyMap);
mobileDevices.add(mobileDevice);
}
if (log.isDebugEnabled()) {
log.debug("All Windows device details have fetched from Windows database.");
}
return mobileDevices;
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
WindowsDAOFactory.closeConnection();
}
}
}

@ -32,7 +32,7 @@ public class WindowsPluginConstants {
public static final String LATITUDE = "LATITUDE";
public static final String LONGITUDE = "LONGITUDE";
public static final String SERIAL = "SERIAL";
public static final String MAC_ADDRESS ="MAC_ADDRESS";
public static final String DEVICE_NAME ="DEVICE_NAME";
public static final String MAC_ADDRESS = "MAC_ADDRESS";
public static final String DEVICE_NAME = "DEVICE_NAME";
}

@ -18,7 +18,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows.util;
import java.util.Map;
/**
*
* Contains utility methods used by Windows plugin.
*/
public class WindowsUtils {
@ -26,9 +25,8 @@ public class WindowsUtils {
String deviceProperty = deviceProperties.get(property);
if (deviceProperty == null) {
return "";
return null;
}
return deviceProperty;
}
}

Loading…
Cancel
Save