From e52d4403b6ba6bd82416550b255e4ca9eb557b3a Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Thu, 19 Jan 2023 01:14:07 +0530 Subject: [PATCH] Fix on API response messages in publisher --- .../mgt/core/impl/ApplicationManagerImpl.java | 66 +++++++++---------- .../mgt/core/impl/ReviewManagerImpl.java | 4 +- ...ApplicationManagementPublisherAPIImpl.java | 12 ++-- .../impl/SPApplicationServiceImpl.java | 6 +- ...ReviewManagementPublisherAdminAPIImpl.java | 4 +- 5 files changed, 47 insertions(+), 45 deletions(-) diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 33ad0f1bde8..6dfe0bbb744 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -437,7 +437,7 @@ public class ApplicationManagerImpl implements ApplicationManager { * @throws ApplicationManagementException if error occurred while uploading artifacts into file system. */ private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, - ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease) + ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); try { @@ -478,7 +478,7 @@ public class ApplicationManagerImpl implements ApplicationManager { * @throws ResourceManagementException if error occurred while uploading */ private ApplicationReleaseDTO uploadPubAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact, - String deviceType) + String deviceType) throws ResourceManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String appInstallerUrl = getPublicAppStorePath(deviceType) + releaseDTO.getPackageName(); @@ -497,7 +497,7 @@ public class ApplicationManagerImpl implements ApplicationManager { .getReleaseByPackages(Collections.singletonList(packageName), tenantId); if (!exitingPubAppReleases.isEmpty()){ String msg = "Public app release exists for package name " + packageName - + ". Hence you can't add new public app for package name " + + ". Hence you cannot add new public app for package name " + packageName; log.error(msg); throw new BadRequestException(msg); @@ -521,7 +521,7 @@ public class ApplicationManagerImpl implements ApplicationManager { * @throws ResourceManagementException if error occurred while uploading */ private ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact, - String deviceType) + String deviceType) throws ResourceManagementException, ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); @@ -669,7 +669,7 @@ public class ApplicationManagerImpl implements ApplicationManager { String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1); if (!extension.equalsIgnoreCase(Constants.MSI) && !extension.equalsIgnoreCase(Constants.APPX)) { - String msg = "Application Type doesn't match with supporting application types of " + + String msg = "Application Type does not match with supporting application types of " + deviceType + "platform which are APPX and MSI"; log.error(msg); throw new BadRequestException(msg); @@ -771,7 +771,7 @@ public class ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.getDBConnection(); if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) { - String msg = "Same binary file is in the server. Hence you can't add same file into the " + String msg = "Same binary file is in the server. Hence you cannot add same file into the " + "server. Device Type: " + deviceType + " and package name: " + packageName; log.error(msg); throw new BadRequestException(msg); @@ -1175,7 +1175,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!hasUserRole(filteringUnrestrictedRoles, userName)) { String msg = "At least one filtering role is not assigned for the user: " + userName + ". Hence user " + userName - + " Can't filter applications by giving these unrestricted role list"; + + " Cannot filter applications by giving these unrestricted role list"; log.error(msg); throw new BadRequestException(msg); } @@ -1382,7 +1382,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.openDBConnection(); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(applicationId, tenantId); if (applicationDTO == null) { - String msg = "Couldn't find application for the application Id: " + applicationId; + String msg = "Could not find application for the application Id: " + applicationId; log.error(msg); throw new NotFoundException(msg); } @@ -2259,7 +2259,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!deviceTypeName.equals(Constants.ALL)) { DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); if (deviceType == null) { - String msg = "Device type doesn't exist. Hence check the application name existence with valid " + String msg = "Device type does not exist. Hence check the application name existence with valid " + "device type name."; log.error(msg); throw new BadRequestException(msg); @@ -2310,7 +2310,7 @@ public class ApplicationManagerImpl implements ApplicationManager { .isExistingAppName(applicationUpdateWrapper.getName().trim(), applicationDTO.getDeviceTypeId(), tenantId)) { String msg = "Already an application registered with same name " + applicationUpdateWrapper.getName() - + ". Hence you can't update the application name from " + applicationDTO.getName() + " to " + + ". Hence you cannot update the application name from " + applicationDTO.getName() + " to " + applicationUpdateWrapper.getName(); log.error(msg); throw new BadRequestException(msg); @@ -2667,7 +2667,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.beginDBTransaction(); if (applicationDAO.getTagForTagName(newTagName, tenantId) != null){ String msg = - "You are trying to modify tag name into existing tag. Therefore you can't modify tag name from " + "You are trying to modify tag name into existing tag. Therefore you cannot modify tag name from " + oldTagName + " to new tag name " + newTagName; log.error(msg); throw new BadRequestException(msg); @@ -2929,7 +2929,7 @@ public class ApplicationManagerImpl implements ApplicationManager { */ private void validateFilter(Filter filter) throws BadRequestException { if (filter == null) { - String msg = "Filter validation is failed, Filter shouldn't be null, hence please verify the request payload"; + String msg = "Filter validation is failed, Filter should not be null, hence please verify the request payload"; log.error(msg); throw new BadRequestException(msg); } @@ -3272,7 +3272,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.getDBConnection(); if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) { String msg = - "Same binary file is in the server. Hence you can't add same file into the " + "Same binary file is in the server. Hence you cannot add same file into the " + "server. Device Type: " + deviceTypeObj.getName() + " and package name: " + applicationDTO.getApplicationReleaseDTOs() .get(0).getPackageName(); @@ -3459,17 +3459,17 @@ public class ApplicationManagerImpl implements ApplicationManager { } appCategories = applicationWrapper.getCategories(); if (appCategories == null) { - String msg = "Application category can't be null."; + String msg = "Application category cannot be null."; log.error(msg); throw new BadRequestException(msg); } if (appCategories.isEmpty()) { - String msg = "Application category can't be empty."; + String msg = "Application category cannot be empty."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(applicationWrapper.getDeviceType())) { - String msg = "Device type can't be empty for the application."; + String msg = "Device type cannot be empty for the application."; log.error(msg); throw new BadRequestException(msg); } @@ -3496,12 +3496,12 @@ public class ApplicationManagerImpl implements ApplicationManager { } appCategories = webAppWrapper.getCategories(); if (appCategories == null) { - String msg = "Web Clip category can't be null."; + String msg = "Web Clip category cannot be null."; log.error(msg); throw new BadRequestException(msg); } if (appCategories.isEmpty()) { - String msg = "Web clip category can't be empty."; + String msg = "Web clip category cannot be empty."; log.error(msg); throw new BadRequestException(msg); } @@ -3534,17 +3534,17 @@ public class ApplicationManagerImpl implements ApplicationManager { } appCategories = publicAppWrapper.getCategories(); if (appCategories == null) { - String msg = "Application category can't be null."; + String msg = "Application category cannot be null."; log.error(msg); throw new BadRequestException(msg); } if (appCategories.isEmpty()) { - String msg = "Application category can't be empty."; + String msg = "Application category cannot be empty."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(publicAppWrapper.getDeviceType())) { - String msg = "Device type can't be empty for the public application."; + String msg = "Device type cannot be empty for the public application."; log.error(msg); throw new BadRequestException(msg); } @@ -3571,17 +3571,17 @@ public class ApplicationManagerImpl implements ApplicationManager { } appCategories = customAppWrapper.getCategories(); if (appCategories == null) { - String msg = "Application category can't be null."; + String msg = "Application category cannot be null."; log.error(msg); throw new BadRequestException(msg); } if (appCategories.isEmpty()) { - String msg = "Application category can't be empty."; + String msg = "Application category cannot be empty."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(customAppWrapper.getDeviceType())) { - String msg = "Device type can't be empty for the application."; + String msg = "Device type cannot be empty for the application."; log.error(msg); throw new BadRequestException(msg); } @@ -3673,7 +3673,7 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public void validateReleaseCreatingRequest(T param, String deviceType) throws ApplicationManagementException { if (param == null) { - String msg = "In order to validate release creating request param shouldn't be null."; + String msg = "In order to validate release creating request param should not be null."; log.error(msg); throw new BadRequestException(msg); } @@ -3682,7 +3682,7 @@ public class ApplicationManagerImpl implements ApplicationManager { AtomicReference entAppReleaseWrapper = new AtomicReference<>( (EntAppReleaseWrapper) param); if (StringUtils.isEmpty(entAppReleaseWrapper.get().getSupportedOsVersions())) { - String msg = "Supported OS Version shouldn't be null or empty."; + String msg = "Supported OS Version should not be null or empty."; log.error(msg); throw new BadRequestException(msg); } @@ -3706,12 +3706,12 @@ public class ApplicationManagerImpl implements ApplicationManager { WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; UrlValidator urlValidator = new UrlValidator(); if (StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) { - String msg = "Version shouldn't be empty or null for the WEB CLIP release creating request."; + String msg = "Version should not be empty or null for the WEB CLIP release creating request."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(webAppReleaseWrapper.getUrl())) { - String msg = "URL shouldn't be null for the application release creating request for application type " + String msg = "URL should not be null for the application release creating request for application type " + "WEB_CLIP"; log.error(msg); throw new BadRequestException(msg); @@ -3724,17 +3724,17 @@ public class ApplicationManagerImpl implements ApplicationManager { } else if (param instanceof PublicAppReleaseWrapper) { PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param; if (StringUtils.isEmpty(publicAppReleaseWrapper.getSupportedOsVersions())) { - String msg = "Supported OS Version shouldn't be null or empty for public app release creating request."; + String msg = "Supported OS Version should not be null or empty for public app release creating request."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(publicAppReleaseWrapper.getVersion())) { - String msg = "Version shouldn't be empty or null for the Public App release creating request."; + String msg = "Version should not be empty or null for the Public App release creating request."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(publicAppReleaseWrapper.getPackageName())) { - String msg = "Package name shouldn't be empty or null for the Public App release creating request."; + String msg = "Package name should not be empty or null for the Public App release creating request."; log.error(msg); throw new BadRequestException(msg); } @@ -3748,12 +3748,12 @@ public class ApplicationManagerImpl implements ApplicationManager { } else if (param instanceof CustomAppReleaseWrapper) { CustomAppReleaseWrapper customAppReleaseWrapper = (CustomAppReleaseWrapper) param; if (StringUtils.isEmpty(customAppReleaseWrapper.getVersion())) { - String msg = "Version shouldn't be empty or null for the custom App release creating request."; + String msg = "Version should not be empty or null for the custom App release creating request."; log.error(msg); throw new BadRequestException(msg); } if (StringUtils.isEmpty(customAppReleaseWrapper.getPackageName())) { - String msg = "Package name shouldn't be empty or null for the custom App release creating request."; + String msg = "Package name should not be empty or null for the custom App release creating request."; log.error(msg); throw new BadRequestException(msg); } diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java index 323149d8941..4e4a00dcb38 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java @@ -393,11 +393,11 @@ public class ReviewManagerImpl implements ReviewManager { } return getReviewTree(this.reviewDAO.getAllReleaseReviews(releaseDTO.getId(), request, tenantId)); } catch (ReviewManagementDAOException e) { - String msg = "Error occured while getting all reviews for application uuid: " + uuid; + String msg = "Error occurred while getting all reviews for application uuid: " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { - String msg ="Error occured while getting the DB connection to get all reviews for application release which" + String msg ="Error occurred while getting the DB connection to get all reviews for application release which" + " has UUID " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 119a08f10bb..1acdc57aa57 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -181,7 +181,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Couldn't find the required artifacts to create new ent. application with the request"; + String msg = "Could not find the required artifacts to create new enterprise application with the request"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -203,7 +203,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Couldn't find the required artifacts to create new web application with the request"; + String msg = "Could not find the required artifacts to create new web application with the request"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -225,7 +225,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Couldn't find the required artifacts to create new public application with the request"; + String msg = "Could not find the required artifacts to create new public application with the request"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -247,7 +247,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Couldn't find the required artifacts to create new custom application with the request"; + String msg = "Could not find the required artifacts to create new custom application with the request"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -392,7 +392,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem if (appName.length() > 20) { String msg = "Invalid app name, maximum length of the application name should be 20 characters."; log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + return Response.status(Response.Status.BAD_REQUEST).build(); } ApplicationManager applicationManager = APIUtil.getApplicationManager(); if (applicationManager.isExistingAppName(appName, deviceType)) { @@ -464,7 +464,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem + applicationReleaseUuid).build(); } catch (RequestValidatingException e) { String msg = - "Couldn't find the binary file with the request. Hence invoke the API with updating application" + "Could not find the binary file with the request. Hence invoke the API with updating application" + " artifact"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java index 4eacf5accf4..c3bbf638948 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java @@ -182,7 +182,8 @@ public class SPApplicationServiceImpl implements SPApplicationService { } SPApplicationManager spAppManager = APIUtil.getSPApplicationManager(); if (spAppManager.isIdentityServerNameExist(identityServerName)) { - return Response.status(Response.Status.CONFLICT).build(); + String msg = "Identity server name already exists"; + return Response.status(Response.Status.CONFLICT).entity(msg).build(); } return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { @@ -209,7 +210,8 @@ public class SPApplicationServiceImpl implements SPApplicationService { } SPApplicationManager spAppManager = APIUtil.getSPApplicationManager(); if (spAppManager.isIdentityServerUrlExist(identityServerUrl)) { - return Response.status(Response.Status.CONFLICT).build(); + String msg = "Identity server Url already exists"; + return Response.status(Response.Status.CONFLICT).entity(msg).build(); } return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java index d6be1a9f897..cf92f433b60 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java @@ -84,7 +84,7 @@ public class ReviewManagementPublisherAdminAPIImpl implements ReviewManagementPu log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (ReviewManagementException | ApplicationManagementException e) { - String msg = "Error occured while getting review data for application release UUID: " + uuid; + String msg = "Error occurred while getting review data for application release UUID: " + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } @@ -105,7 +105,7 @@ public class ReviewManagementPublisherAdminAPIImpl implements ReviewManagementPu log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (ReviewManagementException | ApplicationManagementException e) { - String msg = "Error occured while getting review data for application release UUID: " + uuid; + String msg = "Error occurred while getting review data for application release UUID: " + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); }