Add support for application category list adding for an application.

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent be992c4b8d
commit c6440a779d

@ -0,0 +1,32 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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;
public class LifecycleChanger {
private String action;
private String reason;
public String getAction() { return action; }
public void setAction(String action) { this.action = action; }
public String getReason() { return reason; }
public void setReason(String reason) { this.reason = reason; }
}

@ -49,6 +49,10 @@ public class LifecycleState {
value = "Timestamp of the lifecycle has been updated") value = "Timestamp of the lifecycle has been updated")
private Timestamp updatedAt; private Timestamp updatedAt;
@ApiModelProperty(name = "resonForChange",
value = "Reason for the application release lifecycle change from previous state to current state.")
private String resonForChange;
public String getCurrentState() { public String getCurrentState() {
return currentState; return currentState;
} }
@ -88,4 +92,8 @@ public class LifecycleState {
public void setNextStates(List<String> nextStates) { public void setNextStates(List<String> nextStates) {
this.nextStates = nextStates; this.nextStates = nextStates;
} }
public String getResonForChange() { return resonForChange; }
public void setResonForChange(String resonForChange) { this.resonForChange = resonForChange; }
} }

@ -41,11 +41,11 @@ public class ApplicationDTO {
required = true) required = true)
private String description; private String description;
@ApiModelProperty(name = "appCategory", @ApiModelProperty(name = "appCategories",
value = "Category of the application", value = "Category of the application",
required = true, required = true,
example = "Educational, Gaming, Travel, Entertainment etc") example = "Educational, Gaming, Travel, Entertainment etc")
private String appCategory; private List<String> appCategories;
@ApiModelProperty(name = "type", @ApiModelProperty(name = "type",
value = "Type of the application", value = "Type of the application",
@ -108,13 +108,11 @@ public class ApplicationDTO {
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public String getAppCategory() { public List<String> getAppCategories() {
return appCategory; return appCategories;
} }
public void setAppCategory(String appCategory) { public void setAppCategories(List<String> appCategories) { this.appCategories = appCategories; }
this.appCategory = appCategory;
}
public List<String> getTags() { return tags; } public List<String> getTags() { return tags; }

@ -35,11 +35,11 @@ public class Application {
required = true) required = true)
private String description; private String description;
@ApiModelProperty(name = "appCategory", @ApiModelProperty(name = "appCategories",
value = "CategoryDTO of the application", value = "CategoryDTO of the application",
required = true, required = true,
example = "Educational, Gaming, Travel, Entertainment etc") example = "Educational, Gaming, Travel, Entertainment etc")
private String appCategory; private List<String> appCategories;
@ApiModelProperty(name = "type", @ApiModelProperty(name = "type",
value = "Type of the application", value = "Type of the application",
@ -88,12 +88,12 @@ public class Application {
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public String getAppCategory() { public List<String> getAppCategories() {
return appCategory; return appCategories;
} }
public void setAppCategory(String appCategory) { public void setAppCategories(List<String> appCategories) {
this.appCategory = appCategory; this.appCategories = appCategories;
} }
public List<String> getTags() { return tags; } public List<String> getTags() { return tags; }

@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.common.services;
import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
@ -147,10 +148,11 @@ public interface ApplicationManager {
* To get all the releases of a particular ApplicationDTO. * To get all the releases of a particular ApplicationDTO.
* *
* @param releaseUuid UUID of the ApplicationDTO Release. * @param releaseUuid UUID of the ApplicationDTO Release.
* @param stateName Lifecycle state to change the app * @param lifecycleChanger Lifecycle changer that contains the action and the reson for the change.
* @throws ApplicationManagementException ApplicationDTO Management Exception. * @throws ApplicationManagementException ApplicationDTO Management Exception.
*/ */
void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException; void changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger)
throws ApplicationManagementException;
/** /**
* To update release images such as icons, banner and screenshots. * To update release images such as icons, banner and screenshots.

@ -35,11 +35,11 @@ public class ApplicationWrapper {
required = true) required = true)
private String description; private String description;
@ApiModelProperty(name = "appCategory", @ApiModelProperty(name = "appCategories",
value = "CategoryDTO of the application", value = "CategoryDTO of the application",
required = true, required = true,
example = "Educational, Gaming, Travel, Entertainment etc") example = "Educational, Gaming, Travel, Entertainment etc")
private String appCategory; private List<String> appCategories;
@ApiModelProperty(name = "type", @ApiModelProperty(name = "type",
value = "Type of the application", value = "Type of the application",
@ -85,12 +85,10 @@ public class ApplicationWrapper {
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public String getAppCategory() { public List<String> getAppCategories() { return appCategories; }
return appCategory;
}
public void setAppCategory(String appCategory) { public void setAppCategories(List<String> appCategories) {
this.appCategory = appCategory; this.appCategories = appCategories;
} }
public List<String> getTags() { return tags; } public List<String> getTags() { return tags; }

@ -1478,7 +1478,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
application.setId(rs.getInt("APP_ID")); application.setId(rs.getInt("APP_ID"));
application.setName(rs.getString("APP_NAME")); application.setName(rs.getString("APP_NAME"));
application.setType(rs.getString("APP_TYPE")); application.setType(rs.getString("APP_TYPE"));
application.setAppCategory(rs.getString("APP_CATEGORY")); // application.setAppCategories(rs.getString("APP_CATEGORY"));
application.setSubType(rs.getString("SUB_TYPE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY")); application.setPaymentCurrency(rs.getString("CURRENCY"));
// application.setIsRestricted(rs.getBoolean("RESTRICTED")); // application.setIsRestricted(rs.getBoolean("RESTRICTED"));

@ -174,9 +174,10 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
+ "TENANT_ID, " + "TENANT_ID, "
+ "UPDATED_BY, " + "UPDATED_BY, "
+ "UPDATED_AT, " + "UPDATED_AT, "
+ "REASON, "
+ "AP_APP_RELEASE_ID, " + "AP_APP_RELEASE_ID, "
+ "AP_APP_ID) " + "AP_APP_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE ID = ?));"; + "VALUES (?, ?, ?, ?, ?, ?, ?, (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE ID = ?));";
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
@ -187,8 +188,9 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setString(4, state.getUpdatedBy()); stmt.setString(4, state.getUpdatedBy());
stmt.setTimestamp(5, timestamp); stmt.setTimestamp(5, timestamp);
stmt.setInt(6, appReleaseId); stmt.setString(6, state.getResonForChange());
stmt.setInt(7, appReleaseId); stmt.setInt(7, appReleaseId);
stmt.setInt(8, appReleaseId);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("Error occurred while obtaining the DB connection.", e); log.error("Error occurred while obtaining the DB connection.", e);

@ -29,6 +29,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller; import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller;
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.Pagination;
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; 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.dto.ApplicationDTO;
@ -84,6 +85,7 @@ import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -96,7 +98,6 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -149,7 +150,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationDTO applicationDTO; ApplicationDTO applicationDTO;
List<String> unrestrictedRoles; List<String> unrestrictedRoles;
Optional<CategoryDTO> category; List<Integer> categoryIds = new ArrayList<>();
List<String> tags; List<String> tags;
//validating and verifying application data //validating and verifying application data
@ -189,7 +190,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId); List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
String categoryName = applicationWrapper.getAppCategory(); List<String> appCategories = applicationWrapper.getAppCategories();
if (registeredCategories.isEmpty()) { if (registeredCategories.isEmpty()) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -198,13 +199,21 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
category = registeredCategories.stream().filter(obj -> obj.getCategoryName().equals(categoryName)) for (String cat : appCategories) {
.findAny(); boolean isValidCategory = false;
if (!category.isPresent()) { for (CategoryDTO obj : registeredCategories) {
ConnectionManagerUtil.rollbackDBTransaction(); if (cat.equals(obj.getCategoryName())) {
String msg = "Request contains invalid category: " + categoryName; categoryIds.add(obj.getId());
log.error(msg); isValidCategory = true;
throw new ApplicationManagementException(msg); break;
}
}
if (!isValidCategory) {
String msg = "Application Creating request contains invalid categories. Hence please verify the "
+ "application creating payload.";
log.error(msg);
throw new BadRequestException(msg);
}
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while getting database connection."; String msg = "Error occurred while getting database connection.";
@ -260,6 +269,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId); log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId);
} }
//add application categories
this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId);
//adding application unrestricted roles //adding application unrestricted roles
if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId); this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId);
@ -269,15 +281,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
/*
In current flow, allow to add one category for an application. If it is required to add multiple
categories DAO layer is implemented to match with that requirement. Hence logic is also implemented
this way.
*/
List<Integer> categoryIds = new ArrayList<>();
categoryIds.add(category.get().getId());
this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId);
//adding application tags //adding application tags
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {
List<TagDTO> registeredTags = applicationDAO.getAllTags(tenantId); List<TagDTO> registeredTags = applicationDAO.getAllTags(tenantId);
@ -623,6 +626,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
if (filter == null) {
String msg = "Request Payload is null";
log.error(msg);
throw new BadRequestException(msg);
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationList applicationList = new ApplicationList(); ApplicationList applicationList = new ApplicationList();
@ -631,24 +639,23 @@ public class ApplicationManagerImpl implements ApplicationManager {
List<ApplicationDTO> filteredApplications = new ArrayList<>(); List<ApplicationDTO> filteredApplications = new ArrayList<>();
DeviceType deviceType = null; DeviceType deviceType = null;
try { //set default values
//set default values if (!StringUtils.isEmpty(filter.getDeviceType())) {
if (filter.getLimit() == 0) { deviceType = getDeviceTypeData(filter.getDeviceType());
filter.setLimit(20); }
} if (filter.getLimit() == 0) {
String deviceTypename = filter.getDeviceType(); filter.setLimit(20);
if (!StringUtils.isEmpty(deviceTypename)) { }
deviceType = getDeviceTypeData(deviceTypename);
} if (deviceType == null) {
if (deviceType == null) { deviceType = new DeviceType();
deviceType = new DeviceType(); deviceType.setId(-1);
deviceType.setId(-1); }
}
try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
validateFilter(filter); validateFilter(filter);
appDTOs = applicationDAO.getApplications(filter, deviceType.getId(), tenantId); appDTOs = applicationDAO.getApplications(filter, deviceType.getId(), tenantId);
//todo as a performance improvement get these data from DB. Consider where in clause.
for (ApplicationDTO applicationDTO : appDTOs) { for (ApplicationDTO applicationDTO : appDTOs) {
boolean isSearchingApp = true; boolean isSearchingApp = true;
List<String> filteringTags = filter.getTags(); List<String> filteringTags = filter.getTags();
@ -656,14 +663,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
List<String> filteringUnrestrictedRoles = filter.getUnrestrictedRoles(); List<String> filteringUnrestrictedRoles = filter.getUnrestrictedRoles();
if (!lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) { if (!lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) {
List<String> appUnrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId); List<String> appUnrestrictedRoles = visibilityDAO
.getUnrestrictedRoles(applicationDTO.getId(), tenantId);
applicationDTO.setUnrestrictedRoles(appUnrestrictedRoles);
if ((appUnrestrictedRoles.isEmpty() || hasUserRole(appUnrestrictedRoles, userName)) && ( if ((appUnrestrictedRoles.isEmpty() || hasUserRole(appUnrestrictedRoles, userName)) && (
filteringUnrestrictedRoles == null || filteringUnrestrictedRoles.isEmpty() filteringUnrestrictedRoles == null || filteringUnrestrictedRoles.isEmpty()
|| hasAppUnrestrictedRole(appUnrestrictedRoles, filteringUnrestrictedRoles, || hasAppUnrestrictedRole(appUnrestrictedRoles, filteringUnrestrictedRoles,
userName))) { userName))) {
if (filteringCategories != null && !filteringCategories.isEmpty()) { if (filteringCategories != null && !filteringCategories.isEmpty()) {
List<String> appTagList = applicationDAO.getAppCategories(applicationDTO.getId(), tenantId); List<String> appCategoryList = applicationDAO
boolean isAppCategory = filteringCategories.stream().anyMatch(appTagList::contains); .getAppCategories(applicationDTO.getId(), tenantId);
applicationDTO.setAppCategories(appCategoryList);
boolean isAppCategory = filteringCategories.stream().anyMatch(appCategoryList::contains);
if (!isAppCategory) { if (!isAppCategory) {
isSearchingApp = false; isSearchingApp = false;
} }
@ -699,9 +710,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationList.getPagination().setSize(filter.getOffset()); applicationList.getPagination().setSize(filter.getOffset());
applicationList.getPagination().setCount(applicationList.getApplications().size()); applicationList.getPagination().setCount(applicationList.getApplications().size());
return applicationList; return applicationList;
} catch (UnexpectedServerErrorException e){ } catch (UserStoreException e) {
throw new ApplicationManagementException(e.getMessage(), e);
}catch (UserStoreException e) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
"User-store exception while checking whether the user " + userName + " of tenant " + tenantId "User-store exception while checking whether the user " + userName + " of tenant " + tenantId
+ " has the publisher permission", e); + " has the publisher permission", e);
@ -843,9 +852,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
List<String> tags = this.applicationDAO.getAppTags(appId, tenantId); List<String> tags = this.applicationDAO.getAppTags(appId, tenantId);
List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId); List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId);
applicationDTO.setTags(tags); applicationDTO.setTags(tags);
//todo when support to add multiple categories this has to be changed
if (!categories.isEmpty()){ if (!categories.isEmpty()){
applicationDTO.setAppCategory(categories.get(0)); applicationDTO.setAppCategories(categories);
} }
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
return appDtoToAppResponse(applicationDTO); return appDtoToAppResponse(applicationDTO);
@ -1595,10 +1603,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void changeLifecycleState(String releaseUuid, String stateName) public void changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (lifecycleChanger == null || StringUtils.isEmpty(lifecycleChanger.getAction())) {
String msg = "The Action is null or empty. Please verify the request.";
log.error(msg);
throw new BadRequestException(msg);
}
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
@ -1609,23 +1624,24 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (lifecycleStateManager if (lifecycleStateManager
.isValidStateChange(applicationReleaseDTO.getCurrentState(), stateName, userName, tenantId)) { .isValidStateChange(applicationReleaseDTO.getCurrentState(), lifecycleChanger.getAction(), userName,
if (lifecycleStateManager.isInstallableState(stateName) && applicationReleaseDAO tenantId)) {
if (lifecycleStateManager.isInstallableState(lifecycleChanger.getAction()) && applicationReleaseDAO
.hasExistInstallableAppRelease(applicationReleaseDTO.getUuid(), .hasExistInstallableAppRelease(applicationReleaseDTO.getUuid(),
lifecycleStateManager.getInstallableState(), tenantId)) { lifecycleStateManager.getInstallableState(), tenantId)) {
String msg = "Installable application release is already registered for the application. " String msg = "Installable application release is already registered for the application. "
+ "Therefore it is not permitted to change the lifecycle state from " + "Therefore it is not permitted to change the lifecycle state from "
+ applicationReleaseDTO.getCurrentState() + " to " + stateName; + applicationReleaseDTO.getCurrentState() + " to " + lifecycleChanger.getAction();
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
LifecycleState lifecycleState = new LifecycleState(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(stateName); lifecycleState.setCurrentState(lifecycleChanger.getAction());
lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState()); lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState());
lifecycleState.setUpdatedBy(userName); lifecycleState.setUpdatedBy(userName);
applicationReleaseDTO.setCurrentState(stateName); lifecycleState.setResonForChange(lifecycleChanger.getReason());
applicationReleaseDTO.setCurrentState(lifecycleChanger.getAction());
if (this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) == null) { if (this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) == null) {
String msg = "Application release updating is failed/."; String msg = "Application release updating is failed/.";
log.error(msg); log.error(msg);
@ -1635,7 +1651,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} else { } else {
String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'" String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
+ " to '" + stateName + "'"; + " to '" + lifecycleChanger.getAction() + "'";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
@ -2347,7 +2363,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new RequestValidatingException(msg); throw new RequestValidatingException(msg);
} }
if (StringUtils.isEmpty(applicationWrapper.getAppCategory())) { if (applicationWrapper.getAppCategories().isEmpty()) {
String msg = "Application category can't be empty."; String msg = "Application category can't be empty.";
log.error(msg); log.error(msg);
throw new RequestValidatingException(msg); throw new RequestValidatingException(msg);
@ -2459,7 +2475,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationDTO applicationDTO = new ApplicationDTO(); ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setName(applicationWrapper.getName()); applicationDTO.setName(applicationWrapper.getName());
applicationDTO.setDescription(applicationWrapper.getDescription()); applicationDTO.setDescription(applicationWrapper.getDescription());
applicationDTO.setAppCategory(applicationWrapper.getAppCategory()); applicationDTO.setAppCategories(applicationWrapper.getAppCategories());
applicationDTO.setType(applicationWrapper.getType()); applicationDTO.setType(applicationWrapper.getType());
applicationDTO.setSubType(applicationWrapper.getSubType()); applicationDTO.setSubType(applicationWrapper.getSubType());
applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency());
@ -2492,7 +2508,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setId(applicationDTO.getId()); application.setId(applicationDTO.getId());
application.setName(applicationDTO.getName()); application.setName(applicationDTO.getName());
application.setDescription(applicationDTO.getDescription()); application.setDescription(applicationDTO.getDescription());
application.setAppCategory(applicationDTO.getAppCategory()); application.setAppCategories(applicationDTO.getAppCategories());
application.setType(applicationDTO.getType()); application.setType(applicationDTO.getType());
application.setSubType(applicationDTO.getSubType()); application.setSubType(applicationDTO.getSubType());
application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setPaymentCurrency(applicationDTO.getPaymentCurrency());

@ -2,12 +2,17 @@ package org.wso2.carbon.device.application.mgt.core.dto;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import java.util.ArrayList;
import java.util.List;
public class ApplicationsDTO { public class ApplicationsDTO {
public static ApplicationDTO getApp1() { public static ApplicationDTO getApp1() {
ApplicationDTO app = new ApplicationDTO(); ApplicationDTO app = new ApplicationDTO();
List<String> categories = new ArrayList<>();
app.setAppCategory("Test Category"); categories.add("Test Category");
app.setAppCategories(categories);
app.setDescription("Test app Description"); app.setDescription("Test app Description");
app.setDeviceTypeId(1); app.setDeviceTypeId(1);
app.setName("First Test App"); app.setName("First Test App");

@ -52,7 +52,10 @@ public class ApplicationManagementTest extends BaseTestCase {
ApplicationWrapper applicationWrapper = new ApplicationWrapper(); ApplicationWrapper applicationWrapper = new ApplicationWrapper();
applicationWrapper.setAppCategory("Test Category"); List<String> categories = new ArrayList<>();
categories.add("Test Category");
applicationWrapper.setAppCategories(categories);
applicationWrapper.setDescription("Test Description"); applicationWrapper.setDescription("Test Description");
applicationWrapper.setDeviceType("android"); applicationWrapper.setDeviceType("android");
applicationWrapper.setName("Test Application"); applicationWrapper.setName("Test Application");

@ -35,6 +35,7 @@ import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; 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.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; 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.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
@ -729,6 +730,10 @@ public interface ApplicationManagementPublisherAPI {
code = 400, code = 400,
message = "Bad Request. \n " + message = "Bad Request. \n " +
"Lifecycle State changing request contains unacceptable or vulnerable data"), "Lifecycle State changing request contains unacceptable or vulnerable data"),
@ApiResponse(
code = 403,
message = "Don't have permission to move the lifecycle state of a given application release"
+ " to the given lifecycle state."),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "NOT FOUND. \n Error occurred while adding new lifecycle state.", message = "NOT FOUND. \n Error occurred while adding new lifecycle state.",
@ -745,10 +750,10 @@ public interface ApplicationManagementPublisherAPI {
required = true) required = true)
@PathParam("uuid") String applicationUuid, @PathParam("uuid") String applicationUuid,
@ApiParam( @ApiParam(
name = "action", name = "LifecycleChanger",
value = "Changing lifecycle state", value = "Lifecycle Changer which contains the action and the reason for the lifecycle change.",
required = true) required = true)
@QueryParam("action") String action LifecycleChanger lifecycleChanger
); );
@GET @GET

@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWr
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; 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.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI; 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.exception.ApplicationManagementException;
@ -84,11 +85,15 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
.entity("Couldn't find any application for the requested query.").build(); .entity("Couldn't find any application for the requested query.").build();
} }
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch(BadRequestException e){ } catch (BadRequestException e) {
String msg = "Incompatible request payload is found. Please try with valid request payload."; String msg = "Incompatible request payload is found. Please try with valid request payload.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (ApplicationManagementException e) { } catch (UnexpectedServerErrorException e) {
String msg = "Error Occured when getting supported device types by Entgra IoTS";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application list for publisher "; String msg = "Error occurred while getting the application list for publisher ";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
@ -442,16 +447,19 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/life-cycle/{uuid}") @Path("/life-cycle/{uuid}")
public Response addLifecycleState( public Response addLifecycleState(
@PathParam("uuid") String applicationUuid, @PathParam("uuid") String applicationUuid,
@QueryParam("action") String action) { @Valid LifecycleChanger lifecycleChanger) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
if (StringUtils.isEmpty(action)) { applicationManager.changeLifecycleState(applicationUuid, lifecycleChanger);
String msg = "The Action is null or empty. Please verify the request."; } catch (BadRequestException e) {
log.error(msg); String msg = "Request payload contains invalid data, hence veryfy the request payload.";
return Response.status(Response.Status.BAD_REQUEST).build(); log.error(msg, e);
} return Response.status(Response.Status.BAD_REQUEST).build();
} catch (ForbiddenException e) {
applicationManager.changeLifecycleState( applicationUuid, action); String msg = "You are trying to move the application release into incompatible state for application "
+ "which has application ID: " + applicationUuid;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Could,t find application release for application release uuid: " + applicationUuid; String msg = "Could,t find application release for application release uuid: " + applicationUuid;
log.error(msg, e); log.error(msg, e);
@ -579,9 +587,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
List<String> tagNames) { List<String> tagNames) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.addTags(tagNames); List<String> tags = applicationManager.addTags(tagNames);
String msg = "New application tags are added successfully."; return Response.status(Response.Status.OK).entity(tags).build();
return Response.status(Response.Status.OK).entity(msg).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg); log.error(msg);
@ -602,9 +609,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
List<String> tagNames) { List<String> tagNames) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.addApplicationTags(appId, tagNames); List<String> applicationTags = applicationManager.addApplicationTags(appId, tagNames);
String msg = "New tags are added successfully, for application which has application ID: " + appId +"."; return Response.status(Response.Status.OK).entity(applicationTags).build();
return Response.status(Response.Status.OK).entity(msg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg); log.error(msg);

@ -130,9 +130,8 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
List<String> categoryNames) { List<String> categoryNames) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.addCategories(categoryNames); List<String> categories = applicationManager.addCategories(categoryNames);
String msg = "New application categories are added successfully."; return Response.status(Response.Status.OK).entity(categories).build();
return Response.status(Response.Status.OK).entity(msg).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg); log.error(msg);

@ -80,7 +80,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE(
UPDATED_AT TIMESTAMP NOT NULL, UPDATED_AT TIMESTAMP NOT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL, AP_APP_ID INTEGER NOT NULL,
REASON VARCHAR(45) NULL, REASON TEXT DEFAULT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_AP_APP_LIFECYCLE_STATE_AP_APP_RELEASE1 CONSTRAINT fk_AP_APP_LIFECYCLE_STATE_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID) FOREIGN KEY (AP_APP_RELEASE_ID)

Loading…
Cancel
Save