From 18c3ee23b9aa9ffa57842d1df56a97b82ba2f07f Mon Sep 17 00:00:00 2001 From: geethkokila Date: Sat, 15 Sep 2018 21:58:02 +0530 Subject: [PATCH 1/5] Adding the changes for the app manager --- .../pom.xml | 4 +- .../pom.xml | 17 +------ .../pom.xml | 20 ++------ .../impl/ApplicationStorageManagerImpl.java | 14 ++---- .../pom.xml | 4 +- .../pom.xml | 4 +- .../pom.xml | 4 +- .../pom.xml | 4 +- components/application-mgt/pom.xml | 4 +- .../pom.xml | 4 +- .../src/main/resources/p2.inf | 8 +--- .../pom.xml | 4 +- .../pom.xml | 4 +- .../pom.xml | 28 +++++------ .../pom.xml | 4 +- .../pom.xml | 48 +++++++++++-------- .../pom.xml | 4 +- features/application-mgt/pom.xml | 4 +- 18 files changed, 79 insertions(+), 104 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml index 1bdb6b03d33..a8cd2bb66fc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml @@ -24,11 +24,11 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT org.wso2.carbon.device.application.mgt.authhandler - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT war WSO2 Carbon - Application Management Authentication Handler API Proxy Service for Authentication Handling in WSO2 App Manager. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml index 85c6edd29ad..79f49e38509 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.common - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Application Management Common WSO2 Carbon - Application Management Common @@ -51,21 +51,8 @@ ${carbon.device.mgt.version} Application Management Common Bundle - org.osgi.framework, - org.osgi.service.component, - org.apache.commons.logging, - javax.xml.*, - org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", - org.wso2.carbon.device.mgt.core.dto.*;version="${carbon.device.mgt.version}", - org.wso2.carbon.device.mgt.core.dao.*;version="${carbon.device.mgt.version}", org.wso2.carbon.device.mgt.common.operation.mgt.*;version="${carbon.device.mgt.version}", - org.w3c.dom, - org.json, - org.xml.sax, com.google.gson, - javax.naming, - javax.xml.bind.annotation, - javax.xml.bind, io.swagger.annotations.*;resolution:=optional diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 10f406d4cf3..c5043c346fe 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.core - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Application Management Core WSO2 Carbon - Application Management Core @@ -57,7 +57,6 @@ org.osgi.framework, org.osgi.service.component, org.apache.commons.logging, - javax.xml.*, javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional, org.wso2.carbon.context.*, org.wso2.carbon.utils.*, @@ -71,35 +70,26 @@ org.wso2.carbon.device.application.mgt.common.*, org.wso2.carbon.device.mgt.core.*, org.wso2.carbon.device.mgt.common.*, - org.apache.axis2.*, org.wso2.carbon.user.core.*, org.wso2.carbon.user.api.*, org.wso2.carbon.ndatasource.core, org.wso2.carbon, javax.annotation, - org.bouncycastle.cert, - org.bouncycastle.cert.jcajce, - org.bouncycastle.cms, - org.bouncycastle.jce.provider, - org.bouncycastle.util, org.xml.sax, org.xml.sax.helpers, org.apache.commons.io, org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", org.apache.commons.codec.digest;version="${commons-codec.wso2.osgi.version.range}", org.wso2.carbon.base, - org.wso2.carbon.device.mgt.core.dto.*;version="${carbon.device.mgt.version}", - org.wso2.carbon.device.mgt.core.dao.*;version="${carbon.device.mgt.version}", - net.dongliu.* + net.dongliu.apk.parser.* apk-parser;scope=compile|runtime;inline=false - true - true + + !org.wso2.carbon.device.application.mgt.core.internal.*, org.wso2.carbon.device.application.mgt.core.* - PlatformDeployer 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 899887f7ca5..957f32c022b 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 @@ -23,12 +23,12 @@ 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.ApkFile; import net.dongliu.apk.parser.bean.ApkMeta; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.validator.routines.UrlValidator; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationType; @@ -41,16 +41,10 @@ import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil; -import org.apache.commons.validator.routines.UrlValidator; import org.xml.sax.SAXException; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; +import javax.xml.parsers.ParserConfigurationException; +import java.io.*; import java.text.ParseException; import java.util.HashMap; import java.util.List; @@ -59,8 +53,6 @@ import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.xml.parsers.ParserConfigurationException; - import static org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil.deleteDir; import static org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil.saveFile; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml index ebb2c88188c..f32092e1553 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml @@ -22,13 +22,13 @@ application-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.publisher.api - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT war WSO2 Carbon - Application Management API WSO2 Carbon - Application Management API diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml index 19083272f15..e903f7eff60 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml @@ -22,12 +22,12 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT 4.0.0 org.wso2.carbon.device.application.mgt.publisher.ui - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Application Management Publisher UI WSO2 Carbon - Application Management Publisher UI React Application http://wso2.org diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml index e65148da2e6..f87d02d27cd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml @@ -22,13 +22,13 @@ application-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.store.api - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT war WSO2 Carbon - Application Management API WSO2 Carbon - Application Management API diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml index 4962a730b64..4b37665d874 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml @@ -24,10 +24,10 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT org.wso2.carbon.device.application.mgt.store.ui - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 68f8b0e0e51..166a68acb10 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Component WSO2 Carbon - Application Management Component diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml index f7bedc059ab..571035fb9d0 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.api.feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management API Feature http://wso2.org diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/src/main/resources/p2.inf b/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/src/main/resources/p2.inf index 1d83a6da71b..edf41c6ffd2 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/src/main/resources/p2.inf +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/src/main/resources/p2.inf @@ -1,8 +1,4 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.application -.mgt.api_${feature.version}/webapps/api#application-mgt-publisher#v1.0.war,target:${installFolder}/../. -./deployment/server/webapps/api#application-mgt-publisher#v1.0.war,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.application -.mgt.api_${feature.version}/webapps/api#application-mgt-store#v1.0.war,target:${installFolder}/../. -./deployment/server/webapps/api#application-mgt-store#v1.0.war,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.application.mgt.api_${feature.version}/webapps/api#application-mgt-publisher#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#application-mgt-publisher#v1.0.war,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.application.mgt.api_${feature.version}/webapps/api#application-mgt-store#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#application-mgt-store#v1.0.war,overwrite:true);\ \ No newline at end of file diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.auth.handler.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.auth.handler.feature/pom.xml index 09c5995d73d..80e42d15421 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.auth.handler.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.auth.handler.feature/pom.xml @@ -22,12 +22,12 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT 4.0.0 org.wso2.carbon.device.application.mgt.auth.handler.feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Authentication Handler Feature This feature contains the Authentication Handler implementation for Publisher and Store. diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.extensions.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.extensions.feature/pom.xml index 67e5f3bdd99..504742d4049 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.extensions.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.extensions.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.0.46-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.extensions.feature pom - 3.0.46-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Application Management Extension Feature http://wso2.org WSO2 Application Management Extension Feature diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.feature/pom.xml index 6e72589d1e0..548edd110fe 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.feature/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Aggregate Feature http://wso2.org @@ -45,14 +45,14 @@ org.wso2.carbon.device.application.mgt.publisher.ui.feature zip - - javax.servlet.jsp - javax.servlet.jsp-api - - - org.wso2.orbit.org.scannotation - scannotation - + + + + + + + + @@ -79,10 +79,10 @@ org.wso2.carbon.devicemgt:org.wso2.carbon.device.application.mgt.server.feature:${carbon.device.mgt.version} org.wso2.carbon.devicemgt:org.wso2.carbon.device.application.mgt.publisher.ui.feature:${carbon.device.mgt.version} - - javax.servlet.jsp:javax.servlet.jsp-api - org.wso2.orbit.org.scannotation:scannotation:${scannotation.version} - + + + + diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui.feature/pom.xml index f9889befd73..4e1a6ce4499 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui.feature/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.publisher.ui.feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Publisher UI Feature http://wso2.org diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/pom.xml index f30952ed26e..f70e66d5425 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.server.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Application Management Server Feature http://wso2.org This feature contains the core bundles required for Back-end Application Management functionality @@ -44,16 +44,24 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.application.mgt.core - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.application.mgt.api.feature - zip - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.application.mgt.auth.handler.feature - zip - + + + + + + + + + + + + + + + + + + @@ -103,10 +111,10 @@ org.eclipse.equinox.p2.type.group:false - - org.wso2.carbon.devicemgt:org.wso2.carbon.device.application.mgt.api.feature:${carbon.device.mgt.version} - org.wso2.carbon.devicemgt:org.wso2.carbon.device.application.mgt.auth.handler.feature:${carbon.device.mgt.version} - + + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.application.mgt.common:${carbon.device.mgt.version} @@ -114,12 +122,14 @@ org.wso2.carbon.devicemgt:org.wso2.carbon.device.application.mgt.core:${carbon.device.mgt.version} + + - - org.wso2.carbon.core.server:${carbon.kernel.version} - + + + diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.store.ui.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.store.ui.feature/pom.xml index 95f67bde042..49843464020 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.store.ui.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.store.ui.feature/pom.xml @@ -23,12 +23,12 @@ org.wso2.carbon.devicemgt application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT 4.0.0 org.wso2.carbon.device.application.mgt.store.ui.feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Store UI Feature http://wso2.org diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index 8bc11b1ec42..16d3db95a53 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 application-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Feature http://wso2.org From 93af292037f0188a9642cdb35a6a0f3bebd8c5a3 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Sat, 15 Sep 2018 22:01:30 +0530 Subject: [PATCH 2/5] Resolve conflicts --- pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ee4b6ff4109..de54d162441 100644 --- a/pom.xml +++ b/pom.xml @@ -2195,11 +2195,7 @@ 1.8 2.4.2 - -<<<<<<< HEAD - -======= ->>>>>>> 625589decc78a4f3da8091a227c0fac6e2617c9e + 7.0.85 1.0 From 4c5cdc75fe7bcfd2def3d865e7a9cb54d5487a82 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sat, 15 Sep 2018 22:44:24 +0530 Subject: [PATCH 3/5] Adding application release creating logic --- .../common/services/ApplicationManager.java | 8 +-- .../mgt/core/impl/ApplicationManagerImpl.java | 56 +++++++++++++------ .../impl/ApplicationManagementAPIImpl.java | 6 +- 3 files changed, 45 insertions(+), 25 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/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index cccf451aced..37070b38e4c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -153,20 +153,20 @@ public interface ApplicationManager { void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws ApplicationManagementException; /** - * To validate the application existence for given application id + * Get the application if application is an accessible one. * * @param applicationId ID of the Application. * @throws ApplicationManagementException Application Management Exception. */ - Application validateApplication(int applicationId) throws ApplicationManagementException; + Application getApplicationIfAccessible(int applicationId) throws ApplicationManagementException; /** - * To validate the application release existence for given application release UUID + * Get the application release for given UUID if application release is exists and application id is valid one. * * @param releaseUuid UUID of the Application Release. * @throws ApplicationManagementException Application Management Exception. */ - ApplicationRelease validateApplicationRelease(int applicationId, String releaseUuid) throws + ApplicationRelease getAppReleaseIfExists(int applicationId, String releaseUuid) 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/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 6ffa3699604..fcfa5f4225d 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 @@ -70,6 +70,8 @@ public class ApplicationManagerImpl implements ApplicationManager { private DeviceTypeDAO deviceTypeDAO; private VisibilityDAO visibilityDAO; private ApplicationDAO applicationDAO; + private LifecycleStateDAO lifecycleStateDAO; + public ApplicationManagerImpl() { initDataAccessObjects(); @@ -79,6 +81,7 @@ public class ApplicationManagerImpl implements ApplicationManager { this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO(); this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); + this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();; } @Override @@ -134,9 +137,10 @@ public class ApplicationManagerImpl implements ApplicationManager { lifecycleState.setUpdatedBy(userName); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); + lifecycleState.setUpdatedBy(userName); addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState); - LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - lifecycleStateDAO.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); + this.lifecycleStateDAO + .addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); applicationRelease.setLifecycleState(lifecycleState); applicationReleases.add(applicationRelease); @@ -209,21 +213,36 @@ public class ApplicationManagerImpl implements ApplicationManager { public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - Application application = validateApplication(applicationId); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + Application application = getApplicationIfAccessible(applicationId); validateReleaseCreatingRequest(applicationRelease); if (log.isDebugEnabled()) { log.debug("Application release request is received for the application " + application.toString()); } try { ConnectionManagerUtil.beginDBTransaction(); -// todo consider about lifecycle adding applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO(). createRelease(applicationRelease, application.getId(), tenantId); + LifecycleState lifecycleState = new LifecycleState(); + lifecycleState.setUpdatedBy(userName); + lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); + lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); + lifecycleState.setUpdatedBy(userName); + addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState); + this.lifecycleStateDAO + .addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); ConnectionManagerUtil.commitDBTransaction(); return applicationRelease; } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - throw e; + throw new ApplicationManagementException( + "Error occured while adding application release into IoTS app management Application id of the " + + "application release: " + applicationId, e); + } catch (LifeCycleManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationManagementException( + "Error occured while adding application release lifecycle state to IoTS app management. " + + "Application id of the application release: " + applicationId, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -353,7 +372,7 @@ public class ApplicationManagerImpl implements ApplicationManager { public List getReleases(int applicationId) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - Application application = validateApplication(applicationId); + Application application = getApplicationIfAccessible(applicationId); List applicationReleases; List filteredApplicationReleases = new ArrayList<>(); if (log.isDebugEnabled()) { @@ -393,7 +412,7 @@ public class ApplicationManagerImpl implements ApplicationManager { "need to have admin permission"); } - if (validateApplication(applicationId) == null) { + if (getApplicationIfAccessible(applicationId) == null) { throw new ApplicationManagementException("Invalid Application"); } List applicationReleases = getReleases(applicationId); @@ -427,11 +446,11 @@ public class ApplicationManagerImpl implements ApplicationManager { throws ApplicationManagementException { String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - Application application = validateApplication(applicationId); + Application application = getApplicationIfAccessible(applicationId); if (application == null) { throw new ApplicationManagementException("Invalid Application ID is received"); } - ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, releaseUuid); + ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid); if (applicationRelease == null) { throw new ApplicationManagementException("Invalid Application Release UUID is received"); } @@ -537,12 +556,12 @@ public class ApplicationManagerImpl implements ApplicationManager { } /** - * To validate the pre-request of the ApplicationRelease. + * Get the application if application is an accessible one. * * @param applicationId ID of the Application. * @return Application related with the UUID */ - public Application validateApplication(int applicationId) throws ApplicationManagementException { + public Application getApplicationIfAccessible(int applicationId) throws ApplicationManagementException { if (applicationId <= 0) { throw new ApplicationManagementException("Application id could,t be a negative integer. Hence please add " + "valid application id."); @@ -568,7 +587,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } if (!isAppAllowed) { - throw new NotFoundException("Application of the " + applicationId + " does not exist."); + throw new NotFoundException("Application of the " + applicationId + + " does not exist. Please check whether user have permissions to access the application."); } return application; } catch (UserStoreException e) { @@ -580,12 +600,12 @@ public class ApplicationManagerImpl implements ApplicationManager { } /** - * To validate the pre-request of the ApplicationRelease. + * Get the application release for given UUID if application release is exists and application id is valid one. * * @param applicationUuid UUID of the Application. * @return Application related with the UUID */ - public ApplicationRelease validateApplicationRelease(int applicationId, String applicationUuid) throws + public ApplicationRelease getAppReleaseIfExists(int applicationId, String applicationUuid) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); ApplicationRelease applicationRelease; @@ -694,7 +714,7 @@ public class ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.openDBConnection(); LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid); + ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid); lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState())); } catch (ApplicationManagementDAOException e) { @@ -712,8 +732,8 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationManagementException { try { ConnectionManagerUtil.openDBConnection(); - Application application = validateApplication(applicationId); - ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid); + Application application = getApplicationIfAccessible(applicationId); + ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid); LifecycleStateDAO lifecycleStateDAO; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -828,7 +848,7 @@ public class ApplicationManagerImpl implements ApplicationManager { public Application updateApplication(Application application) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - Application existingApplication = validateApplication(application.getId()); + Application existingApplication = getApplicationIfAccessible(application.getId()); List addingRoleList; List removingRoleList; List addingTags; 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java index 7c4fe746c35..653bc60f5e8 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java @@ -208,7 +208,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { attachments.add(screenshot.getDataHandler().getInputStream()); } } - applicationRelease = applicationManager.validateApplicationRelease(appId, applicationUuid); + applicationRelease = applicationManager.getAppReleaseIfExists(appId, applicationUuid); LifecycleState lifecycleState = applicationManager.getLifecycleState(appId, applicationRelease.getUuid()); if (AppLifecycleState.PUBLISHED.toString().equals(lifecycleState.getCurrentState()) || AppLifecycleState.DEPRECATED.toString().equals(lifecycleState.getCurrentState())) { @@ -260,7 +260,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { return APIUtil.getResponse("Uploading artifacts for the application is failed " + applicationUuid, Response.Status.BAD_REQUEST); } - applicationRelease = applicationManager.validateApplicationRelease(applicationId, applicationUuid); + applicationRelease = applicationManager.getAppReleaseIfExists(applicationId, applicationUuid); applicationRelease = applicationStorageManager .updateReleaseArtifacts(applicationRelease, appType, deviceType, binaryFile.getDataHandler().getInputStream()); @@ -323,7 +323,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { List attachments = new ArrayList<>(); try { - Application application = applicationManager.validateApplication(applicationId); + Application application = applicationManager.getApplicationIfAccessible(applicationId); if (!applicationManager.isApplicationReleaseUpdateAcceptable(application.getId(), applicationRelease.getUuid())) { From b3874ee1baa589c20e4278a8f3e98001b620e69d Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sun, 16 Sep 2018 01:57:08 +0530 Subject: [PATCH 4/5] Refactor the source --- .../common/services/ApplicationManager.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 79 +++++++------------ .../impl/ApplicationManagementAPIImpl.java | 2 +- 3 files changed, 29 insertions(+), 54 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/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 37070b38e4c..1335c6d9dc8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -188,7 +188,7 @@ public interface ApplicationManager { * @return Updated Application Release. * @throws ApplicationManagementException Application Management Exception. */ - boolean isApplicationReleaseUpdateAcceptable(int appId, String appReleaseUuid) + boolean isAcceptableAppReleaseUpdate(int appId, String appReleaseUuid) 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/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 fcfa5f4225d..853ac72e930 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 @@ -40,6 +40,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionExcep import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; @@ -70,6 +71,7 @@ public class ApplicationManagerImpl implements ApplicationManager { private DeviceTypeDAO deviceTypeDAO; private VisibilityDAO visibilityDAO; private ApplicationDAO applicationDAO; + private ApplicationReleaseDAO applicationReleaseDAO; private LifecycleStateDAO lifecycleStateDAO; @@ -81,7 +83,8 @@ public class ApplicationManagerImpl implements ApplicationManager { this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO(); this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); - this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();; + this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); + this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); } @Override @@ -130,17 +133,13 @@ public class ApplicationManagerImpl implements ApplicationManager { + "the payload contains more than one"); } applicationRelease = application.getApplicationReleases().get(0); - applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO(). - createRelease(applicationRelease, application.getId(), tenantId); + applicationRelease = this.applicationReleaseDAO + .createRelease(applicationRelease, application.getId(), tenantId); LifecycleState lifecycleState = new LifecycleState(); - lifecycleState.setUpdatedBy(userName); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); - lifecycleState.setUpdatedBy(userName); addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState); - this.lifecycleStateDAO - .addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); applicationRelease.setLifecycleState(lifecycleState); applicationReleases.add(applicationRelease); @@ -161,12 +160,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg, e); ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException(msg, e); - } catch (LifeCycleManagementDAOException e) { - String msg = "Error occurred while adding application lifecycle state"; - log.error(msg, e); - ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationManagementException(msg, e); - }finally { + } finally { ConnectionManagerUtil.closeDBConnection(); } } @@ -189,13 +183,10 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationList = getRoleRestrictedApplicationList(applicationList, userName); } - for (Application application : applicationList.getApplications()) { - applicationReleases = getReleases(application.getId()); application.setApplicationReleases(applicationReleases); } - return applicationList; } catch (UserStoreException e) { throw new ApplicationManagementException( @@ -210,10 +201,9 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) throws - ApplicationManagementException { + public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) + throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); Application application = getApplicationIfAccessible(applicationId); validateReleaseCreatingRequest(applicationRelease); if (log.isDebugEnabled()) { @@ -221,16 +211,13 @@ public class ApplicationManagerImpl implements ApplicationManager { } try { ConnectionManagerUtil.beginDBTransaction(); - applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO(). - createRelease(applicationRelease, application.getId(), tenantId); + applicationRelease = this.applicationReleaseDAO + .createRelease(applicationRelease, application.getId(), tenantId); LifecycleState lifecycleState = new LifecycleState(); - lifecycleState.setUpdatedBy(userName); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); - lifecycleState.setUpdatedBy(userName); addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState); - this.lifecycleStateDAO - .addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); + ConnectionManagerUtil.commitDBTransaction(); return applicationRelease; } catch (ApplicationManagementDAOException e) { @@ -238,11 +225,6 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException( "Error occured while adding application release into IoTS app management Application id of the " + "application release: " + applicationId, e); - } catch (LifeCycleManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationManagementException( - "Error occured while adding application release lifecycle state to IoTS app management. " - + "Application id of the application release: " + applicationId, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -381,8 +363,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } try { ConnectionManagerUtil.openDBConnection(); - applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO() - .getReleases(application.getName(), application.getType(), tenantId); + applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId); for (ApplicationRelease applicationRelease : applicationReleases) { LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); @@ -425,7 +406,6 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - newAppLifecycleState.setUpdatedBy(userName); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); storedLocations.add(applicationRelease.getAppHashValue()); } @@ -444,8 +424,6 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException { - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); Application application = getApplicationIfAccessible(applicationId); if (application == null) { throw new ApplicationManagementException("Invalid Application ID is received"); @@ -462,7 +440,6 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - newAppLifecycleState.setUpdatedBy(userName); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); }else{ throw new ApplicationManagementException("Can't delete the application release, You have to move the " + @@ -506,15 +483,14 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ValidationException("Username and tenant Id cannot be empty"); } if (application.getAppCategory() == null) { - throw new ValidationException("Username and tenant Id cannot be empty"); + throw new ValidationException("Application category can't be empty"); } isValidApplicationType = isValidAppType(application); if (!isValidApplicationType) { throw new ValidationException( - "App Type contains in the application creating payload doesn't match with " + - "supported app types"); + "App Type contains in the application creating payload doesn't match with supported app types"); } validateApplicationExistence(application); @@ -620,8 +596,7 @@ public class ApplicationManagerImpl implements ApplicationManager { + "parameter to get the relevant application."); } ConnectionManagerUtil.openDBConnection(); - applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().getReleaseByIds - (applicationId, applicationUuid, tenantId); + applicationRelease = this.applicationReleaseDAO.getReleaseByIds(applicationId, applicationUuid, tenantId); if (applicationRelease == null) { throw new ApplicationManagementException("Doesn't exist a application release for application ID: " + applicationId + "and application UUID: " + @@ -644,10 +619,10 @@ public class ApplicationManagerImpl implements ApplicationManager { "Application Id: " + appId); } try { + ApplicationRelease existingAppRelease = getAppReleaseIfExists(appId, applicationRelease.getUuid()); ConnectionManagerUtil.openDBConnection(); // todo consider about lifecycle - applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO() - .updateRelease(appId, applicationRelease, tenantId); + applicationRelease = this.applicationReleaseDAO.updateRelease(appId, applicationRelease, tenantId); return applicationRelease; } finally { @@ -656,7 +631,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public boolean isApplicationReleaseUpdateAcceptable(int appId, String appReleaseUuid) + public boolean isAcceptableAppReleaseUpdate(int appId, String appReleaseUuid) throws ApplicationManagementException { LifecycleState lifecycleState = getLifecycleState(appId, appReleaseUuid); return AppLifecycleState.CREATED.toString().equals(lifecycleState.getCurrentState()) || AppLifecycleState @@ -713,9 +688,8 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState lifecycleState; try { ConnectionManagerUtil.openDBConnection(); - LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid); - lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); + lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState())); } catch (ApplicationManagementDAOException e) { throw new ApplicationManagementException("Failed to get lifecycle state", e); @@ -728,19 +702,20 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws - ApplicationManagementException { + public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) + throws ApplicationManagementException { try { ConnectionManagerUtil.openDBConnection(); Application application = getApplicationIfAccessible(applicationId); ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid); - LifecycleStateDAO lifecycleStateDAO; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + state.setUpdatedBy(userName); - if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) { + if (state.getCurrentState() != null && state.getPreviousState() != null) { validateLifecycleState(state); - lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - lifecycleStateDAO.addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId); + this.lifecycleStateDAO + .addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId); } } catch (LifeCycleManagementDAOException | DBConnectionException e) { throw new ApplicationManagementException("Failed to add lifecycle state", e); 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java index 653bc60f5e8..e49c1bebff0 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java @@ -325,7 +325,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { try { Application application = applicationManager.getApplicationIfAccessible(applicationId); - if (!applicationManager.isApplicationReleaseUpdateAcceptable(application.getId(), + if (!applicationManager.isAcceptableAppReleaseUpdate(application.getId(), applicationRelease.getUuid())) { String msg = "Application release is in the " + applicationRelease.getLifecycleState().getCurrentState() + " state. Hence updating is not acceptable when application in this state"; From ff96884268014454fb211f4453c08acaeea50e19 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sun, 16 Sep 2018 08:55:09 +0530 Subject: [PATCH 5/5] Refactor the source --- .../mgt/core/impl/ApplicationManagerImpl.java | 25 +++++++++---------- .../impl/ApplicationManagementAPIImpl.java | 12 +++++++-- 2 files changed, 22 insertions(+), 15 deletions(-) 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 853ac72e930..b4540d23bd3 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 @@ -98,7 +98,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } validateAppCreatingRequest(application); - validateReleaseCreatingRequest(application.getApplicationReleases().get(0)); + validateAppReleasePayload(application.getApplicationReleases().get(0)); DeviceType deviceType; ApplicationRelease applicationRelease; List applicationReleases = new ArrayList<>(); @@ -205,7 +205,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); Application application = getApplicationIfAccessible(applicationId); - validateReleaseCreatingRequest(applicationRelease); + validateAppReleasePayload(applicationRelease); if (log.isDebugEnabled()) { log.debug("Application release request is received for the application " + application.toString()); } @@ -429,9 +429,6 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException("Invalid Application ID is received"); } ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid); - if (applicationRelease == null) { - throw new ApplicationManagementException("Invalid Application Release UUID is received"); - } LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid()); String currentState = appLifecycleState.getCurrentState(); if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState @@ -612,18 +609,15 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws ApplicationManagementException { - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + validateAppReleasePayload(applicationRelease); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) { log.debug("Updating the Application release. UUID: " + applicationRelease.getUuid() + ", " + "Application Id: " + appId); } try { - ApplicationRelease existingAppRelease = getAppReleaseIfExists(appId, applicationRelease.getUuid()); ConnectionManagerUtil.openDBConnection(); -// todo consider about lifecycle applicationRelease = this.applicationReleaseDAO.updateRelease(appId, applicationRelease, tenantId); - return applicationRelease; } finally { ConnectionManagerUtil.closeDBConnection(); @@ -668,12 +662,12 @@ public class ApplicationManagerImpl implements ApplicationManager { } /** - * To validate a create release request to make sure all the pre-conditions satisfied. + * To validate a app release creating request and app updating request to make sure all the pre-conditions satisfied. * * @param applicationRelease ApplicationRelease that need to be created. * @throws ApplicationManagementException Application Management Exception. */ - private void validateReleaseCreatingRequest(ApplicationRelease applicationRelease) + private void validateAppReleasePayload(ApplicationRelease applicationRelease) throws ApplicationManagementException { if (applicationRelease.getVersion() == null) { @@ -688,8 +682,13 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState lifecycleState; try { ConnectionManagerUtil.openDBConnection(); - ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid); - lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); + lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationId); + if (lifecycleState == null) { + throw new NotFoundException( + "Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: " + + applicationUuid); + + } lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState())); } catch (ApplicationManagementDAOException e) { throw new ApplicationManagementException("Failed to get lifecycle state", e); 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java index e49c1bebff0..f212747cef4 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/ApplicationManagementAPIImpl.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/ApplicationManagementAPIImpl.java @@ -222,7 +222,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { return Response.status(Response.Status.OK) .entity("Successfully uploaded artifacts for the application " + applicationUuid).build(); } catch (NotFoundException e) { - String msg = "Couldn't found application release details and storage details"; + String msg = + "Couldn't found application release details or storage details or lifecycle details. Application id: " + + appId + " App release uuid: " + applicationUuid; log.error(msg, e); return APIUtil.getResponse(e, Response.Status.NOT_FOUND); } catch (ApplicationManagementException e) { @@ -424,7 +426,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid); - } catch (ApplicationManagementException e) { + } catch (NotFoundException e){ + String msg = "Couldn't found application lifecycle details for appid: " + applicationId + + " and app release UUID: " + applicationUuid; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).build(); + } + catch (ApplicationManagementException e) { String msg = "Error occurred while getting lifecycle state."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();