revert-70aa11f8
geethkokila 10 years ago
commit f83d919ed1

@ -45,12 +45,6 @@ public class DeviceManagementRepository {
public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException { public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getProviderType();
try {
DeviceManagerUtil.unregisterDeviceType(deviceType);
} catch (DeviceManagementException e) {
throw new DeviceManagementException("Error occurred while removing device management provider '" +
deviceType + "'", e);
}
providers.remove(deviceType); providers.remove(deviceType);
} }

@ -120,6 +120,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
DeviceType deviceType = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "SELECT ID From DM_DEVICE_TYPE WHERE NAME = ?"; String sql = "SELECT ID From DM_DEVICE_TYPE WHERE NAME = ?";
@ -127,14 +128,11 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
stmt.setString(1, type); stmt.setString(1, type);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
int id = -1;
if (rs.next()) { if (rs.next()) {
id = rs.getInt("ID"); deviceType = new DeviceType();
} deviceType.setId(rs.getInt("ID"));
DeviceType deviceType = new DeviceType();
deviceType.setId(id);
deviceType.setName(type); deviceType.setName(type);
}
return deviceType; return deviceType;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetch device type id for device type " + throw new DeviceManagementDAOException("Error occurred while fetch device type id for device type " +

@ -55,10 +55,9 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.user.core.service.RealmService;
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;
import org.wso2.carbon.user.core.service.RealmService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -267,7 +266,7 @@ public class DeviceManagementServiceComponent {
*/ */
protected void unsetDeviceManager(DeviceMgtService deviceManager) { protected void unsetDeviceManager(DeviceMgtService deviceManager) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); log.debug("Un setting Device Management Service Provider : '" + deviceManager.getProviderType() + "'");
} }
try { try {
this.getPluginRepository().removeDeviceManagementProvider(deviceManager); this.getPluginRepository().removeDeviceManagementProvider(deviceManager);

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
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.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -195,19 +196,32 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType() + "]");
} }
Operation operation = null; Operation operation = null;
Device device;
try { try {
device = deviceManagementService.getCoreDevice(deviceIdentifier);
if (device == null) {
throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceIdentifier.getId() + " and given type" + deviceIdentifier.getType());
}
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
.getNextOperation(deviceId); .getNextOperation(device.getId());
if (dtoOperation != null) { if (dtoOperation != null) {
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} }
return operation; return operation;
} catch (DeviceManagementException deviceMgtException) {
String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId();
log.error(errorMsg, deviceMgtException);
throw new OperationManagementException(errorMsg, deviceMgtException);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving next pending operation", e); throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
} }

@ -42,6 +42,6 @@ public interface OperationDAO {
List<? extends Operation> getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException; List<? extends Operation> getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException;
Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException; Operation getNextOperation(int deviceId) throws OperationManagementDAOException;
} }

@ -66,7 +66,6 @@ public class OperationDAOImpl implements OperationDAO {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection();
} }
} }
@ -462,7 +461,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -483,9 +482,9 @@ public class OperationDAOImpl implements OperationDAO {
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " + "o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " +
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
stmt.setString(1, deviceId.getType()); stmt.setString(1, Operation.Status.PENDING.toString());
stmt.setString(2, deviceId.getId()); stmt.setInt(2, deviceId);
stmt.setString(3, Operation.Status.PENDING.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
Operation operation = null; Operation operation = null;

@ -59,7 +59,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
return operationId; return operationId;
} }
@Override
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;

