Merge branch 'application-mgt-new' into 'application-mgt-new'

Add Ent App Update functionality

See merge request entgra/carbon-device-mgt!150
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
commit 73979a9c6b

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

@ -42,14 +42,6 @@ public interface ApplicationStorageManager {
ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease,
InputStream iconFile, InputStream bannerFile, List<InputStream> screenshots) throws ResourceManagementException; InputStream iconFile, InputStream bannerFile, List<InputStream> screenshots) throws ResourceManagementException;
/**
* To upload image artifacts related with an ApplicationDTO.
*
* @param applicationRelease Release of the application
* @throws ResourceManagementException Resource Management Exception.
*/
void deleteImageArtifacts(ApplicationReleaseDTO applicationRelease) throws ResourceManagementException;
ApplicationInstaller getAppInstallerData(InputStream binaryFile, String deviceType) ApplicationInstaller getAppInstallerData(InputStream binaryFile, String deviceType)
throws ApplicationStorageManagementException; throws ApplicationStorageManagementException;
@ -58,12 +50,11 @@ public interface ApplicationStorageManager {
* To upload release artifacts for an ApplicationDTO. * To upload release artifacts for an ApplicationDTO.
* *
* @param applicationRelease ApplicationDTO Release Object. * @param applicationRelease ApplicationDTO Release Object.
* @param appType ApplicationDTO Type.
* @param deviceType Compatible device tipe of the application. * @param deviceType Compatible device tipe of the application.
* @param binaryFile Binary File for the release. * @param binaryFile Binary File for the release.
* @throws ResourceManagementException Resource Management Exception. * @throws ResourceManagementException Resource Management Exception.
*/ */
ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationRelease, String appType, String deviceType, ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationRelease, String deviceType,
InputStream binaryFile) throws ResourceManagementException; InputStream binaryFile) throws ResourceManagementException;
/** /**
@ -79,10 +70,9 @@ public interface ApplicationStorageManager {
/** /**
* To delete the artifacts related with particular ApplicationDTO Release. * To delete the artifacts related with particular ApplicationDTO Release.
* *
* @param directoryPath Hash value of the application artifact.
* @throws ApplicationStorageManagementException Not Found Exception. * @throws ApplicationStorageManagementException Not Found Exception.
*/ */
void deleteApplicationReleaseArtifacts(String directoryPath) throws ApplicationStorageManagementException; void deleteAppReleaseArtifact(String appReleaseHashVal, String fileName) throws ApplicationStorageManagementException;
/** /**
* To delete all release artifacts related with particular ApplicationDTO Release. * To delete all release artifacts related with particular ApplicationDTO Release.

@ -27,6 +27,6 @@ import java.util.List;
* This interface manages all the operations related with ApplicationDTO Subscription. * This interface manages all the operations related with ApplicationDTO Subscription.
*/ */
public interface SubscriptionManager { public interface SubscriptionManager {
<T> ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List<T> params, String subType, <T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params, String subType,
String action) throws ApplicationManagementException; String action) throws ApplicationManagementException;
} }

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

