Add package name to ApplicationRelease and change ApplicationType enum

feature/appm-store/pbac
Madawa Soysa 6 years ago
parent 05141ead4d
commit 9df8660bdf

@ -105,6 +105,10 @@ public class ApplicationRelease {
value = "Latest Lifecycle state of the application release") value = "Latest Lifecycle state of the application release")
private LifecycleState lifecycleState; private LifecycleState lifecycleState;
@ApiModelProperty(name = "packageName",
value = "Application bundle identifier")
private String packageName;
public int getRatedUsers() { public int getRatedUsers() {
return ratedUsers; return ratedUsers;
} }
@ -257,4 +261,12 @@ public class ApplicationRelease {
public void setLifecycleState(LifecycleState lifecycleState) { public void setLifecycleState(LifecycleState lifecycleState) {
this.lifecycleState = lifecycleState; this.lifecycleState = lifecycleState;
} }
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getPackageName() {
return packageName;
}
} }

@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common;
* Application Types. * Application Types.
*/ */
public enum ApplicationType { public enum ApplicationType {
ANDROID, IOS, WEB_CLIP ENTERPRISE, PUBLIC, WEB, WEB_CLIP
} }

@ -0,0 +1,5 @@
package org.wso2.carbon.device.application.mgt.common;
public enum DeviceType {
ANDROID, IOS
}

@ -63,10 +63,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE,APP_PRICE,STORED_LOCATION, " String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE,"
+ "BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,SHARED_WITH_ALL_TENANTS, " + "STORED_LOCATION, BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,"
+ "APP_META_INFO,CREATED_BY,AP_APP_ID) VALUES " + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,CREATED_BY,AP_APP_ID) "
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
int index = 0; int index = 0;
String generatedColumns[] = {"ID"}; String generatedColumns[] = {"ID"};
@ -77,6 +77,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setInt(++index, tenantId); statement.setInt(++index, tenantId);
statement.setString(++index, applicationRelease.getUuid()); statement.setString(++index, applicationRelease.getUuid());
statement.setString(++index, String.valueOf(applicationRelease.getReleaseType())); statement.setString(++index, String.valueOf(applicationRelease.getReleaseType()));
statement.setString(++index, String.valueOf(applicationRelease.getPackageName()));
statement.setDouble(++index, applicationRelease.getPrice()); statement.setDouble(++index, applicationRelease.getPrice());
statement.setString(++index, applicationRelease.getAppStoredLoc()); statement.setString(++index, applicationRelease.getAppStoredLoc());
statement.setString(++index, applicationRelease.getScreenshotLoc1()); statement.setString(++index, applicationRelease.getScreenshotLoc1());
@ -121,13 +122,14 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = 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," String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, "
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.BANNER_LOCATION, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, " + "SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, "
+ "AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " + "AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, "
+ "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL " + "AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM "
+ "WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?)" + "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 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;"; + "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
@ -350,27 +352,29 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND APP_PRICE = ? AND " + String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND PACKAGE_NAME = ? "
"STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? AND SC_2_LOCATION = ? AND " + + "AND APP_PRICE = ? AND STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? "
"SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? AND APP_META_INFO = ? AND " + + "AND SC_2_LOCATION = ? AND SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? "
"CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;"; + "AND APP_META_INFO = ? AND CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? "
+ "AND ID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, applicationRelease.getVersion()); statement.setString(1, applicationRelease.getVersion());
statement.setString(2, applicationRelease.getUuid()); statement.setString(2, applicationRelease.getUuid());
statement.setString(3, applicationRelease.getReleaseType()); statement.setString(3, applicationRelease.getReleaseType());
statement.setDouble(4, applicationRelease.getPrice()); statement.setString(4, applicationRelease.getPackageName());
statement.setString(5, applicationRelease.getAppStoredLoc()); statement.setDouble(5, applicationRelease.getPrice());
statement.setString(6, applicationRelease.getBannerLoc()); statement.setString(6, applicationRelease.getAppStoredLoc());
statement.setString(7, applicationRelease.getScreenshotLoc1()); statement.setString(7, applicationRelease.getBannerLoc());
statement.setString(8, applicationRelease.getScreenshotLoc2()); statement.setString(8, applicationRelease.getScreenshotLoc1());
statement.setString(9, applicationRelease.getScreenshotLoc3()); statement.setString(9, applicationRelease.getScreenshotLoc2());
statement.setString(10, applicationRelease.getAppHashValue()); statement.setString(10, applicationRelease.getScreenshotLoc3());
statement.setInt(11, applicationRelease.getIsSharedWithAllTenants()); statement.setString(11, applicationRelease.getAppHashValue());
statement.setString(12, applicationRelease.getMetaData()); statement.setInt(12, applicationRelease.getIsSharedWithAllTenants());
statement.setString(13, applicationRelease.getApplicationCreator()); statement.setString(13, applicationRelease.getMetaData());
statement.setTimestamp(14, new Timestamp(System.currentTimeMillis())); statement.setString(14, applicationRelease.getApplicationCreator());
statement.setTimestamp(15, new Timestamp(System.currentTimeMillis()));
statement.executeUpdate(); statement.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -425,6 +429,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID")); applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPackageName(resultSet.getString("PACKAGE_NAME"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));

@ -225,7 +225,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( 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); + "application release: " + applicationId, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();

@ -32,6 +32,7 @@ import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; 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.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.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
@ -200,12 +201,16 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
"application UUID " + applicationRelease.getUuid()); "application UUID " + applicationRelease.getUuid());
} }
if (ApplicationType.ANDROID.toString().equals(deviceType)) { if (DeviceType.ANDROID.toString().equals(deviceType)) {
ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile); ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile);
applicationRelease.setVersion(apkMeta.getVersionName()); 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); 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 { } else {
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " + throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
"application types " + applicationRelease.getUuid()); "application types " + applicationRelease.getUuid());

@ -124,7 +124,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) { if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) {
return Response.status(Response.Status.BAD_REQUEST).build(); 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 = application.getApplicationReleases().get(0);
applicationRelease = applicationStorageManager applicationRelease = applicationStorageManager
.uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(),
@ -173,7 +173,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e), return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
Response.Status.INTERNAL_SERVER_ERROR); Response.Status.INTERNAL_SERVER_ERROR);
} catch (RequestValidatingException e) { } 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); return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
} }
} }
@ -486,7 +486,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return false; 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: " log.error("Binary file is not found for the application release. Application name: "
+ application.getName() + " Application type: " + application.getType()); + application.getName() + " Application type: " + application.getType());
return false; return false;

Loading…
Cancel
Save