Merge branch 'application-mgt-new' of https://gitlab.com/entgra/carbon-device-mgt into application-mgt-new

feature/appm-store/pbac
Jayasanka 6 years ago
commit 1ab3cd0c2b

@ -35,11 +35,11 @@ public class Application {
required = true) required = true)
private String description; private String description;
@ApiModelProperty(name = "appCategories", @ApiModelProperty(name = "categories",
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 List<String> appCategories; private List<String> categories;
@ApiModelProperty(name = "type", @ApiModelProperty(name = "type",
value = "Type of the application", value = "Type of the application",
@ -47,11 +47,11 @@ public class Application {
example = "ENTERPRISE, PUBLIC, WEB, WEB_CLIP etc") example = "ENTERPRISE, PUBLIC, WEB, WEB_CLIP etc")
private String type; private String type;
@ApiModelProperty(name = "subType", @ApiModelProperty(name = "subMethod",
value = "Subscription type of the application", value = "Subscription type of the application",
required = true, required = true,
example = "PAID, FREE") example = "PAID, FREE")
private String subType; private String subMethod;
@ApiModelProperty(name = "paymentCurrency", @ApiModelProperty(name = "paymentCurrency",
value = "Payment currency of the application", value = "Payment currency of the application",
@ -92,12 +92,12 @@ public class Application {
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public List<String> getAppCategories() { public List<String> getCategories() {
return appCategories; return categories;
} }
public void setAppCategories(List<String> appCategories) { public void setCategories(List<String> categories) {
this.appCategories = appCategories; this.categories = categories;
} }
public List<String> getTags() { return tags; } public List<String> getTags() { return tags; }
@ -108,9 +108,9 @@ public class Application {
public void setType(String type) { this.type = type; } public void setType(String type) { this.type = type; }
public String getSubType() { return subType; } public String getSubMethod() { return subMethod; }
public void setSubType(String subType) { this.subType = subType; } public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
public String getPaymentCurrency() { return paymentCurrency; } public String getPaymentCurrency() { return paymentCurrency; }

@ -34,7 +34,9 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag;
import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
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.PublicAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; 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.common.wrapper.WebAppWrapper;
import java.util.List; import java.util.List;
@ -196,6 +198,12 @@ public interface ApplicationManager {
boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updatePubAppRelease(String deviceType, String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updateWebAppRelease(String deviceType, String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/*** /***
* To validate the application creating request * To validate the application creating request
* *

@ -38,20 +38,20 @@ public class ApplicationWrapper {
@NotNull @NotNull
private String description; private String description;
@ApiModelProperty(name = "appCategories", @ApiModelProperty(name = "categories",
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")
@NotNull @NotNull
private List<String> appCategories; private List<String> categories;
@ApiModelProperty(name = "subType", @ApiModelProperty(name = "subMethod",
value = "Subscription type of the application", value = "Subscription type of the application",
required = true, required = true,
example = "PAID, FREE") example = "PAID, FREE")
@NotNull @NotNull
private String subType; private String subMethod;
@ApiModelProperty(name = "paymentCurrency", @ApiModelProperty(name = "paymentCurrency",
value = "Payment currency of the application", value = "Payment currency of the application",
@ -89,19 +89,19 @@ public class ApplicationWrapper {
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public List<String> getAppCategories() { return appCategories; } public List<String> getCategories() { return categories; }
public void setAppCategories(List<String> appCategories) { public void setCategories(List<String> categories) {
this.appCategories = appCategories; this.categories = categories;
} }
public List<String> getTags() { return tags; } public List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; } public void setTags(List<String> tags) { this.tags = tags; }
public String getSubType() { return subType; } public String getSubMethod() { return subMethod; }
public void setSubType(String subType) { this.subType = subType; } public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
public String getPaymentCurrency() { return paymentCurrency; } public String getPaymentCurrency() { return paymentCurrency; }

@ -101,6 +101,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -275,11 +276,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
.getAppInstallerData(binary, deviceType); .getAppInstallerData(binary, deviceType);
String packagename = applicationInstaller.getPackageName(); String packagename = applicationInstaller.getPackageName();
ConnectionManagerUtil.getDBConnection(); try {
if (!isNewRelease && applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId, ConnectionManagerUtil.openDBConnection();
if (!isNewRelease && applicationReleaseDAO
.isActiveReleaseExisitForPackageName(packagename, tenantId,
lifecycleStateManager.getEndState())) { lifecycleStateManager.getEndState())) {
String msg = "Application release is already exist for the package name: " + packagename + String msg = "Application release is already exist for the package name: " + packagename
". Either you can delete all application releases for package " + packagename + " or " + ". Either you can delete all application releases for package " + packagename + " or "
+ "you can add this app release as an new application release, under the existing " + "you can add this app release as an new application release, under the existing "
+ "application."; + "application.";
log.error(msg); log.error(msg);
@ -295,37 +298,38 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ApplicationStorageManagementException(msg); throw new ApplicationStorageManagementException(msg);
} }
if (this.applicationReleaseDAO if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) { String msg =
throw new BadRequestException( "Application release exists for the uploaded binary file. Device Type: " + deviceType;
"Application release exists for the uploaded binary file. Device Type: " + deviceType); log.error(msg);
throw new BadRequestException(msg);
} }
applicationReleaseDTO.setAppHashValue(md5OfApp); applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate); .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
} }
}
} catch (IOException e) {
String msg =
"Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
.getInstallerName();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application package existence."; String msg = "Error occurred when getting database connection for verifying app release data.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when executing the query for verifying application release existence for " String msg =
"Error occurred when executing the query for verifying application release existence for "
+ "the package."; + "the package.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
}
} catch (IOException e) {
String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
.getInstallerName();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@ -749,31 +753,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper, public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationRelease applicationRelease;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Application release creating request is received for the application id: " + applicationId); log.debug("Application release creating request is received for the application id: " + applicationId);
} }
ApplicationDTO applicationDTO = getApplication(applicationId); ApplicationDTO applicationDTO = getApplication(applicationId);
try {
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) { if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
String msg = String msg = "It is possible to add new application release for " + ApplicationType.ENTERPRISE.toString()
"It is possible to add new application release for " + ApplicationType.ENTERPRISE.toString() + " app type. But you are requesting to add new application release for " + applicationDTO.getType()
+ " app type. But you are requesting to add new application release for " + " app type.";
+ applicationDTO.getType() + " app type.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
if (!isValidOsVersions(entAppReleaseWrapper.getSupportedOsVersions(), deviceType.getName())){ if (!isValidOsVersions(entAppReleaseWrapper.getSupportedOsVersions(), deviceType.getName())) {
String msg = "You are trying to add application release which has invalid or unsupported OS versions in " String msg = "You are trying to add application release which has invalid or unsupported OS versions in "
+ "the supportedOsVersions section. Hence, please re-evaluate the request payload."; + "the supportedOsVersions section. Hence, please re-evaluate the request payload.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts( ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(),
applicationArtifact, deviceType.getName(), true); true);
try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
String initialstate = lifecycleStateManager.getInitialState(); String initialstate = lifecycleStateManager.getInitialState();
applicationReleaseDTO.setCurrentState(initialstate); applicationReleaseDTO.setCurrentState(initialstate);
@ -782,7 +785,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId); .createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
this.lifecycleStateDAO this.lifecycleStateDAO
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO); ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return applicationRelease; return applicationRelease;
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
@ -2132,67 +2135,145 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
if (applicationDTO == null) { AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid; applicationDTO.getApplicationReleaseDTOs().get(0));
log.error(msg); validateAppReleaseUpdating(applicationDTO, ApplicationType.ENTERPRISE.toString());
throw new NotFoundException(msg); applicationReleaseDTO.get().setPrice(entAppReleaseWrapper.getPrice());
applicationReleaseDTO.get().setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants());
if (!StringUtils.isEmpty(entAppReleaseWrapper.getSupportedOsVersions())) {
applicationReleaseDTO.get().setSupportedOsVersions(entAppReleaseWrapper.getSupportedOsVersions());
} }
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) { if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) {
String msg = "You trying to perform enterprise app release update on non-enterprise app release."; applicationReleaseDTO.get().setDescription(entAppReleaseWrapper.getDescription());
log.error(msg); }
throw new ForbiddenException(msg); if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) {
applicationReleaseDTO.get().setReleaseType(entAppReleaseWrapper.getReleaseType());
}
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData());
} }
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) { DeviceType deviceTypeObj = getDeviceTypeData(applicationDTO.getDeviceTypeId());
String msg = "Application release in " + applicationReleaseDTO.getCurrentState() applicationReleaseDTO
+ " state. Therefore you are not allowed to update the application release. Hence, " .set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(),
+ "please move application release from " + applicationReleaseDTO.getCurrentState() applicationArtifact));
+ " to updatable state."; }
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction();
}
ConnectionManagerUtil.commitDBTransaction();
return updateStatus;
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
String msg = "Error occured when updating application release artifact in the file system. Ent App release "
+ "UUID:" + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
} }
DeviceType deviceTypeObj = getDeviceTypeData(deviceType); @Override
Double price = entAppReleaseWrapper.getPrice(); public boolean updatePubAppRelease(String deviceType, String releaseUuid,
PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
String applicationSubType = applicationDTO.getSubType(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType)) try {
|| (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) { ConnectionManagerUtil.beginDBTransaction();
throw new BadRequestException( ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
"Invalid app release payload for updating application release. ApplicationDTO price is " + price validateAppReleaseUpdating(applicationDTO, ApplicationType.PUBLIC.toString());
+ " for " + applicationSubType + " application., Application Release UUID " AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
+ releaseUuid + " and supported device type is " + deviceType); applicationDTO.getApplicationReleaseDTOs().get(0));
}
applicationReleaseDTO.setPrice(price); applicationReleaseDTO.get().setPrice(publicAppReleaseWrapper.getPrice());
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationReleaseDTO.get().setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants());
String supportedOSVersions = entAppReleaseWrapper.getSupportedOsVersions(); if (!StringUtils.isEmpty(publicAppReleaseWrapper.getPackageName())) {
if (!StringUtils.isEmpty(supportedOSVersions)) { applicationReleaseDTO.get().setVersion(publicAppReleaseWrapper.getVersion());
if (!isValidOsVersions(supportedOSVersions, deviceType)){
String msg = "You are trying to update application release which has invalid or unsupported OS "
+ "versions in the supportedOsVersions section. Hence, please re-evaluate the request payload.";
log.error(msg);
throw new BadRequestException(msg); }
applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions);
} }
if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) { if (!StringUtils.isEmpty(publicAppReleaseWrapper.getVersion())) {
applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription()); applicationReleaseDTO.get().setVersion(publicAppReleaseWrapper.getVersion());
} }
if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) { if (!StringUtils.isEmpty(publicAppReleaseWrapper.getSupportedOsVersions())) {
applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType()); applicationReleaseDTO.get().setSupportedOsVersions(publicAppReleaseWrapper.getSupportedOsVersions());
} }
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) { if (!StringUtils.isEmpty(publicAppReleaseWrapper.getDescription())) {
applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData()); applicationReleaseDTO.get().setDescription(publicAppReleaseWrapper.getDescription());
}
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getReleaseType())) {
applicationReleaseDTO.get().setReleaseType(publicAppReleaseWrapper.getReleaseType());
}
if (!StringUtils.isEmpty(publicAppReleaseWrapper.getMetaData())) {
applicationReleaseDTO.get().setMetaData(publicAppReleaseWrapper.getMetaData());
} }
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){ applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
applicationReleaseDTO = updateEntAppReleaseArtifact(deviceTypeObj.getName(),
applicationReleaseDTO, applicationArtifact); boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction();
} }
applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact); ConnectionManagerUtil.commitDBTransaction();
return updateStatus;
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating public app release of UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
String msg = "Error occured when updating public app release artifact in the file system. Public app "
+ "release UUID:" + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public boolean updateWebAppRelease(String deviceType, String releaseUuid,
WebAppReleaseWrapper webAppReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
validateAppReleaseUpdating(applicationDTO, ApplicationType.WEB_CLIP.toString());
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null; applicationReleaseDTO.get().setPrice(webAppReleaseWrapper.getPrice());
applicationReleaseDTO.get().setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants());
if (!StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) {
applicationReleaseDTO.get().setVersion(webAppReleaseWrapper.getVersion());
}
if (!StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) {
applicationReleaseDTO.get().setVersion(webAppReleaseWrapper.getVersion());
}
if (!StringUtils.isEmpty(webAppReleaseWrapper.getDescription())) {
applicationReleaseDTO.get().setDescription(webAppReleaseWrapper.getDescription());
}
if (!StringUtils.isEmpty(webAppReleaseWrapper.getReleaseType())) {
applicationReleaseDTO.get().setReleaseType(webAppReleaseWrapper.getReleaseType());
}
if (!StringUtils.isEmpty(webAppReleaseWrapper.getMetaData())) {
applicationReleaseDTO.get().setMetaData(webAppReleaseWrapper.getMetaData());
}
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
} }
@ -2200,12 +2281,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
return updateStatus; return updateStatus;
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating Application release. ApplicationDTO ID ApplicationDTO Release " String msg = "Error occured when updating web app release for web app Release UUID: " + releaseUuid;
+ "UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error occured when updating application release artifact in the file system. Application " String msg = "Error occured when updating web app release artifact in the file system. Web app "
+ "release UUID:" + releaseUuid; + "release UUID:" + releaseUuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
@ -2214,6 +2294,50 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private void validateAppReleaseUpdating(ApplicationDTO applicationDTO, String appType) throws ApplicationManagementException {
if (applicationDTO == null) {
String msg = "Couldn't found an application for requested UUID.";
log.error(msg);
throw new NotFoundException(msg);
}
if (!appType.equals(applicationDTO.getType())) {
String msg = "You trying to perform " + appType + " app release update on " + applicationDTO.getType()
+ " app release.";
log.error(msg);
throw new ForbiddenException(msg);
}
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {
String msg = "Application release in " + applicationReleaseDTO.getCurrentState()
+ " state. Therefore you are not allowed to update the application release. Hence, "
+ "please move application release from " + applicationReleaseDTO.getCurrentState()
+ " to updatable state.";
log.error(msg);
throw new ForbiddenException(msg);
}
String applicationSubType = applicationDTO.getSubType();
double price = applicationReleaseDTO.getPrice();
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType)) || (
price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
throw new BadRequestException("Invalid app release payload for updating application release. Application "
+ "price is " + price + " for " + applicationSubType + " application.");
}
DeviceType deviceTypeObj = getDeviceTypeData(applicationDTO.getDeviceTypeId());
String supportedOSVersions = applicationReleaseDTO.getSupportedOsVersions();
if (!ApplicationType.WEB_CLIP.toString().equals(appType) && !ApplicationType.WEB_APP.toString().equals(appType)
&& !StringUtils.isEmpty(supportedOSVersions) && !isValidOsVersions(
supportedOSVersions, deviceTypeObj.getName())) {
String msg = "You are trying to update application release which has invalid or unsupported OS "
+ "versions in the supportedOsVersions section. Hence, please re-evaluate the request payload.";
log.error(msg);
throw new BadRequestException(msg);
}
}
@Override @Override
public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException { public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException {
@ -2232,7 +2356,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
appCategories = applicationWrapper.getAppCategories(); appCategories = applicationWrapper.getCategories();
if (appCategories == null) { if (appCategories == null) {
String msg = "Application category can't be null."; String msg = "Application category can't be null.";
log.error(msg); log.error(msg);

@ -229,9 +229,9 @@ public class APIUtil {
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType()); DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
applicationDTO.setName(applicationWrapper.getName()); applicationDTO.setName(applicationWrapper.getName());
applicationDTO.setDescription(applicationWrapper.getDescription()); applicationDTO.setDescription(applicationWrapper.getDescription());
applicationDTO.setAppCategories(applicationWrapper.getAppCategories()); applicationDTO.setAppCategories(applicationWrapper.getCategories());
applicationDTO.setType(ApplicationType.ENTERPRISE.toString()); applicationDTO.setType(ApplicationType.ENTERPRISE.toString());
applicationDTO.setSubType(applicationWrapper.getSubType()); applicationDTO.setSubType(applicationWrapper.getSubMethod());
applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency());
applicationDTO.setTags(applicationWrapper.getTags()); applicationDTO.setTags(applicationWrapper.getTags());
applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles());
@ -319,9 +319,9 @@ public class APIUtil {
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.setAppCategories(applicationDTO.getAppCategories()); application.setCategories(applicationDTO.getAppCategories());
application.setType(applicationDTO.getType()); application.setType(applicationDTO.getType());
application.setSubType(applicationDTO.getSubType()); application.setSubMethod(applicationDTO.getSubType());
application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setPaymentCurrency(applicationDTO.getPaymentCurrency());
application.setTags(applicationDTO.getTags()); application.setTags(applicationDTO.getTags());
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());

@ -58,12 +58,12 @@ public class ApplicationManagementTest extends BaseTestCase {
List<String> categories = new ArrayList<>(); List<String> categories = new ArrayList<>();
categories.add("Test Category"); categories.add("Test Category");
applicationWrapper.setAppCategories(categories); applicationWrapper.setCategories(categories);
applicationWrapper.setDescription("Test Description"); applicationWrapper.setDescription("Test Description");
applicationWrapper.setDeviceType("android"); applicationWrapper.setDeviceType("android");
applicationWrapper.setName("Test Application"); applicationWrapper.setName("Test Application");
applicationWrapper.setSubType("Test Sub type"); applicationWrapper.setSubMethod("Test Sub type");
List<String> tags = new ArrayList<>(); List<String> tags = new ArrayList<>();
tags.add("abc"); tags.add("abc");

@ -42,7 +42,9 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease
import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
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.PublicAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; 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.common.wrapper.WebAppWrapper;
import java.util.List; import java.util.List;
@ -747,8 +749,78 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "binaryFile") Attachment binaryFile, @Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam( @ApiParam(
name = "icon", name = "icon",
value = "Icon file of the application release.", value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT
@Path("/pub-app-release/{deviceType}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Update an public app release",
notes = "This will update the public app release",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully update an app release.",
response = ApplicationReleaseDTO.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Public app release updating payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response updatePubAppRelease(
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",
required = true) required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "pubAppReleaseWrapper",
value = "Application release wrapper which is going to update.",
required = true)
@Multipart(
value = "pubAppReleaseWrapper",
type = "application/json") PublicAppReleaseWrapper publicAppReleaseWrapper,
@ApiParam(
name = "icon",
value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile, @Multipart(value = "icon") Attachment iconFile,
@ApiParam( @ApiParam(
name = "banner", name = "banner",
@ -756,8 +828,78 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "banner") Attachment bannerFile, @Multipart(value = "banner") Attachment bannerFile,
@ApiParam( @ApiParam(
name = "screenshot1", name = "screenshot1",
value = "First screenshot of the uploading application", value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT
@Path("/web-app-release/{deviceType}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Update an public app release",
notes = "This will update the public app release",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully update an app release.",
response = ApplicationReleaseDTO.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Public app release updating payload contains unacceptable or vulnerable data"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response updateWebAppRelease(
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",
required = true) required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "pubAppReleaseWrapper",
value = "Application release wrapper which is going to update.",
required = true)
@Multipart(
value = "pubAppReleaseWrapper",
type = "application/json") WebAppReleaseWrapper webAppReleaseWrapper,
@ApiParam(
name = "icon",
value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1, @Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam( @ApiParam(
name = "screenshot2", name = "screenshot2",

@ -32,7 +32,9 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
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.PublicAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; 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.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;
@ -454,6 +456,96 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
@Override
@PUT
@Path("/public-app-release/{deviceType}/{uuid}")
public Response updatePubAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
if (!applicationManager.updatePubAppRelease(deviceType, applicationUUID, publicAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update application release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application or application release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the application release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Path("/web-app-release/{deviceType}/{uuid}")
public Response updateWebAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
if (!applicationManager.updateWebAppRelease(deviceType, applicationUUID, webAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update application release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application or application release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the application release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT @PUT
@Path("/retire/{appId}") @Path("/retire/{appId}")

Loading…
Cancel
Save