From 4cf24e6b0abc2e0bd6d4d61c7641e342ea16e33b Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Wed, 15 Apr 2020 20:14:49 +0530 Subject: [PATCH 1/2] Add HEAD API to check the existence of application --- .../common/services/ApplicationManager.java | 11 +++ .../mgt/core/impl/ApplicationManagerImpl.java | 59 +++++++++++--- .../mgt/core/impl/AppmDataHandlerImpl.java | 5 +- .../application/mgt/core/util/APIUtil.java | 24 +++--- .../application/mgt/core/util/DAOUtil.java | 78 ------------------- .../ApplicationManagementPublisherAPI.java | 46 +++++++++++ ...ApplicationManagementPublisherAPIImpl.java | 30 ++++++- 7 files changed, 150 insertions(+), 103 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 1b1a318689..ab031305f8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -66,6 +66,17 @@ public interface ApplicationManager { Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; + /** + * Check the existence of an application for given application name and the device type. + * + * @param appName Application name + * @param deviceTypeName Device Type name + * @return True if application exists for given application name and the device type, otherwise returns False + * @throws ApplicationManagementException if error occured while checking the application existence for given + * application name and device type or request with invalid device type data. + */ + boolean isExistingAppName(String appName, String deviceTypeName) throws ApplicationManagementException; + /** * Updates an already existing application. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 021037ede3..2662f46a80 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -237,7 +237,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throws ApplicationManagementException { try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream()); String md5OfApp = StorageManagementUtil.getMD5(new ByteArrayInputStream(content)); if (md5OfApp == null) { @@ -302,7 +302,7 @@ public class ApplicationManagerImpl implements ApplicationManager { * @throws ApplicationManagementException if error occurred while deleting application release artifacts. */ private void deleteApplicationArtifacts(List directoryPaths, int tenantId) throws ApplicationManagementException { - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths, tenantId); } catch (ApplicationStorageManagementException e) { @@ -328,7 +328,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease) throws ResourceManagementException, ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); String uuid = UUID.randomUUID().toString(); applicationReleaseDTO.setUuid(uuid); @@ -412,7 +412,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact) throws ResourceManagementException, ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); // The application executable artifacts such as apks are uploaded. try { @@ -505,7 +505,7 @@ public class ApplicationManagerImpl implements ApplicationManager { */ private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException { - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName()); @@ -542,7 +542,7 @@ public class ApplicationManagerImpl implements ApplicationManager { */ private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException{ - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); if (!StringUtils.isEmpty(applicationArtifact.getIconName())) { applicationStorageManager @@ -786,7 +786,7 @@ public class ApplicationManagerImpl implements ApplicationManager { * @throws ApplicationManagementException which throws if error occurs while during application management. */ private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementException { - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); List categories = applicationDTO.getAppCategories(); @@ -1329,7 +1329,7 @@ public class ApplicationManagerImpl implements ApplicationManager { + applicationId); } int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationDTO applicationDTO = getApplication(applicationId); List applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs(); for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { @@ -1445,7 +1445,7 @@ public class ApplicationManagerImpl implements ApplicationManager { public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { ConnectionManagerUtil.beginDBTransaction(); ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO @@ -1793,6 +1793,45 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + @Override + public boolean isExistingAppName(String appName, String deviceTypeName) throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + DeviceManagementProviderService deviceManagementProviderService = DataHolder.getInstance() + .getDeviceManagementService(); + try { + DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); + if (deviceType == null) { + String msg = "Device type doesn't not exist. Hence check the application name existence with valid " + + "device type name."; + log.error(msg); + throw new BadRequestException(msg); + } + try { + ConnectionManagerUtil.openDBConnection(); + if (applicationDAO.isExistingAppName(appName, deviceType.getId(), tenantId)) { + return true; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while getting DB connection to check the existence of application with " + + "name: " + appName + " and the device type: " + deviceTypeName; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred while checking the existence of application with " + "name: " + appName + + "and the device type: " + deviceTypeName + " in the database"; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while getting the device type data for device type: " + deviceTypeName; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } + return false; + } + @Override public Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { @@ -2707,7 +2746,7 @@ public class ApplicationManagerImpl implements ApplicationManager { CustomAppReleaseWrapper customAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { ConnectionManagerUtil.beginDBTransaction(); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java index 621b7c2169..9752d613c0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/AppmDataHandlerImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; +import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; @@ -55,7 +56,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler { @Override public InputStream getArtifactStream(int tenantId, String uuid, String folderName, String artifactName) throws ApplicationManagementException { - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); String appReleaseHashValue; try { @@ -91,7 +92,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler { @Override public InputStream getAgentStream(int tenantId, String deviceType) throws ApplicationManagementException { - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { InputStream inputStream = applicationStorageManager .getFileStream(deviceType, tenantId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 0a7869fd72..a331762a0e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -87,19 +87,25 @@ public class APIUtil { * @return ApplicationStoreManager instance in the current osgi context. */ public static ApplicationStorageManager getApplicationStorageManager() { - if (applicationStorageManager == null) { - synchronized (APIUtil.class) { - if (applicationStorageManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - applicationStorageManager = (ApplicationStorageManager) ctx - .getOSGiService(ApplicationStorageManager.class, null); + + try { + if (applicationStorageManager == null) { + synchronized (DAOUtil.class) { if (applicationStorageManager == null) { - String msg = "ApplicationDTO Storage Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); + applicationStorageManager = ApplicationManagementUtil + .getApplicationStorageManagerInstance(); + if (applicationStorageManager == null) { + String msg = "ApplicationDTO Storage Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } } } } + } catch (Exception e) { + String msg = "Error occurred while getting the application store manager"; + log.error(msg); + throw new IllegalStateException(msg); } return applicationStorageManager; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java index 929c8975c7..284d5fc856 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java @@ -22,7 +22,6 @@ import com.google.gson.reflect.TypeToken; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.ExecutionStatus; import org.wso2.carbon.device.application.mgt.common.SubscriptionType; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; @@ -31,9 +30,6 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; import org.wso2.carbon.device.application.mgt.common.dto.ScheduledSubscriptionDTO; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; @@ -311,80 +307,6 @@ public class DAOUtil { } } - private static volatile ApplicationManager applicationManager; - private static volatile ApplicationStorageManager applicationStorageManager; - private static volatile SubscriptionManager subscriptionManager; - - public static ApplicationManager getApplicationManager() { - if (applicationManager == null) { - synchronized (DAOUtil.class) { - if (applicationManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - applicationManager = - (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null); - if (applicationManager == null) { - String msg = "ApplicationDTO Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } - } - return applicationManager; - } - - /** - * To get the ApplicationDTO Storage Manager from the osgi context. - * @return ApplicationStoreManager instance in the current osgi context. - */ - public static ApplicationStorageManager getApplicationStorageManager() { - - try { - if (applicationStorageManager == null) { - synchronized (DAOUtil.class) { - if (applicationStorageManager == null) { - applicationStorageManager = ApplicationManagementUtil - .getApplicationStorageManagerInstance(); - if (applicationStorageManager == null) { - String msg = "ApplicationDTO Storage Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } - } - } catch (Exception e) { - String msg = "Error occurred while getting the application store manager"; - log.error(msg); - throw new IllegalStateException(msg); - } - return applicationStorageManager; - } - - - /** - * To get the Subscription Manager from the osgi context. - * @return SubscriptionManager instance in the current osgi context. - */ - public static SubscriptionManager getSubscriptionManager() { - if (subscriptionManager == null) { - synchronized (DAOUtil.class) { - if (subscriptionManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - subscriptionManager = - (SubscriptionManager) ctx.getOSGiService(SubscriptionManager.class, null); - if (subscriptionManager == null) { - String msg = "Subscription Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } - } - - return subscriptionManager; - } - public static DeviceManagementProviderService getDeviceManagementService() { // PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); // DeviceManagementProviderService deviceManagementProviderService = diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 870ad616ec..91d17cff5b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -53,6 +53,7 @@ import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.HEAD; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -715,6 +716,51 @@ public interface ApplicationManagementPublisherAPI { @Multipart(value = "screenshot3") Attachment screenshot3 ); + @HEAD + @Path("/device-type/{deviceType}/app-name/{appName}") + @ApiOperation( + httpMethod = "HEAD", + value = "Check the application existence", + notes = "This API is responsible to check whether application exist or not for the given device type and " + + "application name.", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Application exists."), + @ApiResponse( + code = 404, + message = "NOT FOUND. \n Could.t find an application for given device type and application " + + "name."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Found invalid device type with the request."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while checking the application existence" + + " for given application name and device type name the application list.", + response = ErrorResponse.class) + }) + Response isExistingApplication( + @ApiParam( + name = "deviceType", + value = "Application compatible device type name", + required = true) + @PathParam("deviceType") String deviceType, + @ApiParam( + name = "appName", + value = "Application name", + required = true) + @PathParam("appName") String appName + ); + @PUT @Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}") @Produces(MediaType.APPLICATION_JSON) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 9dfcde4f73..033dfaf0ca 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -59,6 +59,7 @@ import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.HEAD; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -319,22 +320,22 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); - // Created new Ent App + // Created new Custom App Application application = applicationManager.createCustomApp(customAppWrapper, constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); } else { - String msg = "Application creation is failed"; + String msg = "Custom app creation is failed"; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } catch (BadRequestException e) { - String msg = "Found incompatible payload with pub custom creating request."; + String msg = "Found incompatible payload with custom app creating request."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { - String msg = "Error occurred while creating the application"; + String msg = "Error occurred while creating a costom application"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { @@ -384,6 +385,27 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } } + @Override + @HEAD + @Path("/device-type/{deviceType}/app-name/{appName}") + public Response isExistingApplication( + @PathParam("deviceType") String deviceType, + @PathParam("appName") String appName ){ + try { + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + if (applicationManager.isExistingAppName(appName, deviceType)) { + return Response.status(Response.Status.OK).build(); + } + return Response.status(Response.Status.NOT_FOUND).build(); + } catch (BadRequestException e) { + log.error("Found invalid device type to check application existence.", e); + return Response.status(Response.Status.BAD_REQUEST).build(); + } catch (ApplicationManagementException e) { + log.error("Internal Error occurred while checking the application existence.", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + @Override @PUT @Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) From 9abe718838ea0fead5ac545e3dd39ad2bc92a7f3 Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Wed, 15 Apr 2020 20:43:08 +0530 Subject: [PATCH 2/2] Fix grammar issue in error message --- .../application/mgt/core/impl/ApplicationManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 2662f46a80..2f81eb2411 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -1801,7 +1801,7 @@ public class ApplicationManagerImpl implements ApplicationManager { try { DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); if (deviceType == null) { - String msg = "Device type doesn't not exist. Hence check the application name existence with valid " + String msg = "Device type doesn't exist. Hence check the application name existence with valid " + "device type name."; log.error(msg); throw new BadRequestException(msg);