From 9bf880cbb0845ada73293a94d914220f5c8fd1c9 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 24 Jun 2019 15:27:10 +0530 Subject: [PATCH] Improve ent app release update method --- .../services/ApplicationStorageManager.java | 11 +- .../common/services/SubscriptionManager.java | 2 +- .../mgt/core/dao/SubscriptionDAO.java | 7 +- .../GenericSubscriptionDAOImpl.java | 39 ++- .../mgt/core/impl/ApplicationManagerImpl.java | 64 +++-- .../impl/ApplicationStorageManagerImpl.java | 240 +++--------------- .../core/impl/SubscriptionManagerImpl.java | 8 +- .../ApplicationManagementPublisherAPI.java | 18 +- ...ApplicationManagementPublisherAPIImpl.java | 14 +- ...cationManagementPublisherAdminAPIImpl.java | 12 +- .../impl/SubscriptionManagementAPIImpl.java | 4 +- 11 files changed, 143 insertions(+), 276 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java index 12dabd87913..5e86145584c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java @@ -42,14 +42,6 @@ public interface ApplicationStorageManager { ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, InputStream iconFile, InputStream bannerFile, List 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. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index e1c10ea9a9c..8cb861dc29f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -27,6 +27,6 @@ import java.util.List; * This interface manages all the operations related with ApplicationDTO Subscription. */ public interface SubscriptionManager { - ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, String subType, + ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List params, String subType, String action) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 0e77e38b8a9..e0280c3d75f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -67,13 +67,13 @@ public interface SubscriptionDAO { Map getDeviceSubscriptions(List deviceIds, int tenantId) throws ApplicationManagementDAOException; - List getSubscribedUsernames(List users, int tenantId) throws + List getSubscribedUserNames(List users, int tenantId) throws ApplicationManagementDAOException; - List getSubscribedRolenames(List roles, int tenantId) throws + List getSubscribedRoleNames(List roles, int tenantId) throws ApplicationManagementDAOException; - List getSubscribedGroupnames(List groups, int tenantId) throws + List getSubscribedGroupNames(List groups, int tenantId) throws ApplicationManagementDAOException; void updateSubscriptions(int tenantId, String updateBy, List paramList, @@ -81,5 +81,6 @@ public interface SubscriptionDAO { List getSubscribedDeviceIds(List deviceIds, int tenantId) throws ApplicationManagementDAOException; + void updateDeviceSubStatus (int operationId, String status, int tenantcId) throws ApplicationManagementDAOException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 26984eeea06..365c05fca9e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -368,7 +368,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getSubscribedUsernames(List users, int tenantId) + public List getSubscribedUserNames(List 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 getSubscribedRolenames(List roles, int tenantId) + public List getSubscribedRoleNames(List roles, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug( @@ -445,7 +445,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List getSubscribedGroupnames(List groups, int tenantId) + public List getSubscribedGroupNames(List 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 getSubscribedDeviceIds(List deviceIds, int tenantId) + @Override + public List getSubscribedDeviceIds(List 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); + } + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 4ee281b420f..61c4f325b37 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -241,6 +241,8 @@ public class ApplicationManagerImpl implements ApplicationManager { return addAppDataIntoDB(applicationDTO, tenantId); } + + private void deleteApplicationArtifacts(List 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 screenshots = applicationArtifact.getScreenshots(); - List screenshotNames = new ArrayList<>(screenshots.keySet()); - - int counter = 1; - for (String scName : screenshotNames) { - if (counter == 1) { - applicationReleaseDTO.setScreenshotName1(scName); - } else if (counter == 2) { - applicationReleaseDTO.setScreenshotName2(scName); - } else if (counter == 3) { - applicationReleaseDTO.setScreenshotName3(scName); + List screenshotStreams = new ArrayList<>(); + + if (screenshots != null){ + List 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++; } - 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 deletingAppReleaseIds = new ArrayList<>(); + List deletingAppHashVals = new ArrayList<>(); for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { List 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())) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java index d79bf483b8c..243fd1bc75a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -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 screenShotStreams) + public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, + InputStream iconFileStream, InputStream bannerFileStream, List 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 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 getIPAInfo(File ipaFile) throws ApplicationStorageManagementException { - Map ipaInfo = new HashMap<>(); - - 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) + /*** + * This method is responsible to delete artifact file which is located in the artifact path. * - * @param zipFilePath file path of the zip - * @param destDirectory destination directory 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 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); + private void deleteAppReleaseArtifact(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 { + String msg = "Tried to delete application release, but it doesn't exist in the file system"; + log.error(msg); + throw new ApplicationStorageManagementException(msg); } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index e32fe3f5cdd..0e3a0985f90 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -93,7 +93,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, + public ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List 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 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); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 42b9485406a..08dfc42d4b9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -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( diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index a06214cd262..05ab98ee3aa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -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 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, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java index ddca629ac66..4f6287e21f7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -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(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java index 94d70c08d10..047b05ad3f2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java @@ -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";