Improve ent app release updating flow

4.x.x
lasanthaDLPDS 6 years ago
parent e846207a49
commit 51fbee445f

@ -21,7 +21,6 @@ package org.wso2.carbon.device.application.mgt.common.services;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.Filter;
@ -32,7 +31,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.response.Category;
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.EntAppReleaseWrapper;
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;
@ -53,7 +52,7 @@ public interface ApplicationManager {
* @return {@link Application}
* @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException}
*/
Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact)
Application createEntApp(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
@ -169,36 +168,33 @@ public interface ApplicationManager {
* To update release images.
*
* @param deviceType Application artifact compatible device type name.
* @param appType Type of the application.
* @param uuid uuid of the ApplicationDTO
* @param applicationArtifact Application artifact that contains names and input streams of the application artifacts.
* @throws ApplicationManagementException ApplicationDTO Management Exception.
*/
void updateApplicationArtifact(String deviceType, String appType, String uuid,
void updateApplicationArtifact(String deviceType, String uuid,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/**
* To create an application release for an ApplicationDTO.
*
* @param applicationId ID of the ApplicationDTO
* @param applicationReleaseWrapper ApplicatonRelease that need to be be created.
* @param entAppReleaseWrapper ApplicatonRelease that need to be be created.
* @return the unique id of the application release, if the application release succeeded else -1
*/
ApplicationRelease createEntAppRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper,
ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/***
*
* @param deviceType Device type which is supported for the Application.
* @param applicationType Application Type
* @param releaseUuid UUID of the application release.
* @param applicationReleaseWrapper {@link ApplicationReleaseDTO}
* @param entAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
boolean updateRelease(String deviceType, String applicationType, String releaseUuid,
ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/***
* To validate the application creating request

@ -58,12 +58,11 @@ public interface ApplicationStorageManager {
* To upload release artifacts for an ApplicationDTO.
*
* @param applicationRelease ApplicationDTO Release Object.
* @param appType ApplicationDTO Type.
* @param deviceType Compatible device tipe of the application.
* @param binaryFile Binary File for the release.
* @throws ResourceManagementException Resource Management Exception.
*/
ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationRelease, String appType, String deviceType,
ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationRelease, String deviceType,
InputStream binaryFile) throws ResourceManagementException;
/**

@ -76,11 +76,11 @@ public class ApplicationWrapper {
@NotNull
private String deviceType;
@ApiModelProperty(name = "applicationReleaseWrappers",
@ApiModelProperty(name = "entAppReleaseWrappers",
value = "List of application releases",
required = true)
@NotNull
private List<ApplicationReleaseWrapper> applicationReleaseWrappers;
private List<EntAppReleaseWrapper> entAppReleaseWrappers;
public String getName() {
@ -107,10 +107,10 @@ public class ApplicationWrapper {
public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; }
public List<ApplicationReleaseWrapper> getApplicationReleaseWrappers() { return applicationReleaseWrappers; }
public List<EntAppReleaseWrapper> getEntAppReleaseWrappers() { return entAppReleaseWrappers; }
public void setApplicationReleaseWrappers(List<ApplicationReleaseWrapper> applicationReleaseWrappers) {
this.applicationReleaseWrappers = applicationReleaseWrappers; }
public void setEntAppReleaseWrappers(List<EntAppReleaseWrapper> entAppReleaseWrappers) {
this.entAppReleaseWrappers = entAppReleaseWrappers; }
public List<String> getUnrestrictedRoles() { return unrestrictedRoles; }

@ -22,7 +22,7 @@ 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 {
public class EntAppReleaseWrapper {
@ApiModelProperty(name = "description",
value = "Description of the application release")

@ -157,11 +157,11 @@ public interface ApplicationReleaseDAO {
/**
* To verify whether application release exist or not for the given app release version.
*
* @param appId ID of the application.
* @param releaseUuid ID of the application.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
String getPackageName(int appId, int tenantId) throws ApplicationManagementDAOException;
String getPackageName(String releaseUuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To verify whether application release exist or not for given application release uuid.

@ -602,39 +602,39 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
}
@Override
public String getPackageName(int appId, int tenantId) throws ApplicationManagementDAOException {
public String getPackageName(String releaseUuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting package name of the application release by application id:" + appId);
log.debug("Getting package name of the application release by application id:" + releaseUuid);
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "SELECT AR.PACKAGE_NAME AS PACKAGE_NAME FROM AP_APP_RELEASE AS AR WHERE AR.AP_APP_ID = ? "
+ "AND AR.TENANT_ID = ? LIMIT 1;";
String sql = "SELECT "
+ "AR.PACKAGE_NAME AS PACKAGE_NAME "
+ "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.UUID = ? "
+ "AND AR.TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId);
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setString(1, releaseUuid);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
try (ResultSet rs = stmt.executeQuery()){
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved package name of the application release with the application ID "
+ appId);
log.debug("Successfully retrieved package name of the application release with the UUID: "
+ releaseUuid);
}
if (rs.next()){
return rs.getString("PACKAGE_NAME");
}
return null;
}
}
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting package name of the application release with app ID: " + appId, e);
"Error occurred while getting package name of the application release with app ID: " + releaseUuid, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection to get application release package name.", e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
}
}

@ -56,7 +56,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Category;
import org.wso2.carbon.device.application.mgt.common.response.Tag;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
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;
@ -131,7 +131,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public Application createApplication(ApplicationWrapper applicationWrapper,
public Application createEntApp(ApplicationWrapper applicationWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -143,8 +143,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
//uploading application artifacts
try {
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
if (!isValidOsVersions(applicationReleaseDTO.getSupportedOsVersions(), applicationWrapper.getDeviceType())) {
String msg = "You are trying to create application which has an application release contains invalid or "
@ -153,16 +151,93 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
applicationWrapper.getDeviceType(), applicationReleaseDTO, applicationArtifact, false);
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact);
//uploading application artifacts
applicationReleaseDTO = uploadEntAppReleaseArtifacts(applicationReleaseDTO, applicationArtifact,
applicationWrapper.getDeviceType(), false);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return addAppDataIntoDB(applicationDTO, tenantId);
}
@Override
public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (log.isDebugEnabled()) {
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();
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
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 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 (!isValidOsVersions(publicAppWrapper.getPublicAppReleaseWrappers().get(0).getSupportedOsVersions(),
publicAppWrapper.getDeviceType())) {
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.";
log.error(msg);
throw new BadRequestException(msg);
}
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 application: " + applicationWrapper.getName();
String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName();
log.error(msg);
throw new ApplicationManagementException(msg, e);
}
//insert application data into database
return addAppDataIntoDB(applicationDTO, tenantId);
}
@ -178,7 +253,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
private ApplicationReleaseDTO addApplicationReleaseArtifacts(String applicationType, String deviceType,
private ApplicationReleaseDTO addApplicationReleaseArtifacts(String deviceType,
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease)
throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -188,7 +263,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setUuid(uuid);
// The application executable artifacts such as apks are uploaded.
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
@ -222,16 +296,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (this.applicationReleaseDAO
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
throw new BadRequestException(
"Application release exists for the uploaded binary file. Application Type: "
+ applicationType + " Device Type: " + deviceType);
"Application release exists for the uploaded binary file. Device Type: " + deviceType);
}
applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationReleaseDTO = applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO,applicationType,
deviceType, binaryDuplicate);
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
}
}
} catch (IOException e) {
@ -252,23 +324,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
} finally {
ConnectionManagerUtil.closeDBConnection();
}
} else if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION);
applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl());
// Since WEB CLIP doesn't have an installer, set uuid as has value for WEB CLIP
applicationReleaseDTO.setAppHashValue(uuid);
}
return applicationReleaseDTO;
}
private ApplicationReleaseDTO updateApplicationReleaseArtifacts(String applicationType, String deviceType,
private ApplicationReleaseDTO updateEntAppReleaseArtifact(String deviceType,
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
// The application executable artifacts such as apks are uploaded.
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
@ -276,8 +341,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
String md5OfApp = StorageManagementUtil.getMD5(binaryClone);
if (md5OfApp == null) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ applicationReleaseDTO.getUuid();
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
+ "release UUID " + applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
@ -287,62 +352,63 @@ public class ApplicationManagerImpl implements ApplicationManager {
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(binary, deviceType);
String packagename = applicationInstaller.getPackageName();
String packageName = applicationInstaller.getPackageName();
try {
ConnectionManagerUtil.getDBConnection();
if (applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId,
lifecycleStateManager.getEndState())) {
String msg = "Application release is already exist for the package name: " + packagename +
". 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 "
+ "application.";
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg = "Same binary file is in the server. Hence you can't add same file into the "
+ "server. Device Type: " + deviceType + " and package name: " + packageName;
log.error(msg);
throw new BadRequestException(msg);
}
if (applicationReleaseDTO.getPackageName() == null){
String msg = "Found null value for application release package name for application "
+ "release which has UUID: " + applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationManagementException(msg);
}
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packagename);
if (this.applicationReleaseDAO
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
throw new BadRequestException(
"Application release exists for the uploaded binary file. Application Type: "
+ applicationType + " Device Tyep: " + deviceType);
if (!applicationReleaseDTO.getPackageName().equals(packageName)){
String msg = "Package name of the new artifact does not match with the package name of "
+ "the exiting application release. Package name of the existing app release "
+ applicationReleaseDTO.getPackageName() + " and package name of the new "
+ "application release " + packageName;
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO.setAppHashValue(md5OfApp);
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packageName);
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationReleaseDTO = applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO,applicationType,
deviceType, binaryDuplicate);
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO);
}
}
}
}
} 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) {
String msg = "Error occurred when getting database connection for verifying application package existence.";
String msg = "Error occurred when getting database connection for verifying application "
+ "release existing for new app hash value.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when executing the query for verifying application release existence for "
+ "the package.";
String msg = "Error occurred when executing the query for verifying application release "
+ "existence for the new app hash value.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
} else if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION);
applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl());
}
}
}
} 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;
}
@ -380,13 +446,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationArtifact applicationArtifact) throws ResourceManagementException{
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
//todo check again
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO);
if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
}
if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
applicationReleaseDTO.setScreenshotName1(null);
applicationReleaseDTO.setScreenshotName2(null);
applicationReleaseDTO.setScreenshotName3(null);
}
Map<String, InputStream> screenshots = applicationArtifact.getScreenshots();
List<String> screenshotNames = new ArrayList<>(screenshots.keySet());
@ -410,87 +478,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
return applicationReleaseDTO;
}
@Override
public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (log.isDebugEnabled()) {
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();
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
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 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 (!isValidOsVersions(publicAppWrapper.getPublicAppReleaseWrappers().get(0).getSupportedOsVersions(),
publicAppWrapper.getDeviceType())) {
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.";
log.error(msg);
throw new BadRequestException(msg);
}
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);
}
//insert application data into database
return addAppDataIntoDB(applicationDTO, tenantId);
}
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -745,7 +732,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public ApplicationRelease createEntAppRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper,
public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationRelease applicationRelease;
@ -764,14 +751,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg);
}
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
if (!isValidOsVersions(applicationReleaseWrapper.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 "
+ "the supportedOsVersions section. Hence, please re-evaluate the request payload.";
log.error(msg);
throw new BadRequestException(msg);
}
ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper,
applicationDTO, applicationArtifact, deviceType.getName());
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper),
applicationArtifact, deviceType.getName(), true);
ConnectionManagerUtil.beginDBTransaction();
String initialstate = lifecycleStateManager.getInitialState();
applicationReleaseDTO.setCurrentState(initialstate);
@ -829,18 +817,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper,
ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact, String deviceTypeName)
private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO,
ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease)
throws ApplicationManagementException {
try {
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
deviceTypeName, APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
true);
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO,
applicationArtifact, isNewRelease);
return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
} catch (ResourceManagementException e) {
String msg =
"Error occurred while uploading application release artifacts. Application ID: " + applicationDTO
.getId();
String msg = "Error occurred while uploading application release artifacts.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
}
}
@ -1310,7 +1296,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public void updateApplicationArtifact(String deviceType, String appType, String uuid,
public void updateApplicationArtifact(String deviceType, String uuid,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean isValidDeviceType = false;
@ -1338,15 +1324,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
if (applicationReleaseDTO == null) {
String msg = "Couldn't found an application release for UUID: " + uuid;
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't found an application which has application release for UUID: " + uuid;
log.error(msg);
throw new NotFoundException(msg);
}
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
String msg = "If Application type is " + applicationDTO.getType() + ", then you don't have application "
+ "release artifact to update for application release UUID: " + uuid;
log.error(msg);
throw new ApplicationManagementException(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);
}
applicationReleaseDTO = updateApplicationReleaseArtifacts(appType, deviceType, applicationReleaseDTO,
applicationArtifact);
applicationReleaseDTO = updateEntAppReleaseArtifact(deviceType,applicationReleaseDTO
, applicationArtifact);
applicationReleaseDTO = this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
if (applicationReleaseDTO == null) {
ConnectionManagerUtil.rollbackDBTransaction();
@ -2105,22 +2107,21 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid,
ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
public boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
.getReleaseByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
if (applicationReleaseDTO == null) {
String msg = "Couldn't found an application release for updating. Application release UUID: " + releaseUuid;
if (applicationDTO == null) {
String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
log.error(msg);
throw new NotFoundException(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, "
@ -2131,15 +2132,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
DeviceType deviceTypeObj = getDeviceTypeData(deviceType);
Double price = applicationReleaseWrapper.getPrice();
String applicationSubType = this.applicationDAO.getApplicationSubTypeByUUID(releaseUuid, tenantId);
if (applicationSubType == null) {
String msg = "Couldn't find an application subscription type for the application release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg);
}
Double price = entAppReleaseWrapper.getPrice();
String applicationSubType = applicationDTO.getSubType();
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType))
|| (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
throw new BadRequestException(
@ -2150,7 +2145,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setPrice(price);
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
String supportedOSVersions = applicationReleaseWrapper.getSupportedOsVersions();
String supportedOSVersions = entAppReleaseWrapper.getSupportedOsVersions();
if (!StringUtils.isEmpty(supportedOSVersions)) {
if (!isValidOsVersions(supportedOSVersions, deviceType)){
String msg = "You are trying to update application release which has invalid or unsupported OS "
@ -2159,18 +2154,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg); }
applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions);
}
if (!StringUtils.isEmpty(applicationReleaseWrapper.getDescription())) {
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription());
if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) {
applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription());
}
if (!StringUtils.isEmpty(applicationReleaseWrapper.getReleaseType())) {
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType());
if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) {
applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType());
}
if (!StringUtils.isEmpty(applicationReleaseWrapper.getMetaData())) {
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData());
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
}
applicationReleaseDTO = updateApplicationReleaseArtifacts(applicationType, deviceTypeObj.getName(),
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
applicationReleaseDTO = updateEntAppReleaseArtifact(deviceTypeObj.getName(),
applicationReleaseDTO, applicationArtifact);
}
applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact);
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null;
@ -2232,10 +2229,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
deviceTypeId = deviceType.getId();
List<ApplicationReleaseWrapper> applicationReleaseWrappers;
applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers();
List<EntAppReleaseWrapper> entAppReleaseWrappers;
entAppReleaseWrappers = applicationWrapper.getEntAppReleaseWrappers();
if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) {
if (entAppReleaseWrappers == null || entAppReleaseWrappers.size() != 1) {
String msg = "Invalid application creating request. Application creating request must have single "
+ "application release. Application name:" + applicationWrapper.getName() + ".";
log.error(msg);
@ -2402,9 +2399,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg);
}
if (param instanceof ApplicationReleaseWrapper) {
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param;
if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())) {
if (param instanceof EntAppReleaseWrapper) {
EntAppReleaseWrapper entAppReleaseWrapper = (EntAppReleaseWrapper) param;
if (StringUtils.isEmpty(entAppReleaseWrapper.getSupportedOsVersions())) {
String msg = "Supported OS Version shouldn't be null or empty.";
log.error(msg);
throw new BadRequestException(msg);

@ -73,7 +73,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
}
@Override
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, InputStream iconFileStream,
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, InputStream iconFileStream,
InputStream bannerFileStream, List<InputStream> screenShotStreams)
throws ResourceManagementException {
String artifactDirectoryPath;
@ -82,15 +82,15 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String scStoredLocation = null;
try {
artifactDirectoryPath = storagePath + applicationRelease.getAppHashValue();
artifactDirectoryPath = storagePath + applicationReleaseDTO.getAppHashValue();
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
iconStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getIconName();
bannerStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getBannerName();
if (iconFileStream != null) {
iconStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getIconName();
saveFile(iconFileStream, iconStoredLocation);
}
if (bannerFileStream != null) {
bannerStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getBannerName();
saveFile(bannerFileStream, bannerStoredLocation);
}
if (!screenShotStreams.isEmpty()) {
@ -103,22 +103,22 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
int count = 1;
for (InputStream screenshotStream : screenShotStreams) {
if (count == 1) {
scStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getScreenshotName1();
scStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getScreenshotName1();
}
if (count == 2) {
scStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getScreenshotName2();
scStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getScreenshotName2();
}
if (count == 3) {
scStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getScreenshotName3();
scStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getScreenshotName3();
}
saveFile(screenshotStream, scStoredLocation);
count++;
}
}
return applicationRelease;
return applicationReleaseDTO;
} catch (IOException e) {
throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " +
"the application " + applicationRelease.getUuid(), e);
"the application " + applicationReleaseDTO.getUuid(), e);
}
}
@ -192,7 +192,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
}
@Override
public ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO, String appType,
public ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO,
String deviceType, InputStream binaryFile) throws ResourceManagementException {
try {
String artifactDirectoryPath;

@ -24,14 +24,13 @@ 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;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
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.EntAppReleaseWrapper;
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;
@ -237,7 +236,7 @@ public class APIUtil {
applicationDTO.setTags(applicationWrapper.getTags());
applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles());
applicationDTO.setDeviceTypeId(deviceType.getId());
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers()
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getEntAppReleaseWrappers()
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
} else if (param instanceof WebAppWrapper){
@ -274,14 +273,14 @@ public class APIUtil {
public static <T> ApplicationReleaseDTO releaseWrapperToReleaseDTO(T param){
ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO();
if (param instanceof ApplicationReleaseWrapper){
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param;
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription());
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType());
applicationReleaseDTO.setPrice(applicationReleaseWrapper.getPrice());
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData());
applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions());
if (param instanceof EntAppReleaseWrapper){
EntAppReleaseWrapper entAppReleaseWrapper = (EntAppReleaseWrapper) param;
applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription());
applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType());
applicationReleaseDTO.setPrice(entAppReleaseWrapper.getPrice());
applicationReleaseDTO.setIsSharedWithAllTenants(entAppReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
applicationReleaseDTO.setSupportedOsVersions(entAppReleaseWrapper.getSupportedOsVersions());
} else if (param instanceof WebAppReleaseWrapper){
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription());

@ -13,7 +13,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease
import org.wso2.carbon.device.application.mgt.common.response.Category;
import org.wso2.carbon.device.application.mgt.common.response.Tag;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
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.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.core.BaseTestCase;
@ -72,17 +72,17 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationWrapper.setTags(tags);
applicationWrapper.setPaymentCurrency("USD");
List<ApplicationReleaseWrapper> applicationReleaseWrappers = new ArrayList<>();
ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper();
List<EntAppReleaseWrapper> entAppReleaseWrappers = new ArrayList<>();
EntAppReleaseWrapper releaseWrapper = new EntAppReleaseWrapper();
releaseWrapper.setDescription("First release");
releaseWrapper.setIsSharedWithAllTenants(false);
releaseWrapper.setMetaData("Just meta data");
releaseWrapper.setReleaseType("free");
releaseWrapper.setPrice(5.7);
releaseWrapper.setSupportedOsVersions("4.0-7.0");
applicationReleaseWrappers.add(releaseWrapper);
entAppReleaseWrappers.add(releaseWrapper);
applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers);
applicationWrapper.setEntAppReleaseWrappers(entAppReleaseWrappers);
ApplicationArtifact applicationArtifact = new ApplicationArtifact();
applicationArtifact.setBannerName("My First Banner");
@ -102,7 +102,7 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationArtifact.setScreenshots(screenshots);
ApplicationManager manager = new ApplicationManagerImpl();
manager.createApplication(applicationWrapper, applicationArtifact);
manager.createEntApp(applicationWrapper, applicationArtifact);
}
@Test
@ -171,12 +171,12 @@ public class ApplicationManagementTest extends BaseTestCase {
}
@Test
public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
public ApplicationRelease createRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
return null;
}
@Test
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
return false;
}
@ -186,7 +186,7 @@ public class ApplicationManagementTest extends BaseTestCase {
}
@Test
public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException {
public void validateReleaseCreatingRequest(EntAppReleaseWrapper entAppReleaseWrapper, String applicationType) throws RequestValidatingException {
}

@ -39,7 +39,7 @@ import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
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;
@ -507,7 +507,7 @@ public interface ApplicationManagementPublisherAPI {
name = "applicationRelease",
value = "The application release that need to be created.",
required = true)
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@ApiParam(
name = "binaryFile",
value = "Binary file of uploading application",
@ -651,7 +651,7 @@ public interface ApplicationManagementPublisherAPI {
);
@PUT
@Path("/app-artifacts/{deviceType}/{appType}/{appId}/{uuid}")
@Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA})
@ApiOperation(
@ -690,11 +690,6 @@ public interface ApplicationManagementPublisherAPI {
value = "Type of the device i.e Android, IOS etc",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "appType",
value = "Type of the application i.e ENTERPRISE, PUBLIC, WEB, WEB-CLIP etc",
required = true)
@PathParam("appType") String appType,
@ApiParam(
name = "uuid",
value = "UUID of the application",
@ -704,7 +699,7 @@ public interface ApplicationManagementPublisherAPI {
);
@PUT
@Path("/app-release/{deviceType}/{appType}/{uuid}")
@Path("/app-release/{deviceType}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -735,30 +730,24 @@ public interface ApplicationManagementPublisherAPI {
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response updateApplicationRelease(
Response updateEntAppRelease(
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "appType",
value = "Type of the application",
required = true)
@PathParam("appType") String appType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",
required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "applicationReleaseWrapper",
name = "entAppReleaseWrapper",
value = "Application release wrapper which is going to update.",
required = true)
@Multipart(
value = "applicationReleaseWrapper",
type = "application/json")
ApplicationReleaseWrapper applicationReleaseWrapper,
value = "entAppReleaseWrapper",
type = "application/json") EntAppReleaseWrapper entAppReleaseWrapper,
@ApiParam(
name = "binaryFile",
value = "Application installer file.",

@ -29,7 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease
import org.wso2.carbon.device.application.mgt.common.response.Category;
import org.wso2.carbon.device.application.mgt.common.response.Tag;
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.EntAppReleaseWrapper;
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;
@ -178,12 +178,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
applicationManager.validateAppCreatingRequest(applicationWrapper);
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0));
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getEntAppReleaseWrappers().get(0));
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Ent App
Application application = applicationManager.createApplication(applicationWrapper,
Application application = applicationManager.createEntApp(applicationWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
@ -284,7 +284,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/ent-app/{appId}")
public Response createEntAppRelease(
@PathParam("appId") int appId,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@ -294,12 +294,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper);
applicationManager.validateReleaseCreatingRequest(entAppReleaseWrapper);
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Ent App release
ApplicationRelease release = applicationManager.createEntAppRelease(appId, applicationReleaseWrapper,
ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
if (release != null) {
return Response.status(Response.Status.CREATED).entity(release).build();
@ -358,24 +358,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override
@PUT
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA})
@Path("/app-artifact/{deviceType}/{appType}/{uuid}")
@Path("/ent-app-artifact/{deviceType}//{uuid}")
public Response updateApplicationArtifact(
@PathParam("deviceType") String deviceType,
@PathParam("appType") String appType,
@PathParam("uuid") String applicationReleaseUuid,
@Multipart("binaryFile") Attachment binaryFile) {
try {
if (!ApplicationType.ENTERPRISE.toString().equals(appType)) {
String msg = "If Application type is " + appType + ", then you don't have application release artifact "
+ "to update for application release UUID: " + applicationReleaseUuid;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ApplicationManager applicationManager = APIUtil.getApplicationManager();
//todo check again
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid,
applicationManager.updateApplicationArtifact(deviceType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null));
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application release. UUID is "
@ -422,25 +414,21 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override
@PUT
@Path("/app-release/{deviceType}/{appType}/{uuid}")
public Response updateApplicationRelease(
@Path("/app-release/{deviceType}/{uuid}")
public Response updateEntAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("appType") String appType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
@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 {
//todo check again
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
if (!applicationManager.updateEntAppRelease(deviceType, applicationUUID, entAppReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
@ -467,10 +455,6 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
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();
} catch (RequestValidatingException e) {
String msg = "Error occurred while updating the application release in the file system";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@ -818,7 +802,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationArtifact.setBannerStream(bannerStream);
}
if (attachmentList != null) {
if (attachmentList != null && !attachmentList.isEmpty()) {
Map<String, InputStream> scrrenshotData = new TreeMap<>();
for (Attachment sc : attachmentList) {
dataHandler = sc.getDataHandler();

Loading…
Cancel
Save