@ -111,23 +111,23 @@ public final class DeviceManagerUtil {
/** /**
* Adds a new device type to the database if it does not exists. * Adds a new device type to the database if it does not exists.
* *
* @param deviceType device type * @param typeName device type
* @return status of the operation * @return status of the operation
*/ */
public static boolean registerDeviceType(String deviceType) throws DeviceManagementException { public static boolean registerDeviceType(String typeName) throws DeviceManagementException {
boolean status; boolean status;
try { try {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType); DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName);
if (deviceTypeId == null) { if (deviceType == null) {
DeviceType dt = new DeviceType(); DeviceType dt = new DeviceType();
dt.setName(deviceType); dt.setName(typeName);
deviceTypeDAO.addDeviceType(dt); deviceTypeDAO.addDeviceType(dt);
} }
status = true; status = true;
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" + throw new DeviceManagementException("Error occurred while registering the device type '" +
deviceType + "'", e); typeName + "'", e);
} }
return status; return status;
} }
@ -135,22 +135,22 @@ public final class DeviceManagerUtil {
/** /**
* Un-registers an existing device type from the device management metadata repository. * Un-registers an existing device type from the device management metadata repository.
* *
* @param deviceType device type * @param typeName device type
* @return status of the operation * @return status of the operation
*/ */
public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException { public static boolean unregisterDeviceType(String typeName) throws DeviceManagementException {
try { try {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType); DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName);
if (deviceTypeId == null) { if (deviceType != null) {
DeviceType dt = new DeviceType(); DeviceType dt = new DeviceType();
dt.setName(deviceType); dt.setName(typeName);
deviceTypeDAO.removeDeviceType(deviceType); deviceTypeDAO.removeDeviceType(typeName);
} }
return true; return true;
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" + throw new DeviceManagementException("Error occurred while registering the device type '" +
deviceType + "'", e); typeName + "'", e);
} }
} }

@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP NOT NULL, CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL,
STATUS VARCHAR(50) NULL, STATUS VARCHAR(50) NULL,
OPERATION_CODE VARCHAR(25) NOT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );

@ -62,6 +62,8 @@ public interface PolicyAdministratorPoint {
List<Policy> getPolicies() throws PolicyManagementException; List<Policy> getPolicies() throws PolicyManagementException;
Policy getPolicy(int policyId) throws PolicyManagementException;
/** /**
* This method gives the device specific policy. * This method gives the device specific policy.
* *

@ -592,11 +592,11 @@ public class PolicyDAOImpl implements PolicyDAO {
resultSet = stmt.executeQuery(); resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
policy.setId(policyId); policy.setId(policyId);
policy.setPolicyName(resultSet.getString("NAME")); policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID")); policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY")); policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
} }
return policy; return policy;

@ -83,6 +83,10 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
return policyManager.getPolicies(); return policyManager.getPolicies();
} }
@Override public Policy getPolicy(int policyId) throws PolicyManagementException {
return policyManager.getPolicy(policyId);
}
@Override @Override
public List<Policy> getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public List<Policy> getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return policyManager.getPoliciesOfDevice(deviceIdentifier); return policyManager.getPoliciesOfDevice(deviceIdentifier);

@ -399,7 +399,7 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.getTimesOfPolicy(policy); policyDAO.getTimesOfPolicy(policy);
policyDAO.getLocationsOfPolicy(policy); policyDAO.getLocationsOfPolicy(policy);
Profile profile = profileDAO.getProfiles(policy.getProfile().getProfileId()); Profile profile = profileDAO.getProfiles(policy.getProfileId());
policy.setProfile(profile); policy.setProfile(profile);
policy.setRoles(roleNames); policy.setRoles(roleNames);

@ -140,7 +140,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ID INT(11) NOT NULL AUTO_INCREMENT, ID INT(11) NOT NULL AUTO_INCREMENT,
PROFILE_ID INT(11) NOT NULL, PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(10) NOT NULL, FEATURE_CODE VARCHAR(30) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL, DEVICE_TYPE_ID INT NOT NULL,
CONTENT BLOB NULL DEFAULT NULL, CONTENT BLOB NULL DEFAULT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),

@ -44,9 +44,11 @@ public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve {
case SUCCESS: case SUCCESS:
case CONTINUE: case CONTINUE:
this.getNext().invoke(request, response, compositeValve); this.getNext().invoke(request, response, compositeValve);
break;
case FAILURE: case FAILURE:
AuthenticationFrameworkUtil.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, AuthenticationFrameworkUtil.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED,
"Failed to authorize the incoming request"); "Failed to authorize the incoming request");
break;
} }
} }

@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP NOT NULL, CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL,
STATUS VARCHAR(50) NULL, STATUS VARCHAR(50) NULL,
OPERATION_CODE VARCHAR(25) NOT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );

Loading…
Cancel
Save