Add APPM public app support

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent be7c1005f6
commit 3179653b6a

@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag;
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.common.wrapper.PublicAppWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import java.util.List;
@ -57,6 +58,9 @@ public interface ApplicationManager {
Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
/**
* Updates an already existing application.
*
@ -226,7 +230,7 @@ public interface ApplicationManager {
void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList)
throws RequestValidatingException;
void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException;
void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException;
void addAplicationCategories(List<String> categories) throws ApplicationManagementException;

@ -19,27 +19,33 @@ package org.wso2.carbon.device.application.mgt.common.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
public class ApplicationReleaseWrapper {
@ApiModelProperty(name = "description",
value = "Description of the application release")
@NotNull
private String description;
@ApiModelProperty(name = "releaseType",
value = "Release type of the application release",
required = true,
example = "alpha, beta etc")
@NotNull
private String releaseType;
@ApiModelProperty(name = "price",
value = "Price of the application release",
required = true)
@NotNull
private Double price;
@ApiModelProperty(name = "isSharedWithAllTenants",
value = "If application release is shared with all tenants it is eqal to 1 otherwise 0",
required = true)
@NotNull
private boolean isSharedWithAllTenants;
@ApiModelProperty(name = "metaData",
@ -49,6 +55,7 @@ public class ApplicationReleaseWrapper {
@ApiModelProperty(name = "supportedOsVersions",
value = "ApplicationDTO release supported OS versions")
@NotNull
private String supportedOsVersions;
public String getReleaseType() {

@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.common.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.util.List;
@ApiModel(value = "ApplicationWrapper", description = "ApplicationWrapper represents the an ApplicationDTO in ApplicationDTO Store")
@ -28,29 +29,28 @@ public class ApplicationWrapper {
@ApiModelProperty(name = "name",
value = "Name of the application",
required = true)
@NotNull
private String name;
@ApiModelProperty(name = "description",
value = "Description of the application",
required = true)
@NotNull
private String description;
@ApiModelProperty(name = "appCategories",
value = "CategoryDTO of the application",
required = true,
example = "Educational, Gaming, Travel, Entertainment etc")
@NotNull
private List<String> appCategories;
@ApiModelProperty(name = "type",
value = "Type of the application",
required = true,
example = "ENTERPRISE, PUBLIC, WEB, WEB_CLIP etc")
private String type;
@ApiModelProperty(name = "subType",
value = "Subscription type of the application",
required = true,
example = "PAID, FREE")
@NotNull
private String subType;
@ApiModelProperty(name = "paymentCurrency",
@ -61,21 +61,25 @@ public class ApplicationWrapper {
@ApiModelProperty(name = "tags",
value = "List of application tags")
@NotNull
private List<String> tags;
@ApiModelProperty(name = "unrestrictedRoles",
value = "List of roles that users should have to access the application")
@NotNull
private List<String> unrestrictedRoles;
@ApiModelProperty(name = "deviceType",
value = "Related device type of the application",
required = true,
example = "IoS, Android, Arduino, RaspberryPi etc")
@NotNull
private String deviceType;
@ApiModelProperty(name = "applicationReleaseWrappers",
value = "List of application releases",
required = true)
@NotNull
private List<ApplicationReleaseWrapper> applicationReleaseWrappers;
@ -95,10 +99,6 @@ public class ApplicationWrapper {
public void setTags(List<String> tags) { this.tags = tags; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public String getSubType() { return subType; }
public void setSubType(String subType) { this.subType = subType; }

@ -0,0 +1,124 @@
/* 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.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@ApiModel(value = "Public App Release Wrapper", description = "This class holds the details when releasing an Public App"
+ " Release to application store")
public class PublicAppReleaseWrapper {
@ApiModelProperty(name = "description",
value = "Description of the public app release")
@NotNull
private String description;
@ApiModelProperty(name = "releaseType",
value = "Release type of the public app release",
required = true,
example = "alpha, beta etc")
@NotNull
private String releaseType;
@ApiModelProperty(name = "price",
value = "Price of the public app release",
required = true)
private Double price;
@ApiModelProperty(name = "isSharedWithAllTenants",
value = "If public app release is shared with all tenants it is equal to 1 otherwise 0",
required = true)
@NotNull
private boolean isSharedWithAllTenants;
@ApiModelProperty(name = "metaData",
value = "Meta data of the public app release",
required = true)
private String metaData;
@ApiModelProperty(name = "version",
value = "Version of the public app release.",
required = true)
@NotNull
private String version;
@ApiModelProperty(name = "packageName",
value = "Package name of the public app release.",
required = true)
@NotNull
private String packageName;
@ApiModelProperty(name = "supportedOsVersions",
value = "ApplicationDTO release supported OS versions")
@NotNull
private String supportedOsVersions;
public String getReleaseType() {
return releaseType;
}
public void setReleaseType(String releaseType) {
this.releaseType = releaseType;
}
public void setIsSharedWithAllTenants(boolean isSharedWithAllTenants) {
this.isSharedWithAllTenants = isSharedWithAllTenants;
}
public void setMetaData(String metaData) {
this.metaData = metaData;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public boolean getIsSharedWithAllTenants() {
return isSharedWithAllTenants;
}
public String getMetaData() {
return metaData;
}
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; }
public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; }
public String getVersion() { return version; }
public void setVersion(String version) { this.version = version; }
public String getPackageName() { return packageName; }
public void setPackageName(String packageName) { this.packageName = packageName; }
public String getSupportedOsVersions() { return supportedOsVersions; }
public void setSupportedOsVersions(String supportedOsVersions) { this.supportedOsVersions = supportedOsVersions; }
}

@ -0,0 +1,121 @@
/* 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.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.util.List;
@ApiModel(value = "PublicAppWrapper", description = "PublicAppWrapper represents an Application in App Store")
public class PublicAppWrapper {
@ApiModelProperty(name = "name",
value = "Name of the public app",
required = true)
@NotNull
private String name;
@ApiModelProperty(name = "description",
value = "Description of the public app",
required = true)
@NotNull
private String description;
@ApiModelProperty(name = "categories",
value = "List of Categories",
required = true,
example = "Educational, Gaming, Travel, Entertainment etc")
@NotNull
private List<String> categories;
@ApiModelProperty(name = "subType",
value = "Subscription method of the public app",
required = true,
example = "PAID, FREE")
@NotNull
private String subMethod;
@ApiModelProperty(name = "deviceType",
value = "Related device type of the public app",
required = true,
example = "IoS, Android, Arduino, RaspberryPi etc")
@NotNull
private String deviceType;
@ApiModelProperty(name = "paymentCurrency",
value = "Payment currency of the web clip",
required = true,
example = "$")
private String paymentCurrency;
@ApiModelProperty(name = "tags",
value = "List of tags")
@NotNull
private List<String> tags;
@ApiModelProperty(name = "unrestrictedRoles",
value = "List of roles that users should have to view the public app")
@NotNull
private List<String> unrestrictedRoles;
@ApiModelProperty(name = "applicationReleaseWrappers",
value = "List of public app releases",
required = true)
@NotNull
private List<PublicAppReleaseWrapper> publicAppReleaseWrappers;
public String getName() {
return name;
}
public void setName(String name) { this.name = name; }
public List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; }
public String getDeviceType() { return deviceType; }
public void setDeviceType(String deviceType) { this.deviceType = deviceType; }
public String getPaymentCurrency() { return paymentCurrency; }
public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; }
public List<String> getUnrestrictedRoles() { return unrestrictedRoles; }
public void setUnrestrictedRoles(List<String> unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public List<PublicAppReleaseWrapper> getPublicAppReleaseWrappers() { return publicAppReleaseWrappers; }
public void setPublicAppReleaseWrappers(List<PublicAppReleaseWrapper> publicAppReleaseWrappers) {
this.publicAppReleaseWrappers = publicAppReleaseWrappers; }
public List<String> getCategories() { return categories; }
public void setCategories(List<String> categories) { this.categories = categories; }
public String getSubMethod() { return subMethod; }
public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
}

@ -21,7 +21,6 @@ import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
//todo add version attribute
@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
public class WebAppReleaseWrapper {

@ -549,7 +549,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
sql += "GROUP_NAME = ? ";
}
sql += "AND AP_APP_RELEASE_ID = ? AND AND TENANT_ID = ?";
sql += "AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
Calendar calendar = Calendar.getInstance();

@ -29,6 +29,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
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.DeviceTypes;
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration;
@ -58,6 +59,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
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.common.wrapper.PublicAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
@ -414,13 +417,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (log.isDebugEnabled()) {
log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : "
log.debug("Web clip create request is received for the tenant : " + tenantId + " From" + " the user : "
+ userName);
}
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
String uuid = UUID.randomUUID().toString();
//todo check installer name exists or not, do it in the validation method
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
applicationReleaseDTO.setUuid(uuid);
applicationReleaseDTO.setAppHashValue(md5);
@ -430,7 +434,49 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
} catch (ResourceManagementException e) {
String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName();
String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName();
log.error(msg);
throw new ApplicationManagementException(msg, e);
}
//insert application data into database
return addAppDataIntoDB(applicationDTO, tenantId);
}
@Override
public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String publicAppStorePath = "";
if (log.isDebugEnabled()) {
log.debug("Public app creating request is received for the tenant : " + tenantId + " From" + " the user : "
+ userName);
}
if (DeviceTypes.ANDROID.toString().equals(publicAppWrapper.getDeviceType())) {
publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL;
} else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) {
publicAppStorePath = Constants.APPLE_STORE_URL;
}
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(publicAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
String uuid = UUID.randomUUID().toString();
String appInstallerUrl = publicAppStorePath + applicationReleaseDTO.getPackageName();
//todo check app package name exist or not, do it in validation method
applicationReleaseDTO.setInstallerName(appInstallerUrl);
String md5 = DigestUtils.md5Hex(appInstallerUrl);
applicationReleaseDTO.setUuid(uuid);
applicationReleaseDTO.setAppHashValue(md5);
//uploading application artifacts
try {
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs()
.add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
} catch (ResourceManagementException e) {
String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName();
log.error(msg);
throw new ApplicationManagementException(msg, e);
}
@ -2255,11 +2301,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(applicationWrapper.getType())) {
String msg = "Application type can't be empty.";
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(applicationWrapper.getDeviceType())) {
String msg = "Device type can't be empty for the application.";
log.error(msg);
@ -2273,8 +2314,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) {
String msg = "Invalid application creating request. Application creating request must have single "
+ "application release. Application name:" + applicationWrapper.getName() + " and type: "
+ applicationWrapper.getType();
+ "application release. Application name:" + applicationWrapper.getName() + ".";
log.error(msg);
throw new BadRequestException(msg);
}
@ -2298,6 +2338,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(webAppWrapper.getType()) || (!ApplicationType.WEB_CLIP.toString()
.equals(webAppWrapper.getType()) && !ApplicationType.WEB_APP.toString()
.equals(webAppWrapper.getType()))) {
String msg = "Web app wrapper contains invalid application type with the request. Hence please verify "
+ "the request payload..";
log.error(msg);
throw new BadRequestException(msg);
}
List<WebAppReleaseWrapper> webAppReleaseWrappers;
webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers();
@ -2309,6 +2357,43 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg);
}
unrestrictedRoles = webAppWrapper.getUnrestrictedRoles();
} else if (param instanceof PublicAppWrapper) {
PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param;
appName = publicAppWrapper.getName();
if (StringUtils.isEmpty(appName)) {
String msg = "Application name cannot be empty for public app.";
log.error(msg);
throw new BadRequestException(msg);
}
appCategories = publicAppWrapper.getCategories();
if (appCategories == null) {
String msg = "Application category can't be null.";
log.error(msg);
throw new BadRequestException(msg);
}
if (appCategories.isEmpty()) {
String msg = "Application category can't be empty.";
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(publicAppWrapper.getDeviceType())) {
String msg = "Device type can't be empty for the public application.";
log.error(msg);
throw new BadRequestException(msg);
}
DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType());
deviceTypeId = deviceType.getId();
List<PublicAppReleaseWrapper> publicAppReleaseWrappers;
publicAppReleaseWrappers = publicAppWrapper.getPublicAppReleaseWrappers();
if (publicAppReleaseWrappers == null || publicAppReleaseWrappers.size() != 1) {
String msg = "Invalid public app creating request. Request must have single release. Application name:"
+ publicAppWrapper.getName() + ".";
log.error(msg);
throw new BadRequestException(msg);
}
unrestrictedRoles = publicAppWrapper.getUnrestrictedRoles();
} else {
String msg = "Invalid payload found with the request. Hence verify the request payload object.";
log.error(msg);
@ -2390,7 +2475,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public <T> void validateReleaseCreatingRequest(T param) throws ApplicationManagementException {
if (param == null) {
String msg = "In order to validate release creating request param shouldn't be null.";
log.error(msg);
@ -2399,18 +2483,23 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (param instanceof ApplicationReleaseWrapper) {
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param;
if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())) {
String msg = "Supported OS Version shouldn't be null or empty.";
log.error(msg);
throw new BadRequestException(msg);
}
} if (param instanceof WebAppReleaseWrapper){
}
if (param instanceof WebAppReleaseWrapper) {
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
UrlValidator urlValidator = new UrlValidator();
if (StringUtils
.isEmpty(webAppReleaseWrapper.getUrl())){
String msg = "URL should't be null for the application release creating request for application type WEB_CLIP";
if (StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) {
String msg = "Version shouldn't be empty or null for the WEB CLIP release creating request.";
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(webAppReleaseWrapper.getUrl())) {
String msg = "URL should't be null for the application release creating request for application type "
+ "WEB_CLIP";
log.error(msg);
throw new BadRequestException(msg);
}
@ -2419,6 +2508,29 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg);
throw new BadRequestException(msg);
}
} else if (param instanceof PublicAppReleaseWrapper) {
PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param;
if (StringUtils.isEmpty(publicAppReleaseWrapper.getSupportedOsVersions())) {
String msg = "Supported OS Version shouldn't be null or empty for public app release creating request.";
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(publicAppReleaseWrapper.getVersion())) {
String msg = "Version shouldn't be empty or null for the Public App release creating request.";
log.error(msg);
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(publicAppReleaseWrapper.getPackageName())) {
String msg = "Package name shouldn't be empty or null for the Public App release creating request.";
log.error(msg);
throw new BadRequestException(msg);
}
} else {
String msg = "Invalid payload found with the release creating request. Hence verify the release creating "
+ "request payload object.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
}
@ -2431,6 +2543,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg);
throw new RequestValidatingException(msg);
}
//todo remove this check, because banner is not mandatory to have
if (bannerFile == null) {
String msg = "Banner file is not found with the application release creating request.";
log.error(msg);
@ -2444,21 +2557,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException {
public void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException {
if (StringUtils.isEmpty(applicationType)) {
String msg = "Application type can't be empty.";
log.error(msg);
throw new RequestValidatingException(msg);
}
if (!isValidAppType(applicationType)) {
String msg = "App Type contains in the application creating payload doesn't match with supported app types.";
log.error(msg);
throw new RequestValidatingException(msg);
}
if (binaryFile == null && ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
String msg = "Binary file is not found with the application release creating request. ApplicationDTO type: "
+ applicationType;
if (binaryFile == null) {
String msg = "Binary file is not found with the application release creating request for ENTERPRISE app "
+ "creating request.";
log.error(msg);
throw new RequestValidatingException(msg);
}

@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
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.Application;
@ -32,6 +33,8 @@ import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
@ -228,7 +231,7 @@ public class APIUtil {
applicationDTO.setName(applicationWrapper.getName());
applicationDTO.setDescription(applicationWrapper.getDescription());
applicationDTO.setAppCategories(applicationWrapper.getAppCategories());
applicationDTO.setType(applicationWrapper.getType());
applicationDTO.setType(ApplicationType.ENTERPRISE.toString());
applicationDTO.setSubType(applicationWrapper.getSubType());
applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency());
applicationDTO.setTags(applicationWrapper.getTags());
@ -250,8 +253,22 @@ public class APIUtil {
List<ApplicationReleaseDTO> applicationReleaseEntities = webAppWrapper.getWebAppReleaseWrappers()
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
} else if (param instanceof PublicAppWrapper) {
PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param;
DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType());
applicationDTO.setName(publicAppWrapper.getName());
applicationDTO.setDescription(publicAppWrapper.getDescription());
applicationDTO.setAppCategories(publicAppWrapper.getCategories());
applicationDTO.setType(ApplicationType.PUBLIC.toString());
applicationDTO.setSubType(publicAppWrapper.getSubMethod());
applicationDTO.setPaymentCurrency(publicAppWrapper.getPaymentCurrency());
applicationDTO.setTags(publicAppWrapper.getTags());
applicationDTO.setUnrestrictedRoles(publicAppWrapper.getUnrestrictedRoles());
applicationDTO.setDeviceTypeId(deviceType.getId());
List<ApplicationReleaseDTO> applicationReleaseEntities = publicAppWrapper.getPublicAppReleaseWrappers()
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
}
return applicationDTO;
}
@ -273,8 +290,19 @@ public class APIUtil {
applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice());
applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl());
applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setSupportedOsVersions("ANY");
applicationReleaseDTO.setSupportedOsVersions(Constants.ANY);
applicationReleaseDTO.setPackageName(Constants.DEFAULT_PCK_NAME);
applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData());
} else if (param instanceof PublicAppReleaseWrapper) {
PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param;
applicationReleaseDTO.setDescription(publicAppReleaseWrapper.getDescription());
applicationReleaseDTO.setReleaseType(publicAppReleaseWrapper.getReleaseType());
applicationReleaseDTO.setVersion(publicAppReleaseWrapper.getVersion());
applicationReleaseDTO.setPackageName(publicAppReleaseWrapper.getPackageName());
applicationReleaseDTO.setPrice(publicAppReleaseWrapper.getPrice());
applicationReleaseDTO.setIsSharedWithAllTenants(publicAppReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setMetaData(publicAppReleaseWrapper.getMetaData());
applicationReleaseDTO.setSupportedOsVersions(publicAppReleaseWrapper.getSupportedOsVersions());
}
return applicationReleaseDTO;
}
@ -287,7 +315,7 @@ public class APIUtil {
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
application.setDeviceType(deviceType.getName());
} else {
application.setDeviceType("ANY");
application.setDeviceType(Constants.ANY);
}
application.setId(applicationDTO.getId());
application.setName(applicationDTO.getName());

@ -38,6 +38,11 @@ public class Constants {
public static final String APP_EXTENSION = ".app";
public static final String FORWARD_SLASH = "/";
public static final String ANY = "ANY";
public static final String DEFAULT_PCK_NAME = "default.app.com";
public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=";
public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";
/**
* Database types supported by Application Management.

@ -60,7 +60,6 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationWrapper.setDeviceType("android");
applicationWrapper.setName("Test Application");
applicationWrapper.setSubType("Test Sub type");
applicationWrapper.setType("ENTERPRISE");
List<String> tags = new ArrayList<>();
tags.add("abc");

@ -42,6 +42,7 @@ 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.common.wrapper.PublicAppWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import java.util.List;
@ -270,6 +271,7 @@ public interface ApplicationManagementPublisherAPI {
);
@POST
@Path("/ent-app")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("multipart/mixed")
@ApiOperation(
@ -300,7 +302,7 @@ public interface ApplicationManagementPublisherAPI {
message = "Internal Server Error. \n Error occurred while creating the application.",
response = ErrorResponse.class)
})
Response createApplication(
Response createEntApp(
@ApiParam(
name = "application",
value = "The application that need to be created.",
@ -404,9 +406,72 @@ public interface ApplicationManagementPublisherAPI {
);
@POST
@Path("/public-app")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("multipart/mixed")
@Path("/{appType}/{appId}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create an public app",
notes = "This will create a new public app",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully created a public app.",
response = ApplicationDTO.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"public app creating payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while creating the public app.",
response = ErrorResponse.class)
})
Response createPubApp(
@ApiParam(
name = "public-app",
value = "The public app that need to be created.",
required = true)
@Multipart("public-app") PublicAppWrapper publicAppWrapper,
@ApiParam(
name = "icon",
value = "Icon of the uploading public app",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading public app",
required = true)
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading public app",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading public app")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading public app")
@Multipart(value = "screenshot3") Attachment screenshot3
);
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes("multipart/mixed")
@Path("/ent-app/{appId}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
@ -435,12 +500,7 @@ public interface ApplicationManagementPublisherAPI {
message = "Internal Server Error. \n Error occurred while creating the application.",
response = ErrorResponse.class)
})
Response createRelease(
@ApiParam(
name = "appType",
value = "Application Type.",
required = true)
@PathParam("appType") String appType,
Response createEntAppRelease(
@ApiParam(
name = "appId",
value = "Id of the application.",

@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
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.common.wrapper.PublicAppWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
@ -168,7 +169,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@POST
@Consumes("multipart/mixed")
public Response createApplication(
@Path("/ent-app")
public Response createEntApp(
@Multipart("application") ApplicationWrapper applicationWrapper,
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@ -181,7 +183,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
try {
applicationManager.validateAppCreatingRequest(applicationWrapper);
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0));
applicationManager.validateBinaryArtifact(binaryFile, applicationWrapper.getType());
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new application entry
@ -245,9 +247,46 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@POST
@Consumes("multipart/mixed")
@Path("/{appType}/{appId}")
public Response createRelease(
@PathParam("appType") String appType,
@Path("/public-app")
public Response createPubApp(
@Multipart("public-app") PublicAppWrapper publicAppWrapper,
@Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
applicationManager.validateAppCreatingRequest(publicAppWrapper);
applicationManager.validateReleaseCreatingRequest(publicAppWrapper.getPublicAppReleaseWrappers().get(0));
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new application entry
Application application = applicationManager.createPublicApp(publicAppWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList));
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "Web app creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the public app.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Error occurred while handling the public app creating request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@POST
@Consumes("multipart/mixed")
@Path("/ent-app/{appId}")
public Response createEntAppRelease(
@PathParam("appId") int appId,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile,
@ -260,7 +299,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper);
applicationManager.validateBinaryArtifact(binaryFile, appType);
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new application release
@ -339,7 +378,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile, appType);
//todo check again
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null));
return Response.status(Response.Status.OK)
@ -402,7 +442,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
applicationManager.validateBinaryArtifact(binaryFile, appType);
//todo check again
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {

Loading…
Cancel
Save