Merge branch 'application-mgt-new' into 'application-mgt-new'

Improve app manager functionalities

See merge request entgra/carbon-device-mgt!14
feature/appm-store/pbac
Inosh Perara 6 years ago
commit e5559b6519

@ -31,7 +31,6 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -45,7 +44,7 @@ public class APIUtil {
private static final String DEFAULT_AGENT_API_TAG = "device_agent"; private static final String DEFAULT_AGENT_API_TAG = "device_agent";
private static final String DEFAULT_CERT_API_TAG = "scep_management"; private static final String DEFAULT_CERT_API_TAG = "scep_management";
private static final String DEFAULT_APP_MGT_TAG = "application_management"; private static final String DEFAULT_APP_MGT_TAG = "application_management";
private static final String DEFAULT_APP_MGT_LCYCLE_MGT_TAG = "lifecycle_management"; private static final String DEFAULT_APP_MGT_REVIEW_MGT_TAG = "review_management";
private static final String DEFAULT_APP_MGT_SUB_MGT_TAG = "subscription_management"; private static final String DEFAULT_APP_MGT_SUB_MGT_TAG = "subscription_management";
public static final String PERMISSION_PROPERTY_NAME = "name"; public static final String PERMISSION_PROPERTY_NAME = "name";
@ -112,7 +111,7 @@ public class APIUtil {
allowedApisTags.add(DEFAULT_CERT_API_TAG); allowedApisTags.add(DEFAULT_CERT_API_TAG);
allowedApisTags.add(DEFAULT_AGENT_API_TAG); allowedApisTags.add(DEFAULT_AGENT_API_TAG);
allowedApisTags.add(DEFAULT_APP_MGT_TAG); allowedApisTags.add(DEFAULT_APP_MGT_TAG);
allowedApisTags.add(DEFAULT_APP_MGT_LCYCLE_MGT_TAG); allowedApisTags.add(DEFAULT_APP_MGT_REVIEW_MGT_TAG);
allowedApisTags.add(DEFAULT_APP_MGT_SUB_MGT_TAG); allowedApisTags.add(DEFAULT_APP_MGT_SUB_MGT_TAG);
return allowedApisTags; return allowedApisTags;
} }

@ -60,10 +60,6 @@ public class ApplicationRelease {
value = "icon file storing location") value = "icon file storing location")
private String iconLoc; private String iconLoc;
@ApiModelProperty(name = "applicationCreator",
value = "Application release creator")
private String applicationCreator;
@ApiModelProperty(name = "releaseType", @ApiModelProperty(name = "releaseType",
value = "Release type of the application release", value = "Release type of the application release",
required = true, required = true,
@ -229,14 +225,6 @@ public class ApplicationRelease {
this.screenshotLoc3 = screenshotLoc3; this.screenshotLoc3 = screenshotLoc3;
} }
public String getApplicationCreator() {
return applicationCreator;
}
public void setApplicationCreator(String applicationCreator) {
this.applicationCreator = applicationCreator;
}
public String getIconLoc() { public String getIconLoc() {
return iconLoc; return iconLoc;
} }

@ -169,7 +169,6 @@ public class Util {
appRelease.setAppHashValue(rs.getString("APP_HASH_VALUE")); appRelease.setAppHashValue(rs.getString("APP_HASH_VALUE"));
appRelease.setAppStoredLoc(rs.getString("STORED_LOCATION")); appRelease.setAppStoredLoc(rs.getString("STORED_LOCATION"));
appRelease.setBannerLoc(rs.getString("BANNER_LOCATION")); appRelease.setBannerLoc(rs.getString("BANNER_LOCATION"));
appRelease.setApplicationCreator(rs.getString("CREATED_BY"));
appRelease.setRating(rs.getDouble("RATING")); appRelease.setRating(rs.getDouble("RATING"));
appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS")); appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS"));
appRelease.setMetaData(rs.getString("APP_META_INFO")); appRelease.setMetaData(rs.getString("APP_META_INFO"));

