Fixing the conflicts

revert-70aa11f8
geethkokila 10 years ago
commit b8462b02ac

@ -76,7 +76,8 @@
org.wso2.carbon.identity.oauth.stub.dto, org.wso2.carbon.identity.oauth.stub.dto,
org.wso2.carbon.ndatasource.core, org.wso2.carbon.ndatasource.core,
org.wso2.carbon.apimgt.impl, org.wso2.carbon.apimgt.impl,
org.wso2.carbon.ndatasource.core org.wso2.carbon.ndatasource.core,
org.apache.axis2.transport.mail
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.device.mgt.core.internal, !org.wso2.carbon.device.mgt.core.internal,

@ -17,46 +17,70 @@
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.Collection; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class DeviceManagementPluginRepository { public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
private Map<String, DeviceManagementService> providers; private Map<String, DeviceManagementService> providers;
private boolean isInited;
private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class);
public DeviceManagementPluginRepository() { public DeviceManagementPluginRepository() {
providers = new HashMap<String, DeviceManagementService>(); providers = Collections.synchronizedMap(new HashMap<String, DeviceManagementService>());
DeviceManagementServiceComponent.registerStartupListener(this);
} }
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getType(); String deviceType = provider.getType();
synchronized (providers) {
try { try {
if (isInited) {
/* Initializing Device Management Service Provider */ /* Initializing Device Management Service Provider */
provider.init(); provider.init();
DeviceManagerUtil.registerDeviceType(deviceType); DeviceManagerUtil.registerDeviceType(deviceType);
}
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new DeviceManagementException("Error occurred while adding device management provider '" + throw new DeviceManagementException("Error occurred while adding device management provider '" +
deviceType + "'"); deviceType + "'", e);
} }
providers.put(deviceType, provider); providers.put(deviceType, provider);
} }
}
public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getType(); providers.remove(provider.getType());
providers.remove(deviceType);
} }
public DeviceManagementService getDeviceManagementService(String type) { public DeviceManagementService getDeviceManagementService(String type) {
return providers.get(type); return providers.get(type);
} }
public Collection<DeviceManagementService> getDeviceManagementProviders(){ @Override
return providers.values(); public void notifyObserver() {
synchronized (providers) {
for (DeviceManagementService provider : providers.values()) {
try {
provider.init();
DeviceManagerUtil.registerDeviceType(provider.getType());
} catch (Throwable e) {
/* Throwable is caught intentionally as failure of one plugin - due to invalid start up parameters,
etc - should not block the initialization of other device management providers */
log.error("Error occurred while initializing device management provider '" +
provider.getType() + "'", e);
}
}
this.isInited = true;
}
} }
} }

@ -22,7 +22,6 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -42,7 +41,6 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.startup.handler.URLPrinterStartupHandler;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
@ -97,8 +95,9 @@ public class DeviceManagementServiceComponent {
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static List<PluginInitializationListener> listeners = new ArrayList<PluginInitializationListener>(); private static List<PluginInitializationListener> listeners = new ArrayList<>();
private static List<DeviceManagementService> deviceManagers = new ArrayList<DeviceManagementService>(); private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
@ -132,6 +131,9 @@ public class DeviceManagementServiceComponent {
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */ /* Registering declarative service instances exposed by DeviceManagementServiceComponent */
this.registerServices(componentContext); this.registerServices(componentContext);
/* This is a workaround to initialize all Device Management Service Providers after the initialization
* of Device Management Service component in order to avoid bundle start up order related complications */
notifyStartupListeners();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device management core bundle has been successfully initialized"); log.debug("Device management core bundle has been successfully initialized");
} }
@ -176,11 +178,9 @@ public class DeviceManagementServiceComponent {
AppManagementConfigurationManager.getInstance().getAppManagementConfig(); AppManagementConfigurationManager.getInstance().getAppManagementConfig();
bundleContext.registerService(ApplicationManagementProviderService.class.getName(), bundleContext.registerService(ApplicationManagementProviderService.class.getName(),
new ApplicationManagerProviderServiceImpl(appConfig, pluginRepository), null); new ApplicationManagerProviderServiceImpl(appConfig, pluginRepository), null);
} catch (ApplicationManagementException appMgtEx) { } catch (ApplicationManagementException e) {
log.error("Application management service not registered."); log.error("Application management service not registered.", e);
} }
bundleContext.registerService(ServerStartupObserver.class, new URLPrinterStartupHandler(), null);
} }
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
@ -316,4 +316,14 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setConfigurationContextService(null); DeviceManagementDataHolder.getInstance().setConfigurationContextService(null);
} }
public static void registerStartupListener(DeviceManagerStartupListener startupListener) {
startupListeners.add(startupListener);
}
public static void notifyStartupListeners() {
for (DeviceManagerStartupListener startupListener : startupListeners) {
startupListener.notifyObserver();
}
}
} }

