Improve app managing functionalties and refactor the source

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 9379c2ae47
commit 1cce5d7e34

@ -38,7 +38,7 @@ public class Application {
private String type; private String type;
private int isFree; private String subType;
private String paymentCurrency; private String paymentCurrency;
@ -105,12 +105,12 @@ public class Application {
this.type = type; this.type = type;
} }
public int getIsFree() { public String getSubType() {
return isFree; return subType;
} }
public void setIsFree(int isFree) { public void setSubType(String subType) {
this.isFree = isFree; this.subType = subType;
} }
public String getPaymentCurrency() { public String getPaymentCurrency() {

@ -84,6 +84,8 @@ public class ApplicationRelease {
private String url; private String url;
private boolean isPublishedRelease;
public int getNoOfRatedUsers() { public int getNoOfRatedUsers() {
return noOfRatedUsers; return noOfRatedUsers;
} }
@ -299,4 +301,12 @@ public class ApplicationRelease {
public void setUrl(String url) { public void setUrl(String url) {
this.url = url; this.url = url;
} }
public boolean isPublishedRelease() {
return isPublishedRelease;
}
public void setPublishedRelease(boolean publishedRelease) {
isPublishedRelease = publishedRelease;
}
} }

@ -68,7 +68,8 @@ public class Util {
application.setName(rs.getString("APP_NAME")); application.setName(rs.getString("APP_NAME"));
application.setType(rs.getString("APP_TYPE")); application.setType(rs.getString("APP_TYPE"));
application.setAppCategory(rs.getString("APP_CATEGORY")); application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setIsFree(rs.getInt("IS_FREE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY"));
application.setIsRestricted(rs.getInt("RESTRICTED")); application.setIsRestricted(rs.getInt("RESTRICTED"));
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
@ -127,7 +128,8 @@ public class Util {
application.setName(rs.getString("APP_NAME")); application.setName(rs.getString("APP_NAME"));
application.setType(rs.getString("APP_TYPE")); application.setType(rs.getString("APP_TYPE"));
application.setAppCategory(rs.getString("APP_CATEGORY")); application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setIsFree(rs.getInt("IS_FREE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY"));
application.setIsRestricted(rs.getInt("RESTRICTED")); application.setIsRestricted(rs.getInt("RESTRICTED"));
} }

@ -66,12 +66,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, " stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, "
+ "IS_FREE, PAYMENT_CURRENCY, RESTRICTED, TENANT_ID) VALUES " + "SUB_TYPE, PAYMENT_CURRENCY, RESTRICTED, TENANT_ID) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); + "(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, application.getName()); stmt.setString(1, application.getName());
stmt.setString(2, application.getType()); stmt.setString(2, application.getType());
stmt.setString(3, application.getAppCategory()); stmt.setString(3, application.getAppCategory());
stmt.setInt(4, application.getIsFree()); stmt.setString(4, application.getSubType());
stmt.setString(5, application.getPaymentCurrency()); stmt.setString(5, application.getPaymentCurrency());
stmt.setInt(6, application.getIsRestricted()); stmt.setInt(6, application.getIsRestricted());
stmt.setInt(7, application.getUser().getTenantId()); stmt.setInt(7, application.getUser().getTenantId());
@ -133,7 +133,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug("Getting application data from the database"); log.debug("Getting application data from the database");
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
} }
int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -141,8 +141,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Pagination pagination = new Pagination(); Pagination pagination = new Pagination();
String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY" String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY"
+ +
" AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " + " AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, "
"AP_UNRESTRICTED_ROLES.ROLE " + "AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE "
+ "AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) "
+ "LEFT JOIN AP_UNRESTRICTED_ROLES ON AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) " + "LEFT JOIN AP_UNRESTRICTED_ROLES ON AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) "
+ "WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; + "WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?";
@ -165,7 +165,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
} }
sql += " LIMIT ? OFFSET ? ORDER BY " + filter.getSortBy() + " APP_ID"; sql += " LIMIT ? OFFSET ? ORDER BY " + filter.getSortBy() + " APP_ID;";
pagination.setLimit(filter.getLimit()); pagination.setLimit(filter.getLimit());
pagination.setOffset(filter.getOffset()); pagination.setOffset(filter.getOffset());
@ -173,22 +173,22 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(paramIndex, tenantId);
stmt.setString(2, AppLifecycleState.REMOVED.toString()); stmt.setString(paramIndex++, AppLifecycleState.REMOVED.toString());
if (filter.getAppType() != null) { if (filter.getAppType() != null) {
stmt.setString(3, filter.getAppType()); stmt.setString(paramIndex++, filter.getAppType());
} }
if (filter.getAppName() != null) { if (filter.getAppName() != null) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(4, filter.getAppName().toLowerCase()); stmt.setString(paramIndex++, filter.getAppName().toLowerCase());
} else { } else {
stmt.setString(4, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%");
} }
} }
stmt.setInt(5, filter.getLimit()); stmt.setInt(paramIndex++, filter.getLimit());
stmt.setInt(6, filter.getOffset()); stmt.setInt(paramIndex, filter.getOffset());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
applicationList.setApplications(Util.loadApplications(rs)); applicationList.setApplications(Util.loadApplications(rs));
applicationList.setPagination(pagination); applicationList.setPagination(pagination);
@ -251,7 +251,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug("Getting application count from the database"); log.debug("Getting application count from the database");
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
} }
int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -272,9 +272,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += ";"; sql += ";";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(paramIndex++, tenantId);
if (filter.getAppName() != null) { if (filter.getAppName() != null) {
stmt.setString(2, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setString(paramIndex, "%" + filter.getAppName().toLowerCase() + "%");
} }
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -304,9 +304,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = String sql =
"SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY "
+ "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, " + + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY,"
"AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, " + + " AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE "
"AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND "
+ "AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, appName); stmt.setString(1, appName);
@ -347,9 +348,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = String sql =
"SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY "
+ "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY, "
+ ".TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, " + + "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE "
"AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND AP_APP.TENANT_ID=?;"; + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND "
+ "AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, applicationId); stmt.setInt(1, applicationId);
@ -389,8 +391,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = String sql =
"SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY "
+ "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID" + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP_TAG.TAG AS TAG, "
+ " FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID = ?;"; + "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES "
+ "WHERE AP_APP.ID = ?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId); stmt.setInt(1, appId);
@ -419,6 +422,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override @Override
public Application editApplication(Application application, int tenantId) throws ApplicationManagementException { public Application editApplication(Application application, int tenantId) throws ApplicationManagementException {
int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId); Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId);
@ -443,31 +447,30 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (application.getIsRestricted() != existingApplication.getIsRestricted()) { if (application.getIsRestricted() != existingApplication.getIsRestricted()) {
sql += "RESTRICTED = ? "; sql += "RESTRICTED = ? ";
} }
if (application.getIsFree() != existingApplication.getIsFree()) { if (!application.getSubType().equals(existingApplication.getSubType())) {
sql += "IS_FREE = ? "; sql += "SUB_TYPE = ? ";
} }
sql += "WHERE ID = ?"; sql += "WHERE ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
if (application.getName() != null && !application.getName().equals(existingApplication.getName())) { if (application.getName() != null && !application.getName().equals(existingApplication.getName())) {
stmt.setString(1, application.getName()); stmt.setString(paramIndex++, application.getName());
} }
if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { if (application.getType() != null && !application.getType().equals(existingApplication.getType())) {
stmt.setString(2, application.getType()); stmt.setString(paramIndex++, application.getType());
} }
if (application.getAppCategory() != null && !application.getAppCategory().equals( if (application.getAppCategory() != null && !application.getAppCategory().equals(
existingApplication.getAppCategory())) { existingApplication.getAppCategory())) {
stmt.setString(3, application.getAppCategory()); stmt.setString(paramIndex++, application.getAppCategory());
} }
if (application.getIsRestricted() != existingApplication.getIsRestricted()) { if (application.getIsRestricted() != existingApplication.getIsRestricted()) {
stmt.setInt(4, application.getIsRestricted()); stmt.setInt(paramIndex++, application.getIsRestricted());
} }
if (application.getIsFree() != existingApplication.getIsFree()) { if (!application.getSubType().equals(existingApplication.getSubType())) {
stmt.setInt(5, application.getIsFree()); stmt.setString(paramIndex++, application.getSubType());
} }
stmt.setInt(paramIndex, application.getId());
stmt.setInt(6, application.getId());
stmt.executeUpdate(); stmt.executeUpdate();
return application; return application;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -580,8 +583,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP_RELEASE.CREATED_AT, AP_APP_RELEASE.PUBLISHED_BY, AP_APP_RELEASE.PUBLISHED_AT, " + "AP_APP_RELEASE.CREATED_AT, AP_APP_RELEASE.PUBLISHED_BY, AP_APP_RELEASE.PUBLISHED_AT, "
+ "AP_APP_RELEASE.STARS," + "AP_APP_RELEASE.STARS,"
+ "AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, " + "AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, "
+ "AP_APP.APP_CATEGORY AS APP_CATEGORY, AP_APP.IS_FREE, AP_UNRESTRICTED_ROLES.ROLE AS ROLE " + "AP_APP.APP_CATEGORY AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, "
+ "FROM AP_APP, AP_UNRESTRICTED_ROLES, AP_APP_RELEASE " + "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_UNRESTRICTED_ROLES, AP_APP_RELEASE "
+ "WHERE AP_APP_RELEASE.UUID=? AND AP_APP.TENANT_ID=?;"; + "WHERE AP_APP_RELEASE.UUID=? AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -602,7 +605,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
application.setName(rs.getString("APP_NAME")); application.setName(rs.getString("APP_NAME"));
application.setType(rs.getString("APP_TYPE")); application.setType(rs.getString("APP_TYPE"));
application.setAppCategory(rs.getString("APP_CATEGORY")); application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setIsFree(rs.getInt("IS_FREE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY"));
application.setIsRestricted(rs.getInt("RESTRICTED")); application.setIsRestricted(rs.getInt("RESTRICTED"));
UnrestrictedRole unrestrictedRole = new UnrestrictedRole(); UnrestrictedRole unrestrictedRole = new UnrestrictedRole();

@ -43,85 +43,5 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
private static final Log log = LogFactory.getLog(OracleApplicationDAOImpl.class); private static final Log log = LogFactory.getLog(OracleApplicationDAOImpl.class);
@Override
public ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting application data from the database");
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
ApplicationList applicationList = new ApplicationList();
Pagination pagination = new Pagination();
String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY"
+ " AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " +
"AP_UNRESTRICTED_ROLES.ROLE AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON " +
"AP_APP.ID = AP_APP_TAG.AP_APP_ID) LEFT JOIN AP_UNRESTRICTED_ROLES ON " +
"AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?";
if (filter == null) {
throw new ApplicationManagementDAOException("Filter need to be instantiated");
}
if (filter.getAppType() != null) {
sql += " AND AP_APP.TYPE ";
sql += "= ?";
}
if (filter.getAppName() != null) {
sql += " AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) {
sql += "= ?";
} else {
sql += "LIKE ?";
}
}
sql += " AND rownum <= ? OFFSET ? " + filter.getSortBy() + " APP_ID";
pagination.setLimit(filter.getLimit());
pagination.setOffset(filter.getOffset());
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, AppLifecycleState.REMOVED.toString());
if (filter.getAppType() != null) {
stmt.setString(3, filter.getAppType());
}
if (filter.getAppName() != null) {
if (filter.isFullMatch()) {
stmt.setString(4, filter.getAppName().toLowerCase());
} else {
stmt.setString(4, "%" + filter.getAppName().toLowerCase() + "%");
}
}
stmt.setInt(5, filter.getLimit());
stmt.setInt(6, filter.getOffset());
rs = stmt.executeQuery();
applicationList.setApplications(Util.loadApplications(rs));
applicationList.setPagination(pagination);
applicationList.getPagination().setSize(filter.getOffset());
applicationList.getPagination().setCount(applicationList.getApplications().size());
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
+ " " + tenantId + ". While executing " + sql, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while "
+ "getting application list for the tenant " + tenantId,
e);
} catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e);
} finally {
Util.cleanupResources(stmt, rs);
}
return applicationList;
}
} }

