Merge branch 'application-mgt-new' of https://gitlab.com/entgra/carbon-device-mgt into application-mgt-new

feature/appm-store/pbac
Jayasanka 6 years ago
commit 29e06ddf4e

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.application.mgt.common.dto; package org.wso2.carbon.device.application.mgt.common;
import java.sql.Timestamp; import java.sql.Timestamp;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -24,13 +24,8 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.List; import java.util.List;
@ApiModel(value = "LifecycleStateDTO", description = "LifecycleStateDTO represents the Lifecycle state for an application release") @ApiModel(value = "LifecycleState", description = "LifecycleState represents the Lifecycle state for an application release")
public class LifecycleStateDTO { public class LifecycleState {
@ApiModelProperty(name = "id",
value = "ID of the application release lifecycle",
required = true)
private int id;
@ApiModelProperty(name = "currentState", @ApiModelProperty(name = "currentState",
value = "Current state of the application release", value = "Current state of the application release",
@ -54,14 +49,6 @@ public class LifecycleStateDTO {
value = "Timestamp of the lifecycle has been updated") value = "Timestamp of the lifecycle has been updated")
private Timestamp updatedAt; private Timestamp updatedAt;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCurrentState() { public String getCurrentState() {
return currentState; return currentState;
} }

@ -24,7 +24,7 @@ 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.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.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
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;
@ -133,24 +133,22 @@ public interface ApplicationManager {
ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException; ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException;
/** /**
* To get all the releases of a particular ApplicationDTO. * To get lifecycle state change flow of a particular Application Release.
* *
* @param applicationId ID of the ApplicationDTO . * @param releaseUuid UUID of the Application Release.
* @param releaseUuid UUID of the ApplicationDTO Release. * @return the List of LifecycleStates which represent the lifecycle change flow of the application releases.
* @return the LifecycleStateDTO of the ApplicationDTO releases related with the particular ApplicationDTO. * @throws ApplicationManagementException Application Management Exception.
* @throws ApplicationManagementException ApplicationDTO Management Exception.
*/ */
LifecycleStateDTO getLifecycleState(int applicationId, String releaseUuid) throws ApplicationManagementException; List<LifecycleState> getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException;
/** /**
* To get all the releases of a particular ApplicationDTO. * To get all the releases of a particular ApplicationDTO.
* *
* @param applicationId ID of the ApplicationDTO.
* @param releaseUuid UUID of the ApplicationDTO Release. * @param releaseUuid UUID of the ApplicationDTO Release.
* @param state Lifecycle state to change the app * @param stateName Lifecycle state to change the app
* @throws ApplicationManagementException ApplicationDTO Management Exception. * @throws ApplicationManagementException ApplicationDTO Management Exception.
*/ */
void changeLifecycleState(int applicationId, String releaseUuid, LifecycleStateDTO state) void changeLifecycleState(String releaseUuid, String stateName)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**

@ -178,6 +178,10 @@ 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, String inactiveState) throws ApplicationManagementDAOException; boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId, String inactiveState)
throws ApplicationManagementDAOException;
boolean hasExistInstallableAppRelease(String releaseUuid, String installableStateName, int tenantId)
throws ApplicationManagementDAOException;
} }