@ -16,10 +16,10 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.license.mgt; package org.wso2.carbon.device.mgt.core.internal;
public class LicenseManagementUtil {
public interface DeviceManagerStartupListener {
void notifyObserver();
} }

@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -30,7 +29,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; 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.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; 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.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
@ -58,7 +56,6 @@ public class OperationManagerImpl implements OperationManager {
private OperationMappingDAO operationMappingDAO; private OperationMappingDAO operationMappingDAO;
private OperationDAO operationDAO; private OperationDAO operationDAO;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
public OperationManagerImpl() { public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@ -68,7 +65,6 @@ public class OperationManagerImpl implements OperationManager {
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO(); operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
operationDAO = OperationManagementDAOFactory.getOperationDAO(); operationDAO = OperationManagementDAOFactory.getOperationDAO();
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
} }
@Override @Override
@ -123,11 +119,8 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
int enrolmentId;
List<Operation> operations = new ArrayList<>();
List<Operation> operations = new ArrayList<Operation>();
int enrolmentId = -1;
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
@ -138,20 +131,17 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType()); "Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
} }
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = operationDAO List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
.getOperationsForDevice(enrolmentId); operationDAO.getOperationsForDevice(enrolmentId);
Operation operation;
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) { for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
operation = OperationDAOUtil.convertOperation(dtoOperation); Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
operations.add(operation); operations.add(operation);
} }
return operations; return operations;
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() "operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() + "'", e);
+ "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" + throw new OperationManagementException("Error occurred while retrieving metadata of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device carrying the identifier '" + deviceId.getId() + "'");
@ -168,18 +158,13 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public List<? extends Operation> getPendingOperations( public List<? extends Operation> getPendingOperations(
DeviceIdentifier deviceId) throws OperationManagementException { DeviceIdentifier deviceId) throws OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType()
+ "]"); + "]");
} }
int enrolmentId;
int enrolmentId = -1; List<Operation> operations = new ArrayList<>();
List<Operation> operations = new ArrayList<Operation>(); List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = new ArrayList<>();
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>();
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
@ -215,11 +200,9 @@ public class OperationManagerImpl implements OperationManager {
"pending operations assigned for '" + deviceId.getType() + "' device '" + "pending operations assigned for '" + deviceId.getType() + "' device '" +
deviceId.getId() + "'", e); deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " + throw new OperationManagementException("Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" "for device Identifier type -'" + deviceId.getType() + "' and device Id '"
+ deviceId.getId(); + deviceId.getId() + "'", e);
log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, e);
} finally { } finally {
try { try {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -236,7 +219,7 @@ public class OperationManagerImpl implements OperationManager {
+ "]"); + "]");
} }
Operation operation = null; Operation operation = null;
int enrolmentId = -1; int enrolmentId;
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
@ -365,14 +348,13 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId) public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException { throws OperationManagementException {
int enrolmentId = -1; int enrolmentId;
Operation operation; Operation operation;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Operation Id:" + operationId + " Device Type:" + deviceId.getType() + " Device Identifier:" + log.debug("Operation Id:" + operationId + " Device Type:" + deviceId.getType() + " Device Identifier:" +
deviceId.getId()); deviceId.getId());
} }
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
@ -414,11 +396,9 @@ public class OperationManagerImpl implements OperationManager {
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() "operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId()
+ "'", e); + "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while retrieving the device " + throw new OperationManagementException("Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" "for device Identifier type -'" + deviceId.getType() + "' and device Id '" +
+ deviceId.getId(); deviceId.getId() + "'", e);
log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, e);
} finally { } finally {
try { try {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -432,9 +412,9 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus( public List<? extends Operation> getOperationsByDeviceAndStatus(
DeviceIdentifier deviceId, Operation.Status status) throws OperationManagementException { DeviceIdentifier deviceId, Operation.Status status) throws OperationManagementException {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<>();
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>(); new ArrayList<>();
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();

@ -18,8 +18,6 @@
*/ */
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
@ -35,15 +33,11 @@ import java.util.List;
public class CommandOperationDAOImpl extends OperationDAOImpl { public class CommandOperationDAOImpl extends OperationDAOImpl {
private static final Log log = LogFactory.getLog(CommandOperationDAOImpl.class);
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId = super.addOperation(operation); int operationId = super.addOperation(operation);
CommandOperation commandOp = (CommandOperation) operation; CommandOperation commandOp = (CommandOperation) operation;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)"); stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)");
@ -60,17 +54,14 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void updateOperation(Operation operation) throws OperationManagementDAOException { public void updateOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement( stmt = connection.prepareStatement(
"UPDATE DM_COMMAND_OPERATION O SET O.ENABLED=? WHERE O.OPERATION_ID=?"); "UPDATE DM_COMMAND_OPERATION O SET O.ENABLED=? WHERE O.OPERATION_ID=?");
stmt.setBoolean(1, operation.isEnabled()); stmt.setBoolean(1, operation.isEnabled());
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally { } finally {
@ -81,12 +72,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
super.deleteOperation(id); super.deleteOperation(id);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID=?"); stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -98,30 +88,23 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
} }
public CommandOperation getOperation(int id) throws OperationManagementDAOException { public CommandOperation getOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
CommandOperation commandOperation = null; CommandOperation commandOperation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID=?"; String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID=?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, id); stmt.setInt(1, id);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commandOperation = new CommandOperation(); commandOperation = new CommandOperation();
commandOperation.setEnabled(rs.getInt("ENABLED") == 0 ? false : true); commandOperation.setEnabled(rs.getInt("ENABLED") != 0);
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the command operation object " + "available for " + throw new OperationManagementDAOException("SQL Error occurred while retrieving the command operation " +
"the id '" "object available for the id '" + id, e);
+ id;
log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -132,23 +115,19 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operationList = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<>();
List<CommandOperation> commandOperationList = new ArrayList<CommandOperation>(); List<CommandOperation> commandOperations = new ArrayList<>();
CommandOperation commandOperation = null;
CommandOperation commandOperation;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select co.OPERATION_ID,ENABLED from DM_COMMAND_OPERATION co " + String sql = "SELECT co.OPERATION_ID,ENABLED FROM DM_COMMAND_OPERATION co " +
"INNER JOIN " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
"AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID"; "AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
@ -156,27 +135,25 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
commandOperation = new CommandOperation(); commandOperation = new CommandOperation();
commandOperation.setEnabled(rs.getInt("ENABLED") == 0 ? false : true); commandOperation.setEnabled(rs.getInt("ENABLED") != 0);
commandOperation.setId(rs.getInt("OPERATION_ID")); commandOperation.setId(rs.getInt("OPERATION_ID"));
commandOperationList.add(commandOperation); commandOperations.add(commandOperation);
} }
for(CommandOperation cmOperation:commandOperationList){ for(CommandOperation cmOperation : commandOperations){
operation = super.getOperation(cmOperation.getId()); operation = super.getOperation(cmOperation.getId());
operation.setEnabled(cmOperation.isEnabled()); operation.setEnabled(cmOperation.isEnabled());
operation.setStatus(status); operation.setStatus(status);
operationList.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
"' with status '" + status.toString(); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operations;
} }
} }

@ -21,10 +21,8 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
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.osgi.service.component.annotations.ConfigurationPolicy;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
@ -43,12 +41,11 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId = super.addOperation(operation); int operationId = super.addOperation(operation);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID, OPERATION_CONFIG) VALUES(?,?)"); stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID, OPERATION_CONFIG) VALUES(?, ?)");
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setObject(2, operation); stmt.setObject(2, operation);
stmt.executeUpdate(); stmt.executeUpdate();
@ -62,12 +59,11 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
super.deleteOperation(id); super.deleteOperation(id);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID=?") ; stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -79,17 +75,14 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void updateOperation(Operation operation) throws OperationManagementDAOException { public void updateOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
super.updateOperation(operation); super.updateOperation(operation);
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION O SET O.OPERATION_CONFIG=? " + stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION O SET O.OPERATION_CONFIG = ? " +
"WHERE O.OPERATION_ID=?"); "WHERE O.OPERATION_ID = ?");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
oos.writeObject(operation); oos.writeObject(operation);
@ -97,7 +90,6 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
stmt.setBytes(1, bao.toByteArray()); stmt.setBytes(1, bao.toByteArray());
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e); throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e);
} catch (IOException e) { } catch (IOException e) {
@ -123,18 +115,15 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public Operation getOperation(int operationId) throws OperationManagementDAOException { public Operation getOperation(int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ConfigOperation configOperation = null; ConfigOperation configOperation = null;
ByteArrayInputStream bais; ByteArrayInputStream bais;
ObjectInputStream ois; ObjectInputStream ois;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_CONFIG FROM DM_CONFIG_OPERATION WHERE OPERATION_ID=?"; String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_CONFIG FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -145,21 +134,16 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
configOperation = (ConfigOperation) ois.readObject(); configOperation = (ConfigOperation) ois.readObject();
} }
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the policy operation object"; throw new OperationManagementDAOException("IO Error occurred while de serialize the policy operation " +
log.error(errorMsg, e); "object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the policy operation object"; throw new OperationManagementDAOException("Class not found error occurred while de serialize the policy " +
log.error(errorMsg, e); "operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the policy operation object " + "available for " + throw new OperationManagementDAOException("SQL Error occurred while retrieving the policy operation " +
"the id '" "object available for the id '"
+ operationId; + operationId, e);
log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -168,24 +152,20 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(
Operation.Status status) throws OperationManagementDAOException { int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ConfigOperation configOperation; ConfigOperation configOperation;
List<Operation> operations = new ArrayList<>();
List<Operation> operationList = new ArrayList<Operation>();
ByteArrayInputStream bais = null; ByteArrayInputStream bais = null;
ObjectInputStream ois = null; ObjectInputStream ois = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select co.OPERATION_ID, co.OPERATION_CONFIG from DM_CONFIG_OPERATION co " + String sql = "SELECT co.OPERATION_ID, co.OPERATION_CONFIG FROM DM_CONFIG_OPERATION co " +
"INNER JOIN " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " +
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " + "AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID";
"AND STATUS=?) dm ON dm.OPERATION_ID = co.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
@ -199,22 +179,17 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
configOperation = (ConfigOperation) ois.readObject(); configOperation = (ConfigOperation) ois.readObject();
configOperation.setStatus(status); configOperation.setStatus(status);
operationList.add(configOperation); operations.add(configOperation);
} }
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the configuration operation object"; throw new OperationManagementDAOException("IO Error occurred while de serialize the configuration " +
log.error(errorMsg, e); "operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the configuration operation object"; throw new OperationManagementDAOException("Class not found error occurred while de serialize the " +
log.error(errorMsg, e); "configuration operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
"' with status '" + status.toString(); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
if (bais != null) { if (bais != null) {
try { try {
@ -233,6 +208,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operations;
} }
} }

@ -39,7 +39,6 @@ public class OperationDAOImpl implements OperationDAO {
private static final Log log = LogFactory.getLog(OperationDAOImpl.class); private static final Log log = LogFactory.getLog(OperationDAOImpl.class);
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
@ -68,17 +67,14 @@ public class OperationDAOImpl implements OperationDAO {
@Override @Override
public void updateOperation(Operation operation) throws OperationManagementDAOException { public void updateOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " + stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP = ? " +
"WHERE O.ID=?"); "WHERE O.ID = ?");
stmt.setTimestamp(1, new Timestamp(new Date().getTime())); stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update operation metadata", e); throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
} finally { } finally {
@ -88,13 +84,11 @@ public class OperationDAOImpl implements OperationDAO {
public void updateOperationStatus(int enrolmentId, int operationId, Operation.Status status) public void updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
throws OperationManagementDAOException { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS=? " + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS = ? " +
"WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?"); "WHERE O.ENROLMENT_ID = ? and O.OPERATION_ID = ?");
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
stmt.setInt(3, operationId); stmt.setInt(3, operationId);
@ -102,28 +96,22 @@ public class OperationDAOImpl implements OperationDAO {
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " + throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
"metadata", "metadata", e);
e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
} }
} }
@Override @Override
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, DEVICE_ID, " +
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," +
"OPERATION_RESPONSE) VALUES(?, ?, ?)"); "OPERATION_RESPONSE) VALUES(?, ?, ?)");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
oos.writeObject(operationResponse); oos.writeObject(operationResponse);
@ -132,12 +120,11 @@ public class OperationDAOImpl implements OperationDAO {
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
stmt.setBytes(3, bao.toByteArray()); stmt.setBytes(3, bao.toByteArray());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while inserting operation response", e); throw new OperationManagementDAOException("Error occurred while inserting operation response", e);
}catch (IOException e) { } catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e); throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
}finally { } finally {
if (bao != null) { if (bao != null) {
try { try {
bao.close(); bao.close();
@ -158,11 +145,10 @@ public class OperationDAOImpl implements OperationDAO {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_OPERATION WHERE ID=?"); stmt = connection.prepareStatement("DELETE DM_OPERATION WHERE ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -174,16 +160,13 @@ public class OperationDAOImpl implements OperationDAO {
@Override @Override
public Operation getOperation(int id) throws OperationManagementDAOException { public Operation getOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation = null; Operation operation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
"DM_OPERATION WHERE id=?"; "DM_OPERATION WHERE id = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, id); stmt.setInt(1, id);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -202,10 +185,8 @@ public class OperationDAOImpl implements OperationDAO {
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the operation object " + "available for the id '" throw new OperationManagementDAOException("SQL Error occurred while retrieving the operation object " +
+ id; "available for the id '" + id, e);
log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -215,19 +196,16 @@ public class OperationDAOImpl implements OperationDAO {
@Override @Override
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException { public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation = null; Operation operation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " +
" From (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + " FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " + "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"DM_ENROLMENT_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.ENROLMENT_ID=?) om " + "DM_ENROLMENT_OPERATION_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID "; "ON o.ID = om.OPERATION_ID ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2, operationId); stmt.setInt(2, operationId);
@ -247,10 +225,8 @@ public class OperationDAOImpl implements OperationDAO {
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"' with id '" + operationId; "available for the device'" + enrolmentId + "' with id '" + operationId, e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -259,26 +235,21 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(
Operation.Status status) throws OperationManagementDAOException { int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>();
List<Operation> operationList = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.ENROLMENT_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
@ -293,40 +264,32 @@ public class OperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(status); operation.setStatus(status);
operationList.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"' with status '" + status.toString(); "available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operations;
} }
@Override @Override
public List<? extends Operation> getOperationsForDevice(int enrolmentId) public List<? extends Operation> getOperationsForDevice(int enrolmentId) throws OperationManagementDAOException {
throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>();
List<Operation> operationList = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE,dm.STATUS FROM DM_OPERATION o " + "OPERATION_CODE, dm.STATUS FROM DM_OPERATION o " +
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.ENROLMENT_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
@ -341,40 +304,34 @@ public class OperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
operationList.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"' with status '"; "available for the device'" + enrolmentId + "' with status '", e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operations;
} }
@Override @Override
public Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException { public Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE FROM DM_OPERATION o " + "OPERATION_CODE FROM DM_OPERATION o " +
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.ENROLMENT_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, Operation.Status.PENDING.toString()); stmt.setString(2, Operation.Status.PENDING.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
Operation operation = null;
Operation operation = null;
if (rs.next()) { if (rs.next()) {
operation = new Operation(); operation = new Operation();
operation.setType(this.getType(rs.getString("TYPE"))); operation.setType(this.getType(rs.getString("TYPE")));
@ -398,28 +355,24 @@ public class OperationDAOImpl implements OperationDAO {
} }
public List<? extends Operation> getOperationsByDeviceStatusAndType(int enrolmentId, public List<? extends Operation> getOperationsByDeviceStatusAndType(
Operation.Status status, Operation.Type type) throws OperationManagementDAOException { int enrolmentId, Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>();
List<Operation> operationList = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o WHERE o.TYPE=?) o " + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " +
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.ENROLMENT_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, type.toString()); stmt.setString(1, type.toString());
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
stmt.setString(3, status.toString()); stmt.setString(3, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
@ -433,22 +386,16 @@ public class OperationDAOImpl implements OperationDAO {
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operationList.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
"' with status '" + status.toString(); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operations;
}
private Operation.Status getStatus(String status) {
return Operation.Status.valueOf(status);
} }
private Operation.Type getType(String type) { private Operation.Type getType(String type) {

@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
@ -38,7 +37,6 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId = super.addOperation(operation); int operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
operation.setId(operationId); operation.setId(operationId);
@ -47,7 +45,6 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)"); "VALUES(?, ?)");
@ -60,22 +57,18 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
} }
return operationId; return operationId;
} }
@Override @Override
public void updateOperation(Operation operation) throws OperationManagementDAOException { public void updateOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
super.updateOperation(operation); super.updateOperation(operation);
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION O SET O.OPERATION_DETAILS=? " + stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION O SET O.OPERATION_DETAILS=? " +
"WHERE O.OPERATION_ID=?"); "WHERE O.OPERATION_ID=?");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
oos.writeObject(operation); oos.writeObject(operation);
@ -83,7 +76,6 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
stmt.setBytes(1, bao.toByteArray()); stmt.setBytes(1, bao.toByteArray());
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e); throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e);
} catch (IOException e) { } catch (IOException e) {
@ -109,7 +101,6 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int operationId) throws OperationManagementDAOException { public void deleteOperation(int operationId) throws OperationManagementDAOException {
super.deleteOperation(operationId); super.deleteOperation(operationId);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
@ -126,18 +117,15 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public Operation getOperation(int operationId) throws OperationManagementDAOException { public Operation getOperation(int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
PolicyOperation policyOperation = null; PolicyOperation policyOperation = null;
ByteArrayInputStream bais; ByteArrayInputStream bais;
ObjectInputStream ois; ObjectInputStream ois;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?"; String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -148,21 +136,15 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
policyOperation = (PolicyOperation) ois.readObject(); policyOperation = (PolicyOperation) ois.readObject();
} }
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the policy operation object"; throw new OperationManagementDAOException("IO Error occurred while de serialize the policy operation " +
log.error(errorMsg, e); "object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the policy operation object"; throw new OperationManagementDAOException("Class not found error occurred while de serialize the " +
log.error(errorMsg, e); "policy operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the policy operation object " + "available for " + throw new OperationManagementDAOException("SQL Error occurred while retrieving the policy operation " +
"the id '" "object available for the id '" + operationId + "'", e);
+ operationId;
log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -173,27 +155,22 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
PolicyOperation policyOperation; PolicyOperation policyOperation;
List<Operation> operations = new ArrayList<>();
List<Operation> operationList = new ArrayList<Operation>();
ByteArrayInputStream bais = null; ByteArrayInputStream bais = null;
ObjectInputStream ois = null; ObjectInputStream ois = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_POLICY_OPERATION po " + String sql = "SELECT po.OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_POLICY_OPERATION po " +
"INNER JOIN " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " +
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " + "AND STATUS = ?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
"AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
@ -202,22 +179,17 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
policyOperation = (PolicyOperation) ois.readObject(); policyOperation = (PolicyOperation) ois.readObject();
policyOperation.setStatus(status); policyOperation.setStatus(status);
operationList.add(policyOperation); operations.add(policyOperation);
} }
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the profile operation object"; throw new OperationManagementDAOException("IO Error occurred while de serialize the profile " +
log.error(errorMsg, e); "operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the profile operation object"; throw new OperationManagementDAOException("Class not found error occurred while de serialize the " +
log.error(errorMsg, e); "profile operation object", e);
throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"' with status '" + status.toString(); "available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e);
} finally { } finally {
if (bais != null) { if (bais != null) {
try { try {
@ -236,6 +208,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operationList; return operations;
} }
} }

@ -19,11 +19,6 @@
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.util; package org.wso2.carbon.device.mgt.core.operation.mgt.dao.util;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.*;
public class OperationDAOUtil { public class OperationDAOUtil {

@ -1,64 +0,0 @@
/*
* 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.core.startup.handler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
import org.wso2.carbon.utils.NetworkUtils;
public class URLPrinterStartupHandler implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(URLPrinterStartupHandler.class);
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
log.info("EMM Console URL : " + this.getEmmUrl());
}
private String getEmmUrl() {
// Hostname
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
// HTTPS port
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
ConfigurationContextService configContextService =
DeviceManagementDataHolder.getInstance().getConfigurationContextService();
int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
int httpsProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
mgtConsoleTransport);
if (httpsProxyPort > 0) {
port = httpsProxyPort;
}
return "https://" + hostName + ":" + port + "/mdm";
}
}

@ -56,6 +56,16 @@
<Export-Package> <Export-Package>
org.wso2.carbon.device.mgt.extensions.* org.wso2.carbon.device.mgt.extensions.*
</Export-Package> </Export-Package>
<Import-Package>
org.wso2.carbon.governance.api.*,
javax.xml.namespace,
org.wso2.carbon.context,
org.wso2.carbon.device.mgt.common.license.mgt,
org.wso2.carbon.registry.api,
org.wso2.carbon.registry.core,
org.wso2.carbon.registry.core.exceptions,
org.wso2.carbon.registry.core.session
</Import-Package>
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>

@ -22,8 +22,10 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager; import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.wso2.carbon.registry.api.Registry; import org.wso2.carbon.registry.api.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.session.UserRegistry;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -32,14 +34,14 @@ public class GenericArtifactManagerFactory {
private static Map<Integer, GenericArtifactManager> tenantArtifactManagers = private static Map<Integer, GenericArtifactManager> tenantArtifactManagers =
new HashMap<Integer, GenericArtifactManager>(); new HashMap<Integer, GenericArtifactManager>();
private static final Object lock = new Object(); private static final Object LOCK = new Object();
public static GenericArtifactManager getTenantAwareGovernanceArtifactManager( public static GenericArtifactManager getTenantAwareGovernanceArtifactManager(
Registry registry) throws LicenseManagementException { Registry registry) throws LicenseManagementException {
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GenericArtifactManager artifactManager; GenericArtifactManager artifactManager;
synchronized (lock) { synchronized (LOCK) {
artifactManager = artifactManager =
tenantArtifactManagers.get(tenantId); tenantArtifactManagers.get(tenantId);
if (artifactManager == null) { if (artifactManager == null) {
@ -54,7 +56,7 @@ public class GenericArtifactManagerFactory {
return artifactManager; return artifactManager;
} catch (RegistryException e) { } catch (RegistryException e) {
throw new LicenseManagementException("Error occurred while initializing GovernanceArtifactManager " + throw new LicenseManagementException("Error occurred while initializing GovernanceArtifactManager " +
"associated with tenant '" + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + "'"); "associated with tenant '" + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + "'", e);
} }
} }

@ -1,38 +0,0 @@
/*
* 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.extensions.license.mgt;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
public class LicenseManagementService implements LicenseManager {
@Override
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
//return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
return null;
}
@Override
public void addLicense(String deviceType, License license) throws LicenseManagementException {
//return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(deviceType, license);
}
}

@ -19,6 +19,8 @@
package org.wso2.carbon.device.mgt.extensions.license.mgt; package org.wso2.carbon.device.mgt.extensions.license.mgt;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
@ -41,9 +43,10 @@ public class RegistryBasedLicenseManager implements LicenseManager {
private Registry registry; private Registry registry;
private GenericArtifactManager artifactManager; private GenericArtifactManager artifactManager;
public RegistryBasedLicenseManager(Registry registry) { public RegistryBasedLicenseManager() {
Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
if (registry == null) { if (registry == null) {
throw new IllegalArgumentException("Registry instance provided is null. Hence, " + throw new IllegalArgumentException("Registry instance retrieved is null. Hence, " +
"'Registry based license manager cannot be initialized'"); "'Registry based license manager cannot be initialized'");
} }
this.registry = registry; this.registry = registry;

@ -39,6 +39,7 @@ import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl;
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl; import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleServiceImpl; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleServiceImpl;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -47,7 +48,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
private static final Log log = LogFactory.getLog(PolicyManagerServiceImpl.class); private static final Log log = LogFactory.getLog(PolicyManagerServiceImpl.class);
PolicyAdministratorPointImpl policyAdministratorPoint; PolicyAdministratorPoint policyAdministratorPoint;
MonitoringManager monitoringManager; MonitoringManager monitoringManager;
private PolicyManager policyManager; private PolicyManager policyManager;
@ -90,42 +91,16 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
@Override @Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
try { try {
Policy policy = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). Policy policy = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
getEffectivePolicy(deviceIdentifier); getEffectivePolicy(deviceIdentifier);
if (policy != null) { if (policy != null) {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier);
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
PolicyOperation policyOperation = new PolicyOperation();
policyOperation.setEnabled(true);
policyOperation.setType(Operation.Type.POLICY);
policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE);
for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation profileOperation = new ProfileOperation();
profileOperation.setCode(feature.getFeatureCode());
profileOperation.setEnabled(true);
profileOperation.setStatus(Operation.Status.PENDING);
profileOperation.setType(Operation.Type.PROFILE);
profileOperation.setPayLoad(feature.getContent());
profileOperationList.add(profileOperation);
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setPayLoad(policyOperation.getProfileOperations());
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
addOperation(policyOperation, deviceIdentifiers);
} else {
return null; return null;
} }
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier);
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(
PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers);
return policy; return policy;
} catch (PolicyEvaluationException e) { } catch (PolicyEvaluationException e) {
String msg = "Error occurred while getting the effective policies from the PEP service for device " + String msg = "Error occurred while getting the effective policies from the PEP service for device " +

@ -0,0 +1,58 @@
/*
* 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.policy.mgt.core.enforcement;
public class PolicyDelegationException extends Exception {
private static final long serialVersionUID = -3151279311929070297L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public PolicyDelegationException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public PolicyDelegationException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public PolicyDelegationException(String msg) {
super(msg);
setErrorMessage(msg);
}
public PolicyDelegationException() {
super();
}
public PolicyDelegationException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,31 @@
/*
* 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.policy.mgt.core.enforcement;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.List;
public interface PolicyEnforcementDelegator {
void delegate(Policy policy, List<Device> devices) throws PolicyDelegationException;
}

@ -0,0 +1,50 @@
/*
* 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.policy.mgt.core.enforcement;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.util.ArrayList;
import java.util.List;
public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegator {
private OperationManager operationManager = new OperationManagerImpl();
@Override
public void delegate(Policy policy, List<Device> devices) throws PolicyDelegationException {
try {
List<DeviceIdentifier> deviceIds = new ArrayList<>();
for (Device device : devices) {
deviceIds.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
}
operationManager.addOperation(PolicyManagerUtil.transformPolicy(policy), deviceIds);
} catch (OperationManagementException e) {
throw new PolicyDelegationException("Error occurred while delegating policy information to " +
"the respective enforcement points", e);
}
}
}

@ -27,6 +27,9 @@ import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.Profile; import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException; import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.core.enforcement.PolicyDelegationException;
import org.wso2.carbon.policy.mgt.core.enforcement.PolicyEnforcementDelegator;
import org.wso2.carbon.policy.mgt.core.enforcement.PolicyEnforcementDelegatorImpl;
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager; import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager; import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager; import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
@ -40,26 +43,38 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class); private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class);
private PolicyManager policyManager; private PolicyManager policyManager;
private ProfileManager profileManager; private ProfileManager profileManager;
private FeatureManager featureManager; private FeatureManager featureManager;
private PolicyEnforcementDelegator delegator;
public PolicyAdministratorPointImpl() { public PolicyAdministratorPointImpl() {
this.policyManager = new PolicyManagerImpl();
policyManager = new PolicyManagerImpl(); this.profileManager = new ProfileManagerImpl();
profileManager = new ProfileManagerImpl(); this.featureManager = new FeatureManagerImpl();
featureManager = new FeatureManagerImpl(); this.delegator = new PolicyEnforcementDelegatorImpl();
} }
@Override @Override
public Policy addPolicy(Policy policy) throws PolicyManagementException { public Policy addPolicy(Policy policy) throws PolicyManagementException {
return policyManager.addPolicy(policy); Policy resultantPolicy = policyManager.addPolicy(policy);
try {
delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
} catch (PolicyDelegationException e) {
throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
}
return resultantPolicy;
} }
@Override @Override
public Policy updatePolicy(Policy policy) throws PolicyManagementException { public Policy updatePolicy(Policy policy) throws PolicyManagementException {
return policyManager.updatePolicy(policy); Policy resultantPolicy = policyManager.updatePolicy(policy);
try {
delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
} catch (PolicyDelegationException e) {
throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
}
return resultantPolicy;
} }
@Override @Override

@ -21,21 +21,21 @@ package org.wso2.carbon.policy.mgt.core.util;
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.w3c.dom.Document; import org.w3c.dom.Document;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementAdminService; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.sql.DataSource; import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
@ -98,4 +98,29 @@ public class PolicyManagerUtil {
buff.deleteCharAt(buff.length() - 1); buff.deleteCharAt(buff.length() - 1);
return buff.toString(); return buff.toString();
} }
public static Operation transformPolicy(Policy policy) {
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
PolicyOperation policyOperation = new PolicyOperation();
policyOperation.setEnabled(true);
policyOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.POLICY);
policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE);
for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation profileOperation = new ProfileOperation();
profileOperation.setCode(feature.getFeatureCode());
profileOperation.setEnabled(true);
profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING);
profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE);
profileOperation.setPayLoad(feature.getContent());
profileOperationList.add(profileOperation);
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setPayLoad(policyOperation.getProfileOperations());
return policyOperation;
}
} }

@ -1,78 +0,0 @@
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID INT auto_increment NOT NULL,
NAME VARCHAR(300) NULL DEFAULT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE (
ID INTEGER auto_increment NOT NULL,
DESCRIPTION TEXT NULL DEFAULT NULL,
NAME VARCHAR(100) NULL DEFAULT NULL,
DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL,
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
STATUS VARCHAR(15) NULL DEFAULT NULL,
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL,
OWNER VARCHAR(45) NULL DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- TO:DO - Remove this INSERT sql statement.
Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');

@ -1,35 +0,0 @@
-- -----------------------------------------------------
-- Table `DM_DEVICE_TYPE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` (
`ID` INT(11) NOT NULL ,
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `DM_DEVICE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
`ID` VARCHAR(20) NOT NULL ,
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
`DATE_OF_ENROLLMENT` DATETIME NULL DEFAULT NULL ,
`DATE_OF_LAST_UPDATE` DATETIME NULL DEFAULT NULL ,
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (`ID`) ,
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) ,
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
FOREIGN KEY (`DEVICE_TYPE_ID` )
REFERENCES `DM_DEVICE_TYPE` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;

@ -1,47 +0,0 @@
<?xml version="1.0"?>
<artifactType type="application/vnd.wso2-license+xml" shortName="license" singularLabel="License" pluralLabel="Licenses"
hasNamespace="false" iconSet="10">
<storagePath>/device-mgt/license/@{overview_name}/@{overview_language}/@{overview_version}</storagePath>
<nameAttribute>overview_name</nameAttribute>
<ui>
<list>
<column name="Device Type">
<data type="path" value="overview_provider" href="@{storagePath}"/>
</column>
<column name="Name">
<data type="path" value="overview_name" href="@{storagePath}"/>
</column>
<column name="Language">
<data type="path" value="overview_language" href="@{storagePath}"/>
</column>
<column name="Version">
<data type="path" value="overview_version" href="@{storagePath}"/>
</column>
</list>
</ui>
<content>
<table name="Overview">
<field type="text" required="true">
<name>Provider</name>
</field>
<field type="text" required="true">
<name>Name</name>
</field>
<field type="text" required="true">
<name>Language</name>
</field>
<field type="text" required="true">
<name>Version</name>
</field>
<field type="text">
<name>Validity From</name>
</field>
<field type="text">
<name>Validity To</name>
</field>
<field type="text-area">
<name>License</name>
</field>
</table>
</content>
</artifactType>
Loading…
Cancel
Save