mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Code cleanup
This commit is contained in:
parent
29bfc6f09f
commit
b7984c18b6
@ -50,6 +50,7 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|||||||
* bind="setDeviceManagerService"
|
* bind="setDeviceManagerService"
|
||||||
* unbind="unsetDeviceManagerService"
|
* unbind="unsetDeviceManagerService"
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class DeviceManagementServiceComponent {
|
public class DeviceManagementServiceComponent {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
||||||
|
|||||||
@ -60,22 +60,22 @@ public class DeviceManagementConfigTests {
|
|||||||
public void testMandateManagementRepositoryElement() {
|
public void testMandateManagementRepositoryElement() {
|
||||||
File malformedConfig =
|
File malformedConfig =
|
||||||
new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
||||||
this.validateConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateDataSourceConfigurationElement() {
|
public void testMandateDataSourceConfigurationElement() {
|
||||||
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
||||||
this.validateConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateJndiLookupDefinitionElement() {
|
public void testMandateJndiLookupDefinitionElement() {
|
||||||
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
||||||
this.validateConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateConfig(File malformedConfig) {
|
private void validateMalformedConfig(File malformedConfig) {
|
||||||
try {
|
try {
|
||||||
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
|
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
|
||||||
Unmarshaller um = ctx.createUnmarshaller();
|
Unmarshaller um = ctx.createUnmarshaller();
|
||||||
@ -83,7 +83,7 @@ public class DeviceManagementConfigTests {
|
|||||||
um.unmarshal(malformedConfig);
|
um.unmarshal(malformedConfig);
|
||||||
Assert.assertTrue(false);
|
Assert.assertTrue(false);
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
log.error("Error while unmarsharlling the device management config", e);
|
log.error("Error occurred while unmarsharlling device management config", e);
|
||||||
Assert.assertTrue(true);
|
Assert.assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,14 +22,14 @@ import java.util.List;
|
|||||||
public abstract class AbstractMobileOperationManager implements OperationManager {
|
public abstract class AbstractMobileOperationManager implements OperationManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||||
throws OperationManagementException {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
|
public boolean addOperation(Operation operation,
|
||||||
OperationManagementException {
|
List<DeviceIdentifier> devices) throws OperationManagementException {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.mobile.dao;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.DataSourceListener;
|
import org.wso2.carbon.device.mgt.mobile.DataSourceListener;
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.*;
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.*;
|
||||||
@ -39,7 +40,7 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(){
|
public void init() throws DeviceManagementException {
|
||||||
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
||||||
if (dataSource != null) {
|
if (dataSource != null) {
|
||||||
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
||||||
@ -88,9 +89,11 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyObserver() {
|
public void notifyObserver() {
|
||||||
|
try {
|
||||||
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
||||||
if(dataSource!=null){
|
|
||||||
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error occurred while resolving mobile device management metadata repository data source", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
* @param config Mobile data source configuration
|
* @param config Mobile data source configuration
|
||||||
* @return data source resolved from the data source definition
|
* @return data source resolved from the data source definition
|
||||||
*/
|
*/
|
||||||
public static DataSource resolveDataSource(MobileDataSourceConfig config) {
|
public static DataSource resolveDataSource(MobileDataSourceConfig config) throws DeviceManagementException {
|
||||||
DataSource dataSource = null;
|
DataSource dataSource = null;
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throw new RuntimeException("Device Management Repository data source configuration " +
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
||||||
@ -64,25 +64,10 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
jndiProperties.put(prop.getName(), prop.getValue());
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
}
|
}
|
||||||
try {
|
dataSource =
|
||||||
dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(
|
MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||||
jndiConfig.getJndiName(), jndiProperties);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Error in looking up data source: " + e.getMessage());
|
|
||||||
}
|
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||||
dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(
|
|
||||||
jndiConfig.getJndiName(), null);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Error in looking up data source: " + e.getMessage());
|
|
||||||
}
|
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dataSource;
|
return dataSource;
|
||||||
@ -96,10 +81,11 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
return (DataSource) InitialContext.doLookup(dataSourceName);
|
return (DataSource) InitialContext.doLookup(dataSourceName);
|
||||||
}
|
}
|
||||||
final InitialContext context = new InitialContext(jndiProperties);
|
final InitialContext context = new InitialContext(jndiProperties);
|
||||||
return (DataSource) context.doLookup(dataSourceName);
|
return (DataSource) context.lookup(dataSourceName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DeviceManagementException(
|
String msg = "Error in looking up data source: " + e.getMessage();
|
||||||
"Error in looking up data source: " + e.getMessage(), e);
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +129,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
try {
|
try {
|
||||||
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(dataSource);
|
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(dataSource);
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error(
|
log.error("Exception occurred while initializing mobile device management database schema", e);
|
||||||
"Exception occurred while initializing mobile device management database schema",
|
|
||||||
e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,8 +147,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
try {
|
try {
|
||||||
initializer.createRegistryDatabase();
|
initializer.createRegistryDatabase();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DeviceManagementException(
|
throw new DeviceManagementException("Error occurred while initializing Mobile Device Management " +
|
||||||
"Error occurred while initializing Mobile Device Management " +
|
|
||||||
"database schema", e);
|
"database schema", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
boolean status = false;
|
boolean status;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
try {
|
try {
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addDevice(mobileDevice);
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addDevice(mobileDevice);
|
||||||
@ -62,7 +62,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
boolean status = false;
|
boolean status;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
try {
|
try {
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
@ -78,7 +78,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
boolean status = false;
|
boolean status;
|
||||||
try {
|
try {
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.deleteDevice(deviceId.getId());
|
.deleteDevice(deviceId.getId());
|
||||||
@ -122,7 +122,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
Device device = null;
|
Device device;
|
||||||
try {
|
try {
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
||||||
getDevice(deviceId.getId());
|
getDevice(deviceId.getId());
|
||||||
@ -143,14 +143,13 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
boolean status = false;
|
boolean status;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
try {
|
try {
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.updateDevice(mobileDevice);
|
.updateDevice(mobileDevice);
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
String msg =
|
String msg = "Error while updating the Android device : " + device.getDeviceIdentifier();
|
||||||
"Error while updating the Android device : " + device.getDeviceIdentifier();
|
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
@ -166,8 +165,8 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
getAllDevices();
|
getAllDevices();
|
||||||
if (mobileDevices != null) {
|
if (mobileDevices != null) {
|
||||||
devices = new ArrayList<Device>();
|
devices = new ArrayList<Device>();
|
||||||
for (int x = 0; x < mobileDevices.size(); x++) {
|
for (MobileDevice mobileDevice : mobileDevices) {
|
||||||
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevices.get(x)));
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
|||||||
@ -88,5 +88,4 @@ public class IOSDeviceManagerService implements DeviceManagerService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user