@ -22,7 +22,7 @@ import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
public class ApplicationReleaseWrapper { public class EntAppReleaseWrapper {
@ApiModelProperty(name = "description", @ApiModelProperty(name = "description",
value = "Description of the application release") 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. * 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 * @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @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. * To verify whether application release exist or not for given application release uuid.

@ -67,13 +67,13 @@ public interface SubscriptionDAO {
Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int tenantId) throws Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
List<String> getSubscribedUsernames(List<String> users, int tenantId) throws List<String> getSubscribedUserNames(List<String> users, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
List<String> getSubscribedRolenames(List<String> roles, int tenantId) throws List<String> getSubscribedRoleNames(List<String> roles, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
List<String> getSubscribedGroupnames(List<String> groups, int tenantId) throws List<String> getSubscribedGroupNames(List<String> groups, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
void updateSubscriptions(int tenantId, String updateBy, List<String> paramList, void updateSubscriptions(int tenantId, String updateBy, List<String> paramList,
@ -81,5 +81,6 @@ public interface SubscriptionDAO {
List<Integer> getSubscribedDeviceIds(List<Integer> deviceIds, int tenantId) throws ApplicationManagementDAOException; List<Integer> getSubscribedDeviceIds(List<Integer> deviceIds, int tenantId) throws ApplicationManagementDAOException;
void updateDeviceSubStatus (int operationId, String status, int tenantcId) throws ApplicationManagementDAOException;
} }

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

@ -368,7 +368,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<String> getSubscribedUsernames(List<String> users, int tenantId) public List<String> getSubscribedUserNames(List<String> users, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for given list of user names."); log.debug("Request received in DAO Layer to get already subscribed users for given list of user names.");
@ -406,7 +406,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<String> getSubscribedRolenames(List<String> roles, int tenantId) public List<String> getSubscribedRoleNames(List<String> roles, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
@ -445,7 +445,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<String> getSubscribedGroupnames(List<String> groups, int tenantId) public List<String> getSubscribedGroupNames(List<String> groups, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for given list of group names."); log.debug("Request received in DAO Layer to get already subscribed groups for given list of group names.");
@ -482,7 +482,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
} }
@Override public List<Integer> getSubscribedDeviceIds(List<Integer> deviceIds, int tenantId) @Override
public List<Integer> getSubscribedDeviceIds(List<Integer> deviceIds, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received to DAO Layer to get already subscribed dvice Ids for given list of device Ids."); log.debug("Request received to DAO Layer to get already subscribed dvice Ids for given list of device Ids.");
@ -560,6 +561,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
stmt.setString(3, username); stmt.setString(3, username);
stmt.setInt(4, releaseId); stmt.setInt(4, releaseId);
stmt.setInt(5, tenantId); stmt.setInt(5, tenantId);
stmt.addBatch();
} }
stmt.executeBatch(); stmt.executeBatch();
} }
@ -573,4 +575,33 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override
public void updateDeviceSubStatus (int operationId, String status, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
try {
conn = this.getDBConnection();
String sql = "UPDATE AP_DEVICE_SUBSCRIPTION "
+ "SET STATUS = ? "
+ "WHERE "
+ "AP_APP_RELEASE_ID = (SELECT AP_DEVICE_SUBSCRIPTION_ID FROM AP_APP_SUB_OP_MAPPING WHERE OPERATION_ID = ?) "
+ "AND TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, status);
stmt.setInt(2, operationId);
stmt.setInt(3, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to update the subscription status of the "
+ "device subscription.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred when obtaining database connection for updating the subscription status of the "
+ "device subscription.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
} }

@ -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.response.Tag;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; 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.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.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.PublicAppReleaseWrapper;
@ -131,7 +131,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application createApplication(ApplicationWrapper applicationWrapper, public Application createEntApp(ApplicationWrapper applicationWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -143,29 +143,106 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper); ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
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 "
+ "unsupported OS versions in the supportedOsVersions section. Hence, please re-evaluate the "
+ "request payload.";
log.error(msg);
throw new BadRequestException(msg);
}
//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 //uploading application artifacts
try { 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 "
+ "unsupported OS versions in the supportedOsVersions section. Hence, please re-evaluate the "
+ "request payload.";
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
applicationWrapper.getDeviceType(), applicationReleaseDTO, applicationArtifact, false);
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact);
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs()
.add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
} catch (ResourceManagementException e) { } 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); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
//insert application data into database
return addAppDataIntoDB(applicationDTO, tenantId); return addAppDataIntoDB(applicationDTO, tenantId);
} }
private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException { private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
try { try {
@ -178,7 +255,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private ApplicationReleaseDTO addApplicationReleaseArtifacts(String applicationType, String deviceType, private ApplicationReleaseDTO addApplicationReleaseArtifacts(String deviceType,
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease) ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -188,7 +265,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setUuid(uuid);
// The application executable artifacts such as apks are uploaded. // The application executable artifacts such as apks are uploaded.
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
try { try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream()); byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
@ -222,16 +298,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (this.applicationReleaseDAO if (this.applicationReleaseDAO
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) { .verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
throw new BadRequestException( throw new BadRequestException(
"Application release exists for the uploaded binary file. Application Type: " "Application release exists for the uploaded binary file. Device Type: " + deviceType);
+ applicationType + " Device Type: " + deviceType);
} }
applicationReleaseDTO.setAppHashValue(md5OfApp); applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO,applicationType, .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
deviceType, binaryDuplicate);
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -251,98 +325,92 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); 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; return applicationReleaseDTO;
} }
private ApplicationReleaseDTO updateApplicationReleaseArtifacts(String applicationType, String deviceType, private ApplicationReleaseDTO updateEntAppReleaseArtifact(String deviceType,
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact) ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
// The application executable artifacts such as apks are uploaded. // The application executable artifacts such as apks are uploaded.
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) { try {
try { byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
try(ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)){ try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
String md5OfApp = StorageManagementUtil.getMD5(binaryClone); String md5OfApp = StorageManagementUtil.getMD5(binaryClone);
if (md5OfApp == null) { if (md5OfApp == null) {
String msg = "Error occurred while md5sum value retrieving process: application UUID " String msg = "Error occurred while retrieving md5sum value from the binary file for application "
+ applicationReleaseDTO.getUuid(); + "release UUID " + applicationReleaseDTO.getUuid();
log.error(msg); log.error(msg);
throw new ApplicationStorageManagementException(msg); throw new ApplicationStorageManagementException(msg);
} }
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)){ if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName()); applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
ApplicationInstaller applicationInstaller = applicationStorageManager ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(binary, deviceType); .getAppInstallerData(binary, deviceType);
String packagename = applicationInstaller.getPackageName(); String packageName = applicationInstaller.getPackageName();
try {
ConnectionManagerUtil.getDBConnection(); ConnectionManagerUtil.getDBConnection();
if (applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId, if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
lifecycleStateManager.getEndState())) { String msg = "Same binary file is in the server. Hence you can't add same file into the "
String msg = "Application release is already exist for the package name: " + packagename + + "server. Device Type: " + deviceType + " and package name: " + packageName;
". Either you can delete all application releases for package " + packagename + " or " log.error(msg);
+ "you can add this app release as an new application release, under the existing " throw new BadRequestException(msg);
+ "application."; }
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); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
applicationReleaseDTO.setVersion(applicationInstaller.getVersion()); if (!applicationReleaseDTO.getPackageName().equals(packageName)){
applicationReleaseDTO.setPackageName(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 "
if (this.applicationReleaseDAO + applicationReleaseDTO.getPackageName() + " and package name of the new "
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) { + "application release " + packageName;
throw new BadRequestException( log.error(msg);
"Application release exists for the uploaded binary file. Application Type: " throw new BadRequestException(msg);
+ applicationType + " Device Tyep: " + deviceType);
} }
applicationReleaseDTO.setAppHashValue(md5OfApp); applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packageName);
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue(); String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO,applicationType, .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate);
deviceType, binaryDuplicate);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue, applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO); applicationReleaseDTO);
} }
} catch (DBConnectionException e) {
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 new app hash value.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
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);
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application package existence.";
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.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
} }
} else if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) { } catch (IOException e) {
applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION); String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl()); .getInstallerName();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
} }
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@ -380,117 +448,50 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationArtifact applicationArtifact) throws ResourceManagementException{ ApplicationArtifact applicationArtifact) throws ResourceManagementException{
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO); if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.getIconName());
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName()); applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
applicationReleaseDTO.setScreenshotName1(null); }
applicationReleaseDTO.setScreenshotName2(null); if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){
applicationReleaseDTO.setScreenshotName3(null); applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.getBannerName());
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
}
Map<String, InputStream> screenshots = applicationArtifact.getScreenshots(); Map<String, InputStream> screenshots = applicationArtifact.getScreenshots();
List<String> screenshotNames = new ArrayList<>(screenshots.keySet()); List<InputStream> screenshotStreams = new ArrayList<>();
int counter = 1; if (screenshots != null){
for (String scName : screenshotNames) { List<String> screenshotNames = new ArrayList<>(screenshots.keySet());
if (counter == 1) { screenshotStreams = new ArrayList<>(screenshots.values());
applicationReleaseDTO.setScreenshotName1(scName);
} else if (counter == 2) { int counter = 1;
applicationReleaseDTO.setScreenshotName2(scName); for (String scName : screenshotNames) {
} else if (counter == 3) { if (counter == 1) {
applicationReleaseDTO.setScreenshotName3(scName); applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.getScreenshotName1());
applicationReleaseDTO.setScreenshotName1(scName);
} else if (counter == 2) {
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.getScreenshotName2());
applicationReleaseDTO.setScreenshotName2(scName);
} else if (counter == 3) {
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.getScreenshotName3());
applicationReleaseDTO.setScreenshotName3(scName);
}
counter++;
} }
counter++;
} }
// Upload images // Upload images
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(), .uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(),
applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values())); applicationArtifact.getBannerStream(), screenshotStreams);
return applicationReleaseDTO; 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 @Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -745,7 +746,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public ApplicationRelease createEntAppRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, 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; ApplicationRelease applicationRelease;
@ -764,14 +765,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); 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 " 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 = uploadReleaseArtifacts(applicationReleaseWrapper, ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
applicationDTO, applicationArtifact, deviceType.getName()); APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper),
applicationArtifact, deviceType.getName(), true);
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
String initialstate = lifecycleStateManager.getInitialState(); String initialstate = lifecycleStateManager.getInitialState();
applicationReleaseDTO.setCurrentState(initialstate); applicationReleaseDTO.setCurrentState(initialstate);
@ -829,18 +831,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper, private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO,
ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact, String deviceTypeName) ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO,
deviceTypeName, APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact, applicationArtifact, isNewRelease);
true);
return addImageArtifacts(applicationReleaseDTO, applicationArtifact); return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = String msg = "Error occurred while uploading application release artifacts.";
"Error occurred while uploading application release artifacts. Application ID: " + applicationDTO log.error(msg);
.getId();
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
} }
@ -1129,6 +1129,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
List<Integer> deletingAppReleaseIds = new ArrayList<>(); List<Integer> deletingAppReleaseIds = new ArrayList<>();
List<String> deletingAppHashVals = new ArrayList<>();
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
@ -1139,9 +1140,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue()); deletingAppHashVals.add(applicationReleaseDTO.getAppHashValue());
deletingAppReleaseIds.add(applicationReleaseDTO.getId()); deletingAppReleaseIds.add(applicationReleaseDTO.getId());
} }
applicationStorageManager.deleteAllApplicationReleaseArtifacts(deletingAppHashVals);
this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds); this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds); this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
this.applicationDAO.deleteApplicationTags(applicationId, tenantId); this.applicationDAO.deleteApplicationTags(applicationId, tenantId);
@ -1186,8 +1188,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
if (!activeApplicationReleaseDTOs.isEmpty()) { if (!activeApplicationReleaseDTOs.isEmpty()) {
String msg = "There are application releases which are not in the state " + lifecycleStateManager String msg = "There are application releases which are not in the " + lifecycleStateManager
.getEndState() + ". Hence you are not allowed to delete the application"; .getEndState() + " state. Hence you are not allowed to delete the application";
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
@ -1232,7 +1234,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue()); applicationStorageManager.deleteAllApplicationReleaseArtifacts(
Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId()); lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId()); applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -1278,10 +1281,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " into updatable state and retry the operation."); + " into updatable state and retry the operation.");
} }
applicationReleaseDTO = this.applicationReleaseDAO applicationReleaseDTO = this.applicationReleaseDAO
.updateRelease(addImageArtifacts(applicationReleaseDTO, applicationArtifact), tenantId); .updateRelease(updateImageArtifacts(applicationReleaseDTO, applicationArtifact), tenantId);
if (applicationReleaseDTO == null) { if (applicationReleaseDTO == null) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "ApplicationDTO release updating count is 0. ApplicationDTO release UUID is " + uuid; String msg = "Application release updating count is 0 for application release UUID: " + uuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
@ -1310,7 +1313,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void updateApplicationArtifact(String deviceType, String appType, String uuid, public void updateApplicationArtifact(String deviceType, String uuid,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean isValidDeviceType = false; boolean isValidDeviceType = false;
@ -1338,15 +1341,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
if (applicationReleaseDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application release for UUID: " + uuid; String msg = "Couldn't found an application which has application release for UUID: " + uuid;
log.error(msg); log.error(msg);
throw new NotFoundException(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, applicationReleaseDTO = updateEntAppReleaseArtifact(deviceType,applicationReleaseDTO
applicationArtifact); , applicationArtifact);
applicationReleaseDTO = this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId); applicationReleaseDTO = this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
if (applicationReleaseDTO == null) { if (applicationReleaseDTO == null) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -2105,22 +2124,26 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, public boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
.getReleaseByUUID(releaseUuid, tenantId);
if (applicationReleaseDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application release for updating. Application release UUID: " + releaseUuid; String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
String msg = "You trying to perform enterprise app release update on non-enterprise app release.";
log.error(msg);
throw new ForbiddenException(msg);
}
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) { if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {
String msg = "Application release in " + applicationReleaseDTO.getCurrentState() String msg = "Application release in " + applicationReleaseDTO.getCurrentState()
+ " state. Therefore you are not allowed to update the application release. Hence, " + " state. Therefore you are not allowed to update the application release. Hence, "
@ -2131,15 +2154,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
DeviceType deviceTypeObj = getDeviceTypeData(deviceType); DeviceType deviceTypeObj = getDeviceTypeData(deviceType);
Double price = applicationReleaseWrapper.getPrice(); Double price = entAppReleaseWrapper.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);
}
String applicationSubType = applicationDTO.getSubType();
if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType)) if (price < 0.0 || (price == 0.0 && ApplicationSubscriptionType.PAID.toString().equals(applicationSubType))
|| (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) { || (price > 0.0 && ApplicationSubscriptionType.FREE.toString().equals(applicationSubType))) {
throw new BadRequestException( throw new BadRequestException(
@ -2150,7 +2167,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setPrice(price); applicationReleaseDTO.setPrice(price);
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
String supportedOSVersions = applicationReleaseWrapper.getSupportedOsVersions(); String supportedOSVersions = entAppReleaseWrapper.getSupportedOsVersions();
if (!StringUtils.isEmpty(supportedOSVersions)) { if (!StringUtils.isEmpty(supportedOSVersions)) {
if (!isValidOsVersions(supportedOSVersions, deviceType)){ if (!isValidOsVersions(supportedOSVersions, deviceType)){
String msg = "You are trying to update application release which has invalid or unsupported OS " String msg = "You are trying to update application release which has invalid or unsupported OS "
@ -2159,18 +2176,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg); } throw new BadRequestException(msg); }
applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions); applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions);
} }
if (!StringUtils.isEmpty(applicationReleaseWrapper.getDescription())) { if (!StringUtils.isEmpty(entAppReleaseWrapper.getDescription())) {
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription()); applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription());
} }
if (!StringUtils.isEmpty(applicationReleaseWrapper.getReleaseType())) { if (!StringUtils.isEmpty(entAppReleaseWrapper.getReleaseType())) {
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType()); applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType());
} }
if (!StringUtils.isEmpty(applicationReleaseWrapper.getMetaData())) { if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
} }
applicationReleaseDTO = updateApplicationReleaseArtifacts(applicationType, deviceTypeObj.getName(), if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
applicationReleaseDTO, applicationArtifact); applicationReleaseDTO = updateEntAppReleaseArtifact(deviceTypeObj.getName(),
applicationReleaseDTO, applicationArtifact);
}
applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact); applicationReleaseDTO = updateImageArtifacts(applicationReleaseDTO, applicationArtifact);
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) != null;
@ -2232,10 +2251,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType()); DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
deviceTypeId = deviceType.getId(); deviceTypeId = deviceType.getId();
List<ApplicationReleaseWrapper> applicationReleaseWrappers; List<EntAppReleaseWrapper> entAppReleaseWrappers;
applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers(); 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 " String msg = "Invalid application creating request. Application creating request must have single "
+ "application release. Application name:" + applicationWrapper.getName() + "."; + "application release. Application name:" + applicationWrapper.getName() + ".";
log.error(msg); log.error(msg);
@ -2402,9 +2421,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
if (param instanceof ApplicationReleaseWrapper) { if (param instanceof EntAppReleaseWrapper) {
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param; EntAppReleaseWrapper entAppReleaseWrapper = (EntAppReleaseWrapper) param;
if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())) { if (StringUtils.isEmpty(entAppReleaseWrapper.getSupportedOsVersions())) {
String msg = "Supported OS Version shouldn't be null or empty."; String msg = "Supported OS Version shouldn't be null or empty.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);

@ -18,14 +18,10 @@
package org.wso2.carbon.device.application.mgt.core.impl; package org.wso2.carbon.device.application.mgt.core.impl;
import com.dd.plist.NSDictionary; import com.dd.plist.NSDictionary;
import com.dd.plist.NSString;
import com.dd.plist.PropertyListFormatException;
import com.dd.plist.PropertyListParser;
import net.dongliu.apk.parser.bean.ApkMeta; import net.dongliu.apk.parser.bean.ApkMeta;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller; import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.DeviceTypes; import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
@ -34,22 +30,11 @@ import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagemen
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.core.exception.ParsingException; import org.wso2.carbon.device.application.mgt.core.exception.ParsingException;
import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser; import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil; import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil.delete;
import static org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil.saveFile; import static org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil.saveFile;
/** /**
@ -59,7 +44,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class); private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
private String storagePath; private String storagePath;
private int screenShotMaxCount; private int screenShotMaxCount;
private static final int BUFFER_SIZE = 4096;
/** /**
* Create a new ApplicationStorageManager Instance * Create a new ApplicationStorageManager Instance
@ -73,8 +57,8 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
@Override @Override
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, InputStream iconFileStream, public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
InputStream bannerFileStream, List<InputStream> screenShotStreams) InputStream iconFileStream, InputStream bannerFileStream, List<InputStream> screenShotStreams)
throws ResourceManagementException { throws ResourceManagementException {
String artifactDirectoryPath; String artifactDirectoryPath;
String iconStoredLocation; String iconStoredLocation;
@ -82,15 +66,15 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String scStoredLocation = null; String scStoredLocation = null;
try { try {
artifactDirectoryPath = storagePath + applicationRelease.getAppHashValue(); artifactDirectoryPath = storagePath + applicationReleaseDTO.getAppHashValue();
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
iconStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getIconName();
bannerStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getBannerName();
if (iconFileStream != null) { if (iconFileStream != null) {
iconStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getIconName();
saveFile(iconFileStream, iconStoredLocation); saveFile(iconFileStream, iconStoredLocation);
} }
if (bannerFileStream != null) { if (bannerFileStream != null) {
bannerStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getBannerName();
saveFile(bannerFileStream, bannerStoredLocation); saveFile(bannerFileStream, bannerStoredLocation);
} }
if (!screenShotStreams.isEmpty()) { if (!screenShotStreams.isEmpty()) {
@ -103,67 +87,26 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
int count = 1; int count = 1;
for (InputStream screenshotStream : screenShotStreams) { for (InputStream screenshotStream : screenShotStreams) {
if (count == 1) { if (count == 1) {
scStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getScreenshotName1(); scStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getScreenshotName1();
} }
if (count == 2) { if (count == 2) {
scStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getScreenshotName2(); scStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getScreenshotName2();
} }
if (count == 3) { if (count == 3) {
scStoredLocation = artifactDirectoryPath + File.separator + applicationRelease.getScreenshotName3(); scStoredLocation = artifactDirectoryPath + File.separator + applicationReleaseDTO.getScreenshotName3();
} }
saveFile(screenshotStream, scStoredLocation); saveFile(screenshotStream, scStoredLocation);
count++; count++;
} }
} }
return applicationRelease; return applicationReleaseDTO;
} catch (IOException e) { } catch (IOException e) {
throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " + throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " +
"the application " + applicationRelease.getUuid(), e); "the application " + applicationReleaseDTO.getUuid(), e);
} }
} }
@Override @Override
public void deleteImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO)
throws ResourceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
String iconName = applicationReleaseDTO.getIconName();
String bannerName = applicationReleaseDTO.getBannerName();
String sc1 = applicationReleaseDTO.getScreenshotName1();
String sc2 = applicationReleaseDTO.getScreenshotName2();
String sc3 = applicationReleaseDTO.getScreenshotName3();
String hashValue = applicationReleaseDTO.getAppHashValue();
if (iconName != null) {
deleteApplicationReleaseArtifacts(
storagePath + Constants.FORWARD_SLASH + hashValue + Constants.FORWARD_SLASH + iconName);
}
if (bannerName != null) {
deleteApplicationReleaseArtifacts(
storagePath + Constants.FORWARD_SLASH + hashValue + Constants.FORWARD_SLASH + bannerName);
}
if (sc1 != null) {
deleteApplicationReleaseArtifacts(
storagePath + Constants.FORWARD_SLASH + hashValue + Constants.FORWARD_SLASH + sc1);
}
if (sc2 != null) {
deleteApplicationReleaseArtifacts(
storagePath + Constants.FORWARD_SLASH + hashValue + Constants.FORWARD_SLASH + sc2);
}
if (sc3 != null) {
deleteApplicationReleaseArtifacts(
storagePath + Constants.FORWARD_SLASH + hashValue + Constants.FORWARD_SLASH + sc3);
}
} catch (ApplicationStorageManagementException e) {
throw new ApplicationStorageManagementException("ApplicationDTO Storage exception while trying to"
+ " update the screen-shot count for the application Release " + applicationReleaseDTO.getUuid() +
" for the tenant " + tenantId, e);
}
}
public ApplicationInstaller getAppInstallerData(InputStream binaryFile, String deviceType) public ApplicationInstaller getAppInstallerData(InputStream binaryFile, String deviceType)
throws ApplicationStorageManagementException { throws ApplicationStorageManagementException {
ApplicationInstaller applicationInstaller = new ApplicationInstaller(); ApplicationInstaller applicationInstaller = new ApplicationInstaller();
@ -192,7 +135,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
@Override @Override
public ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO, String appType, public ApplicationReleaseDTO uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO,
String deviceType, InputStream binaryFile) throws ResourceManagementException { String deviceType, InputStream binaryFile) throws ResourceManagementException {
try { try {
String artifactDirectoryPath; String artifactDirectoryPath;
@ -217,7 +160,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
ApplicationReleaseDTO applicationReleaseDTO) throws ApplicationStorageManagementException { ApplicationReleaseDTO applicationReleaseDTO) throws ApplicationStorageManagementException {
try { try {
String basePath = storagePath + Constants.FORWARD_SLASH;
String appHashValue = applicationReleaseDTO.getAppHashValue(); String appHashValue = applicationReleaseDTO.getAppHashValue();
String bannerName = applicationReleaseDTO.getBannerName(); String bannerName = applicationReleaseDTO.getBannerName();
String iconName = applicationReleaseDTO.getIconName(); String iconName = applicationReleaseDTO.getIconName();
@ -226,26 +168,26 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String screenshot3 = applicationReleaseDTO.getScreenshotName3(); String screenshot3 = applicationReleaseDTO.getScreenshotName3();
if (bannerName != null) { if (bannerName != null) {
StorageManagementUtil StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + bannerName,
.copy(basePath + deletingAppHashValue + bannerName, basePath + appHashValue + bannerName); storagePath + appHashValue + File.separator + bannerName);
} }
if (iconName != null) { if (iconName != null) {
StorageManagementUtil StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + iconName,
.copy(basePath + deletingAppHashValue + iconName, basePath + appHashValue + iconName); storagePath + appHashValue + File.separator + iconName);
} }
if (screenshot1 != null) { if (screenshot1 != null) {
StorageManagementUtil StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + screenshot1,
.copy(basePath + deletingAppHashValue + screenshot1, basePath + appHashValue + screenshot1); storagePath + appHashValue + File.separator + screenshot1);
} }
if (screenshot2 != null) { if (screenshot2 != null) {
StorageManagementUtil StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + screenshot2,
.copy(basePath + deletingAppHashValue + screenshot2, basePath + appHashValue + screenshot2); storagePath + appHashValue + File.separator + screenshot2);
} }
if (screenshot3 != null) { if (screenshot3 != null) {
StorageManagementUtil StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + screenshot3,
.copy(basePath + deletingAppHashValue + screenshot3, basePath + appHashValue + screenshot3); storagePath + appHashValue + File.separator + screenshot3);
} }
deleteApplicationReleaseArtifacts( basePath + deletingAppHashValue); deleteAppReleaseArtifact( storagePath + deletingAppHashValue);
} catch (IOException e) { } catch (IOException e) {
String msg = "Application installer updating is failed because of I/O issue"; String msg = "Application installer updating is failed because of I/O issue";
log.error(msg); log.error(msg);
@ -253,31 +195,23 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
} }
@Override
public void deleteApplicationReleaseArtifacts(String artifactPath) throws ApplicationStorageManagementException {
File artifact = new File(artifactPath);
if (artifact.exists()) {
try { @Override
StorageManagementUtil.delete(artifact); public void deleteAppReleaseArtifact(String appReleaseHashVal, String fileName) throws ApplicationStorageManagementException {
} catch (IOException e) { String artifactPath = storagePath + appReleaseHashVal + File.separator + fileName;
throw new ApplicationStorageManagementException( deleteAppReleaseArtifact(artifactPath);
"Error occured while deleting application release artifacts", e);
}
} else {
throw new ApplicationStorageManagementException(
"Tried to delete application release, but it doesn't exist in the system");
}
} }
@Override @Override
public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths) public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths)
throws ApplicationStorageManagementException { throws ApplicationStorageManagementException {
for (String directoryBasePath : directoryPaths) { for (String directoryBasePath : directoryPaths) {
deleteApplicationReleaseArtifacts(storagePath + directoryBasePath); deleteAppReleaseArtifact(storagePath + directoryBasePath);
} }
} }
@Override
public InputStream getFileSttream (String path) throws ApplicationStorageManagementException { public InputStream getFileSttream (String path) throws ApplicationStorageManagementException {
String filePath = storagePath + path; String filePath = storagePath + path;
try { try {
@ -288,126 +222,26 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
} }
private synchronized Map<String, String> getIPAInfo(File ipaFile) throws ApplicationStorageManagementException { /***
Map<String, String> ipaInfo = new HashMap<>(); * This method is responsible to delete artifact file which is located in the artifact path.
String ipaDirectory = null;
try {
String ipaAbsPath = ipaFile.getAbsolutePath();
ipaDirectory = new File(ipaAbsPath).getParent();
if (new File(ipaDirectory + File.separator + Constants.PAYLOAD).exists()) {
delete(new File(ipaDirectory + File.separator + Constants.PAYLOAD));
}
// unzip ipa zip file
unzip(ipaAbsPath, ipaDirectory);
// fetch app file name, after unzip ipa
String appFileName = "";
for (File file : Objects.requireNonNull(
new File(ipaDirectory + File.separator + Constants.PAYLOAD).listFiles()
)) {
if (file.toString().endsWith(Constants.APP_EXTENSION)) {
appFileName = new File(file.toString()).getAbsolutePath();
break;
}
}
String plistFilePath = appFileName + File.separator + Constants.PLIST_NAME;
// parse info.plist
File plistFile = new File(plistFilePath);
NSDictionary rootDict;
rootDict = (NSDictionary) PropertyListParser.parse(plistFile);
// get version
NSString parameter = (NSString) rootDict.objectForKey(Constants.CF_BUNDLE_VERSION);
ipaInfo.put(Constants.CF_BUNDLE_VERSION, parameter.toString());
if (ipaDirectory != null) {
// remove unzip folder
delete(new File(ipaDirectory + File.separator + Constants.PAYLOAD));
}
} catch (ParseException e) {
String msg = "Error occurred while parsing the plist data";
log.error(msg);
throw new ApplicationStorageManagementException(msg, e);
} catch (IOException e) {
String msg = "Error occurred while accessing the ipa file";
log.error(msg);
throw new ApplicationStorageManagementException(msg, e);
} catch (SAXException | ParserConfigurationException | PropertyListFormatException e) {
log.error(e);
throw new ApplicationStorageManagementException(e.getMessage(), e);
} catch (ApplicationStorageManagementException e) {
String msg = "Error occurred while unzipping the ipa file";
log.error(msg);
throw new ApplicationStorageManagementException(msg, e);
}
return ipaInfo;
}
/**
* Extracts a zip file specified by the zipFilePath to a directory specified by
* destDirectory (will be created if does not exists)
*
* @param zipFilePath file path of the zip
* @param destDirectory destination directory path
*/
private void unzip(String zipFilePath, String destDirectory)
throws IOException, ApplicationStorageManagementException {
File destDir = new File(destDirectory);
boolean isDirCreated;
if (!destDir.exists()) {
isDirCreated = destDir.mkdir();
if (!isDirCreated) {
throw new ApplicationStorageManagementException("Directory Creation Is Failed while iOS app vertion " +
"retrieval");
}
}
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath))) {
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null) {
String filePath = destDirectory + File.separator + entry.getName();
if (!entry.isDirectory()) {
// if the entry is a file, extracts it
extractFile(zipIn, filePath);
} else {
// if the entry is a directory, make the directory
File dir = new File(filePath);
isDirCreated = dir.mkdir();
if (!isDirCreated) {
throw new ApplicationStorageManagementException(
"Directory Creation Is Failed while iOS app vertion " + "retrieval");
}
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
}
}
/**
* Extracts a zip entry (file entry)
* *
* @param zipIn zip input stream * @param artifactPath relative path of the artifact file
* @param filePath file path * @throws ApplicationStorageManagementException when the file couldn't find in the given artifact path or if an
* IO error occured while deleting the artifact.
*/ */
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { private void deleteAppReleaseArtifact(String artifactPath) throws ApplicationStorageManagementException {
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) { File artifact = new File(artifactPath);
byte[] bytesIn = new byte[BUFFER_SIZE]; if (artifact.exists()) {
int read; try {
while ((read = zipIn.read(bytesIn)) != -1) { StorageManagementUtil.delete(artifact);
bos.write(bytesIn, 0, read); } catch (IOException e) {
throw new ApplicationStorageManagementException(
"Error occured while deleting application release artifacts", e);
} }
} else {
String msg = "Tried to delete application release, but it doesn't exist in the file system";
log.error(msg);
throw new ApplicationStorageManagementException(msg);
} }
} }
} }

