@ -76,6 +76,7 @@ import java.util.HashSet;
import java.util.LinkedList ;
import java.util.LinkedList ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Optional ;
import java.util.Queue ;
import java.util.Queue ;
import java.util.Set ;
import java.util.Set ;
import java.util.UUID ;
import java.util.UUID ;
@ -120,19 +121,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
ApplicationStorageManager applicationStorageManager = Util . getApplicationStorageManager ( ) ;
application . setUser ( new User ( userName , tenantId ) ) ;
application . setUser ( new User ( userName , tenantId ) ) ;
if ( log . isDebugEnabled ( ) ) {
log . debug ( "Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName ) ;
}
DeviceType deviceType = null ;
DeviceType deviceType = null ;
List < DeviceType > deviceTypes ;
List < DeviceType > deviceTypes ;
ApplicationRelease applicationRelease ;
ApplicationRelease applicationRelease ;
List < ApplicationRelease > applicationReleases = new ArrayList < > ( ) ;
List < ApplicationRelease > applicationReleases = new ArrayList < > ( ) ;
if ( log . isDebugEnabled ( ) ) {
log . debug ( "Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName ) ;
}
try {
try {
validateAppCreatingRequest ( application , binaryFile , iconFile , bannerFile , attachmentList ) ;
validateAppCreatingRequest ( application , binaryFile , iconFile , bannerFile , attachmentList ) ;
// Getting the device type details to get device type ID for internal mappings
// deviceType = Util.getDeviceManagementService().getDeviceType(application.getDeviceType());
deviceTypes = Util . getDeviceManagementService ( ) . getDeviceTypes ( ) ;
deviceTypes = Util . getDeviceManagementService ( ) . getDeviceTypes ( ) ;
for ( DeviceType dt : deviceTypes ) {
for ( DeviceType dt : deviceTypes ) {
if ( dt . getName ( ) . equals ( application . getDeviceType ( ) ) ) {
if ( dt . getName ( ) . equals ( application . getDeviceType ( ) ) ) {
@ -141,11 +139,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
break ;
break ;
}
}
}
}
if ( deviceType = = null ) {
if ( deviceType = = null ) {
log . error ( "Invalid device type is found with the request. Requested Device Type is: " + application
String msg = "Invalid device type is found with the request. Requested Device Type is: " + application
. getDeviceType ( ) ) ;
. getDeviceType ( ) ;
return null ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
applicationRelease = application . getApplicationReleases ( ) . get ( 0 ) ;
applicationRelease = application . getApplicationReleases ( ) . get ( 0 ) ;
@ -167,10 +165,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleases . add ( applicationRelease ) ;
applicationReleases . add ( applicationRelease ) ;
application . setApplicationReleases ( applicationReleases ) ;
application . setApplicationReleases ( applicationReleases ) ;
} catch ( ResourceManagementException e ) {
} catch ( ResourceManagementException e ) {
throw new ApplicationManagementException ( "" ) ;
String msg = "Error Occured when uploading artifacts of the application.: " + application . getName ( ) ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( DeviceManagementException e ) {
} catch ( DeviceManagementException e ) {
throw new ApplicationManagementException (
String msg = "Error occurred while getting device type id of " + application . getType ( ) ;
"Error occurred while getting device type id of " + application . getType ( ) , e ) ;
throw new ApplicationManagementException ( msg , e ) ;
}
}
try {
try {
@ -185,14 +185,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationList applicationList = applicationDAO . getApplications ( filter , tenantId ) ;
ApplicationList applicationList = applicationDAO . getApplications ( filter , tenantId ) ;
if ( ! applicationList . getApplications ( ) . isEmpty ( ) ) {
if ( ! applicationList . getApplications ( ) . isEmpty ( ) ) {
throw new RequestValidatingException (
String msg =
"Already an application registered with same name - " + applicationList . getApplications ( ) . get ( 0 )
"Already an application registered with same name - " + applicationList . getApplications ( ) . get ( 0 )
. getName ( ) ) ;
. getName ( ) ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
// Insert to application table
// Insert to application table
int appId = this . applicationDAO . createApplication ( application , tenantId ) ;
int appId = this . applicationDAO . createApplication ( application , tenantId ) ;
if ( appId = = - 1 ) {
if ( appId = = - 1 ) {
log . error ( "Application creation is Failed" ) ;
log . error ( "Application creation is Failed" ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
@ -201,15 +202,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
log . debug ( "New Application entry added to AP_APP table. App Id:" + appId ) ;
log . debug ( "New Application entry added to AP_APP table. App Id:" + appId ) ;
}
}
//adding application unrestricted roles
//adding application unrestricted roles
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
List < String > unrestrictedRoles = application . getUnrestrictedRoles ( ) ;
if ( ! isValidRestrictedRole ( application . getUnrestrictedRoles ( ) ) ) {
if ( ! unrestrictedRoles . isEmpty ( ) ) {
if ( ! isValidRestrictedRole ( unrestrictedRoles ) ) {
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 ) ;
}
}
this . visibilityDAO . addUnrestrictedRoles ( application. getUnrestrictedRoles ( ) , 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."
+ " App Id:" + appId ) ;
+ " App Id:" + appId ) ;
@ -217,34 +218,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
List < Category > registeredCatehgories = this . applicationDAO . getAllCategories ( tenantId ) ;
List < Category > registeredCatehgories = this . applicationDAO . getAllCategories ( tenantId ) ;
String categoryName = application . getAppCategory ( ) ;
Optional < Category > category = registeredCatehgories . stream ( ) . filter ( obj - > obj . getCategoryName ( ) . equals ( categoryName ) ) . findAny ( ) ;
if ( registeredCatehgories . isEmpty ( ) | | ! registeredCatehgories . contains ( application . getAppCategory ( ) ) ) {
if ( registeredCatehgories . isEmpty ( ) ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "Registered application category set is empty ." ;
String msg = "Registered application category set is empty category: " + categoryName ;
log . error ( msg ) ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
}
}
if ( ! category . isPresent ( ) ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "Request contains invalid category: " + categoryName ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg ) ;
boolean isValidAppCategory = false ;
for ( Category category : registeredCatehgories ) {
if ( category . getCategoryName ( ) . equals ( application . getAppCategory ( ) ) ) {
isValidAppCategory = true ;
break ;
}
}
}
// if (!isValidAppCategory){
/ *
// ConnectionManagerUtil.rollbackDBTransaction();
In current flow , allow to add one category for an application . If it is required to add multiple
// String msg = "Invalid category type is found. Category: " + application. getAppCategory();
categories DAO layer is implemented to match with that requirement . Hence logic is also implemented
// log.error(msg);
this way .
// throw new RequestValidatingException(msg);
* /
// }
List < Integer > categoryIds = new ArrayList < > ( ) ;
categoryIds . add ( category . get ( ) . getId ( ) ) ;
this . applicationDAO . addCategoryMapping ( categoryIds , appId , tenantId ) ;
// todo add categories
//adding application tags
//adding application tags
if ( ! application . getTags ( ) . isEmpty ( ) ) {
List < String > tags = application . getTags ( ) ;
if ( ! tags . isEmpty ( ) ) {
List < Tag > allRegisteredTags = applicationDAO . getAllTags ( tenantId ) ;
List < Tag > allRegisteredTags = applicationDAO . getAllTags ( tenantId ) ;
List < String > allRegisteredTagNames = new ArrayList < > ( ) ;
List < String > allRegisteredTagNames = new ArrayList < > ( ) ;
List < Integer > tagIds = new ArrayList < > ( ) ;
List < Integer > tagIds = new ArrayList < > ( ) ;
@ -252,17 +255,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
for ( Tag tag : allRegisteredTags ) {
for ( Tag tag : allRegisteredTags ) {
allRegisteredTagNames . add ( tag . getTagName ( ) ) ;
allRegisteredTagNames . add ( tag . getTagName ( ) ) ;
}
}
List < String > newTags = getDifference ( applica tion. getT ags( ) , allRegisteredTagNames ) ;
List < String > newTags = getDifference ( tags, allRegisteredTagNames ) ;
if ( ! newTags . isEmpty ( ) ) {
if ( ! newTags . isEmpty ( ) ) {
this . applicationDAO . addTags ( newTags , tenantId ) ;
this . applicationDAO . addTags ( newTags , tenantId ) ;
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
log . debug ( "New tags entry added to AP_APP_TAG table. App Id:" + appId ) ;
log . debug ( "New tags entry added to AP_APP_TAG table. App Id:" + appId ) ;
}
}
tagIds = this . applicationDAO . getTagIdsForTagNames ( applica tion. getT ags( ) , tenantId ) ;
tagIds = this . applicationDAO . getTagIdsForTagNames ( tags, tenantId ) ;
} else {
} else {
for ( Tag tag : allRegisteredTags ) {
for ( Tag tag : allRegisteredTags ) {
for ( String tagName : applica tion. getT ags( ) ) {
for ( String tagName : tags) {
if ( tagName . equals ( tag . getTagName ( ) ) ) {
if ( tagName . equals ( tag . getTagName ( ) ) ) {
tagIds . add ( tag . getId ( ) ) ;
tagIds . add ( tag . getId ( ) ) ;
break ;
break ;
@ -295,25 +298,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
return application ;
return application ;
} catch ( LifeCycleManagementDAOException e ) {
} catch ( LifeCycleManagementDAOException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
String msg = "Error occured while adding lifecycle state. application name: " + application . getName ( )
"Error occured while adding lifecycle state. application name: " + application . getName ( )
+ " application type: is " + application . getType ( ) ;
+ " application type: is " + application . getType ( ) , e ) ;
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 adding application or application release. application name: " + application
"Error occured while adding application or application release. application name: " + application
. getName ( ) + " application type: " + application . getType ( ) , e ) ;
. getName ( ) + " application type: " + application . getType ( ) ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( DBConnectionException e ) {
} catch ( DBConnectionException e ) {
throw new ApplicationManagementException ( "Error occured while getting database connection. " , e ) ;
String msg = "Error occured while getting database connection." ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( VisibilityManagementDAOException e ) {
} catch ( VisibilityManagementDAOException e ) {
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
throw new ApplicationManagementException (
String msg = "Error occured while adding unrestricted roles. application name: " + application . getName ( )
"Error occured while adding unrestricted roles. application name: " + application . getName ( )
+ " application type: " + application . getType ( ) ;
+ " application type: " + application . getType ( ) , e ) ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( TransactionManagementException e ) {
} catch ( TransactionManagementException e ) {
throw new ApplicationManagementException ( "Error occured while disabling AutoCommit. " , e ) ;
String msg = "Error occured while disabling AutoCommit." ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} catch ( UserStoreException e ) {
} catch ( UserStoreException e ) {
throw new ApplicationManagementException ( "Error occured while disabling AutoCommit. " , e ) ;
ConnectionManagerUtil . rollbackDBTransaction ( ) ;
String msg = "Error occured when validating the unrestricted roles given for the application" ;
log . error ( msg ) ;
throw new ApplicationManagementException ( msg , e ) ;
} finally {
} finally {
ConnectionManagerUtil . closeDBConnection ( ) ;
ConnectionManagerUtil . closeDBConnection ( ) ;
}
}
@ -1363,7 +1377,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
String releaseType = updateRelease . getReleaseType ( ) ;
String releaseType = updateRelease . getReleaseType ( ) ;
Double price = updateRelease . getPrice ( ) ;
Double price = updateRelease . getPrice ( ) ;
int isSharedWithTenants = updateRelease . getIsSharedWithAllTenants ( ) ;
String metaData = updateRelease . getMetaData ( ) ;
String metaData = updateRelease . getMetaData ( ) ;
if ( price < 0.0 | | ( price = = 0.0 & & ApplicationSubscriptionType . PAID . toString ( ) . equals ( app . getSubType ( ) ) )
if ( price < 0.0 | | ( price = = 0.0 & & ApplicationSubscriptionType . PAID . toString ( ) . equals ( app . getSubType ( ) ) )
@ -1379,10 +1392,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
if ( releaseType ! = null ) {
if ( releaseType ! = null ) {
release . setReleaseType ( releaseType ) ;
release . setReleaseType ( releaseType ) ;
}
}
//todo change this when isShared with field change to boolean
if ( isSharedWithTenants = = 0 | | isSharedWithTenants = = 1 ) {
release . setIsSharedWithAllTenants ( isSharedWithTenants ) ;
}
if ( metaData ! = null ) {
if ( metaData ! = null ) {
release . setMetaData ( metaData ) ;
release . setMetaData ( metaData ) ;
}
}
@ -1467,24 +1476,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
String applicationType = application . getType ( ) ;
String applicationType = application . getType ( ) ;
if ( StringUtils . isEmpty ( application . getName ( ) ) ) {
if ( StringUtils . isEmpty ( application . getName ( ) ) ) {
String msg = " ";
String msg = " Application name cannot be empty ";
log . error ( msg ) ;
log . error ( msg ) ;
throw new RequestValidatingException ( "Application name cannot be empty" ) ;
throw new RequestValidatingException ( msg ) ;
}
}
if ( StringUtils . isEmpty ( application . getAppCategory ( ) ) ) {
if ( StringUtils . isEmpty ( application . getAppCategory ( ) ) ) {
throw new RequestValidatingException ( "Application category can't be empty" ) ;
String msg = "Application category can't be empty" ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
if ( StringUtils . isEmpty ( applicationType ) ) {
if ( StringUtils . isEmpty ( applicationType ) ) {
throw new RequestValidatingException ( "Application type can't be empty" ) ;
String msg = "Application type can't be empty" ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
if ( StringUtils . isEmpty ( application . getDeviceType ( ) ) ) {
if ( StringUtils . isEmpty ( application . getDeviceType ( ) ) ) {
throw new RequestValidatingException ( "Device type can't be empty for the application" ) ;
String msg = "Device type can't be empty for the application" ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
isValidApplicationType = isValidAppType ( application . getType ( ) ) ;
isValidApplicationType = isValidAppType ( application . getType ( ) ) ;
if ( ! isValidApplicationType ) {
if ( ! isValidApplicationType ) {
throw new RequestValidatingException (
String msg = "App Type contains in the application creating payload doesn't match with supported app types" ;
"App Type contains in the application creating payload doesn't match with supported app types" ) ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
List < ApplicationRelease > appReleases ;
List < ApplicationRelease > appReleases ;
@ -1495,6 +1511,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
"Invalid application creating request. Application creating request must have single application "
"Invalid application creating request. Application creating request must have single application "
+ "release. Application name:" + application . getName ( ) + " and type: " + application
+ "release. Application name:" + application . getName ( ) + " and type: " + application
. getType ( ) ;
. getType ( ) ;
log . error ( msg ) ;
throw new RequestValidatingException ( msg ) ;
throw new RequestValidatingException ( msg ) ;
}
}
validateReleaseCreatingRequest ( appReleases . get ( 0 ) , applicationType , binaryFile , iconFile , bannerFile ,
validateReleaseCreatingRequest ( appReleases . get ( 0 ) , applicationType , binaryFile , iconFile , bannerFile ,