diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAO.java index afd06ad4f2..10ca96f72a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAO.java @@ -43,10 +43,12 @@ public interface GroupDAO { * * @param deviceGroup group to update. * @param oldGroupName of the group. + * @param oldOwner of the group. * @param tenantId of the group. * @throws GroupManagementDAOException */ - void updateGroup(DeviceGroup deviceGroup, String oldGroupName, int tenantId) throws GroupManagementDAOException; + void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner, int tenantId) + throws GroupManagementDAOException; /** * Delete an existing Device Group. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java index 5ee14ea460..00b3a8bbad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java @@ -67,20 +67,21 @@ public class GroupDAOImpl implements GroupDAO { } @Override - public void updateGroup(DeviceGroup deviceGroup, String oldGroupName, int tenantId) + public void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner, int tenantId) throws GroupManagementDAOException { PreparedStatement stmt = null; try { Connection conn = GroupManagementDAOFactory.getConnection(); String sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, DATE_OF_LAST_UPDATE = ?, OWNER = ? " - + "WHERE GROUP_NAME = ? AND TENANT_ID = ?"; + + "WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, deviceGroup.getDescription()); stmt.setString(2, deviceGroup.getName()); stmt.setLong(3, deviceGroup.getDateOfLastUpdate()); stmt.setString(4, deviceGroup.getOwner()); stmt.setString(5, oldGroupName); - stmt.setInt(6, tenantId); + stmt.setString(6, oldOwner); + stmt.setInt(7, tenantId); stmt.executeUpdate(); } catch (SQLException e) { throw new GroupManagementDAOException("Error occurred while updating deviceGroup '" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java index 94a31ef975..dcc9e4e134 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java @@ -47,11 +47,12 @@ public interface GroupManagementProviderService { /** * Update existing device group. * - * @param deviceGroup to update. - * @param oldGroupName of the group. + * @param deviceGroup to update. + * @param oldGroupName of the group. + * @param oldOwner of the group. * @throws GroupManagementException */ - void updateGroup(DeviceGroup deviceGroup, String oldGroupName) throws GroupManagementException; + void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner) throws GroupManagementException; /** * Delete existing device group. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 43620a82ab..38a4b85212 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -44,6 +44,7 @@ import org.wso2.carbon.user.core.util.UserCoreUtil; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -102,14 +103,16 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid * {@inheritDoc} */ @Override - public void updateGroup(DeviceGroup deviceGroup, String oldGroupName) throws GroupManagementException { + public void updateGroup(DeviceGroup deviceGroup, String oldGroupName, String oldOwner) + throws GroupManagementException { if (deviceGroup == null) { throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); } try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.beginTransaction(); - this.groupDAO.updateGroup(deviceGroup, oldGroupName, tenantId); + deviceGroup.setDateOfLastUpdate(new Date().getTime()); + this.groupDAO.updateGroup(deviceGroup, oldGroupName, oldOwner, tenantId); GroupManagementDAOFactory.commitTransaction(); } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java index e4eb2dfade..fa733444bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java @@ -197,7 +197,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest { try { GroupManagementDAOFactory.beginTransaction(); groupDAO.updateGroup(group, TestDataHolder.generateDummyGroupData().getName(), - TestDataHolder.SUPER_TENANT_ID); + TestDataHolder.generateDummyGroupData().getOwner(), TestDataHolder.SUPER_TENANT_ID); GroupManagementDAOFactory.commitTransaction(); log.debug("Group updated"); } catch (GroupManagementDAOException e) {