From 460394c9da5e6c3815012e3f02c993981bfd2b4d Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 26 Apr 2019 09:49:19 +0530 Subject: [PATCH 1/7] Improve application edit functionality --- .../impl/ArtifactDownloadAPIImpl.java | 1 - .../mgt/common/dto/ApplicationDTO.java | 12 -- .../common/response/ApplicationRelease.java | 10 ++ .../common/services/ApplicationManager.java | 3 +- .../mgt/core/dao/ApplicationDAO.java | 4 +- .../GenericApplicationDAOImpl.java | 31 ++++ .../mgt/core/impl/ApplicationManagerImpl.java | 153 ++++++++++++------ .../services/ApplicationManagementAPI.java | 3 +- .../impl/ApplicationManagementAPIImpl.java | 10 +- 9 files changed, 155 insertions(+), 72 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java index 61b9be5f47..98ae97ed80 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java @@ -55,7 +55,6 @@ public class ArtifactDownloadAPIImpl implements ArtifactDownloadAPI { Response.ResponseBuilder response = Response .ok(fileInputStream, MediaType.APPLICATION_OCTET_STREAM); response.status(Response.Status.OK); -// response.type("application/html"); response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\""); return response.build(); } catch (NotFoundException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java index 83813c3af3..a058e430eb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java @@ -79,12 +79,6 @@ public class ApplicationDTO { example = "1, 2, 3") private int deviceTypeId; - @ApiModelProperty(name = "deviceTypeName", - value = "Related device type of the application", - required = true, - example = "IoS, Android, Arduino, RaspberryPi etc") - private String deviceTypeName; - @ApiModelProperty(name = "appRating", value = "Rating of the aplication") private int appRating; @@ -168,12 +162,6 @@ public class ApplicationDTO { this.unrestrictedRoles = unrestrictedRoles; } - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { this.deviceTypeName = deviceTypeName; } - public int getDeviceTypeId() { return deviceTypeId; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java index f442afc38c..15903198a2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java @@ -66,6 +66,12 @@ public class ApplicationRelease { example = "alpha, beta etc") private String releaseType; + @ApiModelProperty(name = "currentStatus", + value = "CurrentStatus of the Application Release.", + required = true, + example = "CREATED, IN-REVIEW, PUBLISHED etc") + private String currentStatus; + @ApiModelProperty(name = "price", value = "Price of the application release", required = true) @@ -172,4 +178,8 @@ public class ApplicationRelease { public String getSupportedOsVersions() { return supportedOsVersions; } public void setSupportedOsVersions(String supportedOsVersions) { this.supportedOsVersions = supportedOsVersions; } + + public String getCurrentStatus() { return currentStatus; } + + public void setCurrentStatus(String currentStatus) { this.currentStatus = currentStatus; } } 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 b364512ffe..35d4cdb07b 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 @@ -58,7 +58,8 @@ public interface ApplicationManager { * @return Updated Application * @throws ApplicationManagementException ApplicationDTO Management Exception */ - void updateApplication(int applicationId, ApplicationWrapper applicationWrapper) throws ApplicationManagementException; + void updateApplication(int applicationId, ApplicationWrapper applicationWrapper) + throws ApplicationManagementException; /** * Delete an application identified by the unique ID. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index 2d63e01310..3bd7a484dd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -57,9 +57,9 @@ public interface ApplicationDAO { List getAppTags(int appId, int tenantId) throws ApplicationManagementDAOException; - List getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException; - + void deleteTagMapping (List tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException; + List getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException; List getAllCategories(int tenantId) throws ApplicationManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index eb71671971..e0d06c2346 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -934,6 +934,37 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public void deleteTagMapping (List tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException{ + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to delete Tag mappings."); + } + Connection conn; + String sql = "DELETE FROM " + + "AP_APP_TAG_MAPPING tm " + + "WHERE " + + "tm.AP_APP_TAG_ID = ? AND " + + "tm.AP_APP_ID = ? AND " + + "tm.TENANT_ID = ?"; + try { + conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)){ + for (Integer tagId : tagIds){ + stmt.setInt(1, tagId); + stmt.setInt(2, applicationId); + stmt.setInt(3, tenantId); + stmt.addBatch(); + } + stmt.executeBatch(); + } + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when deleting tag mapppig", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred when deleting tag mapping", e); + } + } + @Override public List getAppCategories(int appId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { 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 bbd8489d9f..370c770af1 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 @@ -145,8 +145,8 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO initialApplicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); applicationDTO.getApplicationReleaseDTOs().clear(); - ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), applicationDTO.getDeviceTypeName(), - initialApplicationReleaseDTO, applicationArtifact); + ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), + applicationWrapper.getDeviceType(), initialApplicationReleaseDTO, applicationArtifact); applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact)); } catch (UnexpectedServerErrorException e) { String msg = "Error occurred when getting Device Type data."; @@ -550,7 +550,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!haveAllUserRoles(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 unrestriced role list"; + + " Can't filter applications by giving these unrestricted role list"; log.error(msg); throw new BadRequestException(msg); } @@ -582,8 +582,9 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new NotFoundException(msg); } + DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), - applicationDTO.getDeviceTypeName(), releaseWrapperToReleaseDTO(applicationReleaseWrapper), + deviceType.getName(), releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); @@ -630,18 +631,23 @@ public class ApplicationManagerImpl implements ApplicationManager { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); ApplicationDTO applicationDTO; - List filteredApplicationReleaseDTOs; boolean isVisibleApp = false; try { ConnectionManagerUtil.openDBConnection(); applicationDTO = this.applicationDAO.getApplicationById(appId, tenantId); if (applicationDTO == null) { - throw new NotFoundException("Couldn't find an application for application Id: " + appId); + String msg = "Couldn't find an application for application Id: " + appId; + log.error(msg); + throw new NotFoundException(msg); } - filteredApplicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs().stream() - .filter(applicationReleaseDTO -> applicationReleaseDTO.getCurrentState().equals(state)) - .collect(Collectors.toList()); + List filteredApplicationReleaseDTOs = new ArrayList<>(); + for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { + if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState()) && ( + state == null || applicationReleaseDTO.getCurrentState().equals(state))) { + filteredApplicationReleaseDTOs.add(applicationReleaseDTO); + } + } applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs); if (applicationDTO.getApplicationReleaseDTOs().isEmpty()){ return null; @@ -674,9 +680,14 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ForbiddenException(msg); } return appDtoToAppResponse(applicationDTO); - } catch (UserStoreException e) { - throw new ApplicationManagementException( - "User-store exception while getting application with the application id " + appId); + } catch (LifecycleManagementException e){ + String msg = "Error occurred when getting the last state of the application lifecycle flow"; + log.error(msg); + throw new ApplicationManagementException(msg, e); + }catch (UserStoreException e) { + String msg = "User-store exception while getting application with the application id " + appId; + log.error(msg); + throw new ApplicationManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -1438,14 +1449,36 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } - if (!StringUtils.isEmpty(applicationWrapper.getDeviceType()) && !applicationDTO.getDeviceTypeName() - .equals(applicationWrapper.getDeviceType())) { - String msg = "You are trying to change the compatible device type of the application type and it is not " - + "possible after you create an application for device type. " + - applicationWrapper.getDeviceType() + "Therefore please remove this application and publish " - + "new application with device type: " + applicationWrapper.getDeviceType(); - log.error(msg); - throw new BadRequestException(msg); + + String deviceTypeName = applicationWrapper.getDeviceType(); + if (!StringUtils.isEmpty(deviceTypeName)) { + DeviceType deviceType = getDeviceTypeData(deviceTypeName); + if (!deviceType.getName().equals(deviceTypeName)){ + String msg = "You are trying to change the compatible device type of the application type and it is " + + "not possible after you create an application for device type. " + deviceTypeName + + "Therefore please remove this application and publish new application with device type: " + + deviceTypeName; + log.error(msg); + throw new BadRequestException(msg); + } + } + if (!StringUtils.isEmpty(applicationWrapper.getName())){ + Filter filter = new Filter(); + filter.setFullMatch(true); + filter.setAppName(applicationWrapper.getName().trim()); + filter.setOffset(0); + filter.setLimit(1); + + List applicationList = applicationDAO + .getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId); + if (!applicationList.isEmpty()) { + String msg = "Already an application registered with same name " + applicationWrapper.getName() + + ". Hence you can't update the application name from " + applicationDTO.getName() + " to " + + applicationWrapper.getName(); + log.error(msg); + throw new BadRequestException(msg); + } + applicationDTO.setName(applicationWrapper.getName()); } if (!StringUtils.isEmpty(applicationWrapper.getSubType()) && !applicationDTO.getSubType() .equals(applicationWrapper.getSubType())) { @@ -1473,30 +1506,12 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDTO.setSubType(applicationWrapper.getSubType()); applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); } - if (!StringUtils.isEmpty(applicationWrapper.getName())){ - Filter filter = new Filter(); - filter.setFullMatch(true); - filter.setAppName(applicationWrapper.getName().trim()); - filter.setOffset(0); - filter.setLimit(1); - List applicationList = applicationDAO - .getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId); - if (!applicationList.isEmpty()) { - String msg = "Already an application registered with same name " + applicationWrapper.getName() - + ". Hence you can't update the application name from " + applicationDTO.getName() + " to " - + applicationWrapper.getName(); - log.error(msg); - throw new BadRequestException(msg); - } - applicationDTO.setName(applicationWrapper.getName()); - } if (!StringUtils.isEmpty(applicationWrapper.getDescription())){ applicationDTO.setDescription(applicationWrapper.getDescription()); } List appUnrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationId, tenantId); - List appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId); boolean isExistingAppRestricted = !appUnrestrictedRoles.isEmpty(); boolean isUpdatingAppRestricted = !applicationWrapper.getUnrestrictedRoles().isEmpty(); @@ -1533,15 +1548,48 @@ public class ApplicationManagerImpl implements ApplicationManager { } applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); - List appTags = this.applicationDAO.getAppTags(applicationId, tenantId); - List addingTagList = getDifference(appTags, applicationWrapper.getTags()); - List removingTagList = getDifference(applicationWrapper.getTags(), appTags); - if (!addingTagList.isEmpty()) { -// applicationDAO.addTags(addingTags, application.getId(), tenantId); + String updatingAppCategory = applicationWrapper.getAppCategory(); + if ( updatingAppCategory != null){ + List appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId); + if (!appCategories.contains(updatingAppCategory)){ + List allCategories = this.applicationDAO.getAllCategories(tenantId); + List categoryIds = allCategories.stream() + .filter(category -> category.getCategoryName().equals(updatingAppCategory)) + .map(CategoryDTO::getId).collect(Collectors.toList()); + if (!categoryIds.isEmpty()){ + String msg = + "You are trying to update application category into invalid application category, " + + "it is not registered in the system. Therefore please register the category " + + updatingAppCategory + " and perform the action"; + log.error(msg); + throw new BadRequestException(msg); + } + this.applicationDAO.addCategoryMapping(categoryIds, applicationId, tenantId); + } } - if (!removingTagList.isEmpty()) { - applicationDAO.deleteTags(removingTagList, applicationId, tenantId); + + List updatingAppTags = applicationWrapper.getTags(); + if ( updatingAppTags!= null){ + List appTags = this.applicationDAO.getAppTags(applicationId, tenantId); + List addingTagList = getDifference(appTags, updatingAppTags); + List removingTagList = getDifference(updatingAppTags, appTags); + if (!addingTagList.isEmpty()) { + List allTags = this.applicationDAO.getAllTags(tenantId); + List newTags = addingTagList.stream().filter(updatingTagName -> allTags.stream() + .noneMatch(tag -> tag.getTagName().equals(updatingTagName))).collect(Collectors.toList()); + if (!newTags.isEmpty()){ + this.applicationDAO.addTags(newTags, tenantId); + } + List addingTagIds = this.applicationDAO.getTagIdsForTagNames(addingTagList, tenantId); + this.applicationDAO.addTagMapping(addingTagIds, applicationId, tenantId); + } + if (!removingTagList.isEmpty()) { + List removingTagIds = this.applicationDAO.getTagIdsForTagNames(removingTagList, tenantId); + this.applicationDAO.deleteTagMapping(removingTagIds, applicationId, tenantId); + applicationDAO.deleteTags(removingTagList, applicationId, tenantId); + } } + //todo applicationDAO.editApplication(applicationDTO, tenantId); } catch (UserStoreException e) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -1904,7 +1952,6 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDTO.setTags(applicationWrapper.getTags()); applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); applicationDTO.setDeviceTypeId(deviceType.getId()); - applicationDTO.setDeviceTypeName(deviceType.getName()); List applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() .stream().map(this::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); @@ -1923,9 +1970,11 @@ public class ApplicationManagerImpl implements ApplicationManager { return applicationReleaseDTO; } - private Application appDtoToAppResponse(ApplicationDTO applicationDTO) { + private Application appDtoToAppResponse(ApplicationDTO applicationDTO) + throws BadRequestException, UnexpectedServerErrorException { Application application = new Application(); + DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); application.setId(applicationDTO.getId()); application.setName(applicationDTO.getName()); application.setDescription(applicationDTO.getDescription()); @@ -1935,7 +1984,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setTags(applicationDTO.getTags()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); - application.setDeviceType(applicationDTO.getDeviceTypeName()); + application.setDeviceType(deviceType.getName()); List applicationReleases = applicationDTO.getApplicationReleaseDTOs() .stream().map(this::releaseDtoToRelease).collect(Collectors.toList()); application.setApplicationReleases(applicationReleases); @@ -1943,7 +1992,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } private ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO){ - String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration().getArtifactDownloadEndpoint(); + String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration() + .getArtifactDownloadEndpoint(); String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid(); ApplicationRelease applicationRelease = new ApplicationRelease(); applicationRelease.setDescription(applicationReleaseDTO.getDescription()); @@ -1953,8 +2003,11 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setMetaData(applicationReleaseDTO.getMetaData()); applicationRelease.setUrl(applicationReleaseDTO.getUrl()); + applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState()); + applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); - applicationRelease.setInstallerPath(basePath + Constants.FORWARD_SLASH + applicationReleaseDTO.getInstallerName()); + applicationRelease + .setInstallerPath(basePath + Constants.FORWARD_SLASH + applicationReleaseDTO.getInstallerName()); applicationRelease.setIconPath(basePath + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName()); applicationRelease.setBannerPath(basePath + Constants.FORWARD_SLASH + applicationReleaseDTO.getBannerName()); 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/ApplicationManagementAPI.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/ApplicationManagementAPI.java index 69715b5998..02042a4125 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/ApplicationManagementAPI.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/ApplicationManagementAPI.java @@ -176,8 +176,7 @@ public interface ApplicationManagementAPI { @PathParam("appId") int appId, @ApiParam( name = "state", - value = "state", - defaultValue = "PUBLISHED") + value = "state") @QueryParam("state") String state ); 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java index 4c4e49a2b7..3b99f1c50b 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java @@ -102,15 +102,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Path("/{appId}") public Response getApplication( @PathParam("appId") int appId, - @DefaultValue("PUBLISHED") @QueryParam("state") String state) { + @QueryParam("state") String state) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { Application application = applicationManager.getApplicationById(appId, state); if (application == null){ - String msg = "Couldn't found an application release which is in " + state + " state for application id " - + appId; + String msg = "Could not found an application release which is in " + state + " state."; log.error(msg); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + return Response.status(Response.Status.OK).entity(msg).build(); } return Response.status(Response.Status.OK).entity(application).build(); } catch (NotFoundException e) { @@ -317,6 +316,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } + /* + //todo ---------------------- + */ @PUT @Consumes("application/json") From 7703d217f92e08d27a9bd43b5bd602004fb9be9c Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 26 Apr 2019 23:03:51 +0530 Subject: [PATCH 2/7] Add App updating API --- .../mgt/core/dao/ApplicationDAO.java | 2 +- .../GenericApplicationDAOImpl.java | 76 ++++++------------- .../mgt/core/impl/ApplicationManagerImpl.java | 7 +- .../impl/ApplicationManagementAPIImpl.java | 26 +++---- 4 files changed, 42 insertions(+), 69 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index 3bd7a484dd..efd1bdec20 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -168,7 +168,7 @@ public interface ApplicationDAO { * @return Updated ApplicationDTO. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. */ - ApplicationDTO editApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException; + boolean updateApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException; /** * To delete the application diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index e0d06c2346..64fbb1e7fb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -583,66 +583,36 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } @Override - public ApplicationDTO editApplication(ApplicationDTO application, int tenantId) + public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementDAOException { - int paramIndex = 1; Connection conn; - PreparedStatement stmt = null; - //todo this is wrong - ApplicationDTO existingApplication = this.getApplicationById(application.getId(), tenantId); - - if (existingApplication == null) { - throw new ApplicationManagementDAOException("There doesn't have an application for updating"); - } try { conn = this.getDBConnection(); - String sql = "UPDATE AP_APP SET "; - - if (application.getName() != null && !application.getName().equals(existingApplication.getName())) { - sql += "NAME = ?, "; - } - if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { - sql += "TYPE = ?, "; + String sql = "UPDATE AP_APP AP " + + "SET " + + "AP.NAME = ?, " + + "AP.DESCRIPTION = ?, " + + "AP.SUB_TYPE = ?, " + + "AP.CURRENCY = ? " + + "WHERE AP.ID = ? AND AP.TENANT_ID = ?"; + + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, applicationDTO.getName()); + stmt.setString(2, applicationDTO.getDescription()); + stmt.setString(3, applicationDTO.getSubType()); + stmt.setString(4, applicationDTO.getPaymentCurrency()); + stmt.setInt(5, applicationDTO.getId()); + stmt.setInt(6, tenantId); + return stmt.executeUpdate() > 0; } - if (application.getAppCategory() != null && !application.getAppCategory().equals( - existingApplication.getAppCategory())) { - sql += "APP_CATEGORY = ?, "; - } -// if (application.getIsRestricted() != existingApplication.getIsRestricted()) { -// sql += "RESTRICTED = ? "; -// } - if (!application.getSubType().equals(existingApplication.getSubType())) { - sql += "SUB_TYPE = ? "; - } - - sql += "WHERE ID = ?"; - - stmt = conn.prepareStatement(sql); - if (application.getName() != null && !application.getName().equals(existingApplication.getName())) { - stmt.setString(paramIndex++, application.getName()); - } - if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { - stmt.setString(paramIndex++, application.getType()); - } - if (application.getAppCategory() != null && !application.getAppCategory().equals( - existingApplication.getAppCategory())) { - stmt.setString(paramIndex++, application.getAppCategory()); - } -// if (application.getIsRestricted() != existingApplication.getIsRestricted()) { -// stmt.setBoolean(paramIndex++, application.getIsRestricted()); -// } - if (!application.getSubType().equals(existingApplication.getSubType())) { - stmt.setString(paramIndex++, application.getSubType()); - } - stmt.setInt(paramIndex, application.getId()); - stmt.executeUpdate(); - return application; } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); + String msg = "Error occurred while obtaining the DB connection to update the application."; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while adding the application", e); - } finally { - Util.cleanupResources(stmt, null); + String msg = "Error occurred when obtaining database connection for updating the application."; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); } } 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 370c770af1..e8dc3e72fd 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 @@ -1589,8 +1589,11 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDAO.deleteTags(removingTagList, applicationId, tenantId); } } - //todo - applicationDAO.editApplication(applicationDTO, tenantId); + if (!applicationDAO.updateApplication(applicationDTO, tenantId)){ + String msg = "Any application is not updated for the application ID: " + applicationId; + log.error(msg); + throw new ApplicationManagementException(msg); + } } catch (UserStoreException e) { ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException( 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java index 3b99f1c50b..342e27b029 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.device.application.mgt.common.*; -import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; @@ -34,7 +33,6 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseW import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; -import org.wso2.carbon.device.application.mgt.core.exception.ValidationException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; @@ -316,10 +314,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } - /* - //todo ---------------------- - */ - @PUT @Consumes("application/json") @Path("/{appId}") @@ -328,23 +322,29 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Valid ApplicationWrapper applicationWrapper) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - //todo wrong applicationManager.updateApplication(applicationId, applicationWrapper); return Response.status(Response.Status.OK) - .entity("Application was updated successfully. ApplicationID " + applicationId).build(); + .entity("Application was updated successfully for ApplicationID: " + applicationId).build(); } catch (NotFoundException e) { log.error(e.getMessage()); return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build(); - } catch (ForbiddenException e) { - log.error(e.getMessage()); - return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while modifying the application"; + } 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) { + String msg = "Internal Error occurred while modifying the application."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } } + /* + //todo ---------------------- + */ + @Override @PUT @Path("/{deviceType}/{appId}/{uuid}") From 5c6a3cba1f6bab6830be8086c7ade8ff84086dbb Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sun, 28 Apr 2019 18:16:25 +0530 Subject: [PATCH 3/7] Improve web app authentication Improve web app authentication to unsecure dynamic context paths and further improve app management APIs --- .../mgt/api/services/ArtifactDownloadAPI.java | 2 +- .../mgt/api/services/ConfigRetrieveAPI.java | 8 +- .../src/main/webapp/WEB-INF/web.xml | 10 +- .../common/services/ApplicationManager.java | 5 +- .../wrapper/ApplicationUpdateWrapper.java | 99 +++++++++++++++++++ .../GenericApplicationDAOImpl.java | 2 + .../mgt/core/impl/ApplicationManagerImpl.java | 81 ++++++--------- .../core/lifecycle/LifecycleStateManager.java | 31 +++--- .../LifecycleManagementTest.java | 8 +- ...=> ApplicationManagementPublisherAPI.java} | 45 ++++----- ...pplicationManagementPublisherAPIImpl.java} | 12 +-- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../services/ApplicationManagementAPI.java | 6 +- .../api/services/ReviewManagementAPI.java | 4 +- .../framework/WebappAuthenticationValve.java | 21 +++- .../main/resources/conf/application-mgt.xml | 1 + 16 files changed, 222 insertions(+), 115 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationUpdateWrapper.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/{ApplicationManagementAPI.java => ApplicationManagementPublisherAPI.java} (96%) rename components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/{ApplicationManagementAPIImpl.java => ApplicationManagementPublisherAPIImpl.java} (99%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ArtifactDownloadAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ArtifactDownloadAPI.java index df76facbd2..7a7f4a74ee 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ArtifactDownloadAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ArtifactDownloadAPI.java @@ -42,7 +42,7 @@ import javax.ws.rs.core.Response; @SwaggerDefinition( info = @Info( version = "1.0.0", - title = "ApplicationDTO Management Common Service", + title = "Application Management Artifact Download Service", extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ApplicationManagementArtifactDownloadService"), diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java index 23073823c1..15c76d251e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ConfigRetrieveAPI.java @@ -40,17 +40,17 @@ import javax.ws.rs.core.Response; @SwaggerDefinition( info = @Info( version = "1.0.0", - title = "ApplicationDTO Management Common Service", + title = "Application Management Config Retrieve Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = "name", value = "ApplicationManagementCommonService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/configt"), + @ExtensionProperty(name = "name", value = "ApplicationManagementConfigRetrieveService"), + @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/config"), }) } ) ) @Path("/config") -@Api(value = "ApplicationDTO Management Common Service", description = "This API carries all application management common services") +@Api(value = "ApplicationDTO Management Common Service") @Produces(MediaType.APPLICATION_JSON) public interface ConfigRetrieveAPI { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml index bc86f46a54..63d4e111fc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -43,7 +43,7 @@ doAuthentication - false + true @@ -117,4 +117,12 @@ /* + + nonSecuredEndPoints + + /api/application-mgt/v1.0/artifact/.*, + /api/application-mgt/v1.0/config/.* + + + \ No newline at end of file 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 35d4cdb07b..eb5f11a022 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 @@ -30,6 +30,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.RequestValidating import org.wso2.carbon.device.application.mgt.common.response.Application; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import java.io.InputStream; @@ -53,12 +54,12 @@ public interface ApplicationManager { /** * Updates an already existing application. * - * @param applicationWrapper Application that need to be updated. + * @param applicationUpdateWrapper Application data that need to be updated. * @param applicationId ID of the application * @return Updated Application * @throws ApplicationManagementException ApplicationDTO Management Exception */ - void updateApplication(int applicationId, ApplicationWrapper applicationWrapper) + void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException; /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationUpdateWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationUpdateWrapper.java new file mode 100644 index 0000000000..88e3f95907 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationUpdateWrapper.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "ApplicationWrapper", description = "ApplicationWrapper represents the an ApplicationDTO in ApplicationDTO Store") +public class ApplicationUpdateWrapper { + + + @ApiModelProperty(name = "name", + value = "Name of the application", + required = true) + private String name; + + @ApiModelProperty(name = "description", + value = "Description of the application", + required = true) + private String description; + + @ApiModelProperty(name = "appCategory", + value = "CategoryDTO of the application", + required = true, + example = "Educational, Gaming, Travel, Entertainment etc") + private String appCategory; + + @ApiModelProperty(name = "subType", + value = "Subscription type of the application", + required = true, + example = "PAID, FREE") + private String subType; + + @ApiModelProperty(name = "paymentCurrency", + value = "Payment currency of the application", + required = true, + example = "$") + private String paymentCurrency; + + @ApiModelProperty(name = "tags", + value = "List of application tags") + private List tags; + + @ApiModelProperty(name = "unrestrictedRoles", + value = "List of roles that users should have to access the application") + private List unrestrictedRoles; + + public String getName() { + return name; + } + + public void setName(String name) { this.name = name; } + + public String getAppCategory() { + return appCategory; + } + + public void setAppCategory(String appCategory) { + this.appCategory = appCategory; + } + + public List getTags() { return tags; } + + public void setTags(List tags) { this.tags = tags; } + + public String getSubType() { return subType; } + + public void setSubType(String subType) { this.subType = subType; } + + public String getPaymentCurrency() { return paymentCurrency; } + + public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; } + + public List getUnrestrictedRoles() { return unrestrictedRoles; } + + public void setUnrestrictedRoles(List unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 64fbb1e7fb..f003862396 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -507,10 +507,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP_RELEASE.UUID AS RELEASE_UUID, " + "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, " + "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, " + + "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, " + "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, " + "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, " + "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, " + "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, " + + "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, " + "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, " + "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " 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 e8dc3e72fd..a4996c9a7e 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 @@ -53,6 +53,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease 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.wrapper.ApplicationReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; @@ -1423,7 +1424,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void updateApplication(int applicationId, ApplicationWrapper applicationWrapper) + public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -1441,85 +1442,63 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new NotFoundException(msg); } - if (!StringUtils.isEmpty(applicationWrapper.getType()) && !applicationDTO.getType() - .equals(applicationWrapper.getType())) { - String msg = "You are trying to change the application type and it is not " - + "possible after you create an application. Therefore please remove this application and " - + "publish new application with type: " + applicationWrapper.getType(); - log.error(msg); - throw new BadRequestException(msg); - } - - String deviceTypeName = applicationWrapper.getDeviceType(); - if (!StringUtils.isEmpty(deviceTypeName)) { - DeviceType deviceType = getDeviceTypeData(deviceTypeName); - if (!deviceType.getName().equals(deviceTypeName)){ - String msg = "You are trying to change the compatible device type of the application type and it is " - + "not possible after you create an application for device type. " + deviceTypeName + - "Therefore please remove this application and publish new application with device type: " + - deviceTypeName; - log.error(msg); - throw new BadRequestException(msg); - } - } - if (!StringUtils.isEmpty(applicationWrapper.getName())){ + if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){ Filter filter = new Filter(); filter.setFullMatch(true); - filter.setAppName(applicationWrapper.getName().trim()); + filter.setAppName(applicationUpdateWrapper.getName().trim()); filter.setOffset(0); filter.setLimit(1); List applicationList = applicationDAO .getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId); if (!applicationList.isEmpty()) { - String msg = "Already an application registered with same name " + applicationWrapper.getName() + String msg = "Already an application registered with same name " + applicationUpdateWrapper.getName() + ". Hence you can't update the application name from " + applicationDTO.getName() + " to " - + applicationWrapper.getName(); + + applicationUpdateWrapper.getName(); log.error(msg); throw new BadRequestException(msg); } - applicationDTO.setName(applicationWrapper.getName()); + applicationDTO.setName(applicationUpdateWrapper.getName()); } - if (!StringUtils.isEmpty(applicationWrapper.getSubType()) && !applicationDTO.getSubType() - .equals(applicationWrapper.getSubType())) { - if (!ApplicationSubscriptionType.PAID.toString().equals(applicationWrapper.getSubType()) - && !ApplicationSubscriptionType.FREE.toString().equals(applicationWrapper.getSubType())) { + if (!StringUtils.isEmpty(applicationUpdateWrapper.getSubType()) && !applicationDTO.getSubType() + .equals(applicationUpdateWrapper.getSubType())) { + if (!ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubType()) + && !ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubType())) { String msg = "Invalid application subscription type is found with application updating request " - + applicationWrapper.getSubType(); + + applicationUpdateWrapper.getSubType(); log.error(msg); throw new BadRequestException(msg); - } else if (ApplicationSubscriptionType.FREE.toString().equals(applicationWrapper.getSubType()) && !StringUtils - .isEmpty(applicationWrapper.getPaymentCurrency())) { + } else if (ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubType()) + && !StringUtils.isEmpty(applicationUpdateWrapper.getPaymentCurrency())) { String msg = "If you are going to change Non-Free app as Free app, " + "currency attribute in the application updating payload should be null or \"\""; log.error(msg); throw new ApplicationManagementException(msg); - } else if (ApplicationSubscriptionType.PAID.toString().equals(applicationWrapper.getSubType()) - && StringUtils.isEmpty(applicationWrapper.getPaymentCurrency()) ){ + } else if (ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubType()) + && StringUtils.isEmpty(applicationUpdateWrapper.getPaymentCurrency()) ){ String msg = "If you are going to change Free app as Non-Free app, " + "currency attribute in the application payload should not be null or \"\""; log.error(msg); throw new ApplicationManagementException(msg); } - - applicationDTO.setSubType(applicationWrapper.getSubType()); - applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); + applicationDTO.setSubType(applicationUpdateWrapper.getSubType()); + applicationDTO.setPaymentCurrency(applicationUpdateWrapper.getPaymentCurrency()); } - if (!StringUtils.isEmpty(applicationWrapper.getDescription())){ - applicationDTO.setDescription(applicationWrapper.getDescription()); + if (!StringUtils.isEmpty(applicationUpdateWrapper.getDescription())){ + applicationDTO.setDescription(applicationUpdateWrapper.getDescription()); } List appUnrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationId, tenantId); boolean isExistingAppRestricted = !appUnrestrictedRoles.isEmpty(); - boolean isUpdatingAppRestricted = !applicationWrapper.getUnrestrictedRoles().isEmpty(); + boolean isUpdatingAppRestricted = !applicationUpdateWrapper.getUnrestrictedRoles().isEmpty(); if (isExistingAppRestricted && !isUpdatingAppRestricted) { visibilityDAO.deleteUnrestrictedRoles(appUnrestrictedRoles, applicationId, tenantId); } else if (isUpdatingAppRestricted) { - if (!hasUserRole(applicationWrapper.getUnrestrictedRoles(), userName)) { + if (!hasUserRole(applicationUpdateWrapper.getUnrestrictedRoles(), userName)) { String msg = "You are trying to restrict the visibility of visible application.But you are trying to " + "restrict the visibility to roles that there isn't at least one role is assigned " @@ -1532,12 +1511,12 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!isExistingAppRestricted) { visibilityDAO - .addUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles(), applicationId, tenantId); + .addUnrestrictedRoles(applicationUpdateWrapper.getUnrestrictedRoles(), applicationId, tenantId); } else { - List addingRoleList = getDifference(applicationWrapper.getUnrestrictedRoles(), + List addingRoleList = getDifference(applicationUpdateWrapper.getUnrestrictedRoles(), applicationDTO.getUnrestrictedRoles()); List removingRoleList = getDifference(applicationDTO.getUnrestrictedRoles(), - applicationWrapper.getUnrestrictedRoles()); + applicationUpdateWrapper.getUnrestrictedRoles()); if (!addingRoleList.isEmpty()) { visibilityDAO.addUnrestrictedRoles(addingRoleList, applicationId, tenantId); } @@ -1546,9 +1525,9 @@ public class ApplicationManagerImpl implements ApplicationManager { } } } - applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); + applicationDTO.setUnrestrictedRoles(applicationUpdateWrapper.getUnrestrictedRoles()); - String updatingAppCategory = applicationWrapper.getAppCategory(); + String updatingAppCategory = applicationUpdateWrapper.getAppCategory(); if ( updatingAppCategory != null){ List appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId); if (!appCategories.contains(updatingAppCategory)){ @@ -1556,7 +1535,8 @@ public class ApplicationManagerImpl implements ApplicationManager { List categoryIds = allCategories.stream() .filter(category -> category.getCategoryName().equals(updatingAppCategory)) .map(CategoryDTO::getId).collect(Collectors.toList()); - if (!categoryIds.isEmpty()){ + if (categoryIds.isEmpty()){ + ConnectionManagerUtil.rollbackDBTransaction(); String msg = "You are trying to update application category into invalid application category, " + "it is not registered in the system. Therefore please register the category " @@ -1568,7 +1548,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - List updatingAppTags = applicationWrapper.getTags(); + List updatingAppTags = applicationUpdateWrapper.getTags(); if ( updatingAppTags!= null){ List appTags = this.applicationDAO.getAppTags(applicationId, tenantId); List addingTagList = getDifference(appTags, updatingAppTags); @@ -1590,6 +1570,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } } if (!applicationDAO.updateApplication(applicationDTO, tenantId)){ + ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Any application is not updated for the application ID: " + applicationId; log.error(msg); throw new ApplicationManagementException(msg); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java index 2691b4153e..03598a7f43 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java @@ -211,27 +211,28 @@ public class LifecycleStateManager { return endState; } - public boolean isStateExist(String currentState) { + public String getInstallableState() throws LifecycleManagementException { + String installableState = null; for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { - if (stringStateEntry.getKey().equalsIgnoreCase(currentState)) { - return true; + if (stringStateEntry.getValue().isAppInstallable()) { + installableState = stringStateEntry.getKey(); + break; } } - return false; - } - - public boolean isUpdatable(String state) { - State currentState = getMatchingState(state); - if (currentState.isAppUpdatable()) { - return true; + if (installableState == null){ + String msg = "Haven't defined the installable state in the application-manager.xml. Please add installable " + + "state to the section in the app-manager.xml"; + log.error(msg); + throw new LifecycleManagementException(msg); } - return false; + return installableState; } - public boolean isInstallable(String state) { - State currentState = getMatchingState(state); - if (currentState.isAppInstallable()) { - return true; + public boolean isStateExist(String currentState) { + for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { + if (stringStateEntry.getKey().equalsIgnoreCase(currentState)) { + return true; + } } return false; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 42f1b41f11..4d610fe62a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -53,26 +53,26 @@ public class LifecycleManagementTest { @Test public void CheckUpdatableState() throws LifecycleManagementException { - boolean isUpdatable = lifecycleStateManager.isUpdatable(UPDATABLE_STATE); + boolean isUpdatable = lifecycleStateManager.isUpdatableState(UPDATABLE_STATE); System.out.println(isUpdatable); Assert.assertTrue("Updatable state: " + UPDATABLE_STATE, isUpdatable); } @Test public void CheckNonUpdatableState() throws LifecycleManagementException { - boolean isUpdatable = lifecycleStateManager.isUpdatable(NON_UPDATABLE_STATE); + boolean isUpdatable = lifecycleStateManager.isUpdatableState(NON_UPDATABLE_STATE); Assert.assertFalse("Non Updatable state: " + NON_UPDATABLE_STATE, isUpdatable); } @Test public void CheckInstallableState() throws LifecycleManagementException { - boolean isInstallable = lifecycleStateManager.isInstallable(INSTALLABLE_STATE); + boolean isInstallable = lifecycleStateManager.isInstallableState(INSTALLABLE_STATE); Assert.assertTrue("Installable state: " + INSTALLABLE_STATE, isInstallable); } @Test public void CheckUnInstallableState() throws LifecycleManagementException { - boolean isInstallable = lifecycleStateManager.isInstallable(UNINSTALlABLE_STATE); + boolean isInstallable = lifecycleStateManager.isInstallableState(UNINSTALlABLE_STATE); Assert.assertFalse("UnInstallable state: " + UNINSTALlABLE_STATE, isInstallable); } 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/ApplicationManagementAPI.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 similarity index 96% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java rename to 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 02042a4125..4e27c54dd6 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/ApplicationManagementAPI.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 @@ -32,12 +32,14 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.application.mgt.common.*; +import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; +import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import java.util.List; @@ -60,17 +62,16 @@ import javax.ws.rs.core.Response; @SwaggerDefinition( info = @Info( version = "1.0.0", - title = "ApplicationDTO Management Service", + title = "ApplicationDTO Management Publisher Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = "name", value = "ApplicationManagementService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/applications"), + @ExtensionProperty(name = "name", value = "ApplicationManagementPublisherService"), + @ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/applications"), }) } ), tags = { - @Tag(name = "application_management, device_management", description = "ApplicationDTO Management related " - + "APIs") + @Tag(name = "application_management, device_management", description = "App publisher related APIs") } ) @Scopes( @@ -79,21 +80,21 @@ import javax.ws.rs.core.Response; name = "Get ApplicationDTO Details", description = "Get application details", key = "perm:app:publisher:view", - permissions = {"/device-mgt/application/view"} + permissions = {"/app-mgt/publisher/application/update"} ), @Scope( name = "Update an ApplicationDTO", description = "Update an application", key = "perm:app:publisher:update", - permissions = {"/device-mgt/application/update"} + permissions = {"/app-mgt/publisher/application/update"} ) } ) -@Path("/publisher/applications") +@Path("/applications") @Api(value = "ApplicationDTO Management", description = "This API carries all application management related operations " + "such as get all the applications, add application, etc.") @Produces(MediaType.APPLICATION_JSON) -public interface ApplicationManagementAPI { +public interface ApplicationManagementPublisherAPI { String SCOPE = "scope"; @@ -193,7 +194,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -220,9 +221,9 @@ public interface ApplicationManagementAPI { @PathParam("appId") int appId, @ApiParam( name = "application", - value = "The application that need to be edited.", + value = "Application data that need to be edited.", required = true) - @Valid ApplicationWrapper applicationWrapper + @Valid ApplicationUpdateWrapper applicationUpdateWrapper ); @POST @@ -237,7 +238,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -307,7 +308,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -386,7 +387,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -398,7 +399,7 @@ public interface ApplicationManagementAPI { response = List.class), @ApiResponse( code = 500, - message = "Internal Server Error. \n Error occurred while deleteing the application.", + message = "Internal Server Error. \n Error occurred while deleting the application.", response = ErrorResponse.class) }) Response deleteApplication( @@ -422,7 +423,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -493,7 +494,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -546,7 +547,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -594,7 +595,7 @@ public interface ApplicationManagementAPI { tags = "Lifecycle Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) @@ -626,7 +627,7 @@ public interface ApplicationManagementAPI { tags = "Lifecycle Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:update") }) } ) 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/ApplicationManagementAPIImpl.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 similarity index 99% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java rename to 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 342e27b029..ee83aa5697 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/ApplicationManagementAPIImpl.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 @@ -30,11 +30,12 @@ import org.wso2.carbon.device.application.mgt.common.exception.RequestValidating import org.wso2.carbon.device.application.mgt.common.response.Application; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; -import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; +import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; @@ -50,7 +51,6 @@ import javax.activation.DataHandler; import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -66,9 +66,7 @@ import javax.ws.rs.core.Response; */ @Produces({"application/json"}) @Path("/applications") -public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { - - private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); +public class ApplicationManagementPublisherAPIImpl implements ApplicationManagementPublisherAPI { @POST @Override @@ -319,10 +317,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Path("/{appId}") public Response updateApplication( @PathParam("appId") int applicationId, - @Valid ApplicationWrapper applicationWrapper) { + @Valid ApplicationUpdateWrapper applicationUpdateWrapper) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - applicationManager.updateApplication(applicationId, applicationWrapper); + applicationManager.updateApplication(applicationId, applicationUpdateWrapper); return Response.status(Response.Status.OK) .entity("Application was updated successfully for ApplicationID: " + applicationId).build(); } catch (NotFoundException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml index d1b5e7b247..7b060ca089 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -52,7 +52,7 @@ - + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java index 659ea23496..d42665033f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java @@ -68,7 +68,7 @@ import javax.ws.rs.core.Response; name = "Get ApplicationDTO Details", description = "Get application details", key = "perm:app:store:view", - permissions = {"/device-mgt/application/get"} + permissions = {"/app-mgt/store/application/view"} ) } ) @@ -92,7 +92,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:get") + @ExtensionProperty(name = SCOPE, value = "perm:app:store:view") }) } ) @@ -155,7 +155,7 @@ public interface ApplicationManagementAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:get") + @ExtensionProperty(name = SCOPE, value = "perm:app:store:view") }) } ) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java index 3f889d6e20..045e5163b0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java @@ -72,13 +72,13 @@ import java.util.List; name = "Get Review Details", description = "Get review details", key = "perm:app:review:view", - permissions = {"/device-mgt/review/view"} + permissions = {"/app-mgt/store/review/view"} ), @Scope( name = "Update a Review", description = "Update a comment", key = "perm:app:review:update", - permissions = {"/device-mgt/review/update"} + permissions = {"/app-mgt/store/review/update"} ), } ) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java index 8c837c5338..4b596c4ed3 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java @@ -31,13 +31,14 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthen import org.wso2.carbon.webapp.authenticator.framework.authorizer.WebappTenantAuthorizer; import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; import java.util.StringTokenizer; +import java.util.TreeMap; +import java.util.regex.Pattern; public class WebappAuthenticationValve extends CarbonTomcatValve { private static final Log log = LogFactory.getLog(WebappAuthenticationValve.class); - private static HashMap nonSecuredEndpoints = new HashMap<>(); + private static TreeMap nonSecuredEndpoints = new TreeMap<>(); @Override public void invoke(Request request, Response response, CompositeValve compositeValve) { @@ -126,6 +127,7 @@ public class WebappAuthenticationValve extends CarbonTomcatValve { if (!nonSecuredEndpoints.containsKey(contextPath)) { String param = request.getContext().findParameter("nonSecuredEndPoints"); String skippedEndPoint; + boolean isUriUnsecured = false; if (param != null && !param.isEmpty()) { //Add the nonSecured end-points to cache StringTokenizer tokenizer = new StringTokenizer(param, ","); @@ -137,10 +139,23 @@ public class WebappAuthenticationValve extends CarbonTomcatValve { skippedEndPoint = skippedEndPoint + "/"; } nonSecuredEndpoints.put(skippedEndPoint, "true"); + if (uri.equals(skippedEndPoint) || Pattern.matches(skippedEndPoint, uri)){ + isUriUnsecured = true; + } + } + return isUriUnsecured; + } + } else { + if (nonSecuredEndpoints.containsKey(uri)) { + return true; + } + for (String endpoint : nonSecuredEndpoints.keySet()) { + if (Pattern.matches(endpoint, uri)) { + return true; } } } - return nonSecuredEndpoints.containsKey(uri); + return false; } private void processRequest(Request request, Response response, CompositeValve compositeValve, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 69591ca425..b20305e30b 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -149,6 +149,7 @@ perm:app:review:update perm:app:publisher:view perm:app:publisher:update + perm:app:store:view app-mgt From 8bf0a673360f52ad31e481a417702c0b453f4ac3 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sun, 28 Apr 2019 18:33:17 +0530 Subject: [PATCH 4/7] Add missing log line --- .../services/impl/ApplicationManagementPublisherAPIImpl.java | 2 ++ 1 file changed, 2 insertions(+) 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 ee83aa5697..be37e9e3b2 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 @@ -68,6 +68,8 @@ import javax.ws.rs.core.Response; @Path("/applications") public class ApplicationManagementPublisherAPIImpl implements ApplicationManagementPublisherAPI { + private static Log log = LogFactory.getLog(ApplicationManagementPublisherAPIImpl.class); + @POST @Override @Consumes("application/json") From 5837e53d1ff1fa9917ae6b5146712d06de799b2c Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sun, 28 Apr 2019 19:26:20 +0530 Subject: [PATCH 5/7] Fix scope issue in APPM publisher --- .../ApplicationManagementPublisherAPI.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 4e27c54dd6..5ffaa35752 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 @@ -194,7 +194,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -238,7 +238,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -308,7 +308,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -387,7 +387,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -423,7 +423,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -494,7 +494,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -547,7 +547,7 @@ public interface ApplicationManagementPublisherAPI { tags = "ApplicationDTO Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -595,7 +595,7 @@ public interface ApplicationManagementPublisherAPI { tags = "Lifecycle Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) @@ -627,7 +627,7 @@ public interface ApplicationManagementPublisherAPI { tags = "Lifecycle Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") }) } ) From 93fa110a081685ea51f478902de95706aa522d84 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sun, 28 Apr 2019 20:08:10 +0530 Subject: [PATCH 6/7] Fix App update issue --- .../application/mgt/core/impl/ApplicationManagerImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 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 a4996c9a7e..e5aa75acd7 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 @@ -1493,7 +1493,11 @@ public class ApplicationManagerImpl implements ApplicationManager { List appUnrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationId, tenantId); boolean isExistingAppRestricted = !appUnrestrictedRoles.isEmpty(); - boolean isUpdatingAppRestricted = !applicationUpdateWrapper.getUnrestrictedRoles().isEmpty(); + boolean isUpdatingAppRestricted = false; + if (applicationUpdateWrapper.getUnrestrictedRoles() != null && !applicationUpdateWrapper + .getUnrestrictedRoles().isEmpty()) { + isUpdatingAppRestricted = true; + } if (isExistingAppRestricted && !isUpdatingAppRestricted) { visibilityDAO.deleteUnrestrictedRoles(appUnrestrictedRoles, applicationId, tenantId); From 68b9795201a57c8ab43ce6dd5845887dec2d46dd Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 29 Apr 2019 00:54:10 +0530 Subject: [PATCH 7/7] Fix application update issue --- .../device/application/mgt/core/impl/ApplicationManagerImpl.java | 1 + 1 file changed, 1 insertion(+) 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 e5aa75acd7..7a1f683ba6 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 @@ -1579,6 +1579,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ApplicationManagementException(msg); } + ConnectionManagerUtil.commitDBTransaction(); } catch (UserStoreException e) { ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException(