mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Improve ent app release update method
This commit is contained in:
parent
51fbee445f
commit
9bf880cbb0
@ -42,14 +42,6 @@ public interface ApplicationStorageManager {
|
||||
ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease,
|
||||
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)
|
||||
throws ApplicationStorageManagementException;
|
||||
|
||||
@ -78,10 +70,9 @@ public interface ApplicationStorageManager {
|
||||
/**
|
||||
* To delete the artifacts related with particular ApplicationDTO Release.
|
||||
*
|
||||
* @param directoryPath Hash value of the application artifact.
|
||||
* @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.
|
||||
|
||||
@ -27,6 +27,6 @@ import java.util.List;
|
||||
* This interface manages all the operations related with ApplicationDTO Subscription.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@ -67,13 +67,13 @@ public interface SubscriptionDAO {
|
||||
Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int tenantId) throws
|
||||
ApplicationManagementDAOException;
|
||||
|
||||
List<String> getSubscribedUsernames(List<String> users, int tenantId) throws
|
||||
List<String> getSubscribedUserNames(List<String> users, int tenantId) throws
|
||||
ApplicationManagementDAOException;
|
||||
|
||||
List<String> getSubscribedRolenames(List<String> roles, int tenantId) throws
|
||||
List<String> getSubscribedRoleNames(List<String> roles, int tenantId) throws
|
||||
ApplicationManagementDAOException;
|
||||
|
||||
List<String> getSubscribedGroupnames(List<String> groups, int tenantId) throws
|
||||
List<String> getSubscribedGroupNames(List<String> groups, int tenantId) throws
|
||||
ApplicationManagementDAOException;
|
||||
|
||||
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;
|
||||
|
||||
void updateDeviceSubStatus (int operationId, String status, int tenantcId) throws ApplicationManagementDAOException;
|
||||
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubscribedUsernames(List<String> users, int tenantId)
|
||||
public List<String> getSubscribedUserNames(List<String> users, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
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
|
||||
public List<String> getSubscribedRolenames(List<String> roles, int tenantId)
|
||||
public List<String> getSubscribedRoleNames(List<String> roles, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
@ -445,7 +445,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubscribedGroupnames(List<String> groups, int tenantId)
|
||||
public List<String> getSubscribedGroupNames(List<String> groups, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
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 {
|
||||
if (log.isDebugEnabled()) {
|
||||
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.setInt(4, releaseId);
|
||||
stmt.setInt(5, tenantId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
}
|
||||
@ -573,4 +575,33 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,6 +241,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
return addAppDataIntoDB(applicationDTO, tenantId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException {
|
||||
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
||||
try {
|
||||
@ -446,35 +448,47 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
ApplicationArtifact applicationArtifact) throws ResourceManagementException{
|
||||
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
||||
|
||||
//todo check again
|
||||
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO);
|
||||
|
||||
if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
|
||||
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
|
||||
applicationReleaseDTO.getIconName());
|
||||
applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
|
||||
}
|
||||
if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){
|
||||
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
|
||||
applicationReleaseDTO.getBannerName());
|
||||
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
|
||||
}
|
||||
|
||||
Map<String, InputStream> screenshots = applicationArtifact.getScreenshots();
|
||||
List<InputStream> screenshotStreams = new ArrayList<>();
|
||||
|
||||
if (screenshots != null){
|
||||
List<String> screenshotNames = new ArrayList<>(screenshots.keySet());
|
||||
screenshotStreams = new ArrayList<>(screenshots.values());
|
||||
|
||||
int counter = 1;
|
||||
for (String scName : screenshotNames) {
|
||||
if (counter == 1) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
// Upload images
|
||||
applicationReleaseDTO = applicationStorageManager
|
||||
.uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(),
|
||||
applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values()));
|
||||
applicationArtifact.getBannerStream(), screenshotStreams);
|
||||
return applicationReleaseDTO;
|
||||
}
|
||||
|
||||
@ -1115,6 +1129,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
List<Integer> deletingAppReleaseIds = new ArrayList<>();
|
||||
List<String> deletingAppHashVals = new ArrayList<>();
|
||||
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
|
||||
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
||||
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
|
||||
@ -1125,9 +1140,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new ForbiddenException(msg);
|
||||
}
|
||||
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
||||
deletingAppHashVals.add(applicationReleaseDTO.getAppHashValue());
|
||||
deletingAppReleaseIds.add(applicationReleaseDTO.getId());
|
||||
}
|
||||
applicationStorageManager.deleteAllApplicationReleaseArtifacts(deletingAppHashVals);
|
||||
this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
|
||||
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
|
||||
this.applicationDAO.deleteApplicationTags(applicationId, tenantId);
|
||||
@ -1172,8 +1188,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
}
|
||||
}
|
||||
if (!activeApplicationReleaseDTOs.isEmpty()) {
|
||||
String msg = "There are application releases which are not in the state " + lifecycleStateManager
|
||||
.getEndState() + ". Hence you are not allowed to delete the application";
|
||||
String msg = "There are application releases which are not in the " + lifecycleStateManager
|
||||
.getEndState() + " state. Hence you are not allowed to delete the application";
|
||||
log.error(msg);
|
||||
throw new ForbiddenException(msg);
|
||||
}
|
||||
@ -1218,7 +1234,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new ForbiddenException(msg);
|
||||
}
|
||||
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
||||
applicationStorageManager.deleteAllApplicationReleaseArtifacts(
|
||||
Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
|
||||
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
@ -1264,10 +1281,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
+ " into updatable state and retry the operation.");
|
||||
}
|
||||
applicationReleaseDTO = this.applicationReleaseDAO
|
||||
.updateRelease(addImageArtifacts(applicationReleaseDTO, applicationArtifact), tenantId);
|
||||
.updateRelease(updateImageArtifacts(applicationReleaseDTO, applicationArtifact), tenantId);
|
||||
if (applicationReleaseDTO == null) {
|
||||
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);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
@ -2120,6 +2137,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(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())) {
|
||||
|
||||
@ -18,14 +18,10 @@
|
||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||
|
||||
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 org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
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.dto.ApplicationReleaseDTO;
|
||||
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.core.exception.ParsingException;
|
||||
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.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -59,7 +44,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
||||
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
|
||||
private String storagePath;
|
||||
private int screenShotMaxCount;
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
/**
|
||||
* Create a new ApplicationStorageManager Instance
|
||||
@ -73,8 +57,8 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, InputStream iconFileStream,
|
||||
InputStream bannerFileStream, List<InputStream> screenShotStreams)
|
||||
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
|
||||
InputStream iconFileStream, InputStream bannerFileStream, List<InputStream> screenShotStreams)
|
||||
throws ResourceManagementException {
|
||||
String artifactDirectoryPath;
|
||||
String iconStoredLocation;
|
||||
@ -122,48 +106,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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)
|
||||
throws ApplicationStorageManagementException {
|
||||
ApplicationInstaller applicationInstaller = new ApplicationInstaller();
|
||||
@ -217,7 +160,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
||||
ApplicationReleaseDTO applicationReleaseDTO) throws ApplicationStorageManagementException {
|
||||
|
||||
try {
|
||||
String basePath = storagePath + Constants.FORWARD_SLASH;
|
||||
String appHashValue = applicationReleaseDTO.getAppHashValue();
|
||||
String bannerName = applicationReleaseDTO.getBannerName();
|
||||
String iconName = applicationReleaseDTO.getIconName();
|
||||
@ -226,26 +168,26 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
||||
String screenshot3 = applicationReleaseDTO.getScreenshotName3();
|
||||
|
||||
if (bannerName != null) {
|
||||
StorageManagementUtil
|
||||
.copy(basePath + deletingAppHashValue + bannerName, basePath + appHashValue + bannerName);
|
||||
StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + bannerName,
|
||||
storagePath + appHashValue + File.separator + bannerName);
|
||||
}
|
||||
if (iconName != null) {
|
||||
StorageManagementUtil
|
||||
.copy(basePath + deletingAppHashValue + iconName, basePath + appHashValue + iconName);
|
||||
StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + iconName,
|
||||
storagePath + appHashValue + File.separator + iconName);
|
||||
}
|
||||
if (screenshot1 != null) {
|
||||
StorageManagementUtil
|
||||
.copy(basePath + deletingAppHashValue + screenshot1, basePath + appHashValue + screenshot1);
|
||||
StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + screenshot1,
|
||||
storagePath + appHashValue + File.separator + screenshot1);
|
||||
}
|
||||
if (screenshot2 != null) {
|
||||
StorageManagementUtil
|
||||
.copy(basePath + deletingAppHashValue + screenshot2, basePath + appHashValue + screenshot2);
|
||||
StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + screenshot2,
|
||||
storagePath + appHashValue + File.separator + screenshot2);
|
||||
}
|
||||
if (screenshot3 != null) {
|
||||
StorageManagementUtil
|
||||
.copy(basePath + deletingAppHashValue + screenshot3, basePath + appHashValue + screenshot3);
|
||||
StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + screenshot3,
|
||||
storagePath + appHashValue + File.separator + screenshot3);
|
||||
}
|
||||
deleteApplicationReleaseArtifacts( basePath + deletingAppHashValue);
|
||||
deleteAppReleaseArtifact( storagePath + deletingAppHashValue);
|
||||
} catch (IOException e) {
|
||||
String msg = "Application installer updating is failed because of I/O issue";
|
||||
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 {
|
||||
StorageManagementUtil.delete(artifact);
|
||||
} catch (IOException e) {
|
||||
throw new ApplicationStorageManagementException(
|
||||
"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
|
||||
public void deleteAppReleaseArtifact(String appReleaseHashVal, String fileName) throws ApplicationStorageManagementException {
|
||||
String artifactPath = storagePath + appReleaseHashVal + File.separator + fileName;
|
||||
deleteAppReleaseArtifact(artifactPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths)
|
||||
throws ApplicationStorageManagementException {
|
||||
for (String directoryBasePath : directoryPaths) {
|
||||
deleteApplicationReleaseArtifacts(storagePath + directoryBasePath);
|
||||
deleteAppReleaseArtifact(storagePath + directoryBasePath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getFileSttream (String path) throws ApplicationStorageManagementException {
|
||||
String filePath = storagePath + path;
|
||||
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<>();
|
||||
|
||||
String ipaDirectory = null;
|
||||
/***
|
||||
* This method is responsible to delete artifact file which is located in the artifact path.
|
||||
*
|
||||
* @param artifactPath relative path of the artifact file
|
||||
* @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 deleteAppReleaseArtifact(String artifactPath) throws ApplicationStorageManagementException {
|
||||
File artifact = new File(artifactPath);
|
||||
if (artifact.exists()) {
|
||||
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);
|
||||
StorageManagementUtil.delete(artifact);
|
||||
} 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 filePath file path
|
||||
*/
|
||||
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) {
|
||||
byte[] bytesIn = new byte[BUFFER_SIZE];
|
||||
int read;
|
||||
while ((read = zipIn.read(bytesIn)) != -1) {
|
||||
bos.write(bytesIn, 0, read);
|
||||
"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
|
||||
public <T> ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List<T> params,
|
||||
public <T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params,
|
||||
String subType, String action) throws ApplicationManagementException {
|
||||
if (log.isDebugEnabled()) {
|
||||
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<>();
|
||||
if (SubsciptionType.USER.toString().equals(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getSubscribedUsernames(params, tenantId);
|
||||
subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId);
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
params.removeAll(subscribedEntities);
|
||||
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
}
|
||||
} else if (SubsciptionType.ROLE.toString().equals(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getSubscribedRolenames(params, tenantId);
|
||||
subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId);
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
params.removeAll(subscribedEntities);
|
||||
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
|
||||
}
|
||||
} else if (SubsciptionType.GROUP.toString().equals(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getSubscribedGroupnames(params, tenantId);
|
||||
subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId);
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
params.removeAll(subscribedEntities);
|
||||
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
|
||||
@ -602,10 +602,6 @@ public interface ApplicationManagementPublisherAPI {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
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(
|
||||
code = 403,
|
||||
message = "FORBIDDEN. \n Can't Update the application release in PUBLISHED or DEPRECATED "
|
||||
@ -626,8 +622,7 @@ public interface ApplicationManagementPublisherAPI {
|
||||
@PathParam("uuid") String applicationUUID,
|
||||
@ApiParam(
|
||||
name = "icon",
|
||||
value = "Icon of the uploading application",
|
||||
required = true)
|
||||
value = "Icon of the uploading application")
|
||||
@Multipart(value = "icon") Attachment iconFile,
|
||||
@ApiParam(
|
||||
name = "banner",
|
||||
@ -635,18 +630,15 @@ public interface ApplicationManagementPublisherAPI {
|
||||
@Multipart(value = "banner") Attachment bannerFile,
|
||||
@ApiParam(
|
||||
name = "screenshot1",
|
||||
value = "Screen Shots of the uploading application",
|
||||
required = true)
|
||||
value = "Screen Shots of the uploading application")
|
||||
@Multipart(value = "screenshot1") Attachment screenshot1,
|
||||
@ApiParam(
|
||||
name = "screenshot2",
|
||||
value = "Screen Shots of the uploading application",
|
||||
required = false)
|
||||
value = "Screen Shots of the uploading application")
|
||||
@Multipart(value = "screenshot2") Attachment screenshot2,
|
||||
@ApiParam(
|
||||
name = "screenshot3",
|
||||
value = "Screen Shots of the uploading application",
|
||||
required = false)
|
||||
value = "Screen Shots of the uploading application")
|
||||
@Multipart(value = "screenshot3") Attachment screenshot3
|
||||
);
|
||||
|
||||
@ -699,7 +691,7 @@ public interface ApplicationManagementPublisherAPI {
|
||||
);
|
||||
|
||||
@PUT
|
||||
@Path("/app-release/{deviceType}/{uuid}")
|
||||
@Path("/ent-app-release/{deviceType}/{uuid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@ApiOperation(
|
||||
|
||||
@ -325,22 +325,18 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
@Path("/image-artifacts/{uuid}")
|
||||
public Response updateApplicationImageArtifacts(
|
||||
@PathParam("uuid") String applicationReleaseUuid,
|
||||
@Multipart("icon") Attachment iconFile,
|
||||
@Multipart(value = "icon", required = false) Attachment iconFile,
|
||||
@Multipart(value = "banner", required = false) Attachment bannerFile,
|
||||
@Multipart("screenshot1") Attachment screenshot1,
|
||||
@Multipart("screenshot2") Attachment screenshot2,
|
||||
@Multipart("screenshot3") Attachment screenshot3) {
|
||||
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
|
||||
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
|
||||
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
|
||||
try {
|
||||
List<Attachment> attachments = constructAttachmentList(screenshot1, screenshot2, screenshot3);
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachments);
|
||||
applicationManager.updateApplicationImageArtifact(applicationReleaseUuid,
|
||||
constructApplicationArtifact(null, iconFile, bannerFile, attachments));
|
||||
return Response.status(Response.Status.OK)
|
||||
.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) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
|
||||
@ -414,7 +410,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
|
||||
@Override
|
||||
@PUT
|
||||
@Path("/app-release/{deviceType}/{uuid}")
|
||||
@Path("/ent-app-release/{deviceType}/{uuid}")
|
||||
public Response updateEntAppRelease(
|
||||
@PathParam("deviceType") String deviceType,
|
||||
@PathParam("uuid") String applicationUUID,
|
||||
|
||||
@ -78,23 +78,23 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
|
||||
@DELETE
|
||||
@Path("/{appId}")
|
||||
public Response deleteApplication(
|
||||
@PathParam("appId") int applicatioId) {
|
||||
@PathParam("appId") int applicationId) {
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
try {
|
||||
applicationManager.deleteApplication(applicatioId);
|
||||
String responseMsg = "Successfully deleted the application which has ID: " + applicatioId + "";
|
||||
applicationManager.deleteApplication(applicationId);
|
||||
String responseMsg = "Successfully deleted the application which has ID: " + applicationId + "";
|
||||
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
||||
} catch (NotFoundException e) {
|
||||
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);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
} 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);
|
||||
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
|
||||
} 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);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
|
||||
try {
|
||||
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
|
||||
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();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Couldn't found an application release for UUI: " + uuid;
|
||||
@ -92,7 +92,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
|
||||
try {
|
||||
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
|
||||
ApplicationInstallResponse response = subscriptionManager
|
||||
.performBulkAppInstallation(uuid, subscribers, subType, action);
|
||||
.performBulkAppOperation(uuid, subscribers, subType, action);
|
||||
return Response.status(Response.Status.OK).entity(response).build();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user