@ -93,7 +93,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public <T> ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List<T> params, public <T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params,
String subType, String action) throws ApplicationManagementException { String subType, String action) throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size() log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size()
@ -337,20 +337,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<String> subscribedEntities = new ArrayList<>(); List<String> subscribedEntities = new ArrayList<>();
if (SubsciptionType.USER.toString().equals(subType)) { if (SubsciptionType.USER.toString().equals(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedUsernames(params, tenantId); subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId); subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
} }
} else if (SubsciptionType.ROLE.toString().equals(subType)) { } else if (SubsciptionType.ROLE.toString().equals(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedRolenames(params, tenantId); subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId); subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
} }
} else if (SubsciptionType.GROUP.toString().equals(subType)) { } else if (SubsciptionType.GROUP.toString().equals(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedGroupnames(params, tenantId); subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId); subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);

@ -24,14 +24,13 @@ import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.routines.UrlValidator; import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationType; 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.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.response.Application; 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.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.EntAppReleaseWrapper;
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.PublicAppReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
@ -237,7 +236,7 @@ public class APIUtil {
applicationDTO.setTags(applicationWrapper.getTags()); applicationDTO.setTags(applicationWrapper.getTags());
applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles());
applicationDTO.setDeviceTypeId(deviceType.getId()); applicationDTO.setDeviceTypeId(deviceType.getId());
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getEntAppReleaseWrappers()
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
} else if (param instanceof WebAppWrapper){ } else if (param instanceof WebAppWrapper){
@ -274,14 +273,14 @@ public class APIUtil {
public static <T> ApplicationReleaseDTO releaseWrapperToReleaseDTO(T param){ public static <T> ApplicationReleaseDTO releaseWrapperToReleaseDTO(T param){
ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO(); ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO();
if (param instanceof ApplicationReleaseWrapper){ if (param instanceof EntAppReleaseWrapper){
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param; EntAppReleaseWrapper entAppReleaseWrapper = (EntAppReleaseWrapper) param;
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription()); applicationReleaseDTO.setDescription(entAppReleaseWrapper.getDescription());
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType()); applicationReleaseDTO.setReleaseType(entAppReleaseWrapper.getReleaseType());
applicationReleaseDTO.setPrice(applicationReleaseWrapper.getPrice()); applicationReleaseDTO.setPrice(entAppReleaseWrapper.getPrice());
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants()); applicationReleaseDTO.setIsSharedWithAllTenants(entAppReleaseWrapper.getIsSharedWithAllTenants());
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions()); applicationReleaseDTO.setSupportedOsVersions(entAppReleaseWrapper.getSupportedOsVersions());
} else if (param instanceof WebAppReleaseWrapper){ } else if (param instanceof WebAppReleaseWrapper){
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription()); 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.Category;
import org.wso2.carbon.device.application.mgt.common.response.Tag; 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.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.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.core.BaseTestCase; import org.wso2.carbon.device.application.mgt.core.BaseTestCase;
@ -72,17 +72,17 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationWrapper.setTags(tags); applicationWrapper.setTags(tags);
applicationWrapper.setPaymentCurrency("USD"); applicationWrapper.setPaymentCurrency("USD");
List<ApplicationReleaseWrapper> applicationReleaseWrappers = new ArrayList<>(); List<EntAppReleaseWrapper> entAppReleaseWrappers = new ArrayList<>();
ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper(); EntAppReleaseWrapper releaseWrapper = new EntAppReleaseWrapper();
releaseWrapper.setDescription("First release"); releaseWrapper.setDescription("First release");
releaseWrapper.setIsSharedWithAllTenants(false); releaseWrapper.setIsSharedWithAllTenants(false);
releaseWrapper.setMetaData("Just meta data"); releaseWrapper.setMetaData("Just meta data");
releaseWrapper.setReleaseType("free"); releaseWrapper.setReleaseType("free");
releaseWrapper.setPrice(5.7); releaseWrapper.setPrice(5.7);
releaseWrapper.setSupportedOsVersions("4.0-7.0"); releaseWrapper.setSupportedOsVersions("4.0-7.0");
applicationReleaseWrappers.add(releaseWrapper); entAppReleaseWrappers.add(releaseWrapper);
applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); applicationWrapper.setEntAppReleaseWrappers(entAppReleaseWrappers);
ApplicationArtifact applicationArtifact = new ApplicationArtifact(); ApplicationArtifact applicationArtifact = new ApplicationArtifact();
applicationArtifact.setBannerName("My First Banner"); applicationArtifact.setBannerName("My First Banner");
@ -102,7 +102,7 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationArtifact.setScreenshots(screenshots); applicationArtifact.setScreenshots(screenshots);
ApplicationManager manager = new ApplicationManagerImpl(); ApplicationManager manager = new ApplicationManagerImpl();
manager.createApplication(applicationWrapper, applicationArtifact); manager.createEntApp(applicationWrapper, applicationArtifact);
} }
@Test @Test
@ -171,12 +171,12 @@ public class ApplicationManagementTest extends BaseTestCase {
} }
@Test @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; return null;
} }
@Test @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; return false;
} }
@ -186,7 +186,7 @@ public class ApplicationManagementTest extends BaseTestCase {
} }
@Test @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.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
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.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.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
@ -507,7 +507,7 @@ public interface ApplicationManagementPublisherAPI {
name = "applicationRelease", name = "applicationRelease",
value = "The application release that need to be created.", value = "The application release that need to be created.",
required = true) required = true)
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper, @Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@ApiParam( @ApiParam(
name = "binaryFile", name = "binaryFile",
value = "Binary file of uploading application", value = "Binary file of uploading application",
@ -602,10 +602,6 @@ public interface ApplicationManagementPublisherAPI {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully updated artifacts."), message = "OK. \n Successfully updated artifacts."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Requesting to update image artifacts with invalid application "
+ "or application release data."),
@ApiResponse( @ApiResponse(
code = 403, code = 403,
message = "FORBIDDEN. \n Can't Update the application release in PUBLISHED or DEPRECATED " message = "FORBIDDEN. \n Can't Update the application release in PUBLISHED or DEPRECATED "
@ -626,8 +622,7 @@ public interface ApplicationManagementPublisherAPI {
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@ApiParam( @ApiParam(
name = "icon", name = "icon",
value = "Icon of the uploading application", value = "Icon of the uploading application")
required = true)
@Multipart(value = "icon") Attachment iconFile, @Multipart(value = "icon") Attachment iconFile,
@ApiParam( @ApiParam(
name = "banner", name = "banner",
@ -635,23 +630,20 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "banner") Attachment bannerFile, @Multipart(value = "banner") Attachment bannerFile,
@ApiParam( @ApiParam(
name = "screenshot1", name = "screenshot1",
value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application")
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1, @Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam( @ApiParam(
name = "screenshot2", name = "screenshot2",
value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application")
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2, @Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam( @ApiParam(
name = "screenshot3", name = "screenshot3",
value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application")
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3 @Multipart(value = "screenshot3") Attachment screenshot3
); );
@PUT @PUT
@Path("/app-artifacts/{deviceType}/{appType}/{appId}/{uuid}") @Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA})
@ApiOperation( @ApiOperation(
@ -690,11 +682,6 @@ public interface ApplicationManagementPublisherAPI {
value = "Type of the device i.e Android, IOS etc", value = "Type of the device i.e Android, IOS etc",
required = true) required = true)
@PathParam("deviceType") String deviceType, @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( @ApiParam(
name = "uuid", name = "uuid",
value = "UUID of the application", value = "UUID of the application",
@ -704,7 +691,7 @@ public interface ApplicationManagementPublisherAPI {
); );
@PUT @PUT
@Path("/app-release/{deviceType}/{appType}/{uuid}") @Path("/ent-app-release/{deviceType}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation( @ApiOperation(
@ -735,30 +722,24 @@ public interface ApplicationManagementPublisherAPI {
message = "Internal Server Error. \n Error occurred while releasing the application.", message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateApplicationRelease( Response updateEntAppRelease(
@ApiParam( @ApiParam(
name = "deviceType", name = "deviceType",
value = "Supported device type of the application", value = "Supported device type of the application",
required = true) required = true)
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@ApiParam(
name = "appType",
value = "Type of the application",
required = true)
@PathParam("appType") String appType,
@ApiParam( @ApiParam(
name = "UUID", name = "UUID",
value = "Unique identifier of the ApplicationDTO Release", value = "Unique identifier of the ApplicationDTO Release",
required = true) required = true)
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@ApiParam( @ApiParam(
name = "applicationReleaseWrapper", name = "entAppReleaseWrapper",
value = "Application release wrapper which is going to update.", value = "Application release wrapper which is going to update.",
required = true) required = true)
@Multipart( @Multipart(
value = "applicationReleaseWrapper", value = "entAppReleaseWrapper",
type = "application/json") type = "application/json") EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationReleaseWrapper applicationReleaseWrapper,
@ApiParam( @ApiParam(
name = "binaryFile", name = "binaryFile",
value = "Application installer file.", 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.Category;
import org.wso2.carbon.device.application.mgt.common.response.Tag; 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.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.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.PublicAppWrapper; 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); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(applicationWrapper); applicationManager.validateAppCreatingRequest(applicationWrapper);
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0)); applicationManager.validateReleaseCreatingRequest(applicationWrapper.getEntAppReleaseWrappers().get(0));
applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Ent App // Created new Ent App
Application application = applicationManager.createApplication(applicationWrapper, Application application = applicationManager.createEntApp(applicationWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
@ -284,7 +284,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/ent-app/{appId}") @Path("/ent-app/{appId}")
public Response createEntAppRelease( public Response createEntAppRelease(
@PathParam("appId") int appId, @PathParam("appId") int appId,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper, @Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@ -294,12 +294,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper); applicationManager.validateReleaseCreatingRequest(entAppReleaseWrapper);
applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Ent App release // Created new Ent App release
ApplicationRelease release = applicationManager.createEntAppRelease(appId, applicationReleaseWrapper, ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
if (release != null) { if (release != null) {
return Response.status(Response.Status.CREATED).entity(release).build(); return Response.status(Response.Status.CREATED).entity(release).build();
@ -325,22 +325,18 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/image-artifacts/{uuid}") @Path("/image-artifacts/{uuid}")
public Response updateApplicationImageArtifacts( public Response updateApplicationImageArtifacts(
@PathParam("uuid") String applicationReleaseUuid, @PathParam("uuid") String applicationReleaseUuid,
@Multipart("icon") Attachment iconFile, @Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1, @Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2, @Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
try { try {
List<Attachment> attachments = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> attachments = constructAttachmentList(screenshot1, screenshot2, screenshot3);
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachments);
applicationManager.updateApplicationImageArtifact(applicationReleaseUuid, applicationManager.updateApplicationImageArtifact(applicationReleaseUuid,
constructApplicationArtifact(null, iconFile, bannerFile, attachments)); constructApplicationArtifact(null, iconFile, bannerFile, attachments));
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationReleaseUuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationReleaseUuid).build();
} catch (RequestValidatingException e) {
log.error(e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build(); return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
@ -358,24 +354,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA})
@Path("/app-artifact/{deviceType}/{appType}/{uuid}") @Path("/ent-app-artifact/{deviceType}//{uuid}")
public Response updateApplicationArtifact( public Response updateApplicationArtifact(
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("appType") String appType,
@PathParam("uuid") String applicationReleaseUuid, @PathParam("uuid") String applicationReleaseUuid,
@Multipart("binaryFile") Attachment binaryFile) { @Multipart("binaryFile") Attachment binaryFile) {
try { 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(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
//todo check again
applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid, applicationManager.updateApplicationArtifact(deviceType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null)); constructApplicationArtifact(binaryFile, null, null, null));
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application release. UUID is " .entity("Successfully uploaded artifacts for the application release. UUID is "
@ -422,25 +410,21 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Path("/app-release/{deviceType}/{appType}/{uuid}") @Path("/ent-app-release/{deviceType}/{uuid}")
public Response updateApplicationRelease( public Response updateEntAppRelease(
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("appType") String appType,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper, @Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile, @Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@Multipart("icon") Attachment iconFile, @Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1, @Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2, @Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
//todo check again if (!applicationManager.updateEntAppRelease(deviceType, applicationUUID, entAppReleaseWrapper,
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) { constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. " String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType; + "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
@ -467,10 +451,6 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
String msg = "Error while updating the application release of the application with UUID " + applicationUUID; String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} 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 +798,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationArtifact.setBannerStream(bannerStream); applicationArtifact.setBannerStream(bannerStream);
} }
if (attachmentList != null) { if (attachmentList != null && !attachmentList.isEmpty()) {
Map<String, InputStream> scrrenshotData = new TreeMap<>(); Map<String, InputStream> scrrenshotData = new TreeMap<>();
for (Attachment sc : attachmentList) { for (Attachment sc : attachmentList) {
dataHandler = sc.getDataHandler(); dataHandler = sc.getDataHandler();

@ -78,23 +78,23 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
@DELETE @DELETE
@Path("/{appId}") @Path("/{appId}")
public Response deleteApplication( public Response deleteApplication(
@PathParam("appId") int applicatioId) { @PathParam("appId") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.deleteApplication(applicatioId); applicationManager.deleteApplication(applicationId);
String responseMsg = "Successfully deleted the application which has ID: " + applicatioId + ""; String responseMsg = "Successfully deleted the application which has ID: " + applicationId + "";
return Response.status(Response.Status.OK).entity(responseMsg).build(); return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = String msg =
"Couldn't found application release which is having the ID:" + applicatioId; "Couldn't found application release which is having the ID:" + applicationId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) { } catch (ForbiddenException e) {
String msg = "You don't have require permission to delete the application which has ID: " + applicatioId; String msg = "You don't have require permission to delete the application which has ID: " + applicationId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application which has application ID:: " + applicatioId; String msg = "Error occurred while deleting the application which has application ID:: " + applicationId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -12,7 +12,7 @@
"dependencies": { "dependencies": {
"acorn": "^6.1.1", "acorn": "^6.1.1",
"antd": "^3.15.0", "antd": "^3.15.0",
"axios": "^0.18.0", "axios": "^0.19.0",
"d3": "^5.9.2", "d3": "^5.9.2",
"dagre": "^0.8.4", "dagre": "^0.8.4",
"fetch": "^1.1.0", "fetch": "^1.1.0",

@ -261,24 +261,19 @@ class AddNewAppFormComponent extends React.Component {
var data = new FormData(); let data = new FormData();
// data.append("binaryFile", "/Users/jayasanka/Desktop/gov/viber/a.apk");
// data.append("application", "{\n\t\"name\": \"Tub1111\",\n\t\"description\": \"Watch thousands of hit movies and TV series for free. Tubi is 100% legal unlimited streaming, with no credit cards and no subscription required. Choose what you want to watch, when you want to watch it, with fewer ads than regular TV. Tubi is the largest free streaming service featuring award-winning movies and TV series. There is something for everybody; from comedy to drama, kids to classics, and niche favorites such as Korean dramas, anime, and British series. Download now and start streaming entertainment for free, today!\",\n\t\"appCategories\": [\"EMM\"],\n\t\"subType\": \"FREE\",\n\t\"tags\": [\"tv\", \"movies\"],\n\t\"unrestrictedRoles\": [],\n\t\"deviceType\": \"android\",\n\t\"entAppReleaseWrappers\": [{\n\t\t\"description\": \" SEND A MESSAGE -Skip exchanging phone numbers, just send a message. It's seamless across devices. * SHOW YOUR REACTION - Add a silly sticker\",\n\t\t\"releaseType\": \"GA\",\n\t\t\"price\": 0.0,\n\t\t\"isSharedWithAllTenants\": false,\n\t\t\"metaData\": \"{\\\"developer\\\":\\\"Facebook, Inc.\\\",\\\"Copyright\\\":\\\"\\u00A9 Facebook, Inc.\\\",\\\"Location\\\":\\\"This app may use your location even when it isn't open, which can decrease battery life.\\\"}\",\n\t\t\"ratedUsers\": 0,\n\t\t\"rating\": 0,\n\t\t\"supportedOsVersions\": \"4.0-10.0\"\n\t}]\n}");
// data.append("icon", "/Users/jayasanka/Desktop/gov/angular/i.png");
// data.append("screenshot1", "/Users/jayasanka/Desktop/gov/angular/1.webp");
// data.append("screenshot2", "/Users/jayasanka/Desktop/gov/angular/2.webp");
// data.append("screenshot3", "/Users/jayasanka/Desktop/gov/angular/3.webp");
data.append('binaryFile', binaryFile[0].originFileObj); data.append('binaryFile', binaryFile[0].originFileObj);
data.append('icon', icon[0].originFileObj); data.append('icon', icon[0].originFileObj);
data.append('screenshot1', screenshots[0].originFileObj); data.append('screenshot1', screenshots[0].originFileObj);
data.append('screenshot2', screenshots[1].originFileObj); data.append('screenshot2', screenshots[1].originFileObj);
data.append('screenshot3', screenshots[2].originFileObj); data.append('screenshot3', screenshots[2].originFileObj);
data.append('application', JSON.toString(payload.application)); const json = JSON.stringify(payload.application);
const blob = new Blob([json], {
type: 'application/json'
});
data.append('application', blob);
var xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.withCredentials = true; xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () { xhr.addEventListener("readystatechange", function () {
@ -287,12 +282,10 @@ class AddNewAppFormComponent extends React.Component {
} }
}); });
xhr.open("POST", "https://localhost:9443/ui-request-handler/invoke/application-mgt-publisher/v1.0/applications/ent-app"); const url = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/ent-app";
xhr.setRequestHeader("Content-Type", "multipart/mixed"); xhr.open("POST", url);
xhr.setRequestHeader("X-Platform", "publisher"); xhr.setRequestHeader("X-Platform", "publisher");
xhr.send(data); xhr.send(data);
} }
}); });
}; };

@ -57,7 +57,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
try { try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response = subscriptionManager ApplicationInstallResponse response = subscriptionManager
.performBulkAppInstallation(uuid, deviceIdentifiers, SubsciptionType.DEVICE.toString(), action); .performBulkAppOperation(uuid, deviceIdentifiers, SubsciptionType.DEVICE.toString(), action);
return Response.status(Response.Status.OK).entity(response).build(); return Response.status(Response.Status.OK).entity(response).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUI: " + uuid; String msg = "Couldn't found an application release for UUI: " + uuid;
@ -92,7 +92,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
try { try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response = subscriptionManager ApplicationInstallResponse response = subscriptionManager
.performBulkAppInstallation(uuid, subscribers, subType, action); .performBulkAppOperation(uuid, subscribers, subType, action);
return Response.status(Response.Status.OK).entity(response).build(); return Response.status(Response.Status.OK).entity(response).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload";

Loading…
Cancel
Save