Improve ent app release update method

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent 51fbee445f
commit 9bf880cbb0

@ -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;
@ -78,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;
} }

@ -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;
} }

@ -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);
}
}
} }

@ -241,6 +241,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
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 {
@ -446,35 +448,47 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationArtifact applicationArtifact) throws ResourceManagementException{ ApplicationArtifact applicationArtifact) throws ResourceManagementException{
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
//todo check again
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO);
if (!StringUtils.isEmpty(applicationArtifact.getIconName())) { if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.getIconName());
applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
} }
if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){ if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){
applicationStorageManager.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(),
applicationReleaseDTO.getBannerName());
applicationReleaseDTO.setBannerName(applicationArtifact.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;
} }
@ -1115,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);
@ -1125,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);
@ -1172,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);
} }
@ -1218,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();
@ -1264,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);
} }
@ -2120,6 +2137,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
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); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) { if (!lifecycleStateManager.isUpdatableState(applicationReleaseDTO.getCurrentState())) {

@ -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 applicationReleaseDTO, 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;
@ -122,48 +106,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
} }
@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();
@ -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 artifactPath relative path of the artifact file
* @param destDirectory destination directory 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 unzip(String zipFilePath, String destDirectory) private void deleteAppReleaseArtifact(String artifactPath) throws ApplicationStorageManagementException {
throws IOException, ApplicationStorageManagementException { File artifact = new File(artifactPath);
File destDir = new File(destDirectory); if (artifact.exists()) {
boolean isDirCreated; try {
StorageManagementUtil.delete(artifact);
if (!destDir.exists()) { } catch (IOException e) {
isDirCreated = destDir.mkdir(); throw new ApplicationStorageManagementException(
if (!isDirCreated) { "Error occured while deleting application release artifacts", e);
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);
} }
} 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);

@ -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,18 +630,15 @@ 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
); );
@ -699,7 +691,7 @@ public interface ApplicationManagementPublisherAPI {
); );
@PUT @PUT
@Path("/app-release/{deviceType}/{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(

@ -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();
@ -414,7 +410,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Path("/app-release/{deviceType}/{uuid}") @Path("/ent-app-release/{deviceType}/{uuid}")
public Response updateEntAppRelease( public Response updateEntAppRelease(
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,

@ -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();
} }

@ -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