@ -34,7 +34,9 @@ import java.sql.SQLException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
/** /**
@ -53,18 +55,23 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME, AP_APP_RELEASE_ID, AP_APP_ID) " sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIES_AT,"
+ "VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
try { try {
Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
statement = conn.prepareStatement(sql, new String[] { "id" }); statement = conn.prepareStatement(sql, new String[] { "id" });
statement.setInt(1, tenantId); statement.setInt(1, tenantId);
statement.setString(2, review.getComment()); statement.setString(2, review.getComment());
statement.setInt(3, review.getParentId()); statement.setInt(3, review.getParentId());
statement.setString(4, review.getUsername()); statement.setString(4, review.getUsername());
statement.setString(5,uuid); statement.setTimestamp(5,timestamp);
statement.setString(6,uuid); statement.setTimestamp(6,timestamp);
statement.setString(7,uuid);
statement.setString(8,uuid);
statement.executeUpdate(); statement.executeUpdate();
rs = statement.getGeneratedKeys(); rs = statement.getGeneratedKeys();
return rs.next(); return rs.next();
@ -134,15 +141,19 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=?, MODIFIED_AT=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;";
try { try {
Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, review.getComment()); statement.setString(1, review.getComment());
statement.setInt(2, review.getRating()); statement.setInt(2, review.getRating());
statement.setInt(3, reviewId); statement.setTimestamp(3, timestamp);
statement.setString(4, username); statement.setInt(4, reviewId);
statement.setInt(5, tenantId); statement.setString(5, username);
statement.setInt(6, tenantId);
return statement.executeUpdate(); return statement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("Error occurred while executing review updating query"); throw new ReviewManagementDAOException("Error occurred while executing review updating query");
@ -206,7 +217,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, " sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID "
+ "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND "
+ "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND " + "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;";
@ -230,7 +241,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
throw new ReviewManagementDAOException( throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when verifying application existence", e); "Error occurred while obtaining the DB connection when verifying application existence", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("Error occurred while adding unrestricted roles", e); throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews", e);
}finally { }finally {
Util.cleanupResources(statement, rs); Util.cleanupResources(statement, rs);
} }

@ -116,7 +116,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when verifying application existence", e); "Error occurred while obtaining the DB connection when verifying application existence", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e); throw new ApplicationManagementDAOException(
"DB connection error occured while checking whether application exist or not.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }

@ -21,22 +21,18 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.Application;
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.Rating; import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -65,8 +61,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE," 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," + "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) " + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,AP_APP_ID) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?);"; + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
int index = 0; int index = 0;
String generatedColumns[] = {"ID"}; String generatedColumns[] = {"ID"};
@ -87,7 +83,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setString(++index, applicationRelease.getAppHashValue()); statement.setString(++index, applicationRelease.getAppHashValue());
statement.setInt(++index, applicationRelease.getIsSharedWithAllTenants()); statement.setInt(++index, applicationRelease.getIsSharedWithAllTenants());
statement.setString(++index, applicationRelease.getMetaData()); statement.setString(++index, applicationRelease.getMetaData());
statement.setString(++index, applicationRelease.getApplicationCreator());
statement.setInt(++index, appId); statement.setInt(++index, appId);
statement.executeUpdate(); statement.executeUpdate();
resultSet = statement.getGeneratedKeys(); resultSet = statement.getGeneratedKeys();
@ -107,7 +102,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
/** /**
* To get release details of a specific application. * To get latest updated app release details of a specific application.
* *
* @param applicationName Name of the application. * @param applicationName Name of the application.
* @param applicationType Type of the application. * @param applicationType Type of the application.
@ -123,16 +118,15 @@ 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, " String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS "
+ "AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.BANNER_LOCATION, " + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS "
+ "AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS " + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS "
+ "AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, " + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO , "
+ "AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " + "AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM "
+ "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE "
+ "AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?) " + "NAME=? AND TYPE=? AND TENANT_ID=?) AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND "
+ "AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " + "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;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
@ -179,7 +173,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + " 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 " + + "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" + "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, " + ".PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, " +
"AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " + "AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " +
"AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID AND " + "AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID AND " +
"AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; "AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
@ -226,13 +220,13 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
List<ApplicationRelease> applicationReleases = new ArrayList<>(); List<ApplicationRelease> applicationReleases = new ArrayList<>();
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.SC_2_LOCATION AS " + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, "
+ "SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, " + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
+ "AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AR.RATING FROM AP_APP_RELEASE AS " + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, "
+ "AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME = ? AND TYPE = ? " + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP "
+ "AND TENANT_ID = ?) AND AR.TENANT_ID = ? ;"; + "WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?) AND AR.TENANT_ID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
@ -244,22 +238,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease(); ApplicationRelease applicationRelease = constructApplicationRelease(resultSet);
applicationRelease.setId(resultSet.getInt("RELESE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setRating(resultSet.getDouble("RATING"));
applicationReleases.add(applicationRelease); applicationReleases.add(applicationRelease);
} }
@ -287,7 +266,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException { public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE UUID = ?;"; String sql = "UPDATE AP_APP_RELEASE SET RATING = ?,RATED_USERS = ? WHERE UUID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
@ -354,11 +333,10 @@ 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 PACKAGE_NAME = ? " String sql = "UPDATE AP_APP_RELEASE SET VERSION = ?, UUID = ?, RELEASE_TYPE = ?, PACKAGE_NAME = ?,"
+ "AND APP_PRICE = ? AND STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? " + " APP_PRICE = ?, STORED_LOCATION = ?, BANNER_LOCATION = ?, SC_1_LOCATION = ?, SC_2_LOCATION = ?,"
+ "AND SC_2_LOCATION = ? AND SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? " + " SC_3_LOCATION = ?, APP_HASH_VALUE = ?, SHARED_WITH_ALL_TENANTS = ?, APP_META_INFO = ? "
+ "AND APP_META_INFO = ? AND CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? " + "WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;";
+ "AND ID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
@ -375,8 +353,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setString(11, applicationRelease.getAppHashValue()); statement.setString(11, applicationRelease.getAppHashValue());
statement.setInt(12, applicationRelease.getIsSharedWithAllTenants()); statement.setInt(12, applicationRelease.getIsSharedWithAllTenants());
statement.setString(13, applicationRelease.getMetaData()); statement.setString(13, applicationRelease.getMetaData());
statement.setString(14, applicationRelease.getApplicationCreator()); statement.setInt(14,applicationId);
statement.setTimestamp(15, new Timestamp(System.currentTimeMillis())); statement.setInt(15, tenantId);
statement.setInt(16, applicationRelease.getId());
statement.executeUpdate(); statement.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -441,7 +421,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setRating(resultSet.getDouble("RATING")); applicationRelease.setRating(resultSet.getDouble("RATING"));
return applicationRelease; return applicationRelease;

@ -46,7 +46,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM "
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID=? ORDER BY UPDATED_AT DESC;"; + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID=? ORDER BY UPDATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -58,7 +58,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
lifecycleState = new LifecycleState(); lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID")); lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
} }
@ -82,7 +82,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM "
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;"; + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1,appReleaseId); stmt.setInt(1,appReleaseId);
@ -91,7 +91,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
LifecycleState lifecycleState = new LifecycleState(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID")); lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
lifecycleStates.add(lifecycleState); lifecycleStates.add(lifecycleState);
@ -113,7 +113,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_BY, " String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, "
+ "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);"; + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, state.getCurrentState()); stmt.setString(1, state.getCurrentState());

@ -70,7 +70,7 @@ public class ReviewManagerImpl implements ReviewManager {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isSuccess = false; boolean isSuccess = false;
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.openDBConnection();
Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId); Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId);
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId) if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& review.getRating() > 0 && review.getRating() != existingReview.getRating()) { && review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
@ -81,13 +81,14 @@ public class ReviewManagerImpl implements ReviewManager {
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid); Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
new Thread(task).start(); new Thread(task).start();
review.setUsername(username); review.setUsername(username);
ConnectionManagerUtil.beginDBTransaction();
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId); isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
}
if (isSuccess) { if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} else { } else {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
} }
}
return isSuccess; return isSuccess;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -115,8 +116,8 @@ public class ReviewManagerImpl implements ReviewManager {
log.debug("Review updating request is received for the review id " + reviewId); log.debug("Review updating request is received for the review id " + reviewId);
} }
try { try {
ConnectionManagerUtil.openDBConnection();
if (existingReview == null) { if (existingReview == null) {
ConnectionManagerUtil.openDBConnection();
existingReview = this.reviewDAO.getReview(reviewId); existingReview = this.reviewDAO.getReview(reviewId);
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) { if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) {
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) {

@ -63,7 +63,7 @@ import java.util.List;
} }
), ),
tags = { tags = {
@Tag(name = "store_management", description = "Review Management related APIs") @Tag(name = "review_management", description = "Review Management related APIs")
} }
) )
@Scopes( @Scopes(

@ -51,9 +51,9 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW (
ID INT(11) NOT NULL AUTO_INCREMENT, ID INT(11) NOT NULL AUTO_INCREMENT,
TENANT_ID VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL,
COMMENT VARCHAR(250) NOT NULL, COMMENT VARCHAR(250) NOT NULL,
REPLY_COMMENT VARCHAR(250) NULL, PARENT_ID INT(11) NULL,
CREATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CREATED_AT TIMESTAMP NOT NULL,
MODEFIED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, MODEFIED_AT TIMESTAMP NOT NULL,
RATING INT(11) NULL, RATING INT(11) NULL,
USERNAME VARCHAR(45) NOT NULL, USERNAME VARCHAR(45) NOT NULL,
AP_APP_RELEASE_ID INT(11) NOT NULL, AP_APP_RELEASE_ID INT(11) NOT NULL,
@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE (
PREVIOUSE_STATE VARCHAR(45) NOT NULL, PREVIOUSE_STATE VARCHAR(45) NOT NULL,
TENANT_ID VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL,
UPDATED_BY VARCHAR(100) NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UPDATED_AT TIMESTAMP NOT NULL,
AP_APP_RELEASE_ID INT(11) NOT NULL, AP_APP_RELEASE_ID INT(11) NOT NULL,
AP_APP_ID INT(11) NOT NULL, AP_APP_ID INT(11) NOT NULL,
PRIMARY KEY (ID, AP_APP_RELEASE_ID, AP_APP_ID), PRIMARY KEY (ID, AP_APP_RELEASE_ID, AP_APP_ID),
@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION (
ID INT(11) NOT NULL AUTO_INCREMENT, ID INT(11) NOT NULL AUTO_INCREMENT,
TENANT_ID VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL,
SUBSCRIBED_BY VARCHAR(100) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL,
SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL,
UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL,
UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS AP_GROUP_SUBSCRIPTION (
ID INT(11) NOT NULL AUTO_INCREMENT, ID INT(11) NOT NULL AUTO_INCREMENT,
TENANT_ID VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL,
SUBSCRIBED_BY VARCHAR(100) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL,
SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL,
UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL,
UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
@ -154,7 +154,7 @@ CREATE TABLE IF NOT EXISTS AP_ROLE_SUBSCRIPTION (
TENANT_ID VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL,
ROLE_NAME VARCHAR(100) NOT NULL, ROLE_NAME VARCHAR(100) NOT NULL,
SUBSCRIBED_BY VARCHAR(100) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL,
SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL,
UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL,
UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,

@ -68,9 +68,9 @@ CREATE TABLE IF NOT EXISTS `AP_APP_REVIEW` (
`ID` INT(11) NOT NULL AUTO_INCREMENT, `ID` INT(11) NOT NULL AUTO_INCREMENT,
`TENANT_ID` VARCHAR(45) NOT NULL, `TENANT_ID` VARCHAR(45) NOT NULL,
`COMMENT` VARCHAR(250) NOT NULL, `COMMENT` VARCHAR(250) NOT NULL,
`REPLY_COMMENT` VARCHAR(250) NULL, `PARENT_ID` INT(11) NULL,
`CREATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `CREATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`MODEFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `MODIFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`RATING` INT(11) NULL, `RATING` INT(11) NULL,
`USERNAME` VARCHAR(45) NOT NULL, `USERNAME` VARCHAR(45) NOT NULL,
`AP_APP_RELEASE_ID` INT(11) NOT NULL, `AP_APP_RELEASE_ID` INT(11) NOT NULL,
@ -93,7 +93,7 @@ CREATE INDEX `fk_AP_APP_COMMENT_AP_APP_RELEASE1_idx` ON `AP_APP_REVIEW` (`AP_APP
CREATE TABLE IF NOT EXISTS `AP_APP_LIFECYCLE_STATE` ( CREATE TABLE IF NOT EXISTS `AP_APP_LIFECYCLE_STATE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT, `ID` INT(11) NOT NULL AUTO_INCREMENT,
`CURRENT_STATE` VARCHAR(45) NOT NULL, `CURRENT_STATE` VARCHAR(45) NOT NULL,
`PREVIOUSE_STATE` VARCHAR(45) NOT NULL, `PREVIOUS_STATE` VARCHAR(45) NOT NULL,
`TENANT_ID` VARCHAR(45) NOT NULL, `TENANT_ID` VARCHAR(45) NOT NULL,
`UPDATED_BY` VARCHAR(100) NOT NULL, `UPDATED_BY` VARCHAR(100) NOT NULL,
`UPDATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `UPDATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

Loading…
Cancel
Save