@ -18,7 +18,7 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.dao; package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
import java.util.List; import java.util.List;
@ -35,7 +35,7 @@ public interface LifecycleStateDAO {
* @return Latest Lifecycle State for the given application release * @return Latest Lifecycle State for the given application release
* @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception.
*/ */
LifecycleStateDTO getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws LifeCycleManagementDAOException; LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws LifeCycleManagementDAOException;
/** /**
* To get the latest lifecycle state for the given application id and the application release UUID. * To get the latest lifecycle state for the given application id and the application release UUID.
@ -45,32 +45,31 @@ public interface LifecycleStateDAO {
* @return Latest Lifecycle State for the given application release * @return Latest Lifecycle State for the given application release
* @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception.
*/ */
LifecycleStateDTO getLatestLifeCycleState(int appId, String uuid) throws LifeCycleManagementDAOException; LifecycleState getLatestLifeCycleState(int appId, String uuid) throws LifeCycleManagementDAOException;
/** /**
* To get all changed lifecycle states for the given application release id. * To get all changed lifecycle states for the given application release id.
* @param appReleaseId id of the application release. * @param appReleaseId id of the application release.
* @param tenantId Tenant Id.
* *
* @return Lifecycle States for the given application release * @return Lifecycle States for the given application release
* @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception.
*/ */
List<LifecycleStateDTO> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException; List<LifecycleState> getLifecycleStates(int appReleaseId, int tenantId) throws LifeCycleManagementDAOException;
/** /**
* To add new lifecycle states for the given application release. * To add new lifecycle states for the given application release.
* @param uuid Id of the application release. * @param state LifecycleState.
* @param appId Id of the application.
* @param state LifecycleStateDTO.
* @param tenantId Tenant id * @param tenantId Tenant id
* *
* @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception.
*/ */
void addLifecycleState(LifecycleStateDTO state, int appId, String uuid, int tenantId) void addLifecycleState(LifecycleState state, int appReleaseId, int tenantId)
throws LifeCycleManagementDAOException; throws LifeCycleManagementDAOException;
/** /**
* To delete lifecycle state data of specific application release. * To delete lifecycle state data of specific application release.
* @param releaseId Id of the LifecycleStateDTO. * @param releaseId Id of the LifecycleState.
* *
* @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception. * @throws LifeCycleManagementDAOException Lifecycle Management DAO Exception.
*/ */

@ -129,6 +129,7 @@ public class Util {
*/ */
public static ApplicationReleaseDTO loadAppRelease(ResultSet rs) throws SQLException { public static ApplicationReleaseDTO loadAppRelease(ResultSet rs) throws SQLException {
ApplicationReleaseDTO appRelease = new ApplicationReleaseDTO(); ApplicationReleaseDTO appRelease = new ApplicationReleaseDTO();
appRelease.setId(rs.getInt("RELEASE_ID"));
appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION")); appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION"));
appRelease.setUuid(rs.getString("RELEASE_UUID")); appRelease.setUuid(rs.getString("RELEASE_UUID"));
appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); appRelease.setReleaseType(rs.getString("RELEASE_TYPE"));

@ -144,6 +144,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.CURRENCY AS APP_CURRENCY, "
+ "AP_APP.RATING AS APP_RATING, " + "AP_APP.RATING AS APP_RATING, "
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, " + "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
@ -502,6 +503,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.CURRENCY AS APP_CURRENCY, "
+ "AP_APP.RATING AS APP_RATING, " + "AP_APP.RATING AS APP_RATING, "
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, " + "AP_APP_RELEASE.UUID AS RELEASE_UUID, "

@ -226,7 +226,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
public ApplicationReleaseDTO getReleaseByUUID( String uuid, int tenantId) throws ApplicationManagementDAOException { public ApplicationReleaseDTO getReleaseByUUID( String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection; Connection connection;
String sql = String sql =
"SELECT AR.DESCRIPTION AS RELEASE_DESCRIPTION, " "SELECT AR.ID AS RELEASE_ID, "
+ "AR.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AR.VERSION AS RELEASE_VERSION, " + "AR.VERSION AS RELEASE_VERSION, "
+ "AR.UUID AS RELEASE_UUID, " + "AR.UUID AS RELEASE_UUID, "
+ "AR.RELEASE_TYPE AS RELEASE_TYPE, " + "AR.RELEASE_TYPE AS RELEASE_TYPE, "
@ -752,4 +753,38 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
@Override
public boolean hasExistInstallableAppRelease(String releaseUuid, String installableStateName, int tenantId)
throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) {
log.debug("Verifying application release existence in the installable state: :" + installableStateName);
}
Connection conn;
try {
conn = this.getDBConnection();
String sql = "SELECT AR.ID AS RELEASE_ID "
+ "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.CURRENT_STATE = ? AND "
+ "AR.AP_APP_ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND "
+ "AR.TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, installableStateName);
stmt.setString(2, releaseUuid);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
return rs.next();
}
}
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application release details in installable state: "
+ installableStateName, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection to get application release data in installable "
+ "state.", e);
}
}
} }