@ -108,7 +108,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setDevicetype(deviceType); application.setDevicetype(deviceType);
int appId = this.applicationDAO.createApplication(application, deviceType.getId()); int appId = this.applicationDAO.createApplication(application, deviceType.getId());
if (appId != -1) { if (appId == -1) {
log.error("Application creation Failed"); log.error("Application creation Failed");
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
return null; return null;
@ -350,6 +350,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO() applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO()
.getReleases(application.getName(), application.getType(), tenantId); .getReleases(application.getName(), application.getType(), tenantId);
for (ApplicationRelease applicationRelease : applicationReleases) { for (ApplicationRelease applicationRelease : applicationReleases) {
if (AppLifecycleState.PUBLISHED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())){
applicationRelease.setPublishedRelease(true);
}
if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO(). if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) { getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) {
filteredApplicationReleases.add(applicationRelease); filteredApplicationReleases.add(applicationRelease);
@ -834,14 +838,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
"please remove this application and publish " + "please remove this application and publish " +
"new application with type: " + application.getType()); "new application with type: " + application.getType());
} }
if (existingApplication.getIsFree() != application.getIsFree()) { if (existingApplication.getSubType() != application.getSubType()) {
if (existingApplication.getIsFree() == 1) { if ("PAID".equals(existingApplication.getSubType())) {
if (application.getPaymentCurrency() != null || !application.getPaymentCurrency().equals("")) { if (application.getPaymentCurrency() != null || !application.getPaymentCurrency().equals("")) {
throw new ApplicationManagementException("If you are going to change Non-Free app as Free app, " + throw new ApplicationManagementException("If you are going to change Non-Free app as Free app, " +
"currency attribute in the application updating " + "currency attribute in the application updating " +
"payload should be null or \"\""); "payload should be null or \"\"");
} }
} else if (existingApplication.getIsFree() == 0) { } else if ("FREE".equals(existingApplication.getSubType())) {
if (application.getPaymentCurrency() == null || application.getPaymentCurrency().equals("")) { if (application.getPaymentCurrency() == null || application.getPaymentCurrency().equals("")) {
throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, " + throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, " +
"currency attribute in the application payload " + "currency attribute in the application payload " +
@ -903,7 +907,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return null; return null;
} }
if (filter.getAppType() != null) { if (filter.getAppType() != null) {
Boolean isValidRequest = false; boolean isValidRequest = false;
for (ApplicationType applicationType : ApplicationType.values()) { for (ApplicationType applicationType : ApplicationType.values()) {
if (applicationType.toString().equals(filter.getAppType())) { if (applicationType.toString().equals(filter.getAppType())) {
isValidRequest = true; isValidRequest = true;

@ -39,7 +39,6 @@ public class APIUtil {
private static SubscriptionManager subscriptionManager; private static SubscriptionManager subscriptionManager;
private static UnrestrictedRoleManager unrestrictedRoleManager; private static UnrestrictedRoleManager unrestrictedRoleManager;
public static ApplicationManager getApplicationManager() { public static ApplicationManager getApplicationManager() {
if (applicationManager == null) { if (applicationManager == null) {
synchronized (APIUtil.class) { synchronized (APIUtil.class) {
@ -55,7 +54,6 @@ public class APIUtil {
} }
} }
} }
return applicationManager; return applicationManager;
} }

@ -222,9 +222,13 @@ public interface ApplicationManagementAPI {
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
code = 201, code = 200,
message = "OK. \n Successfully edited the application.", message = "OK. \n Successfully edited the application.",
response = Application.class), response = Application.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Application updating payload contains unacceptable or vulnerable data"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while editing the application.", message = "Internal Server Error. \n Error occurred while editing the application.",
@ -235,7 +239,8 @@ public interface ApplicationManagementAPI {
name = "application", name = "application",
value = "The application that need to be edited.", value = "The application that need to be edited.",
required = true) required = true)
@Valid Application application); @Valid Application application
);
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -265,7 +270,7 @@ public interface ApplicationManagementAPI {
"Application creating payload contains unacceptable or vulnerable data"), "Application creating payload contains unacceptable or vulnerable data"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.", message = "Internal Server Error. \n Error occurred while creating the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response createApplication( Response createApplication(
@ -297,7 +302,8 @@ public interface ApplicationManagementAPI {
name = "screenshot", name = "screenshot",
value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application",
required = true) required = true)
@Multipart(value = "screenshot") List<Attachment> attachmentList); @Multipart(value = "screenshot") List<Attachment> attachmentList
);
@DELETE @DELETE
@Consumes("application/json") @Consumes("application/json")
@ -331,7 +337,8 @@ public interface ApplicationManagementAPI {
name = "UUID", name = "UUID",
value = "Unique identifier of the Application", value = "Unique identifier of the Application",
required = true) required = true)
@PathParam("appid") int applicationId); @PathParam("appid") int applicationId
);
@POST @POST
@Path("/image-artifacts/{appId}/{uuid}") @Path("/image-artifacts/{appId}/{uuid}")
@ -353,8 +360,15 @@ public interface ApplicationManagementAPI {
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
code = 201, code = 200,
message = "OK. \n Successfully uploaded artifacts."), message = "OK. \n Successfully updated artifacts."),
@ApiResponse(
code = 403,
message = "FORBIDDEN. \n Can't Update the application release in PUBLISHED or DEPRECATED "
+ "state. Hence please demote the application and update the application release"),
@ApiResponse(
code = 404,
message = "NOT FOUND. \n Error occurred while updating the application."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.", message = "Internal Server Error. \n Error occurred while getting the application list.",
@ -367,10 +381,11 @@ public interface ApplicationManagementAPI {
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart(value = "icon") Attachment iconFile, @Multipart(value = "icon") Attachment iconFile,
@Multipart(value = "banner") Attachment bannerFile, @Multipart(value = "banner") Attachment bannerFile,
@Multipart(value = "screenshot") List<Attachment> screenshots); @Multipart(value = "screenshot") List<Attachment> screenshots
);
@PUT @PUT
@Path("/app-artifacts/{appId}/{uuid}") @Path("/app-artifacts/{appType}/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation( @ApiOperation(
@ -391,6 +406,10 @@ public interface ApplicationManagementAPI {
@ApiResponse( @ApiResponse(
code = 201, code = 201,
message = "OK. \n Successfully uploaded artifacts."), message = "OK. \n Successfully uploaded artifacts."),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Application artifact updating payload contains unacceptable or vulnerable data"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.", message = "Internal Server Error. \n Error occurred while getting the application list.",
@ -399,11 +418,12 @@ public interface ApplicationManagementAPI {
Response updateApplicationArtifact( Response updateApplicationArtifact(
@ApiParam(name = "appType", value = "Type of the application i.e Android, IOS etc", required = true) @ApiParam(name = "appType", value = "Type of the application i.e Android, IOS etc", required = true)
@PathParam("appType") String appType, @PathParam("appType") String appType,
@ApiParam(name = "id", value = "Id of the application", required = true) @ApiParam(name = "appId", value = "Id of the application", required = true)
@PathParam("uuid") int applicationId, @PathParam("appId") int applicationId,
@ApiParam(name = "uuid", value = "UUID of the application", required = true) @ApiParam(name = "uuid", value = "UUID of the application", required = true)
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("binaryFile") Attachment binaryFile); @Multipart("binaryFile") Attachment binaryFile
);
@PUT @PUT
@Path("/{appId}/{uuid}") @Path("/{appId}/{uuid}")
@ -428,6 +448,10 @@ public interface ApplicationManagementAPI {
code = 201, code = 201,
message = "OK. \n Successfully created an application release.", message = "OK. \n Successfully created an application release.",
response = ApplicationRelease.class), response = ApplicationRelease.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n " +
"Application release updating payload contains unacceptable or vulnerable data"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.", message = "Internal Server Error. \n Error occurred while releasing the application.",
@ -495,11 +519,6 @@ public interface ApplicationManagementAPI {
code = 201, code = 201,
message = "OK. \n Successfully add a lifecycle state.", message = "OK. \n Successfully add a lifecycle state.",
response = Application.class), response = Application.class),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested "
+ "resource."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred adding a lifecycle state.", message = "Internal Server Error. \n Error occurred adding a lifecycle state.",

@ -79,7 +79,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application list for publisher "; String msg = "Error occurred while getting the application list for publisher ";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }
@ -120,34 +120,16 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
List<InputStream> attachments = new ArrayList<>(); List<InputStream> attachments = new ArrayList<>();
List<ApplicationRelease> applicationReleases = new ArrayList<>(); List<ApplicationRelease> applicationReleases = new ArrayList<>();
try { try {
if (iconFile == null) {
log.error("Icon file is not uploaded for the application release of " + application.getName() +
" of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (bannerFile == null) {
log.error("Banner file is not uploaded for the application release of " + application.getName() +
" of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (attachmentList == null || attachmentList.isEmpty()) { if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) {
log.error("Screenshots are not uploaded for the application release of " + application.getName() +
" of application type " + application.getType());
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} } else if (binaryFile == null && ApplicationType.WEB_CLIP.toString().equals(application.getType())) {
applicationRelease = applicationStorageManager
if (binaryFile == null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { .uploadReleaseArtifact(applicationRelease, application.getType(), null);
log.error("Binary file is not uploaded for the application release of " + application.getName() + } else if (binaryFile != null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) {
" of application type " + application.getType()); applicationRelease = applicationStorageManager
return Response.status(Response.Status.BAD_REQUEST).build(); .uploadReleaseArtifact(applicationRelease, application.getType(),
}else if(binaryFile == null && ApplicationType.WEB_CLIP.toString().equals(application.getType())){ binaryFile.getDataHandler().getInputStream());
applicationRelease = applicationStorageManager.uploadReleaseArtifact(applicationRelease, application.getType(),
null);
}else if (binaryFile != null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())){
applicationRelease = applicationStorageManager.uploadReleaseArtifact(applicationRelease, application.getType(),
binaryFile.getDataHandler().getInputStream());
} }
iconFileStream = iconFile.getDataHandler().getInputStream(); iconFileStream = iconFile.getDataHandler().getInputStream();
@ -240,13 +222,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
log.error(msg, e); log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.NOT_FOUND); return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the application"; String msg = "Error occurred while updating the application.";
log.error(msg, e); log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (IOException e) { } catch (IOException e) {
log.error("Exception while trying to read icon, banner files for the application " + applicationUuid); String msg = "Exception while trying to read icon, banner files for the application " + applicationUuid;
return APIUtil.getResponse(new ApplicationManagementException( log.error(msg);
"Exception while trying to read icon, " + "banner files for the application " + applicationUuid, e), return APIUtil.getResponse(new ApplicationManagementException(msg, e),
Response.Status.INTERNAL_SERVER_ERROR); Response.Status.INTERNAL_SERVER_ERROR);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid " log.error("Error occurred while uploading the image artifacts of the application with the uuid "
@ -278,11 +260,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
binaryFile.getDataHandler().getInputStream()); binaryFile.getDataHandler().getInputStream());
applicationManager.updateRelease(applicationId, applicationRelease); applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build(); .entity("Successfully uploaded artifacts for the application release. UUID is " + applicationUuid).build();
} catch (IOException e) { } catch (IOException e) {
log.error("Exception while trying to read icon, banner files for the application " + applicationUuid); String msg =
return APIUtil.getResponse(new ApplicationManagementException( "Exception while trying to read icon, banner files for the application release" + applicationUuid;
"Exception while trying to read icon, banner files for the application " + applicationUuid, e), log.error(msg);
return APIUtil.getResponse(new ApplicationManagementException(msg, e),
Response.Status.BAD_REQUEST); Response.Status.BAD_REQUEST);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid " log.error("Error occurred while uploading the image artifacts of the application with the uuid "
@ -453,4 +436,32 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build(); return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build();
} }
private boolean isValidAppCreatingRequest(Attachment binaryFile, Attachment iconFile, Attachment bannerFile,
List<Attachment> attachmentList, Application application){
if (iconFile == null) {
log.error("Icon file is not found for the application release. Application name: " +
application.getName() + " and type: " + application.getType());
return false;
}
if (bannerFile == null) {
log.error("Banner file is not found for the application release. Application name: " +
application.getName() + " and application type: " + application.getType());
return false;
}
if (attachmentList == null || attachmentList.isEmpty()) {
log.error("Screenshots are not found for the application release. Application name: " +
application.getName() + " Application type: " + application.getType());
return false;
}
if (binaryFile == null && !ApplicationType.WEB_CLIP.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;
}
return true;
}
} }

@ -32,6 +32,7 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
@ -159,9 +160,10 @@ public interface ApplicationManagementAPI {
}) })
Response getApplications( Response getApplications(
@ApiParam( @ApiParam(
name = "searchQuery", name = "filter",
value = "Relevant search query to search on", defaultValue = "*") value = "Filter to get application list",
@QueryParam("query") String searchQuery, required = true)
@Valid Filter filter,
@ApiParam( @ApiParam(
name = "offset", name = "offset",
value = "Provide from which position apps should return", defaultValue = "20") value = "Provide from which position apps should return", defaultValue = "20")
@ -217,35 +219,5 @@ public interface ApplicationManagementAPI {
@QueryParam("appName") String appName @QueryParam("appName") String appName
); );
@GET
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get all the releases or specific release of an application",
notes = "This will retrieve the all the releases or specific release of an application",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved the Application release."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response getApplicationRelease(
@ApiParam(name = "ID", value = "Identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
@ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version);
} }

