Improve web clip registering in APPM

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 0ae7479d49
commit 28bc9f3a77

@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common;
* Application Types. * Application Types.
*/ */
public enum ApplicationType { public enum ApplicationType {
ENTERPRISE, PUBLIC, WEB, WEB_CLIP ENTERPRISE, PUBLIC, WEB_APP, WEB_CLIP
} }

@ -35,7 +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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import java.util.List; import java.util.List;
@ -54,7 +54,7 @@ public interface ApplicationManager {
Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException, RequestValidatingException; throws ApplicationManagementException, RequestValidatingException;
Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**

@ -19,17 +19,22 @@ package org.wso2.carbon.device.application.mgt.common.wrapper;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; 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") @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
public class WebClipReleaseWrapper { public class WebAppReleaseWrapper {
@ApiModelProperty(name = "description", @ApiModelProperty(name = "description",
value = "Description of the web clip release") value = "Description of the web clip release")
@NotNull
private String description; private String description;
@ApiModelProperty(name = "releaseType", @ApiModelProperty(name = "releaseType",
value = "Release type of the web clip release", value = "Release type of the web clip release",
required = true, required = true,
example = "alpha, beta etc") example = "alpha, beta etc")
@NotNull
private String releaseType; private String releaseType;
@ApiModelProperty(name = "price", @ApiModelProperty(name = "price",
@ -40,6 +45,7 @@ public class WebClipReleaseWrapper {
@ApiModelProperty(name = "isSharedWithAllTenants", @ApiModelProperty(name = "isSharedWithAllTenants",
value = "If web clip release is shared with all tenants it is equal to 1 otherwise 0", value = "If web clip release is shared with all tenants it is equal to 1 otherwise 0",
required = true) required = true)
@NotNull
private boolean isSharedWithAllTenants; private boolean isSharedWithAllTenants;
@ApiModelProperty(name = "metaData", @ApiModelProperty(name = "metaData",
@ -47,8 +53,15 @@ public class WebClipReleaseWrapper {
required = true) required = true)
private String metaData; private String metaData;
@ApiModelProperty(name = "version",
value = "Version of the web app release.",
required = true)
@NotNull
private String version;
@ApiModelProperty(name = "url", @ApiModelProperty(name = "url",
value = "URL which is used for WEB-CLIP") value = "URL which is used for WEB-CLIP")
@NotNull
private String url; private String url;
public String getReleaseType() { public String getReleaseType() {
@ -94,4 +107,12 @@ public class WebClipReleaseWrapper {
public String getDescription() { return description; } public String getDescription() { return description; }
public void setDescription(String description) { this.description = 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; }
} }

@ -19,33 +19,45 @@ package org.wso2.carbon.device.application.mgt.common.wrapper;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@ApiModel(value = "WebClipWrapper", description = "WebClipWrapper represents an ApplicationDTO in ApplicationDTO Store") @ApiModel(value = "WebAppWrapper", description = "WebAppWrapper represents an ApplicationDTO in ApplicationDTO Store")
public class WebClipWrapper { public class WebAppWrapper {
@ApiModelProperty(name = "name", @ApiModelProperty(name = "name",
value = "Name of the web clip", value = "Name of the web clip",
required = true) required = true)
@NotNull
private String name; private String name;
@ApiModelProperty(name = "description", @ApiModelProperty(name = "description",
value = "Description of the web clip", value = "Description of the web clip",
required = true) required = true)
@NotNull
private String description; private String description;
@ApiModelProperty(name = "categories", @ApiModelProperty(name = "categories",
value = "List of Categories", value = "List of Categories",
required = true, required = true,
example = "Educational, Gaming, Travel, Entertainment etc") example = "Educational, Gaming, Travel, Entertainment etc")
@NotNull
private List<String> categories; private List<String> categories;
@ApiModelProperty(name = "subType", @ApiModelProperty(name = "subType",
value = "Subscription method of the web clip", value = "Subscription method of the web clip",
required = true, required = true,
example = "PAID, FREE") example = "PAID, FREE")
@NotNull
private String subMethod; private String subMethod;
@ApiModelProperty(name = "Web App Type",
value = "Type of the web app",
required = true,
example = "WEB_APP, WEB_CLIP")
@NotNull
private String type;
@ApiModelProperty(name = "paymentCurrency", @ApiModelProperty(name = "paymentCurrency",
value = "Payment currency of the web clip", value = "Payment currency of the web clip",
required = true, required = true,
@ -54,16 +66,19 @@ public class WebClipWrapper {
@ApiModelProperty(name = "tags", @ApiModelProperty(name = "tags",
value = "List of tags") value = "List of tags")
@NotNull
private List<String> tags; private List<String> tags;
@ApiModelProperty(name = "unrestrictedRoles", @ApiModelProperty(name = "unrestrictedRoles",
value = "List of roles that users should have to view the web clip") value = "List of roles that users should have to view the web clip")
@NotNull
private List<String> unrestrictedRoles; private List<String> unrestrictedRoles;
@ApiModelProperty(name = "applicationReleaseWrappers", @ApiModelProperty(name = "applicationReleaseWrappers",
value = "List of web clip releases", value = "List of web clip releases",
required = true) required = true)
private List<WebClipReleaseWrapper> webClipReleaseWrappers; @NotNull
private List<WebAppReleaseWrapper> webAppReleaseWrappers;
public String getName() { public String getName() {
return name; return name;
@ -87,10 +102,10 @@ public class WebClipWrapper {
public void setDescription(String description) { this.description = description; } public void setDescription(String description) { this.description = description; }
public List<WebClipReleaseWrapper> getWebClipReleaseWrappers() { return webClipReleaseWrappers; } public List<WebAppReleaseWrapper> getWebAppReleaseWrappers() { return webAppReleaseWrappers; }
public void setWebClipReleaseWrappers(List<WebClipReleaseWrapper> webClipReleaseWrappers) { public void setWebAppReleaseWrappers(List<WebAppReleaseWrapper> webAppReleaseWrappers) {
this.webClipReleaseWrappers = webClipReleaseWrappers; } this.webAppReleaseWrappers = webAppReleaseWrappers; }
public List<String> getCategories() { return categories; } public List<String> getCategories() { return categories; }
@ -99,4 +114,8 @@ public class WebClipWrapper {
public String getSubMethod() { return subMethod; } public String getSubMethod() { return subMethod; }
public void setSubMethod(String subMethod) { this.subMethod = subMethod; } public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
} }

@ -1028,7 +1028,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Connection conn; Connection conn;
String sql = "UPDATE " + String sql = "UPDATE " +
"AP_APP_CATEGORY cat " + "AP_APP_CATEGORY cat " +
"SET cat.CATEGORY_NAME = ? " + "SET cat.CATEGORY = ? " +
"WHERE " + "WHERE " +
"cat.ID = ? AND " + "cat.ID = ? AND " +
"cat.TENANT_ID = ?"; "cat.TENANT_ID = ?";

@ -58,8 +58,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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
@ -622,7 +622,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
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();
@ -632,7 +632,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
List<Integer> categoryIds; List<Integer> categoryIds;
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webClipWrapper); ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles();
List<String> tags = applicationDTO.getTags(); List<String> tags = applicationDTO.getTags();
List<String> categories = applicationDTO.getAppCategories(); List<String> categories = applicationDTO.getAppCategories();
@ -645,7 +645,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while getting data which is related to application. application name: " String msg = "Error occurred while getting data which is related to application. application name: "
+ webClipWrapper.getName() + "."; + webAppWrapper.getName() + ".";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
@ -665,7 +665,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error Occured when uploading artifacts of the application: " + webClipWrapper.getName(); String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName();
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
@ -748,7 +748,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = String msg =
"Error occurred while adding lifecycle state. application name: " + webClipWrapper.getName() + "."; "Error occurred while adding lifecycle state. application name: " + webAppWrapper.getName() + ".";
log.error(msg); log.error(msg);
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts( applicationStorageManager.deleteAllApplicationReleaseArtifacts(
@ -764,13 +764,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while adding application or application release. application name: " String msg = "Error occurred while adding application or application release. application name: "
+ webClipWrapper.getName() + "."; + webAppWrapper.getName() + ".";
log.error(msg); log.error(msg);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (LifecycleManagementException e) { } catch (LifecycleManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred when getting initial lifecycle state. application name: " + webClipWrapper String msg = "Error occurred when getting initial lifecycle state. application name: " + webAppWrapper
.getName() + "."; .getName() + ".";
log.error(msg); log.error(msg);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
@ -782,7 +782,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} catch (VisibilityManagementDAOException e) { } catch (VisibilityManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = String msg =
"Error occurred while adding unrestricted roles. application name: " + webClipWrapper.getName() "Error occurred while adding unrestricted roles. application name: " + webAppWrapper.getName()
+ "."; + ".";
log.error(msg); log.error(msg);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
@ -2489,37 +2489,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} else if (param instanceof WebClipWrapper) { } else if (param instanceof WebAppWrapper) {
WebClipWrapper webClipWrapper = (WebClipWrapper) param; WebAppWrapper webAppWrapper = (WebAppWrapper) param;
if (StringUtils.isEmpty(webClipWrapper.getName())) { if (StringUtils.isEmpty(webAppWrapper.getName())) {
String msg = "Web Clip name cannot be empty."; String msg = "Web Clip name cannot be empty.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
if (webClipWrapper.getCategories() == null) { if (webAppWrapper.getCategories() == null) {
String msg = "Web Clip category can't be null."; String msg = "Web Clip category can't be null.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
if (webClipWrapper.getCategories().isEmpty()) { if (webAppWrapper.getCategories().isEmpty()) {
String msg = "Web clip category can't be empty."; String msg = "Web clip category can't be empty.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
List<WebClipReleaseWrapper> webClipReleaseWrappers; List<WebAppReleaseWrapper> webAppReleaseWrappers;
webClipReleaseWrappers = webClipWrapper.getWebClipReleaseWrappers(); webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers();
if (webClipReleaseWrappers == null || webClipReleaseWrappers.size() != 1) { if (webAppReleaseWrappers == null || webAppReleaseWrappers.size() != 1) {
String msg = "Invalid web clip creating request. Web clip creating request must have single " String msg = "Invalid web clip creating request. Web clip creating request must have single "
+ "web clip release. Web clip name:" + webClipWrapper.getName() + "."; + "web clip release. Web clip name:" + webAppWrapper.getName() + ".";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
List<String> unrestrictedRoles = webClipWrapper.getUnrestrictedRoles(); List<String> unrestrictedRoles = webAppWrapper.getUnrestrictedRoles();
if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
if (!isValidRestrictedRole(unrestrictedRoles)) { if (!isValidRestrictedRole(unrestrictedRoles)) {
@ -2538,7 +2538,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
Filter filter = new Filter(); Filter filter = new Filter();
filter.setFullMatch(true); filter.setFullMatch(true);
filter.setAppName(webClipWrapper.getName().trim()); filter.setAppName(webAppWrapper.getName().trim());
filter.setOffset(0); filter.setOffset(0);
filter.setLimit(1); filter.setLimit(1);
List<ApplicationDTO> applicationList = applicationDAO.getApplications(filter, -1, tenantId); List<ApplicationDTO> applicationList = applicationDAO.getApplications(filter, -1, tenantId);
@ -2551,7 +2551,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId); List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
List<String> appCategories = webClipWrapper.getCategories(); List<String> appCategories = webAppWrapper.getCategories();
if (registeredCategories.isEmpty()) { if (registeredCategories.isEmpty()) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -2583,7 +2583,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while getting data which is related to web clip. web clip name: " String msg = "Error occurred while getting data which is related to web clip. web clip name: "
+ webClipWrapper.getName() + "."; + webAppWrapper.getName() + ".";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
@ -2614,16 +2614,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} if (param instanceof WebClipReleaseWrapper){ } if (param instanceof WebAppReleaseWrapper){
WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
UrlValidator urlValidator = new UrlValidator(); UrlValidator urlValidator = new UrlValidator();
if (StringUtils if (StringUtils
.isEmpty(webClipReleaseWrapper.getUrl())){ .isEmpty(webAppReleaseWrapper.getUrl())){
String msg = "URL should't be null for the application release creating request for application type WEB_CLIP"; String msg = "URL should't be null for the application release creating request for application type WEB_CLIP";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
if (!urlValidator.isValid(webClipReleaseWrapper.getUrl())){ if (!urlValidator.isValid(webAppReleaseWrapper.getUrl())){
String msg = "Request payload contains an invalid Web Clip URL."; String msg = "Request payload contains an invalid Web Clip URL.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);

@ -30,8 +30,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.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; 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.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
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.UnexpectedServerErrorException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
@ -235,16 +235,17 @@ public class APIUtil {
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers()
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
} else if (param instanceof WebClipWrapper){ } else if (param instanceof WebAppWrapper){
WebClipWrapper webClipWrapper = (WebClipWrapper) param; WebAppWrapper webAppWrapper = (WebAppWrapper) param;
applicationDTO.setName(webClipWrapper.getName()); applicationDTO.setName(webAppWrapper.getName());
applicationDTO.setDescription(webClipWrapper.getDescription()); applicationDTO.setDescription(webAppWrapper.getDescription());
applicationDTO.setAppCategories(webClipWrapper.getCategories()); applicationDTO.setAppCategories(webAppWrapper.getCategories());
applicationDTO.setSubType(webClipWrapper.getSubMethod()); applicationDTO.setSubType(webAppWrapper.getSubMethod());
applicationDTO.setPaymentCurrency(webClipWrapper.getPaymentCurrency()); applicationDTO.setPaymentCurrency(webAppWrapper.getPaymentCurrency());
applicationDTO.setTags(webClipWrapper.getTags()); applicationDTO.setType(webAppWrapper.getType());
applicationDTO.setUnrestrictedRoles(webClipWrapper.getUnrestrictedRoles()); applicationDTO.setTags(webAppWrapper.getTags());
List<ApplicationReleaseDTO> applicationReleaseEntities = webClipWrapper.getWebClipReleaseWrappers() applicationDTO.setUnrestrictedRoles(webAppWrapper.getUnrestrictedRoles());
List<ApplicationReleaseDTO> applicationReleaseEntities = webAppWrapper.getWebAppReleaseWrappers()
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
} }
@ -262,14 +263,15 @@ public class APIUtil {
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants()); applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData());
applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions()); applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions());
} else if (param instanceof WebClipReleaseWrapper){ } else if (param instanceof WebAppReleaseWrapper){
WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
applicationReleaseDTO.setDescription(webClipReleaseWrapper.getDescription()); applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription());
applicationReleaseDTO.setReleaseType(webClipReleaseWrapper.getReleaseType()); applicationReleaseDTO.setReleaseType(webAppReleaseWrapper.getReleaseType());
applicationReleaseDTO.setPrice(webClipReleaseWrapper.getPrice()); applicationReleaseDTO.setVersion(webAppReleaseWrapper.getVersion());
applicationReleaseDTO.setInstallerName(webClipReleaseWrapper.getUrl()); applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice());
applicationReleaseDTO.setIsSharedWithAllTenants(webClipReleaseWrapper.getIsSharedWithAllTenants()); applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl());
applicationReleaseDTO.setMetaData(webClipReleaseWrapper.getMetaData()); applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData());
} }
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@ -278,7 +280,11 @@ public class APIUtil {
throws BadRequestException, UnexpectedServerErrorException { throws BadRequestException, UnexpectedServerErrorException {
Application application = new Application(); Application application = new Application();
//This is for handling web-apps
if (applicationDTO.getDeviceTypeId() > 0) {
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
application.setDeviceType(deviceType.getName());
}
application.setId(applicationDTO.getId()); application.setId(applicationDTO.getId());
application.setName(applicationDTO.getName()); application.setName(applicationDTO.getName());
application.setDescription(applicationDTO.getDescription()); application.setDescription(applicationDTO.getDescription());
@ -288,7 +294,6 @@ public class APIUtil {
application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setPaymentCurrency(applicationDTO.getPaymentCurrency());
application.setTags(applicationDTO.getTags()); application.setTags(applicationDTO.getTags());
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
application.setDeviceType(deviceType.getName());
application.setRating(applicationDTO.getAppRating()); application.setRating(applicationDTO.getAppRating());
List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs() List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs()
.stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList()); .stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList());

@ -24,8 +24,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.json.JSONException; import org.json.JSONException;
@ -60,6 +62,12 @@ public class HandlerUtil {
} else if (httpMethod instanceof HttpGet) { } else if (httpMethod instanceof HttpGet) {
HttpGet method = (HttpGet) httpMethod; HttpGet method = (HttpGet) httpMethod;
response = client.execute(method); response = client.execute(method);
} else if (httpMethod instanceof HttpPut) {
HttpPut method = (HttpPut) httpMethod;
response = client.execute(method);
} else if (httpMethod instanceof HttpDelete) {
HttpDelete method = (HttpDelete) httpMethod;
response = client.execute(method);
} }
ProxyResponse proxyResponse = new ProxyResponse(); ProxyResponse proxyResponse = new ProxyResponse();

@ -42,7 +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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
@ -375,7 +375,7 @@ public interface ApplicationManagementPublisherAPI {
name = "webapp", name = "webapp",
value = "The web app that need to be created.", value = "The web app that need to be created.",
required = true) required = true)
@Multipart("webapp") WebClipWrapper webClipWrapper, @Multipart("webapp") WebAppWrapper webAppWrapper,
@ApiParam( @ApiParam(
name = "icon", name = "icon",
value = "Icon of the uploading web app", value = "Icon of the uploading web app",

@ -32,7 +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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; 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.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.exception.UnexpectedServerErrorException;
@ -209,7 +209,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Consumes("multipart/mixed") @Consumes("multipart/mixed")
@Path("/web-app") @Path("/web-app")
public Response createWebApp( public Response createWebApp(
@Multipart("webapp") WebClipWrapper webClipWrapper, @Multipart("webapp") WebAppWrapper webAppWrapper,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1, @Multipart("screenshot1") Attachment screenshot1,
@ -218,12 +218,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(webClipWrapper); applicationManager.validateAppCreatingRequest(webAppWrapper);
applicationManager.validateReleaseCreatingRequest(webClipWrapper.getWebClipReleaseWrappers().get(0)); applicationManager.validateReleaseCreatingRequest(webAppWrapper.getWebAppReleaseWrappers().get(0));
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new application entry // Created new application entry
Application application = applicationManager.createWebClip(webClipWrapper, Application application = applicationManager.createWebClip(webAppWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(null, iconFile, bannerFile, attachmentList));
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();

@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_RELEASE(
APP_HASH_VALUE VARCHAR(1000) NOT NULL, APP_HASH_VALUE VARCHAR(1000) NOT NULL,
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
APP_META_INFO CLOB NULL DEFAULT NULL, APP_META_INFO CLOB NULL DEFAULT NULL,
SUPPORTED_OS_VERSIONS VARCHAR(45) NOT NULL, SUPPORTED_OS_VERSIONS VARCHAR(45) NULL DEFAULT NULL,
RATING DOUBLE NULL DEFAULT NULL, RATING DOUBLE NULL DEFAULT NULL,
CURRENT_STATE VARCHAR(45) NOT NULL, CURRENT_STATE VARCHAR(45) NOT NULL,
RATED_USERS INTEGER NULL, RATED_USERS INTEGER NULL,

Loading…
Cancel
Save