@ -19,7 +19,7 @@
package org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate; package org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate;
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.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
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.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
@ -41,7 +41,7 @@ import java.util.List;
public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements LifecycleStateDAO { public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements LifecycleStateDAO {
@Override @Override
public LifecycleStateDTO getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws LifeCycleManagementDAOException { public LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws LifeCycleManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -65,7 +65,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
} }
} }
public LifecycleStateDTO getLatestLifeCycleState(int appId, String uuid) throws LifeCycleManagementDAOException{ public LifecycleState getLatestLifeCycleState(int appId, String uuid) throws LifeCycleManagementDAOException{
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -122,40 +122,45 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
} }
@Override @Override
public List<LifecycleStateDTO> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException { public List<LifecycleState> getLifecycleStates(int appReleaseId, int tenantId) throws LifeCycleManagementDAOException {
List<LifecycleStateDTO> lifecycleStates = new ArrayList<>(); List<LifecycleState> lifecycleStates = new ArrayList<>();
Connection conn = null; Connection conn ;
PreparedStatement stmt = null;
ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " String sql = "SELECT "
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;"; + "CURRENT_STATE, "
stmt = conn.prepareStatement(sql); + "PREVIOUS_STATE, "
+ "UPDATED_AT, "
+ "UPDATED_BY "
+ "FROM AP_APP_LIFECYCLE_STATE "
+ "WHERE AP_APP_RELEASE_ID = ? AND "
+ "TENANT_ID = ? "
+ "ORDER BY UPDATED_AT ASC;";
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setInt(1,appReleaseId); stmt.setInt(1,appReleaseId);
rs = stmt.executeQuery(); stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()){
while (rs.next()) { while (rs.next()) {
LifecycleStateDTO lifecycleState = new LifecycleStateDTO(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
lifecycleStates.add(lifecycleState); lifecycleStates.add(lifecycleState);
} }
}
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection when getting " throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection when getting "
+ "lifecycle states for an application", e); + "lifecycle states for an application", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while retrieving lifecycle states.", e); throw new LifeCycleManagementDAOException("Error occurred while retrieving lifecycle states.", e);
} finally {
Util.cleanupResources(stmt, rs);
} }
return lifecycleStates; return lifecycleStates;
} }
@Override @Override
public void addLifecycleState(LifecycleStateDTO state, int appId, String uuid, int tenantId) throws LifeCycleManagementDAOException { public void addLifecycleState(LifecycleState state, int appReleaseId, int tenantId) throws LifeCycleManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
@ -168,7 +173,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
+ "UPDATED_AT, " + "UPDATED_AT, "
+ "AP_APP_RELEASE_ID, " + "AP_APP_RELEASE_ID, "
+ "AP_APP_ID) " + "AP_APP_ID) "
+ "VALUES (?,?, ?, ?, ?, (SELECT ID FROM AP_APP_RELEASE WHERE UUID=?),?);"; + "VALUES (?, ?, ?, ?, ?, ?, (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE ID = ?));";
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
@ -179,10 +184,9 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setString(4, state.getUpdatedBy()); stmt.setString(4, state.getUpdatedBy());
stmt.setTimestamp(5, timestamp); stmt.setTimestamp(5, timestamp);
stmt.setString(6, uuid); stmt.setInt(6, appReleaseId);
stmt.setInt(7, appId); stmt.setInt(7, appReleaseId);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) { } catch (SQLException e) {
@ -237,12 +241,11 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
} }
private LifecycleStateDTO constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException { private LifecycleState constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException {
LifecycleStateDTO lifecycleState = null; LifecycleState lifecycleState = null;
try { try {
if (rs !=null && rs.next()) { if (rs !=null && rs.next()) {
lifecycleState = new LifecycleStateDTO(); lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));

@ -39,7 +39,7 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationType;
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.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
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.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
@ -311,10 +311,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setCurrentState(initialLifecycleState); applicationReleaseDTO.setCurrentState(initialLifecycleState);
applicationReleaseDTO = this.applicationReleaseDAO applicationReleaseDTO = this.applicationReleaseDAO
.createRelease(applicationReleaseDTO, appId, tenantId); .createRelease(applicationReleaseDTO, appId, tenantId);
LifecycleStateDTO lifecycleStateDTO = getLifecycleStateInstance(initialLifecycleState, LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState,
initialLifecycleState); initialLifecycleState);
this.lifecycleStateDAO this.lifecycleStateDAO
.addLifecycleState(lifecycleStateDTO, appId, applicationReleaseDTO.getUuid(), tenantId); .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
applicationReleaseEntities.add(applicationReleaseDTO); applicationReleaseEntities.add(applicationReleaseDTO);
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
Application application = appDtoToAppResponse(applicationDTO); Application application = appDtoToAppResponse(applicationDTO);
@ -745,11 +745,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
String initialstate = lifecycleStateManager.getInitialState(); String initialstate = lifecycleStateManager.getInitialState();
applicationReleaseDTO.setCurrentState(initialstate); applicationReleaseDTO.setCurrentState(initialstate);
LifecycleStateDTO lifecycleState = getLifecycleStateInstance(initialstate, initialstate); LifecycleState lifecycleState = getLifecycleStateInstance(initialstate, initialstate);
applicationReleaseDTO = this.applicationReleaseDAO applicationReleaseDTO = this.applicationReleaseDAO
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId); .createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
this.lifecycleStateDAO this.lifecycleStateDAO
.addLifecycleState(lifecycleState, applicationId, applicationReleaseDTO.getUuid(), tenantId); .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
applicationRelease = releaseDtoToRelease(applicationReleaseDTO); applicationRelease = releaseDtoToRelease(applicationReleaseDTO);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return applicationRelease; return applicationRelease;
@ -1116,7 +1116,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(""); throw new ApplicationManagementException("");
} }
for (ApplicationReleaseDTO applicationRelease : applicationReleases) { for (ApplicationReleaseDTO applicationRelease : applicationReleases) {
LifecycleStateDTO lifecycleState = null; LifecycleState lifecycleState = null;
try { try {
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
@ -1139,7 +1139,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
// //
// if (state != null && !state.isEmpty()) { // if (state != null && !state.isEmpty()) {
// for (ApplicationReleaseDTO applicationRelease : applicationReleases) { // for (ApplicationReleaseDTO applicationRelease : applicationReleases) {
// if (state.equals(applicationRelease.getLifecycleState().getCurrentState())) { // if (state.equals(applicationRelease.getLifecycleStateChangeFlow().getCurrentState())) {
// filteredReleases.add(applicationRelease); // filteredReleases.add(applicationRelease);
// } // }
// } // }
@ -1147,9 +1147,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
// if (AppLifecycleState.PUBLISHED.toString().equals(state) && filteredReleases.size() > 1) { // if (AppLifecycleState.PUBLISHED.toString().equals(state) && filteredReleases.size() > 1) {
// log.warn("There are more than one application releases is found which is in PUBLISHED state"); // log.warn("There are more than one application releases is found which is in PUBLISHED state");
// filteredReleases.sort((r1, r2) -> { // filteredReleases.sort((r1, r2) -> {
// if (r1.getLifecycleState().getUpdatedAt().after(r2.getLifecycleState().getUpdatedAt())) { // if (r1.getLifecycleStateChangeFlow().getUpdatedAt().after(r2.getLifecycleStateChangeFlow().getUpdatedAt())) {
// return -1; // return -1;
// } else if (r2.getLifecycleState().getUpdatedAt().after(r1.getLifecycleState().getUpdatedAt())) { // } else if (r2.getLifecycleStateChangeFlow().getUpdatedAt().after(r1.getLifecycleStateChangeFlow().getUpdatedAt())) {
// return 1; // return 1;
// } // }
// return 0; // return 0;
@ -1327,17 +1327,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) { if (!deviceSubscriptionDTOS.isEmpty()){
if (!deviceSubscriptionDTO.isUnsubscribed()) { String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() +
String msg = "This application is subscribed to device/s. Therefore you are not permitted to delete " " either subscribed to device/s or it had subscribed to device/s. Therefore you are not "
+ "the application release."; + "permitted to delete the application release.";
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
}
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue()); applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId()); lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId()); applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred when application release data for application release UUID: " + releaseUuid; String msg = "Error occurred when application release data for application release UUID: " + releaseUuid;
@ -1565,72 +1565,84 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public LifecycleStateDTO getLifecycleState(int applicationId, String releaseUuid) public List<LifecycleState> getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException {
throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
LifecycleStateDTO lifecycleState;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid); ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
if (lifecycleState == null) { .getReleaseByUUID(releaseUuid, tenantId);
return null; if (applicationReleaseDTO == null) {
String msg = "Couldn't found an application release for application release UUID: " + releaseUuid;
log.error(msg);
throw new NotFoundException(msg);
} }
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManager.getNextLifecycleStates(lifecycleState.getCurrentState()))); return this.lifecycleStateDAO.getLifecycleStates(applicationReleaseDTO.getId(), tenantId);
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
throw new ApplicationManagementException("Failed to get lifecycle state from database", e); String msg = "Failed to get lifecycle state for application release uuid " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occurred while getting application release for application release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
return lifecycleState;
} }
@Override @Override
public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleStateDTO state) public void changeLifecycleState(String releaseUuid, String stateName)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)) { ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
throw new NotFoundException("Couldn't find application for the application Id: " + applicationId); .getReleaseByUUID(releaseUuid, tenantId);
}
if (!this.applicationReleaseDAO.verifyReleaseExistence(applicationId, releaseUuid, tenantId)) { if (applicationReleaseDTO == null) {
throw new NotFoundException("Couldn't find application release for the application Id: " + applicationId String msg = "Couldn't found an application release for the UUID: " + releaseUuid;
+ " application release uuid: " + releaseUuid); log.error(msg);
throw new NotFoundException(msg);
} }
LifecycleStateDTO currentState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid);
if (currentState == null) { if (lifecycleStateManager
throw new ApplicationManagementException( .isValidStateChange(applicationReleaseDTO.getCurrentState(), stateName, userName, tenantId)) {
"Couldn't find latest lifecycle state for the appId: " + applicationId if (lifecycleStateManager.isInstallableState(stateName) && applicationReleaseDAO
+ " and application release UUID: " + releaseUuid); .hasExistInstallableAppRelease(applicationReleaseDTO.getUuid(),
lifecycleStateManager.getInstallableState(), tenantId)) {
String msg = "Installable application release is already registered for the application. "
+ "Therefore it is not permitted to change the lifecycle state from "
+ applicationReleaseDTO.getCurrentState() + " to " + stateName;
log.error(msg);
throw new ForbiddenException(msg);
} }
state.setPreviousState(currentState.getCurrentState()); LifecycleState lifecycleState = new LifecycleState();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); lifecycleState.setCurrentState(stateName);
state.setUpdatedBy(userName); lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState());
lifecycleState.setUpdatedBy(userName);
if (state.getCurrentState() != null && state.getPreviousState() != null) { applicationReleaseDTO.setCurrentState(stateName);
if (lifecycleStateManager.isValidStateChange(state.getPreviousState(), state.getCurrentState(), this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
userName, tenantId)) { this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
//todo any other application release in PUBLISHED state for the application( i.e for the appid)
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} else { } else {
ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" + " to '" + " to '" + stateName + "'";
+ state.getCurrentState() + "'"); log.error(msg);
throw new ApplicationManagementException( throw new ApplicationManagementException(msg);
"Lifecycle State Validation failed. ApplicationDTO Id: " + applicationId
+ " ApplicationDTO release UUID: " + releaseUuid);
}
} }
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( String msg = "Failed to add lifecycle state for Application release UUID: " + releaseUuid;
"Failed to add lifecycle state. ApplicationDTO Id: " + applicationId + " ApplicationDTO release UUID: " log.error(msg);
+ releaseUuid, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
//todo ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(""); String msg = "Error occurred when accessing application release data of application release which has the "
+ "application release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1898,11 +1910,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
* By invoking the method, it returns Lifecycle State Instance. * By invoking the method, it returns Lifecycle State Instance.
* @param currentState Current state of the lifecycle * @param currentState Current state of the lifecycle
* @param previousState Previouse state of the Lifecycle * @param previousState Previouse state of the Lifecycle
* @return {@link LifecycleStateDTO} * @return {@link LifecycleState}
*/ */
private LifecycleStateDTO getLifecycleStateInstance(String currentState, String previousState) { private LifecycleState getLifecycleStateInstance(String currentState, String previousState) {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
LifecycleStateDTO lifecycleState = new LifecycleStateDTO(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(currentState); lifecycleState.setCurrentState(currentState);
lifecycleState.setPreviousState(previousState); lifecycleState.setPreviousState(previousState);
lifecycleState.setUpdatedBy(userName); lifecycleState.setUpdatedBy(userName);

@ -47,7 +47,7 @@ public class LifecycleStateManager {
if (lifecycleState.getProceedingStates() != null) { if (lifecycleState.getProceedingStates() != null) {
lifecycleState.getProceedingStates().replaceAll(String::toUpperCase); lifecycleState.getProceedingStates().replaceAll(String::toUpperCase);
} }
lifecycleStates.put(lifecycleState.getName(), lifecycleState); lifecycleStates.put(lifecycleState.getName().toUpperCase(), lifecycleState);
try { try {
PermissionUtils.putPermission(lifecycleState.getPermission()); PermissionUtils.putPermission(lifecycleState.getPermission());
} catch (PermissionManagementException e) { } catch (PermissionManagementException e) {
@ -123,15 +123,10 @@ public class LifecycleStateManager {
} }
private String getPermissionForStateChange(String nextState) { private String getPermissionForStateChange(String nextState) {
Iterator it = lifecycleStates.entrySet().iterator(); for (Map.Entry<String, LifecycleState> lifecycyleState : lifecycleStates.entrySet()) {
LifecycleState nextLifecycleState; if (lifecycyleState.getKey().equalsIgnoreCase(nextState)) {
while (it.hasNext()) { return lifecycyleState.getValue().getPermission();
Map.Entry pair = (Map.Entry) it.next(); }
if (pair.getKey().toString().equalsIgnoreCase(nextState)) {
nextLifecycleState = lifecycleStates.get(nextState);
return nextLifecycleState.getPermission();
}
it.remove();
} }
return null; return null;
} }

@ -666,7 +666,7 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "screenshot3") Attachment screenshot3); @Multipart(value = "screenshot3") Attachment screenshot3);
@GET @GET
@Path("/lifecycle/{appId}/{uuid}") @Path("/life-cycle/state-changes/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -687,16 +687,22 @@ public interface ApplicationManagementPublisherAPI {
message = "OK. \n Successfully retrieved lifecycle states.", message = "OK. \n Successfully retrieved lifecycle states.",
response = List.class, response = List.class,
responseContainer = "List"), responseContainer = "List"),
@ApiResponse(
code = 404,
message = "NOT FOUND. \n Couldn't found an application release for application release UUID."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the lifecycle list.", message = "Internal Server Error. \n Error occurred while getting the lifecycle list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getLifecycleState(@PathParam("appId") int applicationId, Response getLifecycleStates(
@ApiParam(
name = "uuid",
value = "UUID of the application release.")
@PathParam("uuid") String applicationUuid); @PathParam("uuid") String applicationUuid);
@POST @POST
@Path("/lifecycle/{appId}/{uuid}") @Path("/life-cycle/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -732,11 +738,6 @@ public interface ApplicationManagementPublisherAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response addLifecycleState( Response addLifecycleState(
@ApiParam(
name = "appId",
value = "Identifier of the ApplicationDTO",
required = true)
@PathParam("appId") int applicationId,
@ApiParam( @ApiParam(
name = "uuid", name = "uuid",
value = "UUID of the ApplicationDTO Release", value = "UUID of the ApplicationDTO Release",

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,16 +13,16 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.publisher.api.services.impl; package org.wso2.carbon.device.application.mgt.publisher.api.services.impl;
import org.apache.commons.lang.StringUtils;
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.apache.cxf.jaxrs.ext.multipart.Attachment; 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.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
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;
@ -166,18 +165,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("screenshot2") Attachment screenshot2, @Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = new ArrayList<>(); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
if (screenshot1 != null) {
attachmentList.add(screenshot1);
}
if (screenshot2 != null) {
attachmentList.add(screenshot2);
}
if (screenshot3 != null) {
attachmentList.add(screenshot3);
}
try { try {
applicationManager.validateAppCreatingRequest(applicationWrapper); applicationManager.validateAppCreatingRequest(applicationWrapper);
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0), applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0),
@ -220,18 +208,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("screenshot2") Attachment screenshot2, @Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = new ArrayList<>(); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
if (screenshot1 != null) {
attachmentList.add(screenshot1);
}
if (screenshot2 != null) {
attachmentList.add(screenshot2);
}
if (screenshot3 != null) {
attachmentList.add(screenshot3);
}
try { try {
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper, appType); applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper, appType);
applicationManager.validateBinaryArtifact(binaryFile, appType); applicationManager.validateBinaryArtifact(binaryFile, appType);
@ -270,17 +247,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("screenshot2") Attachment screenshot2, @Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart("screenshot3") Attachment screenshot3) {
try { try {
List<Attachment> attachments = new ArrayList<>(); List<Attachment> attachments = constructAttachmentList(screenshot1, screenshot2, screenshot3);
if (screenshot1 != null) {
attachments.add(screenshot1);
}
if (screenshot2 != null) {
attachments.add(screenshot2);
}
if (screenshot3 != null) {
attachments.add(screenshot3);
}
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachments); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachments);
applicationManager.updateApplicationImageArtifact(applicationReleaseUuid, applicationManager.updateApplicationImageArtifact(applicationReleaseUuid,
@ -384,16 +351,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Multipart("screenshot2") Attachment screenshot2, @Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) { @Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = new ArrayList<>(); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
if (screenshot1 != null){
screenshots.add(screenshot1);
}
if (screenshot2 != null) {
screenshots.add(screenshot2);
}
if (screenshot3 != null) {
screenshots.add(screenshot3);
}
try { try {
applicationManager.validateBinaryArtifact(binaryFile, appType); applicationManager.validateBinaryArtifact(binaryFile, appType);
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots); applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
@ -457,52 +415,42 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
/*
//todo ----------------------
*/
@GET @GET
@Path("/lifecycle/{appId}/{uuid}") @Path("/life-cycle/state-changes/{uuid}")
public Response getLifecycleState( public Response getLifecycleStates(
@PathParam("appId") int applicationId, @PathParam("uuid") String releaseUuid) {
@PathParam("uuid") String applicationUuid) {
LifecycleStateDTO lifecycleState;
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid); List<LifecycleState> lifecycleStates = applicationManager.getLifecycleStateChangeFlow(releaseUuid);
if (lifecycleState == null) { return Response.status(Response.Status.OK).entity(lifecycleStates).build();
String msg = "Couldn't found application lifecycle details for appid: " + applicationId } catch (NotFoundException e) {
+ " and app release UUID: " + applicationUuid; String msg = "Couldn't found an application release for UUID: " + releaseUuid;
log.error(msg); log.error(msg);
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while getting lifecycle state."; String msg =
"Error occurred while getting lifecycle states for application release UUID: " + releaseUuid;
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).build();
} }
return Response.status(Response.Status.OK).entity(lifecycleState).build();
} }
@POST @POST
@Path("/lifecycle/{appId}/{uuid}") @Path("/life-cycle/{uuid}")
public Response addLifecycleState( public Response addLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid, @PathParam("uuid") String applicationUuid,
@QueryParam("action") String action) { @QueryParam("action") String action) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
if (action == null || action.isEmpty()) { if (StringUtils.isEmpty(action)) {
String msg = "The Action is null or empty. Please check the request"; String msg = "The Action is null or empty. Please verify the request.";
log.error(msg); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} }
LifecycleStateDTO state = new LifecycleStateDTO();
state.setCurrentState(action); applicationManager.changeLifecycleState( applicationUuid, action);
applicationManager.changeLifecycleState(applicationId, applicationUuid, state);
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Could,t find application release for application id: " + applicationId String msg = "Could,t find application release for application release uuid: " + applicationUuid;
+ " and application release uuid: " + applicationUuid;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -528,6 +476,29 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
/***
* Construct the screenshot list by evaluating the availability of each screenshot.
*
* @param screenshot1 First Screenshot
* @param screenshot2 Second Screenshot
* @param screenshot3 Third Screenshot
* @return List of {@link Attachment}
*/
private List<Attachment> constructAttachmentList(Attachment screenshot1, Attachment screenshot2,
Attachment screenshot3) {
List<Attachment> attachments = new ArrayList<>();
if (screenshot1 != null) {
attachments.add(screenshot1);
}
if (screenshot2 != null) {
attachments.add(screenshot2);
}
if (screenshot3 != null) {
attachments.add(screenshot3);
}
return attachments;
}
/*** /***
* *
* @param binaryFile binary file of the application release * @param binaryFile binary file of the application release
@ -633,7 +604,5 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
} }
} }

@ -20,49 +20,18 @@ package org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin
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.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.Filter;
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.ApplicationStorageManagementException;
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.ApplicationRelease;
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.common.wrapper.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
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.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
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.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI;
import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ApplicationManagementPublisherAdminAPI; import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ApplicationManagementPublisherAdminAPI;
import javax.activation.DataHandler;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
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.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Implementation of Application Management related APIs. * Implementation of Application Management related APIs.

Loading…
Cancel
Save