From af75a20bdff81fc8ec5d2ddd065a82d2327aa424 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 31 Jul 2019 13:01:51 +0530 Subject: [PATCH] Change APPM update responses --- .../common/services/ApplicationManager.java | 10 +++--- .../mgt/core/impl/ApplicationManagerImpl.java | 24 +++++++------ ...ApplicationManagementPublisherAPIImpl.java | 34 +++++++++++-------- 3 files changed, 37 insertions(+), 31 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 dff0bd6721..fc822e6d10 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,12 +66,12 @@ public interface ApplicationManager { /** * Updates an already existing application. * - * @param applicationUpdateWrapper Application data that need to be updated. * @param applicationId ID of the application + * @param applicationUpdateWrapper Application data that need to be updated. * @return Updated Application * @throws ApplicationManagementException ApplicationDTO Management Exception */ - void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) + Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException; /** @@ -194,13 +194,13 @@ public interface ApplicationManager { * @param applicationArtifact {@link ApplicationArtifact} * @return If the application release is updated correctly True returns, otherwise retuen False */ - boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, + ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; - boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, + ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; - boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, + ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; /*** 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 4846337549..13308abf03 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 @@ -32,7 +32,6 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller; import org.wso2.carbon.device.application.mgt.common.DeviceTypes; import org.wso2.carbon.device.application.mgt.common.LifecycleChanger; import org.wso2.carbon.device.application.mgt.common.Pagination; -import org.wso2.carbon.device.application.mgt.common.config.MDMConfig; import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.ApplicationList; @@ -1616,7 +1615,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) + public Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -1759,6 +1758,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg); } ConnectionManagerUtil.commitDBTransaction(); + return APIUtil.appDtoToAppResponse(applicationDTO); } catch (UserStoreException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Error occurred while checking whether logged in user is ADMIN or not when updating " @@ -2295,14 +2295,13 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, + public ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); try { ConnectionManagerUtil.beginDBTransaction(); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId); - AtomicReference applicationReleaseDTO = new AtomicReference<>( applicationDTO.getApplicationReleaseDTOs().get(0)); validateAppReleaseUpdating(applicationDTO, ApplicationType.ENTERPRISE.toString()); @@ -2321,20 +2320,21 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData()); } - if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){ + if (!StringUtils.isEmpty(applicationArtifact.getInstallerName()) + && applicationArtifact.getInstallerStream() != null) { DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); applicationReleaseDTO .set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(), applicationArtifact)); } applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact)); - boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; if (!updateStatus) { ConnectionManagerUtil.rollbackDBTransaction(); + return null; } ConnectionManagerUtil.commitDBTransaction(); - return updateStatus; + return APIUtil.releaseDtoToRelease(applicationReleaseDTO.get()); } catch (DBConnectionException e) { String msg = "Error occurred while getting the database connection to update enterprise app release which " + "has release UUID: " + releaseUuid; @@ -2361,7 +2361,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, + public ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -2399,9 +2399,10 @@ public class ApplicationManagerImpl implements ApplicationManager { boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; if (!updateStatus) { ConnectionManagerUtil.rollbackDBTransaction(); + return null; } ConnectionManagerUtil.commitDBTransaction(); - return updateStatus; + return APIUtil.releaseDtoToRelease(applicationReleaseDTO.get()); } catch (DBConnectionException e) { String msg = "Error occurred while getting the database connection to update public app release which " + "has release UUID: " + releaseUuid; @@ -2428,7 +2429,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, + public ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -2462,9 +2463,10 @@ public class ApplicationManagerImpl implements ApplicationManager { boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; if (!updateStatus) { ConnectionManagerUtil.rollbackDBTransaction(); + return null; } ConnectionManagerUtil.commitDBTransaction(); - return updateStatus; + return APIUtil.releaseDtoToRelease(applicationReleaseDTO.get()); } catch (DBConnectionException e) { String msg = "Error occurred while getting the database connection to update web app release which " + "has release UUID: " + releaseUuid; 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 ac267b79de..237a99f6d8 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 @@ -391,19 +391,17 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Valid ApplicationUpdateWrapper applicationUpdateWrapper) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - applicationManager.updateApplication(applicationId, applicationUpdateWrapper); - return Response.status(Response.Status.OK) - .entity("Application was updated successfully for ApplicationID: " + applicationId).build(); + Application application = applicationManager.updateApplication(applicationId, applicationUpdateWrapper); + return Response.status(Response.Status.OK).entity(application).build(); } catch (NotFoundException e) { log.error(e.getMessage()); return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build(); - } catch (BadRequestException e) { + } catch (BadRequestException e) { String msg = "Error occurred while modifying the application. Found bad request payload for updating the " + "application"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } - catch (ApplicationManagementException e) { + } catch (ApplicationManagementException e) { String msg = "Internal Error occurred while modifying the application."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); @@ -425,14 +423,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - if (!applicationManager.updateEntAppRelease(applicationUUID, entAppReleaseWrapper, - constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) { + ApplicationRelease applicationRelease = applicationManager + .updateEntAppRelease(applicationUUID, entAppReleaseWrapper, + constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots)); + if (applicationRelease == null) { String msg ="Ent app release updating is failed. Please contact the administrator. Application release " + "UUID: " + applicationUUID; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return Response.status(Response.Status.OK).entity("Ent app release is successfully updated.").build(); + return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { String msg = "Invalid request to update ent app release for application release UUID " + applicationUUID; @@ -469,14 +469,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - if (!applicationManager.updatePubAppRelease(applicationUUID, publicAppReleaseWrapper, - constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) { + ApplicationRelease applicationRelease = applicationManager + .updatePubAppRelease(applicationUUID, publicAppReleaseWrapper, + constructApplicationArtifact(null, iconFile, bannerFile, screenshots)); + if (applicationRelease == null) { String msg ="Public app release updating is failed. Please contact the administrator. " + "Application release UUID: " + applicationUUID + ", Supported device type:"; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return Response.status(Response.Status.OK).entity("Public app release is successfully updated.").build(); + return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { String msg = "Invalid request to update public app release for application release UUID " + applicationUUID; log.error(msg, e); @@ -512,14 +514,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - if (!applicationManager.updateWebAppRelease(applicationUUID, webAppReleaseWrapper, - constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) { + ApplicationRelease applicationRelease = applicationManager + .updateWebAppRelease(applicationUUID, webAppReleaseWrapper, + constructApplicationArtifact(null, iconFile, bannerFile, screenshots)); + if (applicationRelease == null) { String msg ="web app release updating is failed. Please contact the administrator. Application " + "release UUID: " + applicationUUID; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return Response.status(Response.Status.OK).entity("Web app release is successfully updated.").build(); + return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID; log.error(msg, e);