mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Refactoring
This commit is contained in:
parent
179e34aa92
commit
7a8f3c64dc
@ -110,8 +110,8 @@ import javax.ws.rs.core.Response;
|
|||||||
permissions = {"/device-mgt/application/category/create"}
|
permissions = {"/device-mgt/application/category/create"}
|
||||||
),
|
),
|
||||||
@Scope(
|
@Scope(
|
||||||
name = "Delete an Application",
|
name = "Delete an Application category",
|
||||||
description = "Delete an application",
|
description = "Delete an application category",
|
||||||
key = "perm:application-category:delete",
|
key = "perm:application-category:delete",
|
||||||
permissions = {"/device-mgt/application/category/delete"}
|
permissions = {"/device-mgt/application/category/delete"}
|
||||||
)
|
)
|
||||||
@ -823,13 +823,14 @@ public interface ApplicationManagementAPI {
|
|||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 200,
|
code = 200,
|
||||||
message = "OK. \n Successfully retrieved existing categories.",
|
message = "OK. \n Successfully retrieved existing categories.",
|
||||||
response = Application.class),
|
response = List.class),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 400,
|
code = 400,
|
||||||
message = "Bad request. Required parameters are not provided"),
|
message = "Bad request. Required parameters are not provided"),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 500,
|
code = 500,
|
||||||
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
message = "Internal Server Error. \n Error occurred while getting the application "
|
||||||
|
+ "categories.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
Response getCategories();
|
Response getCategories();
|
||||||
@ -855,14 +856,14 @@ public interface ApplicationManagementAPI {
|
|||||||
value = {
|
value = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 200,
|
code = 200,
|
||||||
message = "OK. \n Successfully retrieved existing categories.",
|
message = "OK. \n Successfully deleted the application with the given name.",
|
||||||
response = Application.class),
|
response = Application.class),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 400,
|
code = 400,
|
||||||
message = "Bad request. Required parameters are not provided"),
|
message = "Bad request. Required parameters are not provided"),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 500,
|
code = 500,
|
||||||
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
message = "Internal Server Error. \n Error occurred while deleting applcation category.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
Response deleteCategory(
|
Response deleteCategory(
|
||||||
|
|||||||
@ -537,7 +537,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (ID FROM "
|
String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM "
|
||||||
+ "APPM_APPLICATION_CATEGORY WHERE NAME = ?)";
|
+ "APPM_APPLICATION_CATEGORY WHERE NAME = ?)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -22,7 +22,16 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.CarbonConstants;
|
import org.wso2.carbon.CarbonConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.application.mgt.common.*;
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Category;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Filter;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.User;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Visibility;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
||||||
@ -62,22 +71,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
application.setUuid(HelperUtil.generateApplicationUuid());
|
application.setUuid(HelperUtil.generateApplicationUuid());
|
||||||
application.setCreatedAt(new Date());
|
application.setCreatedAt(new Date());
|
||||||
application.setModifiedAt(new Date());
|
application.setModifiedAt(new Date());
|
||||||
|
Platform platform = DataHolder.getInstance().getPlatformManager()
|
||||||
|
.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
|
||||||
|
|
||||||
|
if (platform == null) {
|
||||||
|
throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
Category category = DataHolder.getInstance().getCategoryManager()
|
||||||
|
.getCategory(application.getCategory().getName());
|
||||||
|
if (category == null) {
|
||||||
|
throw new NotFoundException("Invalid Category is provided for the application " + application.getUuid());
|
||||||
|
}
|
||||||
|
application.setCategory(category);
|
||||||
try {
|
try {
|
||||||
Platform platform = DataHolder.getInstance().getPlatformManager().getPlatform(application.getUser()
|
|
||||||
.getTenantId(), application.getPlatform().getIdentifier());
|
|
||||||
|
|
||||||
if (platform == null) {
|
|
||||||
throw new NotFoundException(
|
|
||||||
"Invalid platform is provided for the application " + application.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
Category category = DataHolder.getInstance().getCategoryManager()
|
|
||||||
.getCategory(application.getCategory().getName());
|
|
||||||
if (category == null) {
|
|
||||||
throw new NotFoundException(
|
|
||||||
"Invalid Category is provided for the application " + application.getUuid());
|
|
||||||
}
|
|
||||||
application.setCategory(category);
|
|
||||||
ConnectionManagerUtil.beginDBTransaction();
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
|
||||||
// Validating the platform
|
// Validating the platform
|
||||||
@ -119,48 +126,49 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isApplicationOwnerOrAdmin(application.getUuid(), userName, tenantId)) {
|
if (!isApplicationOwnerOrAdmin(application.getUuid(), userName, tenantId)) {
|
||||||
throw new ApplicationManagementException("User " + userName + " does not have permissions to edit the "
|
throw new ApplicationManagementException(
|
||||||
+ "application with the UUID " + application.getUuid());
|
"User " + userName + " does not have permissions to edit the " + "application with the UUID "
|
||||||
|
+ application.getUuid());
|
||||||
}
|
}
|
||||||
if (this.getApplication(application.getUuid()) != null) {
|
if (this.getApplication(application.getUuid()) != null) {
|
||||||
try {
|
if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {
|
||||||
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
|
throw new NotFoundException("Platform information not available with the application!");
|
||||||
Platform platform = DataHolder.getInstance().getPlatformManager()
|
}
|
||||||
.getPlatform(tenantId, application.getPlatform().getIdentifier());
|
Platform platform = DataHolder.getInstance().getPlatformManager()
|
||||||
if (platform == null) {
|
.getPlatform(tenantId, application.getPlatform().getIdentifier());
|
||||||
throw new NotFoundException(
|
if (platform == null) {
|
||||||
"Platform specified by identifier " + application.getPlatform().getIdentifier()
|
throw new NotFoundException(
|
||||||
+ " is not found. Please give a valid platform identifier.");
|
"Platform specified by identifier " + application.getPlatform().getIdentifier()
|
||||||
}
|
+ " is not found. Please give a valid platform identifier.");
|
||||||
|
}
|
||||||
|
application.setPlatform(platform);
|
||||||
|
|
||||||
if (application.getCategory() != null) {
|
if (application.getCategory() != null) {
|
||||||
String applicationCategoryName = application.getCategory().getName();
|
String applicationCategoryName = application.getCategory().getName();
|
||||||
if (applicationCategoryName == null || applicationCategoryName.isEmpty()) {
|
if (applicationCategoryName == null || applicationCategoryName.isEmpty()) {
|
||||||
throw new ApplicationManagementException("Application category name cannot be null or "
|
throw new ApplicationManagementException(
|
||||||
+ "empty. Cannot edit the application.");
|
"Application category name cannot be null or " + "empty. Cannot edit the application.");
|
||||||
}
|
|
||||||
Category category = DataHolder.getInstance().getCategoryManager()
|
|
||||||
.getCategory(application.getCategory().getName());
|
|
||||||
if (category == null) {
|
|
||||||
throw new NotFoundException(
|
|
||||||
"Invalid Category is provided for the application " + application.getUuid() + ". "
|
|
||||||
+ "Cannot edit application");
|
|
||||||
}
|
|
||||||
application.setCategory(category);
|
|
||||||
}
|
|
||||||
application.setPlatform(platform);
|
|
||||||
ConnectionManagerUtil.beginDBTransaction();
|
|
||||||
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
|
||||||
application.setModifiedAt(new Date());
|
|
||||||
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
|
|
||||||
Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(),
|
|
||||||
application.getVisibility());
|
|
||||||
modifiedApplication.setVisibility(visibility);
|
|
||||||
ConnectionManagerUtil.commitDBTransaction();
|
|
||||||
return modifiedApplication;
|
|
||||||
} else {
|
|
||||||
throw new NotFoundException("Platform information not available with the application!");
|
|
||||||
}
|
}
|
||||||
|
Category category = DataHolder.getInstance().getCategoryManager()
|
||||||
|
.getCategory(application.getCategory().getName());
|
||||||
|
if (category == null) {
|
||||||
|
throw new NotFoundException(
|
||||||
|
"Invalid Category is provided for the application " + application.getUuid() + ". "
|
||||||
|
+ "Cannot edit application");
|
||||||
|
}
|
||||||
|
application.setCategory(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
||||||
|
application.setModifiedAt(new Date());
|
||||||
|
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
|
||||||
|
Visibility visibility = DataHolder.getInstance().getVisibilityManager()
|
||||||
|
.put(application.getId(), application.getVisibility());
|
||||||
|
modifiedApplication.setVisibility(visibility);
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
return modifiedApplication;
|
||||||
} catch (ApplicationManagementDAOException e) {
|
} catch (ApplicationManagementDAOException e) {
|
||||||
ConnectionManagerUtil.rollbackDBTransaction();
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user