From dae8c0976155f4069c3e28824092e0dce409a936 Mon Sep 17 00:00:00 2001 From: osh Date: Wed, 5 Jul 2023 22:38:10 +0530 Subject: [PATCH] Resolve comments --- .../mgt/core/config/Extension.java | 3 +-- .../vpp/GenericVppApplicationDAOImpl.java | 1 - .../application/mgt/core/util/APIUtil.java | 23 ++++++++----------- .../core/util/ApplicationManagementUtil.java | 8 ------- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/config/Extension.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/config/Extension.java index 9ded8d3608..553ee67172 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/config/Extension.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/config/Extension.java @@ -88,8 +88,7 @@ public class Extension { SubscriptionManager, VisibilityManager, ApplicationStorageManager, - PlatformStorageManager, - MetadataManagementService + PlatformStorageManager } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/vpp/GenericVppApplicationDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/vpp/GenericVppApplicationDAOImpl.java index 1e935d35de..936e8da7e3 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/vpp/GenericVppApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/vpp/GenericVppApplicationDAOImpl.java @@ -458,7 +458,6 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp stmt.setString(5, vppAssociationDTO.getPricingParam()); stmt.setInt(6, vppAssociationDTO.getId()); stmt.setLong(7, tenantId); - stmt.executeUpdate(); if (stmt.executeUpdate() == 1) { return vppAssociationDTO; } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java index 2e8536feb8..d37a85dee6 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java @@ -27,7 +27,6 @@ import io.entgra.device.mgt.core.application.mgt.core.serviceprovider.ISServiceP import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService; -import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -117,23 +116,19 @@ public class APIUtil { } public static MetadataManagementService getMetadataManager() { - try { - if (metadataManagementService == null) { - synchronized (APIUtil.class) { + if (metadataManagementService == null) { + synchronized (APIUtil.class) { + if (metadataManagementService == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + metadataManagementService = + (MetadataManagementService) ctx.getOSGiService(MetadataManagementService.class, null); if (metadataManagementService == null) { - metadataManagementService = ApplicationManagementUtil.getDeviceManagerInstance(); - if (metadataManagementService == null) { - String msg = "MetadataManagement Service service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } + String msg = "MetadataManagement Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } } } - } catch (Exception e) { - String msg = "Error occurred while getting the vpp manager"; - log.error(msg); - throw new IllegalStateException(msg); } return metadataManagementService; } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java index d739f0f68a..36920d013c 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java @@ -210,14 +210,6 @@ public class ApplicationManagementUtil { // TODO: implement as an extension return new VppApplicationManagerImpl(); } - - public static MetadataManagementService getDeviceManagerInstance() throws InvalidConfigurationException { - ConfigurationManager configurationManager = ConfigurationManager.getInstance(); - Extension extension = configurationManager.getExtension(Extension.Name.MetadataManagementService); - return getInstance(extension, MetadataManagementService.class); - } - - /** * This is useful to delete application artifacts if any error occurred while creating release/application * after uploading the artifacts