From 9df8660bdf58319347d2465784ec9f1bc6c4dc8d Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Thu, 20 Sep 2018 16:52:58 +0530 Subject: [PATCH] Add package name to ApplicationRelease and change ApplicationType enum --- .../mgt/common/ApplicationRelease.java | 12 ++++ .../mgt/common/ApplicationType.java | 2 +- .../application/mgt/common/DeviceType.java | 5 ++ .../GenericApplicationReleaseDAOImpl.java | 59 ++++++++++--------- .../mgt/core/impl/ApplicationManagerImpl.java | 2 +- .../impl/ApplicationStorageManagerImpl.java | 11 +++- .../impl/ApplicationManagementAPIImpl.java | 6 +- 7 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceType.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index 2d23fed141b..6f451266167 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -105,6 +105,10 @@ public class ApplicationRelease { value = "Latest Lifecycle state of the application release") private LifecycleState lifecycleState; + @ApiModelProperty(name = "packageName", + value = "Application bundle identifier") + private String packageName; + public int getRatedUsers() { return ratedUsers; } @@ -257,4 +261,12 @@ public class ApplicationRelease { public void setLifecycleState(LifecycleState lifecycleState) { this.lifecycleState = lifecycleState; } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getPackageName() { + return packageName; + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java index bfcd77a58fd..3b0049e51aa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java @@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common; * Application Types. */ public enum ApplicationType { - ANDROID, IOS, WEB_CLIP + ENTERPRISE, PUBLIC, WEB, WEB_CLIP } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceType.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceType.java new file mode 100644 index 00000000000..b3bddc448ed --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/DeviceType.java @@ -0,0 +1,5 @@ +package org.wso2.carbon.device.application.mgt.common; + +public enum DeviceType { + ANDROID, IOS +} 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/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index 105d72fc252..7dc83b1586b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -63,10 +63,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE,APP_PRICE,STORED_LOCATION, " - + "BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,SHARED_WITH_ALL_TENANTS, " - + "APP_META_INFO,CREATED_BY,AP_APP_ID) VALUES " - + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE," + + "STORED_LOCATION, BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE," + + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,CREATED_BY,AP_APP_ID) " + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; int index = 0; String generatedColumns[] = {"ID"}; @@ -77,6 +77,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setInt(++index, tenantId); statement.setString(++index, applicationRelease.getUuid()); statement.setString(++index, String.valueOf(applicationRelease.getReleaseType())); + statement.setString(++index, String.valueOf(applicationRelease.getPackageName())); statement.setDouble(++index, applicationRelease.getPrice()); statement.setString(++index, applicationRelease.getAppStoredLoc()); statement.setString(++index, applicationRelease.getScreenshotLoc1()); @@ -121,14 +122,15 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," - + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " - + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " - + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, " - + "AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " - + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL " - + "WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?)" - + " AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " + String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, " + + "AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.BANNER_LOCATION, " + + "AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS " + + "SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, " + + "AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, " + + "AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " + + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " + + "AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?) " + + "AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " + "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; try { @@ -350,27 +352,29 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; - String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND APP_PRICE = ? AND " + - "STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? AND SC_2_LOCATION = ? AND " + - "SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? AND APP_META_INFO = ? AND " + - "CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;"; + String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND PACKAGE_NAME = ? " + + "AND APP_PRICE = ? AND STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? " + + "AND SC_2_LOCATION = ? AND SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? " + + "AND APP_META_INFO = ? AND CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? " + + "AND ID = ?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); statement.setString(1, applicationRelease.getVersion()); statement.setString(2, applicationRelease.getUuid()); statement.setString(3, applicationRelease.getReleaseType()); - statement.setDouble(4, applicationRelease.getPrice()); - statement.setString(5, applicationRelease.getAppStoredLoc()); - statement.setString(6, applicationRelease.getBannerLoc()); - statement.setString(7, applicationRelease.getScreenshotLoc1()); - statement.setString(8, applicationRelease.getScreenshotLoc2()); - statement.setString(9, applicationRelease.getScreenshotLoc3()); - statement.setString(10, applicationRelease.getAppHashValue()); - statement.setInt(11, applicationRelease.getIsSharedWithAllTenants()); - statement.setString(12, applicationRelease.getMetaData()); - statement.setString(13, applicationRelease.getApplicationCreator()); - statement.setTimestamp(14, new Timestamp(System.currentTimeMillis())); + statement.setString(4, applicationRelease.getPackageName()); + statement.setDouble(5, applicationRelease.getPrice()); + statement.setString(6, applicationRelease.getAppStoredLoc()); + statement.setString(7, applicationRelease.getBannerLoc()); + statement.setString(8, applicationRelease.getScreenshotLoc1()); + statement.setString(9, applicationRelease.getScreenshotLoc2()); + statement.setString(10, applicationRelease.getScreenshotLoc3()); + statement.setString(11, applicationRelease.getAppHashValue()); + statement.setInt(12, applicationRelease.getIsSharedWithAllTenants()); + statement.setString(13, applicationRelease.getMetaData()); + statement.setString(14, applicationRelease.getApplicationCreator()); + statement.setTimestamp(15, new Timestamp(System.currentTimeMillis())); statement.executeUpdate(); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( @@ -425,6 +429,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); applicationRelease.setUuid(resultSet.getString("UUID")); applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); + applicationRelease.setPackageName(resultSet.getString("PACKAGE_NAME")); applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); 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 dc6d240b192..f2e851f5ee2 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 @@ -225,7 +225,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException( - "Error occured while adding application release into IoTS app management Application id of the " + "Error occurred while adding application release into IoTS app management Application id of the " + "application release: " + applicationId, e); } finally { ConnectionManagerUtil.closeDBConnection(); 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 957f32c022b..c2080fbcda1 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 @@ -32,6 +32,7 @@ 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; +import org.wso2.carbon.device.application.mgt.common.DeviceType; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; @@ -200,12 +201,16 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager "application UUID " + applicationRelease.getUuid()); } - if (ApplicationType.ANDROID.toString().equals(deviceType)) { + if (DeviceType.ANDROID.toString().equals(deviceType)) { ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile); applicationRelease.setVersion(apkMeta.getVersionName()); - } else if (ApplicationType.IOS.toString().equals(deviceType)) { + applicationRelease.setPackageName(apkMeta.getPackageName()); + } else if (DeviceType.IOS.toString().equals(deviceType)) { NSDictionary plistInfo = ArtifactsParser.readiOSManifestFile(binaryFile); - applicationRelease.setVersion(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString()); + applicationRelease + .setVersion(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString()); + applicationRelease + .setPackageName(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_IDENTIFIER_KEY).toString()); } else { throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " + "application types " + applicationRelease.getUuid()); 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 f57b2185dfc..15cfb1e9954 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 @@ -124,7 +124,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) { return Response.status(Response.Status.BAD_REQUEST).build(); } - if (ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + if (!ApplicationType.ENTERPRISE.toString().equals(application.getType())) { applicationRelease = application.getApplicationReleases().get(0); applicationRelease = applicationStorageManager .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), @@ -173,7 +173,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e), Response.Status.INTERNAL_SERVER_ERROR); } catch (RequestValidatingException e) { - log.error("Error occured while handling the application creating request"); + log.error("Error occurred while handling the application creating request"); return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); } } @@ -486,7 +486,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { return false; } - if (binaryFile == null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + if (binaryFile == null && ApplicationType.ENTERPRISE.toString().equals(application.getType())) { log.error("Binary file is not found for the application release. Application name: " + application.getName() + " Application type: " + application.getType()); return false;