From cfa40c0d2be0c6b58c94941f42ca2c7a3ebe81bd Mon Sep 17 00:00:00 2001 From: Gimhan-minion Date: Thu, 22 Aug 2024 17:38:24 +0530 Subject: [PATCH] Fix tag feature modifications after review --- .../mgt/api/jaxrs/service/api/DeviceManagementService.java | 4 ++-- .../api/jaxrs/service/impl/DeviceManagementServiceImpl.java | 2 +- .../api/jaxrs/service/impl/TagManagementServiceImpl.java | 2 +- .../mgt/core/service/TagManagementProviderServiceImpl.java | 6 ++++++ .../mgt/core/device/mgt/core/common/TestDataHolder.java | 4 ++-- .../mgt/core/service/TagManagementProviderServiceTest.java | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java index e201133681..889d50e5fd 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java @@ -338,10 +338,10 @@ public interface DeviceManagementService { @QueryParam("requireDeviceInfo") boolean requireDeviceInfo, @ApiParam( - name = "tags", + name = "tag", value = "Describes the tags associated with the enrolment", required = false) - @QueryParam("tags") + @QueryParam("tag") List tags, @ApiParam( name = "offset", diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java index 448d580cc7..a137b7ba9b 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -151,7 +151,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("since") String since, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("requireDeviceInfo") boolean requireDeviceInfo, - @QueryParam("tags") List tags, + @QueryParam("tag") List tags, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { try { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/TagManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/TagManagementServiceImpl.java index 26b484538e..c780c4226b 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/TagManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/TagManagementServiceImpl.java @@ -126,7 +126,7 @@ public class TagManagementServiceImpl implements TagManagementService { log.debug(msg, e); } return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorResponse.ErrorResponseBuilder(). - setMessage(msg).build()).build(); + setMessage(e.getMessage()).build()).build(); } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceImpl.java index ea163eef79..822c3b6497 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceImpl.java @@ -172,6 +172,12 @@ public class TagManagementProviderServiceImpl implements TagManagementProviderSe log.error(msg); throw new TagNotFoundException(msg); } + Tag tagWithName = tagDAO.getTagByName(tag.getName(), tenantId); + if (tagWithName != null && tagWithName.getId() != tag.getId()) { + String msg = "Tag with name: " + tag.getName() + " already exists."; + log.error(msg); + throw new BadRequestException(msg); + } tagDAO.updateTag(tag, tenantId); DeviceManagementDAOFactory.commitTransaction(); } catch (TagManagementDAOException | TransactionManagementException e) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/common/TestDataHolder.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/common/TestDataHolder.java index 579678ec97..65f45a47d9 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/common/TestDataHolder.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/common/TestDataHolder.java @@ -41,8 +41,8 @@ public class TestDataHolder { public final static String TEST_DEVICE_TYPE = "TEST-DEVICE-TYPE"; public final static Integer SUPER_TENANT_ID = -1234; - public final static Integer ALTERNATE_TENANT_ID = -1235; - public final static Integer ALTERNATE_TENANT_ID_1 = -1236; + public final static Integer ALTERNATE_TENANT_ID = 1234; + public final static Integer ALTERNATE_TENANT_ID_1 = 1235; public final static String SUPER_TENANT_DOMAIN = "carbon.super"; public final static String initialDeviceIdentifier = "12345"; public final static String initialDeviceName = "TEST-DEVICE"; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceTest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceTest.java index 5039f8f70e..16277c99a5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceTest.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/service/TagManagementProviderServiceTest.java @@ -72,7 +72,7 @@ public class TagManagementProviderServiceTest extends BaseDeviceManagementTest { tagManagementProviderService.addTags(TestUtils.createTagList2()); } - @Test(expectedExceptions = {TagNotFoundException.class}, dependsOnMethods = "createTags") + @Test(expectedExceptions = {TagNotFoundException.class, BadRequestException.class, TagManagementException.class}) public void updateTagsNotFound() throws TagNotFoundException, TagManagementException, BadRequestException { String updateDescString = "This tag is updated"; tagManagementProviderService.updateTag(new Tag(10,"tag10", updateDescString));