Merge branch 'application-mgt-new' into 'application-mgt-new'

Format and improve APPM publisher service

See merge request entgra/carbon-device-mgt!157
feature/appm-store/pbac
Dharmakeerthi Lasantha 6 years ago
commit 34ec7f7815

@ -508,7 +508,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
//set default values //set default values
if (!StringUtils.isEmpty(filter.getDeviceType())) { if (!StringUtils.isEmpty(filter.getDeviceType())) {
deviceType = getDeviceTypeData(filter.getDeviceType()); deviceType = APIUtil.getDeviceTypeData(filter.getDeviceType());
} }
if (filter.getLimit() == 0) { if (filter.getLimit() == 0) {
filter.setLimit(20); filter.setLimit(20);
@ -579,6 +579,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationList.setApplications(applications); applicationList.setApplications(applications);
applicationList.setPagination(pagination); applicationList.setPagination(pagination);
return applicationList; return applicationList;
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection to get applications by filtering from "
+ "requested filter.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
"User-store exception while checking whether the user " + userName + " of tenant " + tenantId "User-store exception while checking whether the user " + userName + " of tenant " + tenantId
@ -766,7 +771,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
if (!isValidOsVersions(entAppReleaseWrapper.getSupportedOsVersions(), deviceType.getName())) { if (!isValidOsVersions(entAppReleaseWrapper.getSupportedOsVersions(), deviceType.getName())) {
String msg = "You are trying to add application release which has invalid or unsupported OS versions in " String msg = "You are trying to add application release which has invalid or unsupported OS versions in "
+ "the supportedOsVersions section. Hence, please re-evaluate the request payload."; + "the supportedOsVersions section. Hence, please re-evaluate the request payload.";
@ -823,12 +828,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
return applicationDTO; return applicationDTO;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException( String msg = "Error occurred while obtaining the database connection for getting application for the "
"Error occurred while obtaining the database connection for getting application for the application ID: " + "application ID: " + applicationId;
+ applicationId, e); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException( String msg = "Error occurred while getting application data for application ID: " + applicationId;
"Error occurred while getting application data for application ID: " + applicationId, e); log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -916,6 +923,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
return APIUtil.appDtoToAppResponse(applicationDTO); return APIUtil.appDtoToAppResponse(applicationDTO);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to get application for application ID: "
+ appId;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (LifecycleManagementException e) { } catch (LifecycleManagementException e) {
String msg = "Error occurred when getting the last state of the application lifecycle flow"; String msg = "Error occurred when getting the last state of the application lifecycle flow";
log.error(msg); log.error(msg);
@ -934,17 +946,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application getApplicationByUuid(String uuid) throws ApplicationManagementException{ public Application getApplicationByUuid(String releaseUuid) throws ApplicationManagementException{
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isVisibleApp = false; boolean isVisibleApp = false;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(uuid, tenantId); ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + uuid; String msg = "Couldn't found an application for application release UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
@ -970,8 +982,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
return APIUtil.appDtoToAppResponse(applicationDTO); return APIUtil.appDtoToAppResponse(applicationDTO);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to get application for application "
+ "release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "User-store exception occurred while getting application for application release UUID " + uuid; String msg = "User-store exception occurred while getting application for application release UUID " + releaseUuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -985,17 +1002,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { public Application getApplicationByUuid(String releaseUuid, String state) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isVisibleApp = false; boolean isVisibleApp = false;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(uuid, tenantId); ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + uuid; String msg = "Couldn't found an application for application release UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
@ -1033,12 +1050,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
return APIUtil.appDtoToAppResponse(applicationDTO); return APIUtil.appDtoToAppResponse(applicationDTO);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to get application for application "
+ "release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (LifecycleManagementException e) { } catch (LifecycleManagementException e) {
String msg = "Error occurred when getting the last state of the application lifecycle flow"; String msg = "Error occurred when getting the last state of the application lifecycle flow";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "User-store exception while getting application with the application release UUID " + uuid; String msg = "User-store exception while getting application with the application release UUID " + releaseUuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -1153,6 +1175,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.applicationDAO.deleteCategoryMapping(applicationId, tenantId); this.applicationDAO.deleteCategoryMapping(applicationId, tenantId);
this.applicationDAO.deleteApplication(applicationId, tenantId); this.applicationDAO.deleteApplication(applicationId, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to delete application which has "
+ "application ID: " + applicationId;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when deleting application which has application ID: "
+ applicationId;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred when getting application data for application id: " + applicationId; String msg = "Error occurred when getting application data for application id: " + applicationId;
@ -1198,6 +1230,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
this.applicationDAO.retireApplication(applicationId); this.applicationDAO.retireApplication(applicationId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to retire an application which has "
+ "application ID:" + applicationId;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when retiring application which has application ID: "
+ applicationId;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting application data for application id: " + applicationId; String msg = "Error occurred when getting application data for application id: " + applicationId;
log.error(msg); log.error(msg);
@ -1242,6 +1284,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId()); lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId()); applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to delete application release which "
+ "has UUID:" + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when deleting application release which has UUID: "
+ releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} 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;
@ -1294,8 +1346,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = String msg =
"Error occured when getting DB connection to update image artifacts of the application release of haveing uuid " "Error occured when getting DB connection to update image artifacts of the application release "
+ uuid + "."; + "which has uuid " + uuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating application release image artifacts which has "
+ "UUID: " + uuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
}catch (ApplicationManagementDAOException e) { }catch (ApplicationManagementDAOException e) {
@ -1316,7 +1373,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void updateApplicationArtifact(String deviceType, String uuid, public void updateApplicationArtifact(String deviceType, String releaseUuid,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean isValidDeviceType = false; boolean isValidDeviceType = false;
@ -1332,7 +1389,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
if (!isValidDeviceType) { if (!isValidDeviceType) {
String msg = "Invalid request to update application release artifact, invalid application type: " String msg = "Invalid request to update application release artifact, invalid application type: "
+ deviceType + " for application release uuid: " + uuid; + deviceType + " for application release uuid: " + releaseUuid;
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
@ -1344,15 +1401,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application which has application release for UUID: " + uuid; String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) { if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) {
String msg = "If Application type is " + applicationDTO.getType() + ", then you don't have application " String msg = "If Application type is " + applicationDTO.getType() + ", then you don't have application "
+ "release artifact to update for application release UUID: " + uuid; + "release artifact to update for application release UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
@ -1373,7 +1430,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (applicationReleaseDTO == null) { if (applicationReleaseDTO == null) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( throw new ApplicationManagementException(
"ApplicationDTO release updating count is 0. ApplicationDTO release UUID: " + uuid); "ApplicationDTO release updating count is 0. ApplicationDTO release UUID: " + releaseUuid);
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -1383,15 +1440,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
String msg = String msg = "Error occured while starting the transaction to update application release artifact which has "
"Error occured while starting the transaction to update application release artifact of the application uuid " + "application uuid " + releaseUuid + ".";
+ uuid + ".";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = String msg = "Error occured when getting DB connection to update application release artifact of the "
"Error occured when getting DB connection to update application release artifact of the application release uuid " + "application release uuid " + releaseUuid + ".";
+ uuid + ".";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationStorageManagementException e) { } catch (ApplicationStorageManagementException e) {
@ -1421,6 +1476,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
return this.lifecycleStateDAO.getLifecycleStates(applicationReleaseDTO.getId(), tenantId); return this.lifecycleStateDAO.getLifecycleStates(applicationReleaseDTO.getId(), tenantId);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to get lifecycle state change flow for "
+ "application release which has UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
String msg = "Failed to get lifecycle state for application release uuid " + releaseUuid; String msg = "Failed to get lifecycle state for application release uuid " + releaseUuid;
log.error(msg); log.error(msg);
@ -1489,6 +1549,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to change lifecycle state of the "
+ "application release which has UUID:" + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when changing lifecycle state of application release which "
+ "has UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
}catch (LifeCycleManagementDAOException e) { }catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Failed to add lifecycle state for Application release UUID: " + releaseUuid; String msg = "Failed to add lifecycle state for Application release UUID: " + releaseUuid;
@ -1518,6 +1588,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDAO.addCategories(newCategories, tenantId); applicationDAO.addCategories(newCategories, tenantId);
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to add application categories.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when adding application categories.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when getting existing categories or when inserting new application categories."; String msg = "Error occured when getting existing categories or when inserting new application categories.";
@ -1677,26 +1755,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (UserStoreException e) { } catch (UserStoreException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( String msg = "Error occurred while checking whether logged in user is ADMIN or not when updating "
"Error occurred while checking whether logged in user is ADMIN or not when updating application of application id: " + "application of application id: " + applicationId;
+ applicationId); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( String msg = "Error occurred while updating the application, application id: " + applicationId;
"Error occurred while updating the application, application id: " + applicationId); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (VisibilityManagementDAOException e) { } catch (VisibilityManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( String msg = "Error occurred while updating the visibility restriction of the application. Application id: "
"Error occurred while updating the visibility restriction of the application. ApplicationDTO id is " + applicationId;
+ applicationId); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new ApplicationManagementException( String msg = "Error occurred while starting database transaction for application updating. Application id: "
"Error occurred while starting database transaction for application updating. ApplicationDTO id is " + applicationId;
+ applicationId); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException( String msg = "Error occurred while getting database connection for application updating. Application id: "
"Error occurred while getting database connection for application updating. ApplicationDTO id is " + applicationId;
+ applicationId); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1719,10 +1801,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
responseTagList.add(responseTag); responseTagList.add(responseTag);
}); });
return responseTagList; return responseTagList;
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to get registered tags";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting registered tags from the system."; String msg = "Error occurred when getting registered tags from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1745,10 +1831,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
responseCategoryList.add(responseCategory); responseCategoryList.add(responseCategory);
}); });
return responseCategoryList; return responseCategoryList;
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to get registered categories.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting registered tags from the system."; String msg = "Error occurred when getting registered tags from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1774,10 +1864,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to delete application tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when deleting application tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Id or deleting tag mapping from the system."; String msg = "Error occurred when getting tag Id or deleting tag mapping from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1799,10 +1897,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationDAO.deleteTag(tag.getId(), tenantId); applicationDAO.deleteTag(tag.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to delete registered tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when deleting registered tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Id or deleting the tag from the system."; String msg = "Error occurred when getting tag Id or deleting the tag from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1828,10 +1934,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationDAO.deleteTag(tag.getId(), tenantId); applicationDAO.deleteTag(tag.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to delete unused tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when deleting unused tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Ids or deleting the tag from the system."; String msg = "Error occurred when getting tag Ids or deleting the tag from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1865,10 +1979,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
tag.setTagName(newTagName); tag.setTagName(newTagName);
applicationDAO.updateTag(tag, tenantId); applicationDAO.updateTag(tag, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update application tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating application tag.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Ids or deleting the tag from the system."; String msg = "Error occurred when getting tag Ids or deleting the tag from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -1899,6 +2021,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to add tags.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when adding tags.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred either getting registered tags or adding new tags."; String msg = "Error occurred either getting registered tags or adding new tags.";
@ -1943,6 +2073,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to add application tags.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when adding application tags.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while accessing application tags. Application ID: " + appId; String msg = "Error occurred while accessing application tags. Application ID: " + appId;
@ -1978,6 +2116,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to add categories.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when adding categories.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred either getting registered categories or adding new categories."; String msg = "Error occurred either getting registered categories or adding new categories.";
@ -1989,28 +2135,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void deleteCategory(String tagName) throws ApplicationManagementException { public void deleteCategory(String categoryName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
CategoryDTO category = applicationDAO.getCategoryForCategoryName(tagName, tenantId); CategoryDTO category = applicationDAO.getCategoryForCategoryName(categoryName, tenantId);
if (category == null){ if (category == null){
String msg = "Couldn't found a category for category name " + tagName + "."; String msg = "Couldn't found a category for category name " + categoryName + ".";
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (applicationDAO.hasCategoryMapping(category.getId(), tenantId)){ if (applicationDAO.hasCategoryMapping(category.getId(), tenantId)){
String msg = "Category " + category.getCategoryName() String msg = "Category " + category.getCategoryName() + " is used by some applications. Therefore it "
+ " is used by some applications. Therefore it is not permitted to delete the application category."; + "is not permitted to delete the application category.";
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
applicationDAO.deleteCategory(category.getId(), tenantId); applicationDAO.deleteCategory(category.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to delete category.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when deleting category.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting category Id or deleting the category from the system."; String msg = "Error occurred when getting category Id or deleting the category from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -2030,10 +2184,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
category.setCategoryName(newCategoryName); category.setCategoryName(newCategoryName);
applicationDAO.updateCategory(category, tenantId); applicationDAO.updateCategory(category, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update category.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating categiry.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting tag Ids or deleting the category from the system."; String msg = "Error occurred when getting tag Ids or deleting the category from the system.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -2154,7 +2316,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){ if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){
DeviceType deviceTypeObj = getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
applicationReleaseDTO applicationReleaseDTO
.set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(), .set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(),
applicationArtifact)); applicationArtifact));
@ -2167,6 +2329,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return updateStatus; return updateStatus;
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update enterprise app release which "
+ "has release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating enterprise app release which has release UUID: "
+ releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid; String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid;
@ -2225,6 +2397,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return updateStatus; return updateStatus;
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update public app release which "
+ "has release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating public app release which has release UUID:."
+ releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating public app release of UUID: " + releaseUuid; String msg = "Error occured when updating public app release of UUID: " + releaseUuid;
@ -2279,6 +2461,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return updateStatus; return updateStatus;
} catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update web app release which "
+ "has release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating web app release which has release UUID:."
+ releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating web app release for web app Release UUID: " + releaseUuid; String msg = "Error occured when updating web app release for web app Release UUID: " + releaseUuid;
@ -2326,7 +2518,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "price is " + price + " for " + applicationSubType + " application."); + "price is " + price + " for " + applicationSubType + " application.");
} }
DeviceType deviceTypeObj = getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
String supportedOSVersions = applicationReleaseDTO.getSupportedOsVersions(); String supportedOSVersions = applicationReleaseDTO.getSupportedOsVersions();
if (!ApplicationType.WEB_CLIP.toString().equals(appType) && !ApplicationType.WEB_APP.toString().equals(appType) if (!ApplicationType.WEB_CLIP.toString().equals(appType) && !ApplicationType.WEB_APP.toString().equals(appType)
&& !StringUtils.isEmpty(supportedOSVersions) && !isValidOsVersions( && !StringUtils.isEmpty(supportedOSVersions) && !isValidOsVersions(
@ -2372,7 +2564,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType()); DeviceType deviceType = APIUtil.getDeviceTypeData(applicationWrapper.getDeviceType());
deviceTypeId = deviceType.getId(); deviceTypeId = deviceType.getId();
List<EntAppReleaseWrapper> entAppReleaseWrappers; List<EntAppReleaseWrapper> entAppReleaseWrappers;
@ -2447,7 +2639,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType()); DeviceType deviceType = APIUtil.getDeviceTypeData(publicAppWrapper.getDeviceType());
deviceTypeId = deviceType.getId(); deviceTypeId = deviceType.getId();
List<PublicAppReleaseWrapper> publicAppReleaseWrappers; List<PublicAppReleaseWrapper> publicAppReleaseWrappers;
@ -2623,58 +2815,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private <T> DeviceType getDeviceTypeData( T deviceTypeAttr) @Override
throws BadRequestException, UnexpectedServerErrorException {
List<DeviceType> deviceTypes;
try {
deviceTypes = DAOUtil.getDeviceManagementService().getDeviceTypes();
if(deviceTypeAttr instanceof String){
for (DeviceType dt : deviceTypes) {
if (dt.getName().equals(deviceTypeAttr)) {
return dt;
}
}
} else if (deviceTypeAttr instanceof Integer){
for (DeviceType dt : deviceTypes) {
if (dt.getId() == (Integer) deviceTypeAttr) {
return dt;
}
}
} else {
String msg = "Invalid device type class is received. Device type class: " + deviceTypeAttr.getClass()
.getName();
log.error(msg);
throw new BadRequestException(msg);
}
String msg =
"Invalid device type Attribute is found with the request. Device Type attribute: " + deviceTypeAttr;
log.error(msg);
throw new BadRequestException(msg);
} catch (DeviceManagementException e) {
String msg = "Error occured when getting device types which are supported by the Entgra IoTS";
log.error(msg);
throw new UnexpectedServerErrorException(msg);
}
}
public void updateSubsStatus (int operationId, String status) throws ApplicationManagementException { public void updateSubsStatus (int operationId, String status) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
ConnectionManagerUtil.beginDBTransaction();
if (!subscriptionDAO.updateDeviceSubStatus(operationId, status, tenantId)){ if (!subscriptionDAO.updateDeviceSubStatus(operationId, status, tenantId)){
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Didn't update an any app subscription of device for operation Id: " + operationId; String msg = "Didn't update an any app subscription of device for operation Id: " + operationId;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occured while updating app subscription status of the device."; String msg = "Error occured while updating app subscription status of the device.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while obersving the database connection to update aoo subscription status of "
+ "device.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while executing database transaction";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
} }
} }
@Override
public String getPlistArtifact(String releaseUuid) throws ApplicationManagementException { public String getPlistArtifact(String releaseUuid) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
@ -2711,12 +2882,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
.replace("$appName", applicationDTO.getName()); .replace("$appName", applicationDTO.getName());
return StringEscapeUtils.unescapeXml(plistContent); return StringEscapeUtils.unescapeXml(plistContent);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException( String msg = "Error occurred while obtaining the database connection for getting application for the release UUID: "
"Error occurred while obtaining the database connection for getting application for the release UUID: " + releaseUuid;
+ releaseUuid, e); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException( String msg = "Error occurred while getting application data for release UUID: " + releaseUuid;
"Error occurred while getting application data for release UUID: " + releaseUuid, e); log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }

Loading…
Cancel
Save