mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add application release deleting API
This commit is contained in:
parent
3a5cf16c26
commit
f95f872732
@ -0,0 +1,68 @@
|
|||||||
|
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.common.dto;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class DeviceSubscriptionDTO {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String subscribedBy;
|
||||||
|
private Timestamp subscribedTimestamp;
|
||||||
|
private boolean isUnsubscribed;
|
||||||
|
private String unsubscribedBy;
|
||||||
|
private Timestamp unsubscribedTimestapm;
|
||||||
|
private String subscribedFrom;
|
||||||
|
private int deviceId;
|
||||||
|
|
||||||
|
public int getId() { return id; }
|
||||||
|
|
||||||
|
public void setId(int id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getSubscribedBy() { return subscribedBy; }
|
||||||
|
|
||||||
|
public void setSubscribedBy(String subscribedBy) { this.subscribedBy = subscribedBy; }
|
||||||
|
|
||||||
|
public Timestamp getSubscribedTimestamp() { return subscribedTimestamp; }
|
||||||
|
|
||||||
|
public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
|
||||||
|
this.subscribedTimestamp = subscribedTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUnsubscribed() { return isUnsubscribed; }
|
||||||
|
|
||||||
|
public void setUnsubscribed(boolean unsubscribed) { isUnsubscribed = unsubscribed; }
|
||||||
|
|
||||||
|
public String getUnsubscribedBy() { return unsubscribedBy; }
|
||||||
|
|
||||||
|
public void setUnsubscribedBy(String unsubscribedBy) { this.unsubscribedBy = unsubscribedBy; }
|
||||||
|
|
||||||
|
public Timestamp getUnsubscribedTimestapm() { return unsubscribedTimestapm; }
|
||||||
|
|
||||||
|
public void setUnsubscribedTimestapm(Timestamp unsubscribedTimestapm) {
|
||||||
|
this.unsubscribedTimestapm = unsubscribedTimestapm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubscribedFrom() { return subscribedFrom; }
|
||||||
|
|
||||||
|
public void setSubscribedFrom(String subscribedFrom) { this.subscribedFrom = subscribedFrom; }
|
||||||
|
|
||||||
|
public int getDeviceId() { return deviceId; }
|
||||||
|
|
||||||
|
public void setDeviceId(int deviceId) { this.deviceId = deviceId; }
|
||||||
|
}
|
||||||
@ -76,7 +76,7 @@ public interface ApplicationManager {
|
|||||||
* @param releaseUuid UUID of tha application release
|
* @param releaseUuid UUID of tha application release
|
||||||
* @throws ApplicationManagementException ApplicationDTO Management Exception
|
* @throws ApplicationManagementException ApplicationDTO Management Exception
|
||||||
*/
|
*/
|
||||||
String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
|
void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To get the applications based on the search filter.
|
* To get the applications based on the search filter.
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.dao;
|
|||||||
|
|
||||||
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.dto.DeviceSubscriptionDTO;
|
||||||
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.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
@ -86,4 +87,8 @@ public interface SubscriptionDAO {
|
|||||||
*/
|
*/
|
||||||
void subscribeGroupToApplication(int tenantId, String subscribedBy, List<DeviceGroup> groupList, int appId,
|
void subscribeGroupToApplication(int tenantId, String subscribedBy, List<DeviceGroup> groupList, int appId,
|
||||||
int releaseId) throws ApplicationManagementDAOException;
|
int releaseId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws
|
||||||
|
ApplicationManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
|
|||||||
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
|
||||||
|
|
||||||
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.DeviceSubscriptionDTO;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
|
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
|
||||||
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.services.ApplicationStorageManager;
|
||||||
@ -94,6 +95,31 @@ public class Util {
|
|||||||
return applications;
|
return applications;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create list of device subscription objects from the result set retrieved from the Database.
|
||||||
|
*
|
||||||
|
* @param rs ResultSet
|
||||||
|
* @return List of device subscriptions that is retrieved from the Database.
|
||||||
|
* @throws SQLException SQL Exception
|
||||||
|
* @throws JSONException JSONException.
|
||||||
|
*/
|
||||||
|
public static List<DeviceSubscriptionDTO> loadDeviceSubscriptions(ResultSet rs) throws SQLException {
|
||||||
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
DeviceSubscriptionDTO deviceSubscriptionDTO = new DeviceSubscriptionDTO();
|
||||||
|
deviceSubscriptionDTO.setId(rs.getInt("ID"));
|
||||||
|
deviceSubscriptionDTO.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
|
||||||
|
deviceSubscriptionDTO.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
|
||||||
|
deviceSubscriptionDTO.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
|
||||||
|
deviceSubscriptionDTO.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
|
||||||
|
deviceSubscriptionDTO.setUnsubscribedTimestapm(rs.getTimestamp("UNSUBSCRIBED_AT"));
|
||||||
|
deviceSubscriptionDTO.setSubscribedFrom(rs.getString("SUBSCRIBED_FROM"));
|
||||||
|
deviceSubscriptionDTO.setDeviceId(rs.getInt("DEVICE_ID"));
|
||||||
|
deviceSubscriptionDTOS.add(deviceSubscriptionDTO);
|
||||||
|
}
|
||||||
|
return deviceSubscriptionDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates {@link ApplicationReleaseDTO} object with the result obtained from the database.
|
* Populates {@link ApplicationReleaseDTO} object with the result obtained from the database.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -19,16 +19,21 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
|
||||||
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.SubscriptionDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
|
||||||
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 org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -44,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
conn = this.getDBConnection();
|
conn = this.getDBConnection();
|
||||||
long time = System.currentTimeMillis() / 1000;
|
long time = System.currentTimeMillis() / 1000;
|
||||||
String sql = "INSERT INTO AP_DEVICE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, "
|
String sql = "INSERT INTO AP_DEVICE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, "
|
||||||
+ "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?)";
|
+ "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
for (Device device : deviceList) {
|
for (Device device : deviceList) {
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
@ -168,4 +173,50 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
Util.cleanupResources(stmt, null);
|
Util.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws
|
||||||
|
ApplicationManagementDAOException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting device subscriptions for the application release id " + appReleaseId
|
||||||
|
+ " from the database");
|
||||||
|
}
|
||||||
|
Connection conn;
|
||||||
|
try {
|
||||||
|
conn = this.getDBConnection();
|
||||||
|
String sql = "SELECT "
|
||||||
|
+ "DS.ID AS ID, "
|
||||||
|
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
|
||||||
|
+ "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
|
||||||
|
+ "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
|
||||||
|
+ "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
|
||||||
|
+ "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
|
||||||
|
+ "DS.SUBSCRIBED_FROM AS SUBSCRIBED_FROM, "
|
||||||
|
+ "DS.DM_DEVICE_ID AS DEVICE_ID "
|
||||||
|
+ "FROM AP_DEVICE_SUBSCRIPTION DS "
|
||||||
|
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?";
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, appReleaseId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Successfully retrieved device subscriptions for application release id "
|
||||||
|
+ appReleaseId);
|
||||||
|
}
|
||||||
|
return Util.loadDeviceSubscriptions(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg =
|
||||||
|
"Error occurred while getting device subscription data for application ID: " + appReleaseId + ".";
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg =
|
||||||
|
"Error occurred while obtaining the DB connection for getting device subscription for applicationID: "
|
||||||
|
+ appReleaseId + ".";
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionType
|
|||||||
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
||||||
import org.wso2.carbon.device.application.mgt.common.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.LifecycleStateDTO;
|
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
|
||||||
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;
|
||||||
@ -59,6 +60,7 @@ import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
|||||||
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.ApplicationReleaseDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||||
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.SubscriptionDAO;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||||
@ -109,6 +111,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
private ApplicationDAO applicationDAO;
|
private ApplicationDAO applicationDAO;
|
||||||
private ApplicationReleaseDAO applicationReleaseDAO;
|
private ApplicationReleaseDAO applicationReleaseDAO;
|
||||||
private LifecycleStateDAO lifecycleStateDAO;
|
private LifecycleStateDAO lifecycleStateDAO;
|
||||||
|
private SubscriptionDAO subscriptionDAO;
|
||||||
private LifecycleStateManager lifecycleStateManager;
|
private LifecycleStateManager lifecycleStateManager;
|
||||||
|
|
||||||
public ApplicationManagerImpl() {
|
public ApplicationManagerImpl() {
|
||||||
@ -121,6 +124,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||||
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
|
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
|
||||||
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
||||||
|
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@ -1230,86 +1234,91 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deleteApplicationRelease(int applicationId, String releaseUuid)
|
public void deleteApplicationRelease(int applicationId, String releaseUuid)
|
||||||
throws ApplicationManagementException {
|
throws ApplicationManagementException {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
||||||
ApplicationDTO application;
|
|
||||||
try {
|
try {
|
||||||
ConnectionManagerUtil.beginDBTransaction();
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
application = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
|
||||||
if (application == null) {
|
.getReleaseByUUID(releaseUuid, tenantId);
|
||||||
throw new NotFoundException("Couldn't find an application for application ID: " + applicationId);
|
if (applicationReleaseDTO == null) {
|
||||||
}
|
String msg = "Couldn't find an application release for application release UUID: " + releaseUuid;
|
||||||
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION) && !application
|
log.error(msg);
|
||||||
.getUnrestrictedRoles().isEmpty() && hasUserRole(application.getUnrestrictedRoles(), userName)) {
|
throw new NotFoundException(msg);
|
||||||
throw new ForbiddenException(
|
|
||||||
"You don't have permission for deleting application release. ApplicationDTO id: " + applicationId
|
|
||||||
+ " and release UUID: " + releaseUuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationReleaseDTO applicationRelease = this.applicationReleaseDAO
|
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getInitialState())) {
|
||||||
.getReleaseByIds(applicationId, releaseUuid, tenantId);
|
String msg = "Application state is not in the initial state: " + lifecycleStateManager.getInitialState()
|
||||||
if (applicationRelease == null) {
|
+ ". Therefore you are not permitted to delete the application release.";
|
||||||
throw new NotFoundException("Couldn't find an application release for application ID: " + applicationId
|
log.error(msg);
|
||||||
+ " and release UUID: " + releaseUuid);
|
throw new ForbiddenException(msg);
|
||||||
}
|
}
|
||||||
LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
||||||
.getLatestLifeCycleState(applicationId, releaseUuid);
|
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
|
||||||
if (appLifecycleState == null) {
|
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
|
||||||
throw new NotFoundException(
|
if (!deviceSubscriptionDTO.isUnsubscribed()) {
|
||||||
"Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: "
|
String msg = "This application is subscribed to device/s. Therefore you are not permitted to delete "
|
||||||
+ releaseUuid);
|
+ "the application release.";
|
||||||
}
|
log.error(msg);
|
||||||
String currentState = appLifecycleState.getCurrentState();
|
throw new ForbiddenException(msg);
|
||||||
if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString()
|
|
||||||
.equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) {
|
|
||||||
LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(),
|
|
||||||
appLifecycleState.getCurrentState());
|
|
||||||
if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
|
||||||
newAppLifecycleState.getCurrentState(), userName, tenantId)) {
|
|
||||||
this.lifecycleStateDAO
|
|
||||||
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
|
||||||
tenantId);
|
|
||||||
ConnectionManagerUtil.commitDBTransaction();
|
|
||||||
} else {
|
|
||||||
List<String> lifecycleFlow = searchLifecycleStateFlow(currentState,
|
|
||||||
AppLifecycleState.REMOVED.toString());
|
|
||||||
for (String nextState : lifecycleFlow) {
|
|
||||||
LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState);
|
|
||||||
if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) {
|
|
||||||
this.lifecycleStateDAO
|
|
||||||
.addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(),
|
|
||||||
tenantId);
|
|
||||||
} else {
|
|
||||||
ConnectionManagerUtil.rollbackDBTransaction();
|
|
||||||
throw new ApplicationManagementException(
|
|
||||||
"Can't delete the application release, You have to move the "
|
|
||||||
+ "lifecycle state from " + currentState + " to " + nextState);
|
|
||||||
}
|
|
||||||
currentState = nextState;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
//todo delete application release data ON delete cascade
|
||||||
throw new ApplicationManagementException(
|
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
||||||
"Can't delete the application release, You have to move the " + "lifecycle state from "
|
|
||||||
+ currentState + " to acceptable " + "state");
|
// LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO
|
||||||
}
|
// .getLatestLifeCycleState(applicationId, releaseUuid);
|
||||||
return applicationRelease.getAppHashValue();
|
// if (appLifecycleState == null) {
|
||||||
|
// throw new NotFoundException(
|
||||||
|
// "Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: "
|
||||||
|
// + releaseUuid);
|
||||||
|
// }
|
||||||
|
// String currentState = appLifecycleState.getCurrentState();
|
||||||
|
// if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString()
|
||||||
|
// .equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) {
|
||||||
|
// LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(),
|
||||||
|
// appLifecycleState.getCurrentState());
|
||||||
|
// if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
||||||
|
// newAppLifecycleState.getCurrentState(), userName, tenantId)) {
|
||||||
|
// this.lifecycleStateDAO
|
||||||
|
// .addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
||||||
|
// tenantId);
|
||||||
|
// ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
// } else {
|
||||||
|
// List<String> lifecycleFlow = searchLifecycleStateFlow(currentState,
|
||||||
|
// AppLifecycleState.REMOVED.toString());
|
||||||
|
// for (String nextState : lifecycleFlow) {
|
||||||
|
// LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState);
|
||||||
|
// if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) {
|
||||||
|
// this.lifecycleStateDAO
|
||||||
|
// .addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(),
|
||||||
|
// tenantId);
|
||||||
|
// } else {
|
||||||
|
// ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
// throw new ApplicationManagementException(
|
||||||
|
// "Can't delete the application release, You have to move the "
|
||||||
|
// + "lifecycle state from " + currentState + " to " + nextState);
|
||||||
|
// }
|
||||||
|
// currentState = nextState;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// throw new ApplicationManagementException(
|
||||||
|
// "Can't delete the application release, You have to move the " + "lifecycle state from "
|
||||||
|
// + currentState + " to acceptable " + "state");
|
||||||
|
// }
|
||||||
|
// return applicationReleaseDTO.getAppHashValue();
|
||||||
} catch (ApplicationManagementDAOException e) {
|
} catch (ApplicationManagementDAOException e) {
|
||||||
ConnectionManagerUtil.rollbackDBTransaction();
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
throw new ApplicationManagementDAOException(
|
String msg = "Error ocured when getting application data or application release data for application id of "
|
||||||
"Error ocured when getting application data or application release data for application id of "
|
+ applicationId + " application release UUID of the " + releaseUuid;
|
||||||
+ applicationId + " application release UUID of the " + releaseUuid);
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
} catch (LifeCycleManagementDAOException e) {
|
} catch (ApplicationStorageManagementException e) {
|
||||||
ConnectionManagerUtil.rollbackDBTransaction();
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
throw new ApplicationManagementException(
|
String msg = "Error occured when deleteing the application release artifact from the file system. Application release UUID: " + releaseUuid;
|
||||||
"Error occured when deleting application release for application ID of " + applicationId
|
log.error(msg);
|
||||||
+ " and application release UUID of " + releaseUuid, e);
|
throw new ApplicationManagementException(msg, e);
|
||||||
} catch (UserStoreException e) {
|
|
||||||
throw new ApplicationManagementException(
|
|
||||||
"Error occured when checking permission for executing application release update. ApplicationDTO ID: "
|
|
||||||
+ applicationId + " and ApplicationDTO UUID: " + releaseUuid);
|
|
||||||
} finally {
|
} finally {
|
||||||
ConnectionManagerUtil.closeDBConnection();
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,33 +28,18 @@ import io.swagger.annotations.ExtensionProperty;
|
|||||||
import io.swagger.annotations.Info;
|
import io.swagger.annotations.Info;
|
||||||
import io.swagger.annotations.SwaggerDefinition;
|
import io.swagger.annotations.SwaggerDefinition;
|
||||||
import io.swagger.annotations.Tag;
|
import io.swagger.annotations.Tag;
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||||
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
||||||
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.Filter;
|
|
||||||
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.response.ApplicationRelease;
|
|
||||||
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 javax.validation.Valid;
|
|
||||||
import javax.ws.rs.Consumes;
|
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.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIs to handle application management related tasks.
|
* APIs to handle application management related tasks.
|
||||||
@ -92,19 +77,19 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
String SCOPE = "scope";
|
String SCOPE = "scope";
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{appid}/{uuid}")
|
@Path("/release/{appId}/{uuid}")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
produces = MediaType.APPLICATION_JSON,
|
produces = MediaType.APPLICATION_JSON,
|
||||||
httpMethod = "GET",
|
httpMethod = "DELETE",
|
||||||
value = "get all applications",
|
value = "Delete application release.",
|
||||||
notes = "This will get all applications",
|
notes = "This will delete application release for given UUID",
|
||||||
tags = "ApplicationDTO Management",
|
tags = "Application Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:view")
|
@ExtensionProperty(name = SCOPE, value = "perm:admin:app:publisher:update")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -112,11 +97,11 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
value = {
|
value = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 200,
|
code = 200,
|
||||||
message = "OK. \n Successfully delete application releaset.",
|
message = "OK. \n Successfully delete application release.",
|
||||||
response = ApplicationList.class),
|
response = ApplicationList.class),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 404,
|
code = 404,
|
||||||
message = "Not Found. There doesn't have an application release with UUID" +
|
message = "Not Found. There doesn't have an application release for UUID" +
|
||||||
"query."),
|
"query."),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 500,
|
code = 500,
|
||||||
@ -127,7 +112,7 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
name = "appId",
|
name = "appId",
|
||||||
value = "application Id",
|
value = "application Id",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("appid") int applicationId,
|
@PathParam("appId") int applicationId,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "uuid",
|
name = "uuid",
|
||||||
value = "application release UUID",
|
value = "application release UUID",
|
||||||
|
|||||||
@ -74,16 +74,14 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
|
|||||||
private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class);
|
private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class);
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{appid}/{uuid}")
|
@Path("/release/{appId}/{uuid}")
|
||||||
public Response deleteApplicationRelease(
|
public Response deleteApplicationRelease(
|
||||||
@PathParam("appid") int applicationId,
|
@PathParam("appId") int applicationId,
|
||||||
@PathParam("uuid") String releaseUuid) {
|
@PathParam("uuid") String releaseUuid) {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
||||||
try {
|
try {
|
||||||
String storedLocation = applicationManager.deleteApplicationRelease(applicationId, releaseUuid);
|
applicationManager.deleteApplicationRelease(applicationId, releaseUuid);
|
||||||
applicationStorageManager.deleteApplicationReleaseArtifacts(storedLocation);
|
String responseMsg = "Successfully deleted the application release for uuid: " + releaseUuid + "";
|
||||||
String responseMsg = "Successfully deleted the application release of: " + applicationId + "";
|
|
||||||
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
String msg = "Couldn't found application release which is having application id: " + applicationId
|
String msg = "Couldn't found application release which is having application id: " + applicationId
|
||||||
@ -100,10 +98,6 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
|
|||||||
String msg = "Error occurred while deleting the application: " + applicationId;
|
String msg = "Error occurred while deleting the application: " + applicationId;
|
||||||
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();
|
||||||
} catch (ApplicationStorageManagementException e) {
|
|
||||||
String msg = "Error occurred while deleting the application storage: " + applicationId;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user