@ -20,25 +20,26 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl;
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.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI;
import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/** /**
* Implementation of Application Management related APIs. * Implementation of Application Management related APIs.
@ -54,33 +55,37 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Consumes("application/json") @Consumes("application/json")
@Override @Override
public Response getApplications( public Response getApplications(
@QueryParam("query") String searchQuery, @Valid Filter filter,
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
if (limit == 0) { if (limit == 0) {
limit = DEFAULT_LIMIT; limit = DEFAULT_LIMIT;
} }
Filter filter = new Filter();
filter.setOffset(offset); filter.setOffset(offset);
filter.setLimit(limit); filter.setLimit(limit);
filter.setAppName(searchQuery);
ApplicationList applications = applicationManager.getApplications(filter); ApplicationList applications = applicationManager.getApplications(filter);
List<ApplicationRelease> publishedApplicationRelease = new ArrayList<>();
for (Application application : applications.getApplications()) { for (Application application : applications.getApplications()) {
// ToDo : use better approach to solve this
String uuId = applicationManager.getUuidOfLatestRelease(application.getId()); for (ApplicationRelease appRelease: application.getApplicationReleases()){
if (uuId != null){ if (appRelease.isPublishedRelease()){
application.setUuidOfLatestRelease(uuId); publishedApplicationRelease.add(appRelease);
// ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0); }
// application.setIconOfLatestRelease(imageArtifact);
}else{
// ToDo set default icon
} }
if (publishedApplicationRelease.size()>1){
String msg = "Application " + application.getName()
+ " has more than one PUBLISHED application releases";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(msg).build();
}
application.setApplicationReleases(publishedApplicationRelease);
publishedApplicationRelease.clear();
} }
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
@ -95,57 +100,41 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@GET @GET
@Consumes("application/json") @Consumes("application/json")
@Path("/{appType}") @Path("/{appType}")
public Response getApplication(@PathParam("appType") String appType, @QueryParam("appName") String appName) { public Response getApplication(
@PathParam("appType") String appType,
@QueryParam("appName") String appName) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); List<ApplicationRelease> publishedApplicationRelease = new ArrayList<>();
try { try {
Application application = applicationManager.getApplication(appType, appName); Application application = applicationManager.getApplication(appType, appName);
if (application == null) { if (application == null) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
.entity("Application with UUID " + appType + " not found").build(); .entity("Application with application type: " + appType + " not found").build();
} }
// ToDo : use better approach to solve this for (ApplicationRelease appRelease : application.getApplicationReleases()) {
String uuId = applicationManager.getUuidOfLatestRelease(application.getId()); if (appRelease.isPublishedRelease()) {
if (uuId != null){ publishedApplicationRelease.add(appRelease);
application.setUuidOfLatestRelease(uuId); }
// ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0);
// application.setIconOfLatestRelease(imageArtifact);
}else{
// ToDo set default icon
} }
if (publishedApplicationRelease.size() > 1) {
String msg =
"Application " + application.getName() + " has more than one PUBLISHED application releases";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
application.setApplicationReleases(publishedApplicationRelease);
return Response.status(Response.Status.OK).entity(application).build(); return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Error occurred while getting application with the uuid " + appType, e); log.error("Error occurred while getting application with the application type: " + appType
+ " and application name: " + appName, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} }
} }
//todo WIP // todo --> get applications by category
@Override
@Path("/{uuid}")
@GET
public Response getApplicationRelease(@PathParam("uuid") String applicationUUID,
@QueryParam("version") String version) {
return null;
// try {
// if (version == null || version.isEmpty()) {
//// List<ApplicationRelease> applicationReleases = applicationReleaseManager.getReleases(applicationUUID);
//// return Response.status(Response.Status.OK).entity(applicationReleases).build();
// } else {
//// ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version);
//// return Response.status(Response.Status.OK).entity(applicationRelease).build();
// }
// } catch (NotFoundException e) {
// return Response.status(Response.Status.NOT_FOUND).build();
// } catch (ApplicationManagementException e) {
// log.error("Error while getting all the application releases for the application with the UUID "
// + applicationUUID, e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
}
} }

Loading…
Cancel
Save