Add get application and add new release APIs

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent e747c0bdb0
commit 19f088d222

@ -95,10 +95,10 @@ public class ApplicationDTO {
example = "REMOVED, ACTIVE") example = "REMOVED, ACTIVE")
private String status; private String status;
@ApiModelProperty(name = "applicationReleases", @ApiModelProperty(name = "applicationReleaseDTOs",
value = "List of application releases", value = "List of application releases",
required = true) required = true)
private List<ApplicationReleaseDTO> applicationReleases; private List<ApplicationReleaseDTO> applicationReleaseDTOs;
public int getId() { public int getId() {
return id; return id;
@ -152,12 +152,12 @@ public class ApplicationDTO {
this.paymentCurrency = paymentCurrency; this.paymentCurrency = paymentCurrency;
} }
public List<ApplicationReleaseDTO> getApplicationReleases() { public List<ApplicationReleaseDTO> getApplicationReleaseDTOs() {
return applicationReleases; return applicationReleaseDTOs;
} }
public void setApplicationReleases(List<ApplicationReleaseDTO> applicationReleases) { public void setApplicationReleaseDTOs(List<ApplicationReleaseDTO> applicationReleaseDTOs) {
this.applicationReleases = applicationReleases; this.applicationReleaseDTOs = applicationReleaseDTOs;
} }
public List<String> getUnrestrictedRoles() { public List<String> getUnrestrictedRoles() {

@ -28,6 +28,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
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.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.response.Application; import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
@ -165,11 +166,11 @@ public interface ApplicationManager {
* To create an application release for an ApplicationDTO. * To create an application release for an ApplicationDTO.
* *
* @param applicationId ID of the ApplicationDTO * @param applicationId ID of the ApplicationDTO
* @param applicationRelease ApplicatonRelease that need to be be created. * @param applicationReleaseWrapper ApplicatonRelease that need to be be created.
* @return the unique id of the application release, if the application release succeeded else -1 * @return the unique id of the application release, if the application release succeeded else -1
*/ */
ApplicationReleaseDTO createRelease(int applicationId, ApplicationReleaseDTO applicationRelease) ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper,
throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/*** /***
* *
@ -201,8 +202,8 @@ public interface ApplicationManager {
* @param applicationType Type of the application * @param applicationType Type of the application
* @throws RequestValidatingException throws if payload does not satisfy requrements. * @throws RequestValidatingException throws if payload does not satisfy requrements.
*/ */
void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType)
String applicationType) throws RequestValidatingException; throws RequestValidatingException;
/*** /***
* *

@ -24,6 +24,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO;
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.util.List; import java.util.List;
/** /**
@ -115,8 +116,7 @@ public interface ApplicationDAO {
* @return the application * @return the application
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/ */
ApplicationDTO getApplicationById(String id, int tenantId) throws ApplicationDTO getApplicationById(String id, int tenantId) throws ApplicationManagementDAOException;
ApplicationManagementDAOException;
/** /**
* To get the application with the given id * To get the application with the given id

@ -142,12 +142,11 @@ public interface ApplicationReleaseDAO {
/** /**
* To verify whether application release exist or not for the given app release version. * To verify whether application release exist or not for the given app release version.
* *
* @param appId ID of the application.
* @param hashVal Hash value of the application release. * @param hashVal Hash value of the application release.
* @param tenantId Tenant Id * @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/ */
boolean verifyReleaseExistenceByHash(int appId, String hashVal, int tenantId) boolean verifyReleaseExistenceByHash(String hashVal, int tenantId)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;
/** /**
@ -177,6 +176,6 @@ public interface ApplicationReleaseDAO {
* @return True if application release package name already exist in the IoT server, Otherwise returns False. * @return True if application release package name already exist in the IoT server, Otherwise returns False.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId) throws ApplicationManagementDAOException; boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId, String inactiveState) throws ApplicationManagementDAOException;
} }

@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.config.Configuration; import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -47,66 +48,6 @@ public class Util {
private static final Log log = LogFactory.getLog(Util.class); private static final Log log = LogFactory.getLog(Util.class);
// /**
// * To create application object from the result set retrieved from the Database.
// *
// * @param rs ResultSet
// * @return List of Applications that is retrieved from the Database.
// * @throws SQLException SQL Exception
// * @throws JSONException JSONException.
// */
// public static List<ApplicationDTO> loadApplications(ResultSet rs) throws SQLException, JSONException {
//
// List<ApplicationDTO> applications = new ArrayList<>();
// ApplicationDTO application = null;
// int applicationId = -1;
// boolean hasNext = rs.next();
//
// while (hasNext) {
// if (applicationId != rs.getInt("APP_ID")) {
// if (application != null) {
// applications.add(application);
// }
// applicationId = rs.getInt("APP_ID");
// application = new ApplicationDTO();
// application.setTags(new ArrayList<>());
// application.setUnrestrictedRoles(new ArrayList<>());
// application.setId(applicationId);
// application.setName(rs.getString("APP_NAME"));
// application.setType(rs.getString("APP_TYPE"));
// application.setAppCategories(rs.getString("APP_CATEGORY"));
// application.setSubType(rs.getString("SUB_TYPE"));
// application.setPaymentCurrency(rs.getString("CURRENCY"));
// application.setIsRestricted(rs.getBoolean("RESTRICTED"));
// application.setStatus(rs.getString("STATUS"));
// String tag = rs.getString("APP_TAG");
// String unrestrictedRole = rs.getString("ROLE");
// if (tag != null) {
// application.getTags().add(tag);
// }
// if (unrestrictedRole != null) {
// application.getUnrestrictedRoles().add(unrestrictedRole);
// }
// } else {
// String tag = rs.getString("APP_TAG");
// String unrestrictedRole = rs.getString("ROLE");
// if (application != null) {
// if (tag != null && !application.getTags().contains(tag)) {
// application.getTags().add(tag);
// }
// if (unrestrictedRole != null && !application.getUnrestrictedRoles().contains(unrestrictedRole)) {
// application.getUnrestrictedRoles().add(unrestrictedRole);
// }
// }
// }
// hasNext = rs.next();
// if (!hasNext) {
// applications.add(application);
// }
// }
// return applications;
// }
/** /**
* To create application object from the result set retrieved from the Database. * To create application object from the result set retrieved from the Database.
* *
@ -128,7 +69,7 @@ public class Util {
applications.add(application); applications.add(application);
} }
application = new ApplicationDTO(); application = new ApplicationDTO();
application.setApplicationReleases(new ArrayList<>()); application.setApplicationReleaseDTOs(new ArrayList<>());
applicationId = rs.getInt("APP_ID"); applicationId = rs.getInt("APP_ID");
application.setId(applicationId); application.setId(applicationId);
application.setName(rs.getString("APP_NAME")); application.setName(rs.getString("APP_NAME"));
@ -139,10 +80,10 @@ public class Util {
application.setStatus(rs.getString("APP_STATUS")); application.setStatus(rs.getString("APP_STATUS"));
application.setAppRating(rs.getInt("APP_RATING")); application.setAppRating(rs.getInt("APP_RATING"));
application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID")); application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID"));
application.getApplicationReleases().add(loadAppRelease(rs)); application.getApplicationReleaseDTOs().add(loadAppRelease(rs));
} else { } else {
if (application != null && application.getApplicationReleases() != null) { if (application != null && application.getApplicationReleaseDTOs() != null) {
application.getApplicationReleases().add(loadAppRelease(rs)); application.getApplicationReleaseDTOs().add(loadAppRelease(rs));
} }
} }
hasNext = rs.next(); hasNext = rs.next();
@ -189,41 +130,18 @@ public class Util {
* @throws SQLException SQL Exception * @throws SQLException SQL Exception
* @throws JSONException JSONException. * @throws JSONException JSONException.
*/ */
public static ApplicationDTO loadApplication(ResultSet rs) throws SQLException, JSONException { public static ApplicationDTO loadApplication(ResultSet rs)
throws SQLException, JSONException, UnexpectedServerErrorException {
ApplicationDTO application = null; List<ApplicationDTO> applicationDTOs = loadApplications(rs);
int applicatioId; if (applicationDTOs.isEmpty()) {
int iteration = 0; return null;
if (rs != null) { }
while (rs.next()) { if (applicationDTOs.size() > 1) {
if (iteration == 0) { String msg = "Internal server error. Found more than one application for requested application ID";
application = new ApplicationDTO(); log.error(msg);
application.setTags(new ArrayList<>()); throw new UnexpectedServerErrorException(msg);
application.setUnrestrictedRoles(new ArrayList<>());
applicatioId = rs.getInt("APP_ID");
application.setId(applicatioId);
application.setName(rs.getString("APP_NAME"));
application.setType(rs.getString("APP_TYPE"));
application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY"));
// application.setIsRestricted(rs.getBoolean("RESTRICTED"));
application.setDeviceTypeId(rs.getInt("DEVICE_TYPE_ID"));
}
String tag = rs.getString("APP_TAG");
String unrestrictedRole = rs.getString("ROLE");
if (tag != null && !application.getTags().contains(tag)) {
application.getTags().add(tag);
}
if (unrestrictedRole != null && !application.getUnrestrictedRoles().contains(unrestrictedRole)) {
application.getUnrestrictedRoles().add(unrestrictedRole);
}
iteration++;
}
} }
return application; return applicationDTOs.get(0);
} }
/** /**

@ -24,17 +24,16 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO;
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.Pagination;
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
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.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
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.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -163,8 +162,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "FROM AP_APP " + "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON " + "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
+ "AP_APP.TENANT_ID = ? AND " + "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID"; + "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) { if (filter == null) {
throw new ApplicationManagementDAOException("Filter need to be instantiated"); throw new ApplicationManagementDAOException("Filter need to be instantiated");
@ -381,14 +380,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override @Override
public ApplicationDTO getApplicationById(String id, int tenantId) throws public ApplicationDTO getApplicationById(String id, int tenantId) throws ApplicationManagementDAOException {
ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application with the id:" + id); log.debug("Getting application with the id:" + id);
} }
@ -423,14 +423,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override @Override
public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) throws public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId)
ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application with the release UUID: " + releaseUuid + " from the database"); log.debug("Getting application with the release UUID: " + releaseUuid + " from the database");
} }
@ -470,14 +472,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override @Override
public ApplicationDTO getApplicationById(int applicationId, int tenantId) throws public ApplicationDTO getApplicationById(int applicationId, int tenantId)
ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application with the id (" + applicationId + ") from the database"); log.debug("Getting application with the id (" + applicationId + ") from the database");
} }
@ -486,28 +490,48 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = String sql = "SELECT "
"SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + "AP_APP.ID AS APP_ID, "
+ "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + "AP_APP.NAME AS APP_NAME, "
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP.DEVICE_TYPE_ID AS DEVICE_TYPE_ID, " + "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
+ "AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE AS ROLE FROM " + "AP_APP.TYPE AS APP_TYPE, "
+ "((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "AP_APP.STATUS AS APP_STATUS, "
+ "LEFT JOIN AP_UNRESTRICTED_ROLE ON AP_APP.ID = AP_UNRESTRICTED_ROLE.AP_APP_ID) WHERE " + "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
+ "AP_APP.ID = ? AND AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; + "AP_APP.CURRENCY AS APP_CURRENCY, "
+ "AP_APP.RATING AS APP_RATING, "
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
+ "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
+ "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);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.setString(3, AppLifecycleState.REMOVED.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application with the id " log.debug("Successfully retrieved basic details of the application with the id "
+ applicationId); + applicationId);
} }
return Util.loadApplication(rs); return Util.loadApplication(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app id " + applicationId + "Error occurred while getting application details with app id " + applicationId +
@ -516,6 +540,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
@ -555,10 +581,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public ApplicationDTO editApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException { public ApplicationDTO editApplication(ApplicationDTO application, int tenantId)
throws ApplicationManagementDAOException {
int paramIndex = 1; int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
//todo this is wrong
ApplicationDTO existingApplication = this.getApplicationById(application.getId(), tenantId); ApplicationDTO existingApplication = this.getApplicationById(application.getId(), tenantId);
if (existingApplication == null) { if (existingApplication == null) {
@ -883,7 +911,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "FROM " + "FROM "
+ "AP_APP_TAG tag INNER JOIN AP_APP_TAG_MAPPING tag_map ON tag.ID = tag_map.AP_APP_TAG_ID " + "AP_APP_TAG tag INNER JOIN AP_APP_TAG_MAPPING tag_map ON tag.ID = tag_map.AP_APP_TAG_ID "
+ "INNER JOIN AP_APP app ON tag_map.AP_APP_ID = app.ID " + "INNER JOIN AP_APP app ON tag_map.AP_APP_ID = app.ID "
+ "WHERE app.ID = ? and app.TENANT_ID = ?"; + "WHERE app.ID = ? AND app.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){ try (PreparedStatement stmt = conn.prepareStatement(sql)){
@ -915,7 +943,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "FROM " + "FROM "
+ "AP_APP_CATEGORY cat INNER JOIN AP_APP_CATEGORY_MAPPING cat_map ON cat.ID = cat_map.AP_APP_CATEGORY_ID " + "AP_APP_CATEGORY cat INNER JOIN AP_APP_CATEGORY_MAPPING cat_map ON cat.ID = cat_map.AP_APP_CATEGORY_ID "
+ "INNER JOIN AP_APP app ON cat_map.AP_APP_ID = app.ID " + "INNER JOIN AP_APP app ON cat_map.AP_APP_ID = app.ID "
+ "WHERE app.ID = ? and app.TENANT_ID = ?"; + "WHERE app.ID = ? AND app.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){ try (PreparedStatement stmt = conn.prepareStatement(sql)){
@ -1019,7 +1047,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
List<ApplicationReleaseDTO> applicationReleaseList = new ArrayList<>(); List<ApplicationReleaseDTO> applicationReleaseList = new ArrayList<>();
applicationReleaseList.add(appRelease); applicationReleaseList.add(appRelease);
application.setApplicationReleases(applicationReleaseList); application.setApplicationReleaseDTOs(applicationReleaseList);
} }
return application; return application;
} catch (SQLException e) { } catch (SQLException e) {

@ -456,35 +456,27 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
@Override @Override
public boolean verifyReleaseExistenceByHash(int appId, String hashVal, int tenantId) throws ApplicationManagementDAOException { public boolean verifyReleaseExistenceByHash(String hashVal, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application id:" + appId log.debug("Verifying application release existence by application hash value: " + hashVal);
+ " and application hash value: " + hashVal);
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = String sql = "SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.APP_HASH_VALUE = ? AND "
"SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.AP_APP_ID = ? AND " + "AR.TENANT_ID = ?;";
+ "AR.APP_HASH_VALUE = ? AND AR.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId); stmt.setString(1, hashVal);
stmt.setString(2, hashVal); stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application release with the application ID "
+ appId + " ApplicationDTO release hash value: " + hashVal);
}
return rs.next(); return rs.next();
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while getting application release details with app ID: " + appId "Error occurred while getting application release details for application release hash value: "
+ " App release hash value: " + hashVal + " While executing query ", e); + hashVal + " While executing query ", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
@ -658,7 +650,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
@Override @Override
public boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId) throws ApplicationManagementDAOException { public boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId, String inactiveState)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence for package name:" + packageName); log.debug("Verifying application release existence for package name:" + packageName);
} }
@ -671,7 +664,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, packageName); stmt.setString(1, packageName);
stmt.setString(2, AppLifecycleState.REMOVED.toString()); stmt.setString(2, inactiveState);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
return rs.next(); return rs.next();

@ -73,6 +73,7 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
@ -141,8 +142,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ userName); + userName);
} }
try { try {
applicationDTO = addApplicationReleaseArtifacts(appWrapperToAppDTO(applicationWrapper), applicationDTO = appWrapperToAppDTO(applicationWrapper);
applicationArtifact); ApplicationReleaseDTO initialApplicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs()
.add(addApplicationReleaseArtifacts(applicationDTO.getType(), applicationDTO.getDeviceTypeName(),
initialApplicationReleaseDTO, applicationArtifact));
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
String msg = "Error occurred when getting Device Type data."; String msg = "Error occurred when getting Device Type data.";
log.error(msg); log.error(msg);
@ -263,7 +268,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.debug("Creating a new release. App Id:" + appId); log.debug("Creating a new release. App Id:" + appId);
} }
String initialLifecycleState = lifecycleStateManager.getInitialState(); String initialLifecycleState = lifecycleStateManager.getInitialState();
applicationReleaseDTO = applicationDTO.getApplicationReleases().get(0); applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
applicationReleaseDTO.setCurrentState(initialLifecycleState); applicationReleaseDTO.setCurrentState(initialLifecycleState);
applicationReleaseDTO = this.applicationReleaseDAO.createRelease(applicationReleaseDTO, appId, tenantId); applicationReleaseDTO = this.applicationReleaseDAO.createRelease(applicationReleaseDTO, appId, tenantId);
LifecycleStateDTO lifecycleStateDTO = getLifecycleStateInstance(initialLifecycleState, LifecycleStateDTO lifecycleStateDTO = getLifecycleStateInstance(initialLifecycleState,
@ -271,7 +276,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.lifecycleStateDAO this.lifecycleStateDAO
.addLifecycleState(lifecycleStateDTO, appId, applicationReleaseDTO.getUuid(), tenantId); .addLifecycleState(lifecycleStateDTO, appId, applicationReleaseDTO.getUuid(), tenantId);
applicationReleaseEntities.add(applicationReleaseDTO); applicationReleaseEntities.add(applicationReleaseDTO);
applicationDTO.setApplicationReleases(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
application = appDtoToAppResponse(applicationDTO); application = appDtoToAppResponse(applicationDTO);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} }
@ -318,20 +323,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private ApplicationDTO addApplicationReleaseArtifacts(ApplicationDTO applicationDTO, private ApplicationReleaseDTO addApplicationReleaseArtifacts(String applicationType, String deviceType,
ApplicationArtifact applicationArtifact) throws ResourceManagementException, ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
List<ApplicationReleaseDTO> applicationReleaseEntities = new ArrayList<>();
ApplicationReleaseDTO applicationReleaseDTO;
applicationReleaseDTO = applicationDTO.getApplicationReleases().get(0);
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setUuid(uuid);
// The application executable artifacts such as apks are uploaded. // The application executable artifacts such as apks are uploaded.
if (ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) { if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
try { try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream()); byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
@ -339,11 +341,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
ApplicationInstaller applicationInstaller = applicationStorageManager ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(binary, applicationDTO.getDeviceTypeName()); .getAppInstallerData(binary, deviceType);
String packagename = applicationInstaller.getPackageName(); String packagename = applicationInstaller.getPackageName();
ConnectionManagerUtil.getDBConnection(); ConnectionManagerUtil.getDBConnection();
if (applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId)) { if (applicationReleaseDAO.isActiveReleaseExisitForPackageName(packagename, tenantId,
lifecycleStateManager.getEndState())) {
String msg = "Application release is already exist for the package name: " + packagename + String msg = "Application release is already exist for the package name: " + packagename +
". Either you can delete all application releases for package " + packagename + " or " ". Either you can delete all application releases for package " + packagename + " or "
+ "you can add this app release as an new application release, under the existing " + "you can add this app release as an new application release, under the existing "
@ -353,10 +356,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationReleaseDTO.setVersion(applicationInstaller.getVersion()); applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packagename); applicationReleaseDTO.setPackageName(packagename);
String md5OfApp = StorageManagementUtil.getMD5(new ByteArrayInputStream(content));
if (md5OfApp == null) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
if (this.applicationReleaseDAO
.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
throw new BadRequestException(
"Application release exists for the uploaded binary file. Application Type: "
+ applicationType + " Device Tyep: " + deviceType);
}
applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, applicationDTO.getType(), .uploadReleaseArtifact(applicationReleaseDTO,applicationType,
applicationDTO.getDeviceTypeName(), binaryDuplicate); deviceType, binaryDuplicate);
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -377,7 +397,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} else if (ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { } else if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION); applicationReleaseDTO.setVersion(Constants.DEFAULT_VERSION);
applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl()); applicationReleaseDTO.setInstallerName(applicationReleaseDTO.getUrl());
// Since WEB CLIP doesn't have an installer, set uuid as has value for WEB CLIP // Since WEB CLIP doesn't have an installer, set uuid as has value for WEB CLIP
@ -407,9 +427,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(), .uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(),
applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values())); applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values()));
applicationReleaseEntities.add(applicationReleaseDTO); return applicationReleaseDTO;
applicationDTO.setApplicationReleases(applicationReleaseEntities);
return applicationDTO;
} }
@Override @Override
@ -528,50 +546,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override public ApplicationReleaseDTO createRelease(int applicationId, ApplicationReleaseDTO applicationRelease) @Override
public ApplicationRelease createRelease(int applicationId,
ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); ApplicationRelease applicationRelease;
// validateAppReleasePayload(applicationRelease);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("ApplicationDTO release request is received for the application id: " + applicationId); log.debug("ApplicationDTO release request is received for the application id: " + applicationId);
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO existingApplication = this.applicationDAO.getApplicationById(applicationId, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId);
if (existingApplication == null) { if (applicationDTO == null) {
throw new NotFoundException("Couldn't find application for the application Id: " + applicationId); String msg = "Couldn't find application for the application Id: " + applicationId;
log.error(msg);
throw new NotFoundException(msg);
} }
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
applicationDTO.getDeviceTypeName(), releaseWrapperToReleaseDTO(applicationReleaseWrapper),
applicationArtifact);
// todo check whether admin or app creator. String initialstate = lifecycleStateManager.getInitialState();
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { applicationReleaseDTO.setCurrentState(initialstate);
String msg = "You don't have permission to create application release for the application id: " LifecycleStateDTO lifecycleState = getLifecycleStateInstance(initialstate, initialstate);
+ applicationId
+ ". In order to create ann new application realse, you should be either ADMIN user or the application created user.";
throw new ForbiddenException(msg);
}
if (!existingApplication.getUnrestrictedRoles().isEmpty() && !isRoleExists(
existingApplication.getUnrestrictedRoles(), userName)) {
String msg = "ApplicationDTO is visible to limited roles and those roles are not assigned to " + userName;
throw new ApplicationManagementException(msg);
}
if (this.applicationReleaseDAO
.verifyReleaseExistenceByHash(applicationId, applicationRelease.getAppHashValue(), tenantId)) {
throw new BadRequestException("ApplicationDTO release exists for the application Id: " + applicationId
+ " and uploaded binary file");
}
String packageName = this.applicationReleaseDAO.getPackageName(applicationId, tenantId);
if (packageName != null && !packageName.equals(applicationRelease.getPackageName())) {
throw new BadRequestException(
"Package name in the payload is different from the existing package name of other application" +
" releases.");
}
applicationRelease = this.applicationReleaseDAO
.createRelease(applicationRelease, existingApplication.getId(), tenantId);
LifecycleStateDTO lifecycleState = getLifecycleStateInstance(AppLifecycleState.CREATED.toString(),
AppLifecycleState.CREATED.toString());
this.lifecycleStateDAO this.lifecycleStateDAO
.addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(), tenantId); .addLifecycleState(lifecycleState, applicationId, applicationReleaseDTO.getUuid(), tenantId);
applicationReleaseDTO = this.applicationReleaseDAO
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
applicationRelease = releaseDtoToRelease(applicationReleaseDTO);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return applicationRelease; return applicationRelease;
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
@ -592,36 +596,43 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( throw new ApplicationManagementException(
"Error occurred while adding new application release for application " + applicationId, e); "Error occurred while adding new application release for application " + applicationId, e);
} catch (UserStoreException e) { } catch (ResourceManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( String msg =
"Error occurred whecn checking whether user is admin user or not. ApplicationDTO release: " "Error occurred while uploading application release artifacts. Application ID: " + applicationId;
+ applicationId, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
@Override public ApplicationDTO getApplicationById(int appId, String state) throws ApplicationManagementException { @Override
public ApplicationDTO getApplicationById(int appId, String state) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationDTO application; ApplicationDTO application;
boolean isAppAllowed = false; boolean isAppAllowed = false;
List<ApplicationReleaseDTO> applicationReleases;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
application = this.applicationDAO.getApplicationById(appId, tenantId); application = this.applicationDAO.getApplicationById(appId, tenantId);
if (application == null) { if (application == null) {
throw new NotFoundException("Couldn't find an application for application Id: " + appId); throw new NotFoundException("Couldn't find an application for application Id: " + appId);
} }
List<String> tags = this.applicationDAO.getAppTags(appId, tenantId);
List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId);
application.setTags(tags);
//todo when support to add multiple categories this has to be changed
if (!categories.isEmpty()){
application.setAppCategory(categories.get(0));
}
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application, state);
application.setApplicationReleases(applicationReleases);
return application; return application;
} }
if (!application.getUnrestrictedRoles().isEmpty()) { List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId);
if (isRoleExists(application.getUnrestrictedRoles(), userName)) { if (!unrestrictedRoles.isEmpty()) {
if (isRoleExists(unrestrictedRoles, userName)) {
isAppAllowed = true; isAppAllowed = true;
} }
} else { } else {
@ -629,10 +640,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
if (!isAppAllowed) { if (!isAppAllowed) {
return null; String msg = "You are trying to access visibility restricted application. You don't have required "
+ "roles to view this application,";
log.error(msg);
throw new ForbiddenException(msg);
} }
applicationReleases = getReleases(application, state);
application.setApplicationReleases(applicationReleases);
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
@ -657,7 +669,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application, state); applicationReleases = getReleases(application, state);
application.setApplicationReleases(applicationReleases); application.setApplicationReleaseDTOs(applicationReleases);
return application; return application;
} }
@ -673,7 +685,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return null; return null;
} }
applicationReleases = getReleases(application, state); applicationReleases = getReleases(application, state);
application.setApplicationReleases(applicationReleases); application.setApplicationReleaseDTOs(applicationReleases);
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
@ -737,7 +749,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application = this.applicationDAO.getApplication(appName, appType, tenantId); application = this.applicationDAO.getApplication(appName, appType, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application, null); applicationReleases = getReleases(application, null);
application.setApplicationReleases(applicationReleases); application.setApplicationReleaseDTOs(applicationReleases);
return application; return application;
} }
@ -754,7 +766,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationReleases = getReleases(application, null); applicationReleases = getReleases(application, null);
application.setApplicationReleases(applicationReleases); application.setApplicationReleaseDTOs(applicationReleases);
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
@ -1713,6 +1725,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper,
String applicationType) throws RequestValidatingException { String applicationType) throws RequestValidatingException {
if (applicationReleaseWrapper == null){
String msg = "Application Release shouldn't be null.";
log.error(msg);
throw new RequestValidatingException(msg);
}
if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) { if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
UrlValidator urlValidator = new UrlValidator(); UrlValidator urlValidator = new UrlValidator();
if (StringUtils if (StringUtils
@ -1784,7 +1802,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDTO.setDeviceTypeName(deviceType.getName()); applicationDTO.setDeviceTypeName(deviceType.getName());
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers()
.stream().map(this::releaseWrapperToReleaseDTO).collect(Collectors.toList()); .stream().map(this::releaseWrapperToReleaseDTO).collect(Collectors.toList());
applicationDTO.setApplicationReleases(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
return applicationDTO; return applicationDTO;
} }
@ -1813,7 +1831,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setTags(applicationDTO.getTags()); application.setTags(applicationDTO.getTags());
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
application.setDeviceType(applicationDTO.getDeviceTypeName()); application.setDeviceType(applicationDTO.getDeviceTypeName());
List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleases() List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs()
.stream().map(this::releaseDtoToRelease).collect(Collectors.toList()); .stream().map(this::releaseDtoToRelease).collect(Collectors.toList());
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;

@ -208,22 +208,13 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String deviceType, InputStream binaryFile) throws ResourceManagementException { String deviceType, InputStream binaryFile) throws ResourceManagementException {
try { try {
String artifactDirectoryPath; String artifactDirectoryPath;
String md5OfApp;
String artifactPath; String artifactPath;
byte [] content = IOUtils.toByteArray(binaryFile); byte [] content = IOUtils.toByteArray(binaryFile);
md5OfApp = getMD5(new ByteArrayInputStream(content)); artifactDirectoryPath = storagePath + applicationReleaseDTO.getAppHashValue();
if (md5OfApp == null) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
artifactDirectoryPath = storagePath + md5OfApp;
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
artifactPath = artifactDirectoryPath + File.separator + applicationReleaseDTO.getInstallerName(); artifactPath = artifactDirectoryPath + File.separator + applicationReleaseDTO.getInstallerName();
saveFile(new ByteArrayInputStream(content), artifactPath); saveFile(new ByteArrayInputStream(content), artifactPath);
applicationReleaseDTO.setAppHashValue(md5OfApp);
} catch (IOException e) { } catch (IOException e) {
String msg = "IO Exception while saving the release artifacts in the server for the application UUID " String msg = "IO Exception while saving the release artifacts in the server for the application UUID "
+ applicationReleaseDTO.getUuid(); + applicationReleaseDTO.getUuid();
@ -283,17 +274,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} }
} }
private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException {
String md5;
try {
md5 = DigestUtils.md5Hex(binaryFile);
} catch (IOException e) {
throw new ApplicationStorageManagementException
("IO Exception while trying to get the md5sum value of application");
}
return md5;
}
private synchronized Map<String, String> getIPAInfo(File ipaFile) throws ApplicationStorageManagementException { private synchronized Map<String, String> getIPAInfo(File ipaFile) throws ApplicationStorageManagementException {
Map<String, String> ipaInfo = new HashMap<>(); Map<String, String> ipaInfo = new HashMap<>();

@ -103,7 +103,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int applicationReleaseId = application.getApplicationReleases().get(0).getId(); int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
@ -144,7 +144,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int applicationReleaseId = application.getApplicationReleases().get(0).getId(); int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
@ -188,7 +188,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int applicationReleaseId = application.getApplicationReleases().get(0).getId(); int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
@ -239,7 +239,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int applicationReleaseId = application.getApplicationReleases().get(0).getId(); int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
List<Device> deviceList = new ArrayList<>(); List<Device> deviceList = new ArrayList<>();
@ -266,8 +266,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
//todo: generate operation payload correctly for all types of devices. //todo: generate operation payload correctly for all types of devices.
operation.setPayLoad( operation.setPayLoad(
"{'type':'enterprise', 'url':'" + application.getApplicationReleases().get(0).getInstallerName() "{'type':'enterprise', 'url':'" + application.getApplicationReleaseDTOs().get(0).getInstallerName()
+ "', 'app':'" + application.getApplicationReleases().get(0).getUuid() + "'}"); + "', 'app':'" + application.getApplicationReleaseDTOs().get(0).getUuid() + "'}");
return operation; return operation;
} }

@ -19,10 +19,12 @@
package org.wso2.carbon.device.application.mgt.core.util; package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
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.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
import java.io.File; import java.io.File;
@ -120,4 +122,15 @@ public class StorageManagementUtil {
throw new IOException(msg); throw new IOException(msg);
} }
} }
public static String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException {
String md5;
try {
md5 = DigestUtils.md5Hex(binaryFile);
} catch (IOException e) {
throw new ApplicationStorageManagementException
("IO Exception while trying to get the md5sum value of application");
}
return md5;
}
} }

@ -20,7 +20,7 @@ package org.wso2.carbon.device.application.mgt.handler.util;
public class HandlerConstants { public class HandlerConstants {
public static final String PUBLISHER_APPLICATION_NAME = "application-mgt-publisher"; public static final String PUBLISHER_APPLICATION_NAME = "application-mgt-publisher";
public static final String APP_REG_ENDPOINT = "/api-application-registration/register"; public static final String APP_REG_ENDPOINT = "/api-application-registration/register";
public static final String UI_CONFIG_ENDPOINT = "/api/application-mgt/v1.0/app-mgt/ui-config"; public static final String UI_CONFIG_ENDPOINT = "/api/application-mgt/v1.0/config/ui-config";
public static final String TOKEN_ENDPOINT = "/oauth2/token"; public static final String TOKEN_ENDPOINT = "/oauth2/token";
public static final String AUTHORIZATION = "Authorization"; public static final String AUTHORIZATION = "Authorization";
public static final String BASIC = "Basic "; public static final String BASIC = "Basic ";

@ -36,6 +36,8 @@ import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import java.util.List; import java.util.List;
@ -155,9 +157,12 @@ public interface ApplicationManagementAPI {
code = 200, code = 200,
message = "OK. \n Successfully retrieved relevant application.", message = "OK. \n Successfully retrieved relevant application.",
response = ApplicationDTO.class), response = ApplicationDTO.class),
@ApiResponse(
code = 403,
message = "Don't have permission to access the application"),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "ApplicationDTO not found"), message = "Application not found"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting relevant application.", message = "Internal Server Error. \n Error occurred while getting relevant application.",
@ -290,78 +295,78 @@ public interface ApplicationManagementAPI {
@Multipart(value = "screenshot3") Attachment screenshot3 @Multipart(value = "screenshot3") Attachment screenshot3
); );
// @POST @POST
// @Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
// @Consumes("multipart/mixed") @Consumes("multipart/mixed")
// @Path("/{deviceType}/{appType}/{appId}") @Path("/{deviceType}/{appType}/{appId}")
// @ApiOperation( @ApiOperation(
// consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
// produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
// httpMethod = "POST", httpMethod = "POST",
// value = "Create an application", value = "Create an application",
// notes = "This will create a new application", notes = "This will create a new application",
// tags = "ApplicationDTO Management", tags = "ApplicationDTO Management",
// extensions = { extensions = {
// @Extension(properties = { @Extension(properties = {
// @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
// }) })
// } }
// ) )
// @ApiResponses( @ApiResponses(
// value = { value = {
// @ApiResponse( @ApiResponse(
// code = 201, code = 201,
// message = "OK. \n Successfully created an application.", message = "OK. \n Successfully created an application.",
// response = Application.class), response = ApplicationRelease.class),
// @ApiResponse( @ApiResponse(
// code = 400, code = 400,
// message = "Bad Request. \n " + message = "Bad Request. \n " +
// "ApplicationDTO creating payload contains unacceptable or vulnerable data"), "ApplicationDTO creating payload contains unacceptable or vulnerable data"),
// @ApiResponse( @ApiResponse(
// code = 500, code = 500,
// message = "Internal Server Error. \n Error occurred while creating the application.", message = "Internal Server Error. \n Error occurred while creating the application.",
// response = ErrorResponse.class) response = ErrorResponse.class)
// }) })
// Response createRelease( Response createRelease(
// @PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
// @PathParam("appId") String appType, @PathParam("appId") String appType,
// @PathParam("appId") int appId, @PathParam("appId") int appId,
// @ApiParam( @ApiParam(
// name = "applicationRelease", name = "applicationRelease",
// value = "The application release that need to be created.", value = "The application release that need to be created.",
// required = true) required = true)
// @Multipart("applicationRelease") ApplicationReleaseDTO applicationRelease, @Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
// @ApiParam( @ApiParam(
// name = "binaryFile", name = "binaryFile",
// value = "Binary file of uploading application", value = "Binary file of uploading application",
// required = true) required = true)
// @Multipart(value = "binaryFile") Attachment binaryFile, @Multipart(value = "binaryFile") Attachment binaryFile,
// @ApiParam( @ApiParam(
// name = "icon", name = "icon",
// value = "Icon of the uploading application", value = "Icon of the uploading application",
// required = true) required = true)
// @Multipart(value = "icon") Attachment iconFile, @Multipart(value = "icon") Attachment iconFile,
// @ApiParam( @ApiParam(
// name = "banner", name = "banner",
// value = "Banner of the uploading application", value = "Banner of the uploading application",
// required = true) required = true)
// @Multipart(value = "banner") Attachment bannerFile, @Multipart(value = "banner") Attachment bannerFile,
// @ApiParam( @ApiParam(
// name = "screenshot1", name = "screenshot1",
// value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application",
// required = true) required = true)
// @Multipart(value = "screenshot1") Attachment screenshot1, @Multipart(value = "screenshot1") Attachment screenshot1,
// @ApiParam( @ApiParam(
// name = "screenshot2", name = "screenshot2",
// value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application",
// required = false) required = false)
// @Multipart(value = "screenshot2") Attachment screenshot2, @Multipart(value = "screenshot2") Attachment screenshot2,
// @ApiParam( @ApiParam(
// name = "screenshot3", name = "screenshot3",
// value = "Screen Shots of the uploading application", value = "Screen Shots of the uploading application",
// required = false) required = false)
// @Multipart(value = "screenshot3") Attachment screenshot3 @Multipart(value = "screenshot3") Attachment screenshot3
// ); );
@DELETE @DELETE
@Consumes("application/json") @Consumes("application/json")

@ -29,6 +29,8 @@ import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
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.response.Application; import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
@ -109,7 +111,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
String msg = "ApplicationDTO with application id: " + appId + " not found"; String msg = "ApplicationDTO with application id: " + appId + " not found";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) { } catch(ForbiddenException e){
String msg = "You don't have permission to access the application. application id: " + appId;
log.error(msg);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the id " + appId; String msg = "Error occurred while getting application with the id " + appId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
@ -167,91 +174,56 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
// @POST @POST
// @Consumes("multipart/mixed") @Consumes("multipart/mixed")
// @Path("/{deviceType}/{appType}/{appId}") @Path("/{deviceType}/{appType}/{appId}")
// public Response createRelease( public Response createRelease(
// @PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
// @PathParam("appType") String appType, @PathParam("appType") String appType,
// @PathParam("appId") int appId, @PathParam("appId") int appId,
// @Multipart("applicationRelease") ApplicationReleaseDTO applicationRelease, @Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
// @Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
// @Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
// @Multipart("banner") Attachment bannerFile, @Multipart("banner") Attachment bannerFile,
// @Multipart("screenshot1") Attachment screenshot1, @Multipart("screenshot1") Attachment screenshot1,
// @Multipart("screenshot2") Attachment screenshot2, @Multipart("screenshot2") Attachment screenshot2,
// @Multipart("screenshot3") Attachment screenshot3) { @Multipart("screenshot3") Attachment screenshot3) {
// ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
// ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); List<Attachment> attachmentList = new ArrayList<>();
// InputStream iconFileStream;
// InputStream bannerFileStream; if (screenshot1 != null) {
// List<InputStream> attachments = new ArrayList<>(); attachmentList.add(screenshot1);
// List<Attachment> attachmentList = new ArrayList<>(); }
// attachmentList.add(screenshot1); if (screenshot2 != null) {
// if (screenshot2 != null) { attachmentList.add(screenshot2);
// attachmentList.add(screenshot2); }
// } if (screenshot3 != null) {
// if (screenshot3 != null) { attachmentList.add(screenshot3);
// attachmentList.add(screenshot3); }
// }
// try {
// try { applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper, appType);
// applicationManager applicationManager.isValidAttachmentSet(binaryFile, iconFile, bannerFile, attachmentList, appType);
// .validateReleaseCreatingRequest(applicationRelease, appType, binaryFile, iconFile, bannerFile,
// attachmentList); // Created new application release
// ApplicationRelease release = applicationManager.createRelease(appId, applicationReleaseWrapper,
// // The application executable artifacts such as apks are uploaded. constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
// if (!ApplicationType.ENTERPRISE.toString().equals(appType)) { if (release != null) {
// applicationRelease = applicationStorageManager return Response.status(Response.Status.CREATED).entity(release).build();
// .uploadReleaseArtifact(applicationRelease, appType, deviceType, null); } else {
// } else { log.error("ApplicationDTO Creation Failed");
// applicationRelease = applicationStorageManager return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
// .uploadReleaseArtifact(applicationRelease, appType, deviceType, }
// binaryFile.getDataHandler().getInputStream()); } catch (ApplicationManagementException e) {
// if (applicationRelease.getInstallerName() == null || applicationRelease.getAppHashValue() == null) { String msg = "Error occurred while creating the application";
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); log.error(msg, e);
// } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
// } } catch (RequestValidatingException e) {
// String msg = "Error occurred while handling the application creating request";
// iconFileStream = iconFile.getDataHandler().getInputStream(); log.error(msg, e);
// bannerFileStream = bannerFile.getDataHandler().getInputStream(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
// }
// for (Attachment screenshot : attachmentList) { }
// attachments.add(screenshot.getDataHandler().getInputStream());
// }
//
// // Upload images
// applicationRelease = applicationStorageManager
// .uploadImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
// applicationRelease.setUuid(UUID.randomUUID().toString());
//
// // Created new application release entry
// ApplicationReleaseDTO release = applicationManager.createRelease(appId, applicationRelease);
// if (release != null) {
// return Response.status(Response.Status.CREATED).entity(release).build();
// } else {
// log.error("ApplicationDTO Creation Failed");
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
// }
// } catch (ApplicationManagementException e) {
// String msg = "Error occurred while creating the application";
// log.error(msg, e);
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
// } catch (ResourceManagementException e) {
// String msg = "Error occurred while uploading the releases artifacts of the application ID: " + appId;
// log.error(msg, e);
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
// } catch (IOException e) {
// String msg = "Error while uploading binary file and resources for the application release of the "
// + "application ID: " + appId;
// log.error(msg, e);
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
// } catch (RequestValidatingException e) {
// String msg = "Error occurred while handling the application creating request";
// log.error(msg, e);
// return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
// }
// }
@Override @Override
@PUT @PUT

Loading…
Cancel
Save