@ -67,7 +67,6 @@ import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException ;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException ;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException ;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException ;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException ;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException ;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException ;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException ;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException ;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder ;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder ;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager ;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager ;
@ -145,9 +144,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDTO = appWrapperToAppDTO ( applicationWrapper ) ;
applicationDTO = appWrapperToAppDTO ( applicationWrapper ) ;
ApplicationReleaseDTO initialApplicationReleaseDTO = applicationDTO . getApplicationReleaseDTOs ( ) . get ( 0 ) ;
ApplicationReleaseDTO initialApplicationReleaseDTO = applicationDTO . getApplicationReleaseDTOs ( ) . get ( 0 ) ;
applicationDTO . getApplicationReleaseDTOs ( ) . clear ( ) ;
applicationDTO . getApplicationReleaseDTOs ( ) . clear ( ) ;
applicationDTO . getApplicationReleaseDTOs ( )
. add ( addApplicationReleaseArtifacts ( applicationDTO . getType ( ) , applicationDTO . getDeviceTypeName ( ) ,
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts ( applicationDTO . getType ( ) , applicationDTO . getDeviceTypeName ( ) ,
initialApplicationReleaseDTO , applicationArtifact ) ) ;
initialApplicationReleaseDTO , applicationArtifact ) ;
applicationDTO . getApplicationReleaseDTOs ( ) . add ( addImageArtifacts ( applicationReleaseDTO , applicationArtifact ) ) ;
} catch ( UnexpectedServerErrorException e ) {
} catch ( UnexpectedServerErrorException e ) {
String msg = "Error occurred when getting Device Type data." ;
String msg = "Error occurred when getting Device Type data." ;
log . error ( msg ) ;
log . error ( msg ) ;
@ -161,8 +161,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
try {
List < ApplicationReleaseDTO > applicationReleaseEntities = new ArrayList < > ( ) ;
List < ApplicationReleaseDTO > applicationReleaseEntities = new ArrayList < > ( ) ;
ApplicationReleaseDTO applicationReleaseDTO ;
ApplicationReleaseDTO applicationReleaseDTO ;
Filter filter = new Filter ( ) ;
Filter filter = new Filter ( ) ;
filter . setFullMatch ( true ) ;
filter . setFullMatch ( true ) ;
filter . setAppName ( applicationDTO . getName ( ) . trim ( ) ) ;
filter . setAppName ( applicationDTO . getName ( ) . trim ( ) ) ;
filter . setOffset ( 0 ) ;
filter . setOffset ( 0 ) ;
@ -193,10 +193,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
List < String > unrestrictedRoles = applicationWrapper . getUnrestrictedRoles ( ) ;
List < String > unrestrictedRoles = applicationWrapper . getUnrestrictedRoles ( ) ;
if ( ! unrestrictedRoles . isEmpty ( ) ) {
if ( ! unrestrictedRoles . isEmpty ( ) ) {
if ( ! isValidRestrictedRole ( unrestrictedRoles ) ) {
if ( ! isValidRestrictedRole ( unrestrictedRoles ) ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "Unrestricted role list contain role/roles which are not in the user store." ;
String msg = "Unrestricted role list contain role/roles which are not in the user store." ;
log . error ( msg ) ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
}
}
if ( ! hasUserRole ( unrestrictedRoles , userName ) ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg =
"You are trying to restrict the visibility of the application for a role set, but in order to perform the action at least one role should be assigned to user: "
+ userName ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
this . visibilityDAO . addUnrestrictedRoles ( unrestrictedRoles , appId , tenantId ) ;
this . visibilityDAO . addUnrestrictedRoles ( unrestrictedRoles , appId , tenantId ) ;
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
log . debug ( "New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table."
log . debug ( "New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table."
@ -251,7 +261,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
tagIds = this . applicationDAO . getTagIdsForTagNames ( tags , tenantId ) ;
tagIds = this . applicationDAO . getTagIdsForTagNames ( tags , tenantId ) ;
} else {
} else {
for ( TagDTO tagDTO : registeredTags ) {
for ( TagDTO tagDTO : registeredTags ) {
for ( String tagName : tags ) {
for ( String tagName : tags ) {
if ( tagName . equals ( tagDTO . getTagName ( ) ) ) {
if ( tagName . equals ( tagDTO . getTagName ( ) ) ) {
@ -403,6 +412,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
// Since WEB CLIP doesn't have an installer, set uuid as has value for WEB CLIP
// Since WEB CLIP doesn't have an installer, set uuid as has value for WEB CLIP
applicationReleaseDTO . setAppHashValue ( uuid ) ;
applicationReleaseDTO . setAppHashValue ( uuid ) ;
}
}
return applicationReleaseDTO ;
}
private ApplicationReleaseDTO addImageArtifacts ( ApplicationReleaseDTO applicationReleaseDTO ,
ApplicationArtifact applicationArtifact ) throws ResourceManagementException {
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
applicationReleaseDTO . setIconName ( applicationArtifact . getIconName ( ) ) ;
applicationReleaseDTO . setIconName ( applicationArtifact . getIconName ( ) ) ;
applicationReleaseDTO . setBannerName ( applicationArtifact . getBannerName ( ) ) ;
applicationReleaseDTO . setBannerName ( applicationArtifact . getBannerName ( ) ) ;
@ -441,8 +456,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
DeviceType deviceType = null ;
DeviceType deviceType = null ;
try {
try {
validateFilter ( filter ) ;
//set default values
//set default values
if ( StringUtils . isEmpty ( filter . getSortBy ( ) ) ) {
if ( StringUtils . isEmpty ( filter . getSortBy ( ) ) ) {
filter . setSortBy ( "ASC" ) ;
filter . setSortBy ( "ASC" ) ;
@ -456,6 +469,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
ConnectionManagerUtil . openDBConnection ( ) ;
ConnectionManagerUtil . openDBConnection ( ) ;
validateFilter ( filter ) ;
if ( deviceType = = null ) {
if ( deviceType = = null ) {
appDTOs = applicationDAO . getApplications ( filter , 0 , tenantId ) ;
appDTOs = applicationDAO . getApplications ( filter , 0 , tenantId ) ;
} else {
} else {
@ -464,57 +479,39 @@ public class ApplicationManagerImpl implements ApplicationManager {
for ( ApplicationDTO app : appDTOs ) {
for ( ApplicationDTO app : appDTOs ) {
boolean isSearchingApp = true ;
boolean isSearchingApp = true ;
List < String > tags = filter . getTags ( ) ;
List < String > filteringTags = filter . getTags ( ) ;
List < String > categories = filter . getAppCategories ( ) ;
List < String > filteringCategories = filter . getAppCategories ( ) ;
List < String > unrestrictedRoles = filter . getUnrestrictedRoles ( ) ;
List < String > filteringUnrestrictedRoles = filter . getUnrestrictedRoles ( ) ;
if ( lifecycleStateManager . getEndState ( ) . equals ( app . getStatus ( ) ) ) {
isSearchingApp = false ;
}
if ( unrestrictedRoles ! = null & & ! unrestrictedRoles . isEmpty ( ) ) {
if ( ! isRoleExists ( unrestrictedRoles , userName ) ) {
if ( ! lifecycleStateManager . getEndState ( ) . equals ( app . getStatus ( ) ) ) {
String msg = "At least one filtering role is not assigned for the user: " + userName
+ ". Hence user " + userName
+ " Can't filter applications by giving these unrestriced role list" ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
List < String > appUnrestrictedRoles = visibilityDAO . getUnrestrictedRoles ( app . getId ( ) , tenantId ) ;
List < String > appUnrestrictedRoles = visibilityDAO . getUnrestrictedRoles ( app . getId ( ) , tenantId ) ;
boolean isUnrestrictedRoleExistForApp = false ;
if ( ( appUnrestrictedRoles . isEmpty ( ) | | hasUserRole ( appUnrestrictedRoles , userName ) ) & & (
for ( String role : unrestrictedRoles ) {
filteringUnrestrictedRoles = = null | | filteringUnrestrictedRoles . isEmpty ( )
if ( appUnrestrictedRoles . contains ( role ) ) {
| | hasAppUnrestrictedRole ( appUnrestrictedRoles , filteringUnrestrictedRoles ,
isUnrestrictedRoleExistForApp = true ;
userName ) ) ) {
if ( filteringCategories ! = null & & ! filteringCategories . isEmpty ( ) ) {
List < String > appTagList = applicationDAO . getAppCategories ( app . getId ( ) , tenantId ) ;
boolean isAppCategory = false ;
for ( String category : filteringCategories ) {
if ( appTagList . contains ( category ) ) {
isAppCategory = true ;
break ;
break ;
}
}
}
}
if ( ! isUnrestrictedRoleExistForApp ) {
if ( ! isAppCategory ) {
isSearchingApp = false ;
isSearchingApp = false ;
}
}
}
}
if ( tags ! = null & & ! tags. isEmpty ( ) ) {
if ( fil teringT ags ! = null & & ! fil teringT ags. isEmpty ( ) ) {
List < String > appTagList = applicationDAO . getAppTags ( app . getId ( ) , tenantId ) ;
List < String > appTagList = applicationDAO . getAppTags ( app . getId ( ) , tenantId ) ;
boolean is TagExistFor App = false ;
boolean is AppTag = false ;
for ( String tag : tags) {
for ( String tag : fil teringT ags) {
if ( appTagList . contains ( tag ) ) {
if ( appTagList . contains ( tag ) ) {
isTagExistForApp = true ;
isAppTag = true ;
break ;
}
}
if ( ! isTagExistForApp ) {
isSearchingApp = false ;
}
}
if ( categories ! = null & & ! categories . isEmpty ( ) ) {
List < String > appTagList = applicationDAO . getAppCategories ( app . getId ( ) , tenantId ) ;
boolean isCategoryExistForApp = false ;
for ( String category : categories ) {
if ( appTagList . contains ( category ) ) {
isCategoryExistForApp = true ;
break ;
break ;
}
}
}
}
if ( ! is CategoryExistFor App) {
if ( ! isAppTag ) {
isSearchingApp = false ;
isSearchingApp = false ;
}
}
}
}
@ -522,6 +519,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
filteredApplications . add ( app ) ;
filteredApplications . add ( app ) ;
}
}
}
}
}
}
for ( ApplicationDTO appDTO : filteredApplications ) {
for ( ApplicationDTO appDTO : filteredApplications ) {
applications . add ( appDtoToAppResponse ( appDTO ) ) ;
applications . add ( appDtoToAppResponse ( appDTO ) ) ;
@ -546,6 +545,25 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
}
}
private boolean hasAppUnrestrictedRole ( List < String > appUnrestrictedRoles , List < String > filteringUnrestrictedRoles ,
String userName ) throws BadRequestException , UserStoreException {
if ( ! haveAllUserRoles ( filteringUnrestrictedRoles , userName ) ) {
String msg =
"At least one filtering role is not assigned for the user: " + userName + ". Hence user " + userName
+ " Can't filter applications by giving these unrestriced role list" ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
if ( ! appUnrestrictedRoles . isEmpty ( ) ) {
for ( String role : filteringUnrestrictedRoles ) {
if ( appUnrestrictedRoles . contains ( role ) ) {
return true ;
}
}
}
return false ;
}
@Override
@Override
public ApplicationRelease createRelease ( int applicationId ,
public ApplicationRelease createRelease ( int applicationId ,
ApplicationReleaseWrapper applicationReleaseWrapper , ApplicationArtifact applicationArtifact )
ApplicationReleaseWrapper applicationReleaseWrapper , ApplicationArtifact applicationArtifact )
@ -567,6 +585,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts ( applicationDTO . getType ( ) ,
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts ( applicationDTO . getType ( ) ,
applicationDTO . getDeviceTypeName ( ) , releaseWrapperToReleaseDTO ( applicationReleaseWrapper ) ,
applicationDTO . getDeviceTypeName ( ) , releaseWrapperToReleaseDTO ( applicationReleaseWrapper ) ,
applicationArtifact ) ;
applicationArtifact ) ;
applicationReleaseDTO = addImageArtifacts ( applicationReleaseDTO , applicationArtifact ) ;
String initialstate = lifecycleStateManager . getInitialState ( ) ;
String initialstate = lifecycleStateManager . getInitialState ( ) ;
applicationReleaseDTO . setCurrentState ( initialstate ) ;
applicationReleaseDTO . setCurrentState ( initialstate ) ;
@ -607,45 +626,54 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override
@Override
public Application DTO getApplicationById ( int appId , String state ) throws ApplicationManagementException {
public Application getApplicationById ( int appId , String state ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
ApplicationDTO application ;
ApplicationDTO applicationDTO ;
boolean isAppAllowed = false ;
List < ApplicationReleaseDTO > filteredApplicationReleaseDTOs ;
boolean isVisibleApp = false ;
try {
try {
ConnectionManagerUtil . openDBConnection ( ) ;
ConnectionManagerUtil . openDBConnection ( ) ;
application = this . applicationDAO . getApplicationById ( appId , tenantId ) ;
application DTO = this . applicationDAO . getApplicationById ( appId , tenantId ) ;
if ( application = = null ) {
if ( application DTO = = null ) {
throw new NotFoundException ( "Couldn't find an application for application Id: " + appId ) ;
throw new NotFoundException ( "Couldn't find an application for application Id: " + appId ) ;
}
}
filteredApplicationReleaseDTOs = applicationDTO . getApplicationReleaseDTOs ( ) . stream ( )
. filter ( applicationReleaseDTO - > applicationReleaseDTO . getCurrentState ( ) . equals ( state ) )
. collect ( Collectors . toList ( ) ) ;
applicationDTO . setApplicationReleaseDTOs ( filteredApplicationReleaseDTOs ) ;
if ( applicationDTO . getApplicationReleaseDTOs ( ) . isEmpty ( ) ) {
return null ;
}
List < String > tags = this . applicationDAO . getAppTags ( appId , tenantId ) ;
List < String > tags = this . applicationDAO . getAppTags ( appId , tenantId ) ;
List < String > categories = this . applicationDAO . getAppCategories ( appId , tenantId ) ;
List < String > categories = this . applicationDAO . getAppCategories ( appId , tenantId ) ;
application . setTags ( tags ) ;
application DTO . setTags ( tags ) ;
//todo when support to add multiple categories this has to be changed
//todo when support to add multiple categories this has to be changed
if ( ! categories . isEmpty ( ) ) {
if ( ! categories . isEmpty ( ) ) {
application . setAppCategory ( categories . get ( 0 ) ) ;
application DTO . setAppCategory ( categories . get ( 0 ) ) ;
}
}
if ( isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) ) {
if ( isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) ) {
return app lication;
return app DtoToAppResponse( app licationDTO) ;
}
}
List < String > unrestrictedRoles = this . visibilityDAO . getUnrestrictedRoles ( appId , tenantId ) ;
List < String > unrestrictedRoles = this . visibilityDAO . getUnrestrictedRoles ( appId , tenantId ) ;
if ( ! unrestrictedRoles . isEmpty ( ) ) {
if ( ! unrestrictedRoles . isEmpty ( ) ) {
if ( isRoleExists ( unrestrictedRoles , userName ) ) {
if ( hasUserRole ( unrestrictedRoles , userName ) ) {
is AppAllowed = true ;
is Visible App = true ;
}
}
} else {
} else {
is AppAllowed = true ;
is Visible App = true ;
}
}
if ( ! is AppAllowed ) {
if ( ! is Visible App) {
String msg = "You are trying to access visibility restricted application. You don't have required "
String msg = "You are trying to access visibility restricted application. You don't have required "
+ "roles to view this application," ;
+ "roles to view this application," ;
log . error ( msg ) ;
log . error ( msg ) ;
throw new ForbiddenException ( msg ) ;
throw new ForbiddenException ( msg ) ;
}
}
return app lication;
return app DtoToAppResponse( app licationDTO) ;
} catch ( UserStoreException e ) {
} catch ( UserStoreException e ) {
throw new ApplicationManagementException (
throw new ApplicationManagementException (
"User-store exception while getting application with the application id " + appId ) ;
"User-store exception while getting application with the application id " + appId ) ;
@ -674,7 +702,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( isRoleExists ( application . getUnrestrictedRoles ( ) , userName ) ) {
if ( hasUserRole ( application . getUnrestrictedRoles ( ) , userName ) ) {
isAppAllowed = true ;
isAppAllowed = true ;
}
}
} else {
} else {
@ -695,7 +723,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
}
}
private boolean isRoleExists ( Collection < String > unrestrictedRoleList , String userName ) throws UserStoreException {
private boolean hasUserRole ( Collection < String > unrestrictedRoleList , String userName ) throws UserStoreException {
String [ ] roleList ;
String [ ] roleList ;
roleList = getRolesOfUser ( userName ) ;
roleList = getRolesOfUser ( userName ) ;
for ( String unrestrictedRole : unrestrictedRoleList ) {
for ( String unrestrictedRole : unrestrictedRoleList ) {
@ -708,6 +736,20 @@ public class ApplicationManagerImpl implements ApplicationManager {
return false ;
return false ;
}
}
private boolean haveAllUserRoles ( Collection < String > unrestrictedRoleList , String userName )
throws UserStoreException {
String [ ] roleList ;
roleList = getRolesOfUser ( userName ) ;
for ( String unrestrictedRole : unrestrictedRoleList ) {
for ( String role : roleList ) {
if ( ! unrestrictedRole . equals ( role ) ) {
return false ;
}
}
}
return true ;
}
private boolean isValidRestrictedRole ( Collection < String > unrestrictedRoleList ) throws UserStoreException {
private boolean isValidRestrictedRole ( Collection < String > unrestrictedRoleList ) throws UserStoreException {
List < String > roleList = new ArrayList < > ( Arrays . asList ( getRoleNames ( ) ) ) ;
List < String > roleList = new ArrayList < > ( Arrays . asList ( getRoleNames ( ) ) ) ;
return roleList . containsAll ( unrestrictedRoleList ) ;
return roleList . containsAll ( unrestrictedRoleList ) ;
@ -754,7 +796,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( isRoleExists ( application . getUnrestrictedRoles ( ) , userName ) ) {
if ( hasUserRole ( application . getUnrestrictedRoles ( ) , userName ) ) {
isAppAllowed = true ;
isAppAllowed = true ;
}
}
} else {
} else {
@ -784,7 +826,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil . openDBConnection ( ) ;
ConnectionManagerUtil . openDBConnection ( ) ;
application = this . applicationDAO . getApplicationByRelease ( appReleaseUUID , tenantId ) ;
application = this . applicationDAO . getApplicationByRelease ( appReleaseUUID , tenantId ) ;
if ( application . getUnrestrictedRoles ( ) . isEmpty ( ) | | isRoleExists ( application . getUnrestrictedRoles ( ) ,
if ( application . getUnrestrictedRoles ( ) . isEmpty ( ) | | hasUserRole ( application . getUnrestrictedRoles ( ) ,
userName ) ) {
userName ) ) {
return application ;
return application ;
}
}
@ -867,7 +909,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
if ( ! isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) & & ! application
if ( ! isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) & & ! application
. getUnrestrictedRoles ( ) . isEmpty ( ) & & isRoleExists ( application . getUnrestrictedRoles ( ) , userName ) ) {
. getUnrestrictedRoles ( ) . isEmpty ( ) & & hasUserRole ( application . getUnrestrictedRoles ( ) , userName ) ) {
throw new ForbiddenException (
throw new ForbiddenException (
"You don't have permission to delete this application. In order to delete an application you "
"You don't have permission to delete this application. In order to delete an application you "
+ "need to have required permission. ApplicationDTO ID: " + applicationId ) ;
+ "need to have required permission. ApplicationDTO ID: " + applicationId ) ;
@ -988,7 +1030,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new NotFoundException ( "Couldn't find an application for application ID: " + applicationId ) ;
throw new NotFoundException ( "Couldn't find an application for application ID: " + applicationId ) ;
}
}
if ( ! isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) & & ! application
if ( ! isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) & & ! application
. getUnrestrictedRoles ( ) . isEmpty ( ) & & isRoleExists ( application . getUnrestrictedRoles ( ) , userName ) ) {
. getUnrestrictedRoles ( ) . isEmpty ( ) & & hasUserRole ( application . getUnrestrictedRoles ( ) , userName ) ) {
throw new ForbiddenException (
throw new ForbiddenException (
"You don't have permission for deleting application release. ApplicationDTO id: " + applicationId
"You don't have permission for deleting application release. ApplicationDTO id: " + applicationId
+ " and release UUID: " + releaseUuid ) ;
+ " and release UUID: " + releaseUuid ) ;
@ -1094,77 +1136,76 @@ public class ApplicationManagerImpl implements ApplicationManager {
return false ;
return false ;
}
}
//todo check whether user is whether admin user or application owner, otherwise throw an exception
@Override
@Override
public void updateApplicationImageArtifact ( int appId , String uuid , InputStream iconFileStream ,
//todo with this implementation user has to provide all image artifacts in order to update one image artifact as
InputStream bannerFileStream , List < InputStream > attachments ) throws ApplicationManagementException {
// well. Therefore enhance this later.
public void updateApplicationImageArtifact ( String uuid , ApplicationArtifact applicationArtifact )
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
ApplicationReleaseDTO applicationRelease ;
ApplicationReleaseDTO applicationRelease DTO ;
try {
try {
if ( appId < = 0 ) {
throw new ValidationException (
"ApplicationDTO id could,t be a negative integer. Hence please add valid application id." ) ;
}
ConnectionManagerUtil . beginDBTransaction ( ) ;
ConnectionManagerUtil . beginDBTransaction ( ) ;
applicationRelease = this . applicationReleaseDAO . getReleaseByIds ( appId , uuid , tenantId ) ;
applicationReleaseDTO = this . applicationReleaseDAO . getReleaseByUUID ( uuid , tenantId ) ;
if ( applicationRelease = = null ) {
if ( applicationReleaseDTO = = null ) {
throw new NotFoundException (
String msg = "Application release image artifact uploading is failed. Doesn't exist a application "
"Doesn't exist a application release for application ID: " + appId + "and application UUID: "
+ "release for application ID: application UUID: " + uuid ;
+ uuid ) ;
log . error ( msg ) ;
}
throw new NotFoundException ( msg ) ;
LifecycleStateDTO lifecycleState = this . lifecycleStateDAO
}
. getLatestLifeCycleState ( appId , applicationRelease . getUuid ( ) ) ;
if ( AppLifecycleState . PUBLISHED . toString ( ) . equals ( lifecycleState . getCurrentState ( ) )
String currentState = applicationReleaseDTO . getCurrentState ( ) ;
| | AppLifecycleState . DEPRECATED . toString ( ) . equals ( lifecycleState . getCurrentState ( ) ) ) {
if ( ! lifecycleStateManager . isUpdatableState ( currentState ) ) {
throw new ForbiddenException ( "Can't Update the application release in PUBLISHED or DEPRECATED state. "
throw new ForbiddenException (
+ "Hence please demote the application and update the application release" ) ;
"Can't Update the application release. Application release is in " + currentState
}
+ " and it is not an release updatable state. Hence please move the application release"
applicationRelease = applicationStorageManager
+ " into updatable state and retry the operation." ) ;
. updateImageArtifacts ( applicationRelease , iconFileStream , bannerFileStream , attachments ) ;
}
applicationRelease = this . applicationReleaseDAO . updateRelease ( appId , applicationRelease , tenantId ) ;
applicationStorageManager . deleteImageArtifacts ( applicationReleaseDTO ) ;
if ( applicationRelease = = null ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
"ApplicationDTO release updating count is 0. ApplicationDTO id: " + appId
+ " ApplicationDTO release UUID: " + uuid ) ;
applicationReleaseDTO = this . applicationReleaseDAO
. updateRelease ( addImageArtifacts ( applicationReleaseDTO , applicationArtifact ) , tenantId ) ;
if ( applicationReleaseDTO = = null ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "ApplicationDTO release updating count is 0. ApplicationDTO release UUID is " + uuid ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
}
}
ConnectionManagerUtil . commitDBTransaction ( ) ;
ConnectionManagerUtil . commitDBTransaction ( ) ;
} catch ( DBConnectionException e ) {
} catch ( DBConnectionException e ) {
throw new ApplicationManagementException (
String msg =
"Error occured when getting DB connection to update image artifacts of the application, appid: "
"Error occured when getting DB connection to update image artifacts of the application release of haveing uuid "
+ appId + " and uuid " + uuid + "." , e ) ;
+ uuid + "." ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( ApplicationManagementDAOException e ) {
} catch ( ApplicationManagementDAOException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
String msg =
"Error occured while getting application release data for updating image artifacts of the application, appid: "
"Error occured while getting application release data for updating image artifacts of the application release uuid "
+ appId + " and uuid " + uuid + "." , e ) ;
+ uuid + "." ;
} catch ( LifeCycleManagementDAOException e ) {
log . error ( msg ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException ( msg , e ) ;
throw new ApplicationManagementException (
"Error occured while getting latest lifecycle state for updating image artifacts of the application, appid: "
+ appId + " and uuid " + uuid + "." , e ) ;
} catch ( ResourceManagementException e ) {
} catch ( ResourceManagementException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
String msg = "Error occured while updating image artifacts of the application release uuid " + uuid + "." ;
"Error occured while updating image artifacts of the application, appid: " + appId + " and uuid "
log . error ( msg ) ;
+ uuid + " to the system." , e ) ;
throw new ApplicationManagementException ( msg , e ) ;
} finally {
} finally {
ConnectionManagerUtil . closeDBConnection ( ) ;
ConnectionManagerUtil . closeDBConnection ( ) ;
}
}
}
}
//todo check whether package names are same
@Override
@Override
public void updateApplicationArtifact ( int appId , String deviceType , String uuid, InputStream binaryFile )
public void updateApplicationArtifact ( String deviceType , String appType, String uuid ,
throws ApplicationManagementException {
ApplicationArtifact applicationArtifact ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
ApplicationReleaseDTO applicationRelease ;
try {
boolean isValidDeviceType = false ;
boolean isValidDeviceType = false ;
List < DeviceType > deviceTypes = Util . getDeviceManagementService ( ) . getDeviceTypes ( ) ;
List < DeviceType > deviceTypes ;
try {
deviceTypes = Util . getDeviceManagementService ( ) . getDeviceTypes ( ) ;
for ( DeviceType dt : deviceTypes ) {
for ( DeviceType dt : deviceTypes ) {
if ( dt . getName ( ) . equals ( deviceType ) ) {
if ( dt . getName ( ) . equals ( deviceType ) ) {
isValidDeviceType = true ;
isValidDeviceType = true ;
@ -1172,59 +1213,64 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
}
}
if ( ! isValidDeviceType ) {
if ( ! isValidDeviceType ) {
throw new ValidationException (
String msg = "Invalid request to update application release artifact, invalid application type: "
"Invalid request to update application release artifact, invalid application type: "
+ deviceType + " for application release uuid: " + uuid ;
+ deviceType + " for ApplicationDTO id: " + appId + " application release uuid: " + uuid ) ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
}
if ( appId < = 0 ) {
} catch ( DeviceManagementException e ) {
throw new ValidationException (
String msg = "Error occured while getting supported device types in IoTS" ;
"ApplicationDTO id could,t be a negative integer. Hence please add valid application id. application type: "
log . error ( msg ) ;
+ deviceType + " ApplicationDTO id: " + appId + " UUID: " + uuid ) ;
throw new ApplicationManagementException ( msg , e ) ;
}
}
try {
ConnectionManagerUtil . beginDBTransaction ( ) ;
ConnectionManagerUtil . beginDBTransaction ( ) ;
ApplicationDTO application = this . applicationDAO . getApplicationById ( appId , tenantId ) ;
ApplicationReleaseDTO applicationReleaseDTO = this . applicationReleaseDAO . getReleaseByUUID ( uuid , tenantId ) ;
if ( application = = null ) {
if ( applicationReleaseDTO = = null ) {
throw new NotFoundException ( "Doesn't exist a application for the application ID: " + appId ) ;
String msg = "Couldn't found an application release for UUID: " + uuid ;
}
log . error ( msg ) ;
applicationRelease = this . applicationReleaseDAO . getReleaseByIds ( appId , uuid , tenantId ) ;
throw new NotFoundException ( msg ) ;
if ( applicationRelease = = null ) {
throw new NotFoundException (
"Doesn't exist a application release for application ID: " + appId + "and application UUID: "
+ uuid ) ;
}
}
applicationRelease = applicationStorageManager
. updateReleaseArtifacts ( applicationRelease , application . getType ( ) , application . getDeviceTypeName ( ) ,
String deletingAppHashValue = applicationReleaseDTO . getAppHashValue ( ) ;
binaryFile ) ;
applicationReleaseDTO = addApplicationReleaseArtifacts ( appType , deviceType , applicationReleaseDTO ,
applicationRelease = this . applicationReleaseDAO . updateRelease ( appId , applicationRelease , tenantId ) ;
applicationArtifact ) ;
if ( applicationRelease = = null ) {
applicationStorageManager . copyImageArtifactsAndDeleteInstaller ( deletingAppHashValue , applicationReleaseDTO ) ;
applicationReleaseDTO = this . applicationReleaseDAO . updateRelease ( applicationReleaseDTO , tenantId ) ;
if ( applicationReleaseDTO = = null ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
throw new ApplicationManagementException (
"ApplicationDTO release updating count is 0. ApplicationDTO id: " + appId
"ApplicationDTO release updating count is 0. ApplicationDTO release UUID: " + uuid ) ;
+ " ApplicationDTO release UUID: " + uuid ) ;
}
}
ConnectionManagerUtil . commitDBTransaction ( ) ;
ConnectionManagerUtil . commitDBTransaction ( ) ;
} catch ( ApplicationManagementDAOException e ) {
} catch ( ApplicationManagementDAOException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException ( "Error occured while getting/updating APPM DB." , e ) ;
String msg = "Error occured while getting/updating APPM DB for updating application Installer." ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( TransactionManagementException e ) {
} catch ( TransactionManagementException e ) {
throw new ApplicationManagementException (
String msg =
"Error occured while starting the transaction to update application release artifact of the application, appid: "
"Error occured while starting the transaction to update application release artifact of the application uuid "
+ appId + " and uuid " + uuid + "." , e ) ;
+ uuid + "." ;
} catch ( RequestValidatingException e ) {
log . error ( msg ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException ( msg , e ) ;
throw new ApplicationManagementException ( "Error occured while updating application artifact." , e ) ;
} catch ( DeviceManagementException e ) {
throw new ApplicationManagementException ( "Error occured while getting supported device types in IoTS" , e ) ;
} catch ( DBConnectionException e ) {
} catch ( DBConnectionException e ) {
throw new ApplicationManagementException (
String msg =
"Error occured when getting DB connection to update application release artifact of the application, appid: "
"Error occured when getting DB connection to update application release artifact of the application release uuid "
+ appId + " and uuid " + uuid + "." , e ) ;
+ uuid + "." ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( ApplicationStorageManagementException e ) {
} catch ( ApplicationStorageManagementException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException ( "In order to update the artifact, couldn't find it in the system" ,
throw new ApplicationManagementException ( "In order to update the artifact, couldn't find it in the system" ,
e ) ;
e ) ;
} catch ( ResourceManagementException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "Error occured when updating application installer." ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} finally {
} finally {
ConnectionManagerUtil . closeDBConnection ( ) ;
ConnectionManagerUtil . closeDBConnection ( ) ;
}
}
@ -1246,7 +1292,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
// unRestrictedApplications.add(application);
// unRestrictedApplications.add(application);
// } else {
// } else {
// try {
// try {
// if ( isRoleExists (application.getUnrestrictedRoles(), userName)) {
// if ( hasUserRole (application.getUnrestrictedRoles(), userName)) {
// unRestrictedApplications.add(application);
// unRestrictedApplications.add(application);
// }
// }
// } catch (UserStoreException e) {
// } catch (UserStoreException e) {
@ -1366,82 +1412,137 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override
@Override
public ApplicationDTO updateApplication ( int applicationId , ApplicationDTO application )
public void updateApplication ( int applicationId , ApplicationWrapper applicationWrapper )
throws ApplicationManagementException {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
ApplicationDTO existingApplication ;
ApplicationDTO applicationDTO ;
boolean isExistingAppRestricted = false ;
List < String > addingRoleList ;
List < String > removingRoleList ;
List < String > addingTags ;
List < String > removingTags ;
try {
try {
ConnectionManagerUtil . beginDBTransaction ( ) ;
ConnectionManagerUtil . beginDBTransaction ( ) ;
existingApplication = this . applicationDAO . getApplicationById ( applicationId , tenantId ) ;
applicationDTO = this . applicationDAO . getApplicationById ( applicationId , tenantId ) ;
if ( existingApplication = = null ) {
if ( applicationDTO = = null ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new NotFoundException ( "Tried to update ApplicationDTO which is not in the publisher, "
String msg = "Tried to update Application which is not in the publisher. Please verify "
+ "Please verify application details" ) ;
+ "application details" ;
log . error ( msg ) ;
throw new NotFoundException ( msg ) ;
}
if ( ! StringUtils . isEmpty ( applicationWrapper . getType ( ) ) & & ! applicationDTO . getType ( )
. equals ( applicationWrapper . getType ( ) ) ) {
String msg = "You are trying to change the application type and it is not "
+ "possible after you create an application. Therefore please remove this application and "
+ "publish new application with type: " + applicationWrapper . getType ( ) ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
}
if ( ! existingApplication . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( ! StringUtils . isEmpty ( applicationWrapper . getDeviceType ( ) ) & & ! applicationDTO . getDeviceTypeName ( )
isExistingAppRestricted = true ;
. equals ( applicationWrapper . getDeviceType ( ) ) ) {
String msg = "You are trying to change the compatible device type of the application type and it is not "
+ "possible after you create an application for device type. " +
applicationWrapper . getDeviceType ( ) + "Therefore please remove this application and publish "
+ "new application with device type: " + applicationWrapper . getDeviceType ( ) ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
}
if ( ! StringUtils . isEmpty ( applicationWrapper . getSubType ( ) ) & & ! applicationDTO . getSubType ( )
. equals ( applicationWrapper . getSubType ( ) ) ) {
if ( ! ApplicationSubscriptionType . PAID . toString ( ) . equals ( applicationWrapper . getSubType ( ) )
& & ! ApplicationSubscriptionType . FREE . toString ( ) . equals ( applicationWrapper . getSubType ( ) ) ) {
String msg = "Invalid application subscription type is found with application updating request "
+ applicationWrapper . getSubType ( ) ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
if ( ! isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) & & ! (
} else if ( ApplicationSubscriptionType . FREE . toString ( ) . equals ( applicationWrapper . getSubType ( ) ) & & ! StringUtils
isExistingAppRestricted & & isRoleExists ( existingApplication . getUnrestrictedRoles ( ) , userName ) ) ) {
. isEmpty ( applicationWrapper . getPaymentCurrency ( ) ) ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "If you are going to change Non-Free app as Free app, "
throw new ForbiddenException ( "You are not authorized user to update application" ) ;
+ "currency attribute in the application updating payload should be null or \"\"" ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
} else if ( ApplicationSubscriptionType . PAID . toString ( ) . equals ( applicationWrapper . getSubType ( ) )
& & StringUtils . isEmpty ( applicationWrapper . getPaymentCurrency ( ) ) ) {
String msg = "If you are going to change Free app as Non-Free app, "
+ "currency attribute in the application payload should not be null or \"\"" ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
}
}
if ( ! existingApplication . getType ( ) . equals ( application . getType ( ) ) ) {
applicationDTO . setSubType ( applicationWrapper . getSubType ( ) ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
applicationDTO . setPaymentCurrency ( applicationWrapper . getPaymentCurrency ( ) ) ;
throw new ApplicationManagementException ( "You are trying to change the application type and it is not "
+ "possible after you create an application. Therefore please remove this application and "
+ "publish new application with type: " + application . getType ( ) ) ;
}
}
if ( ! existingApplication . getSubType ( ) . equals ( application . getSubType ( ) ) ) {
if ( ! StringUtils . isEmpty ( applicationWrapper . getName ( ) ) ) {
if ( ApplicationSubscriptionType . PAID . toString ( ) . equals ( existingApplication . getSubType ( ) ) & & (
Filter filter = new Filter ( ) ;
! "" . equals ( application . getPaymentCurrency ( ) ) | | application . getPaymentCurrency ( ) ! = null ) ) {
filter . setFullMatch ( true ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
filter . setAppName ( applicationWrapper . getName ( ) . trim ( ) ) ;
throw new ApplicationManagementException ( "If you are going to change Non-Free app as Free app, "
filter . setOffset ( 0 ) ;
+ "currency attribute in the application updating payload should be null or \"\"" ) ;
filter . setLimit ( 1 ) ;
} else if ( ApplicationSubscriptionType . FREE . toString ( ) . equals ( existingApplication . getSubType ( ) ) & & (
application . getPaymentCurrency ( ) = = null | | "" . equals ( application . getPaymentCurrency ( ) ) ) ) {
List < ApplicationDTO > applicationList = applicationDAO
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
. getApplications ( filter , applicationDTO . getDeviceTypeId ( ) , tenantId ) ;
throw new ApplicationManagementException ( "If you are going to change Free app as Non-Free app, "
if ( ! applicationList . isEmpty ( ) ) {
+ "currency attribute in the application payload should not be null or \"\"" ) ;
String msg = "Already an application registered with same name " + applicationWrapper . getName ( )
+ ". Hence you can't update the application name from " + applicationDTO . getName ( ) + " to "
+ applicationWrapper . getName ( ) ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
}
applicationDTO . setName ( applicationWrapper . getName ( ) ) ;
}
}
if ( isExistingAppRestricted & & application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( ! StringUtils . isEmpty ( applicationWrapper . getDescription ( ) ) ) {
visibilityDAO . deleteUnrestrictedRoles ( existingApplication . getUnrestrictedRoles ( ) , application . getId ( ) ,
applicationDTO . setDescription ( applicationWrapper . getDescription ( ) ) ;
tenantId ) ;
}
} else if ( ! isExistingAppRestricted & & ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
visibilityDAO . addUnrestrictedRoles ( application . getUnrestrictedRoles ( ) , application . getId ( ) , tenantId ) ;
List < String > appUnrestrictedRoles = this . visibilityDAO . getUnrestrictedRoles ( applicationId , tenantId ) ;
} else if ( isExistingAppRestricted & & ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
List < String > appCategories = this . applicationDAO . getAppCategories ( applicationId , tenantId ) ;
addingRoleList = getDifference ( application . getUnrestrictedRoles ( ) ,
existingApplication . getUnrestrictedRoles ( ) ) ;
boolean isExistingAppRestricted = ! appUnrestrictedRoles . isEmpty ( ) ;
removingRoleList = getDifference ( existingApplication . getUnrestrictedRoles ( ) ,
boolean isUpdatingAppRestricted = ! applicationWrapper . getUnrestrictedRoles ( ) . isEmpty ( ) ;
application . getUnrestrictedRoles ( ) ) ;
if ( isExistingAppRestricted & & ! isUpdatingAppRestricted ) {
visibilityDAO . deleteUnrestrictedRoles ( appUnrestrictedRoles , applicationId , tenantId ) ;
} else if ( isUpdatingAppRestricted ) {
if ( ! hasUserRole ( applicationWrapper . getUnrestrictedRoles ( ) , userName ) ) {
String msg =
"You are trying to restrict the visibility of visible application.But you are trying to "
+ "restrict the visibility to roles that there isn't at least one role is assigned "
+ "to user: " + userName + ". Therefore, it is not allowed and you should have "
+ "added at least one role that assigned to " + userName + " user into "
+ "restricting role set." ;
log . error ( msg ) ;
throw new BadRequestException ( msg ) ;
}
if ( ! isExistingAppRestricted ) {
visibilityDAO
. addUnrestrictedRoles ( applicationWrapper . getUnrestrictedRoles ( ) , applicationId , tenantId ) ;
} else {
List < String > addingRoleList = getDifference ( applicationWrapper . getUnrestrictedRoles ( ) ,
applicationDTO . getUnrestrictedRoles ( ) ) ;
List < String > removingRoleList = getDifference ( applicationDTO . getUnrestrictedRoles ( ) ,
applicationWrapper . getUnrestrictedRoles ( ) ) ;
if ( ! addingRoleList . isEmpty ( ) ) {
if ( ! addingRoleList . isEmpty ( ) ) {
visibilityDAO . addUnrestrictedRoles ( addingRoleList , application . getId ( ) , tenantId ) ;
visibilityDAO . addUnrestrictedRoles ( addingRoleList , application Id, tenantId ) ;
}
}
if ( ! removingRoleList . isEmpty ( ) ) {
if ( ! removingRoleList . isEmpty ( ) ) {
visibilityDAO . deleteUnrestrictedRoles ( removingRoleList , application . getId ( ) , tenantId ) ;
visibilityDAO . deleteUnrestrictedRoles ( removingRoleList , application Id, tenantId ) ;
}
}
}
}
}
applicationDTO . setUnrestrictedRoles ( applicationWrapper . getUnrestrictedRoles ( ) ) ;
addingTags = getDifference ( existingApplication . getTags ( ) , application . getTags ( ) ) ;
List < String > appTags = this . applicationDAO . getAppTags ( applicationId , tenantId ) ;
removingTags = getDifference ( application . getTags ( ) , existingApplication . getTags ( ) ) ;
List < String > addingTagList = getDifference ( appTags , applicationWrapper . getTags ( ) ) ;
if ( ! addingTags . isEmpty ( ) ) {
List < String > removingTagList = getDifference ( applicationWrapper . getTags ( ) , appTags ) ;
if ( ! addingTagList . isEmpty ( ) ) {
// applicationDAO.addTags(addingTags, application.getId(), tenantId);
// applicationDAO.addTags(addingTags, application.getId(), tenantId);
}
}
if ( ! removingTags . isEmpty ( ) ) {
if ( ! removingTag Li st . isEmpty ( ) ) {
applicationDAO . deleteTags ( removingTags , application . getId ( ) , tenantId ) ;
applicationDAO . deleteTags ( removingTag Li st , application Id, tenantId ) ;
}
}
return applicationDAO . editApplication ( application , tenantId ) ;
applicationDAO . editApplication ( application DTO , tenantId ) ;
} catch ( UserStoreException e ) {
} catch ( UserStoreException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
throw new ApplicationManagementException (
@ -1613,7 +1714,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
String applicationReleaseCreatedUser = lifecycleStateDAO
String applicationReleaseCreatedUser = lifecycleStateDAO
. getAppReleaseCreatedUsername ( applicationId , releaseUuid , tenantId ) ;
. getAppReleaseCreatedUsername ( applicationId , releaseUuid , tenantId ) ;
if ( ! isAdminUser & & ! ( ! unrestrictedRoles . isEmpty ( ) & & isRoleExists ( unrestrictedRoles , userName ) )
if ( ! isAdminUser & & ! ( ! unrestrictedRoles . isEmpty ( ) & & hasUserRole ( unrestrictedRoles , userName ) )
& & ! userName . equals ( applicationReleaseCreatedUser ) ) {
& & ! userName . equals ( applicationReleaseCreatedUser ) ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ForbiddenException ( "You are not authorized user to update application" ) ;
throw new ForbiddenException ( "You are not authorized user to update application" ) ;
@ -1630,11 +1731,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " State" ) ;
+ " State" ) ;
}
}
release = applicationStorageManager
// release = applicationStorageManager
. updateImageArtifacts ( release , iconFileStream , bannerFileStream , attachments ) ;
// .deleteImageArtifacts(release, iconFileStream, bannerFileStream, attachments);
release = applicationStorageManager
// release = applicationStorageManager
. updateReleaseArtifacts ( release , app . getType ( ) , deviceType , binaryFileStram ) ;
// .copyImageArtifactsAndDeleteInstaller(release, app.getType(), deviceType, binaryFileStram);
return applicationReleaseDAO . updateRelease ( applicationId, release, tenantId ) ! = null ;
return applicationReleaseDAO . updateRelease ( release, tenantId ) ! = null ;
} catch ( DeviceManagementException e ) {
} catch ( DeviceManagementException e ) {
throw new ApplicationManagementException ( "Error occured when validating the device type " + deviceType , e ) ;
throw new ApplicationManagementException ( "Error occured when validating the device type " + deviceType , e ) ;
} catch ( UserStoreException e ) {
} catch ( UserStoreException e ) {
@ -1651,31 +1752,32 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException (
throw new ApplicationManagementException (
"Error occured when updating ApplicationDTO release. ApplicationDTO ID " + applicationId
"Error occured when updating ApplicationDTO release. ApplicationDTO ID " + applicationId
+ " ApplicationDTO Release UUID: " + releaseUuid , e ) ;
+ " ApplicationDTO Release UUID: " + releaseUuid , e ) ;
} catch ( ApplicationStorageManagementException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
"Error occured when updating application release artifact. ApplicationDTO ID " + applicationId
+ " ApplicationDTO release UUID: " + releaseUuid , e ) ;
} catch ( ResourceManagementException e ) {
// updating images
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
"Error occured when updating image artifact of the application release. ApplicationDTO ID: "
+ applicationId + " ApplicationDTO release UUID: " + releaseUuid , e ) ;
} catch ( RequestValidatingException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
"Error occured when validating application release artifact for device type " + deviceType
+ " And application type " + app . getType ( ) + ". Applicationn ID: " + applicationId
+ " ApplicationDTO release UUID: " + releaseUuid ) ;
}
}
// catch (ApplicationStorageManagementException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw new ApplicationManagementException(
// "Error occured when updating application release artifact. ApplicationDTO ID " + applicationId
// + " ApplicationDTO release UUID: " + releaseUuid, e);
// }
// catch (ResourceManagementException e) {
// // updating images
// ConnectionManagerUtil.rollbackDBTransaction();
// throw new ApplicationManagementException(
// "Error occured when updating image artifact of the application release. ApplicationDTO ID: "
// + applicationId + " ApplicationDTO release UUID: " + releaseUuid, e);
// } catch (RequestValidatingException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw new ApplicationManagementException(
// "Error occured when validating application release artifact for device type " + deviceType
// + " And application type " + app.getType() + ". Applicationn ID: " + applicationId
// + " ApplicationDTO release UUID: " + releaseUuid);
// }
}
}
@Override
@Override
public void validateAppCreatingRequest ( ApplicationWrapper applicationWrapper ) throws RequestValidatingException {
public void validateAppCreatingRequest ( ApplicationWrapper applicationWrapper ) throws RequestValidatingException {
boolean isValidApplicationType ;
String applicationType = applicationWrapper . getType ( ) ;
String applicationType = applicationWrapper . getType ( ) ;
if ( StringUtils . isEmpty ( applicationWrapper . getName ( ) ) ) {
if ( StringUtils . isEmpty ( applicationWrapper . getName ( ) ) ) {
@ -1699,13 +1801,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new RequestValidatingException ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
isValidApplicationType = isValidAppType ( applicationWrapper . getType ( ) ) ;
if ( ! isValidApplicationType ) {
String msg = "App Type contains in the application creating payload doesn't match with supported app types." ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
List < ApplicationReleaseWrapper > applicationReleaseWrappers ;
List < ApplicationReleaseWrapper > applicationReleaseWrappers ;
applicationReleaseWrappers = applicationWrapper . getApplicationReleaseWrappers ( ) ;
applicationReleaseWrappers = applicationWrapper . getApplicationReleaseWrappers ( ) ;
@ -1754,8 +1849,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
@Override
public void isValidAttachmentSet( Attachment binaryFile , Attachment iconFile , Attachment bannerFile ,
public void validateImageArtifacts( Attachment iconFile , Attachment bannerFile ,
List < Attachment > attachmentList , String applicationType ) throws RequestValidatingException {
List < Attachment > attachmentList ) throws RequestValidatingException {
if ( iconFile = = null ) {
if ( iconFile = = null ) {
String msg = "Icon file is not found with the application release creating request." ;
String msg = "Icon file is not found with the application release creating request." ;
log . error ( msg ) ;
log . error ( msg ) ;
@ -1771,8 +1866,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
log . error ( msg ) ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
if ( StringUtils . isEmpty ( applicationType ) ) {
}
String msg = "Application type is empty and it cannot be empty" ;
@Override
public void validateBinaryArtifact ( Attachment binaryFile , String applicationType ) throws RequestValidatingException {
if ( StringUtils . isEmpty ( applicationType ) ) {
String msg = "Application type can't be empty." ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
if ( ! isValidAppType ( applicationType ) ) {
String msg = "App Type contains in the application creating payload doesn't match with supported app types." ;
log . error ( msg ) ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}