@ -212,11 +212,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
}
}
@Override
public ApplicationRelease getReleaseByUuid ( String applicationUuid ) throws ApplicationManagementException {
return null ;
}
@Override
@Override
public String getUuidOfLatestRelease ( int appId ) throws ApplicationManagementException {
public String getUuidOfLatestRelease ( int appId ) throws ApplicationManagementException {
try {
try {
@ -293,40 +288,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
}
}
@Override
public Application getApplicationById ( int applicationId ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
Application application ;
boolean isAppAllowed = false ;
try {
ConnectionManagerUtil . openDBConnection ( ) ;
application = ApplicationManagementDAOFactory . getApplicationDAO ( )
. getApplicationById ( applicationId , tenantId ) ;
if ( isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) ) {
return application ;
}
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( isRoleExists ( application . getUnrestrictedRoles ( ) , userName ) ) {
isAppAllowed = true ;
}
} else {
isAppAllowed = true ;
}
if ( ! isAppAllowed ) {
return null ;
}
return application ;
} catch ( UserStoreException e ) {
throw new ApplicationManagementException (
"User-store exception while getting application with the " + "application id " + applicationId , e ) ;
} finally {
ConnectionManagerUtil . closeDBConnection ( ) ;
}
}
@Override
@Override
public Application getApplicationByRelease ( String appReleaseUUID ) throws ApplicationManagementException {
public Application getApplicationByRelease ( String appReleaseUUID ) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
@ -448,7 +409,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if ( application = = null ) {
if ( application = = null ) {
throw new ApplicationManagementException ( "Invalid Application ID is received" ) ;
throw new ApplicationManagementException ( "Invalid Application ID is received" ) ;
}
}
ApplicationRelease applicationRelease = validateApplicationRelease ( releaseUuid) ;
ApplicationRelease applicationRelease = validateApplicationRelease ( applicationId, releaseUuid) ;
if ( applicationRelease = = null ) {
if ( applicationRelease = = null ) {
throw new ApplicationManagementException ( "Invalid Application Release UUID is received" ) ;
throw new ApplicationManagementException ( "Invalid Application Release UUID is received" ) ;
}
}
@ -557,19 +518,44 @@ public class ApplicationManagerImpl implements ApplicationManager {
/ * *
/ * *
* To validate the pre - request of the ApplicationRelease .
* To validate the pre - request of the ApplicationRelease .
*
*
* @param applicationI D ID of the Application .
* @param applicationI d ID of the Application .
* @return Application related with the UUID
* @return Application related with the UUID
* /
* /
public Application validateApplication ( int applicationI D ) throws ApplicationManagementException {
public Application validateApplication ( int applicationI d ) throws ApplicationManagementException {
if ( applicationI D < = 0 ) {
if ( applicationI d < = 0 ) {
throw new ApplicationManagementException ( "Application UUID is null. Application UUID is a required "
throw new ApplicationManagementException ( "Application id could,t be a negative integer. Hence please add " +
+ "parameter to get the relevant application .") ;
"valid application id .") ;
}
}
Application application = DataHolder . getInstance ( ) . getApplicationManager ( ) . getApplicationById ( applicationID ) ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
if ( application = = null ) {
String userName = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ;
throw new NotFoundException ( "Application of the " + applicationID + " does not exist." ) ;
Application application ;
boolean isAppAllowed = false ;
try {
ConnectionManagerUtil . openDBConnection ( ) ;
application = ApplicationManagementDAOFactory . getApplicationDAO ( )
. getApplicationById ( applicationId , tenantId ) ;
if ( isAdminUser ( userName , tenantId , CarbonConstants . UI_ADMIN_PERMISSION_COLLECTION ) ) {
return application ;
}
if ( ! application . getUnrestrictedRoles ( ) . isEmpty ( ) ) {
if ( isRoleExists ( application . getUnrestrictedRoles ( ) , userName ) ) {
isAppAllowed = true ;
}
} else {
isAppAllowed = true ;
}
if ( ! isAppAllowed ) {
throw new NotFoundException ( "Application of the " + applicationId + " does not exist." ) ;
}
return application ;
} catch ( UserStoreException e ) {
throw new ApplicationManagementException (
"User-store exception while getting application with the " + "application id " + applicationId , e ) ;
} finally {
ConnectionManagerUtil . closeDBConnection ( ) ;
}
}
return application ;
}
}
/ * *
/ * *
@ -578,18 +564,33 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param applicationUuid UUID of the Application .
* @param applicationUuid UUID of the Application .
* @return Application related with the UUID
* @return Application related with the UUID
* /
* /
public ApplicationRelease validateApplicationRelease ( String applicationUuid ) throws ApplicationManagementException {
public ApplicationRelease validateApplicationRelease ( int applicationId , String applicationUuid ) throws
if ( applicationUuid = = null ) {
ApplicationManagementException {
throw new ApplicationManagementException ( "Application UUID is null. Application UUID is a required "
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( true ) ;
+ "parameter to get the relevant application." ) ;
ApplicationRelease applicationRelease ;
}
try {
ApplicationRelease applicationRelease = DataHolder . getInstance ( ) . getApplicationManager ( )
if ( applicationId < = 0 ) {
. getReleaseByUuid ( applicationUuid ) ;
throw new ApplicationManagementException (
if ( applicationRelease = = null ) {
"Application id could,t be a negative integer. Hence please add " +
throw new ApplicationManagementException (
"valid application id." ) ;
"Application with UUID " + applicationUuid + " does not exist." ) ;
}
if ( applicationUuid = = null ) {
throw new ApplicationManagementException ( "Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application." ) ;
}
ConnectionManagerUtil . openDBConnection ( ) ;
applicationRelease = ApplicationManagementDAOFactory . getApplicationReleaseDAO ( ) . getReleaseByIds
( applicationId , applicationUuid , tenantId ) ;
if ( applicationRelease = = null ) {
throw new ApplicationManagementException ( "Doesn't exist a application release for application ID: " +
applicationId + "and application UUID: " +
applicationUuid ) ;
}
return applicationRelease ;
} finally {
ConnectionManagerUtil . closeDBConnection ( ) ;
}
}
return applicationRelease ;
}
}
@Override
@Override
@ -672,8 +673,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
try {
ConnectionManagerUtil . openDBConnection ( ) ;
ConnectionManagerUtil . openDBConnection ( ) ;
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory . getLifecycleStateDAO ( ) ;
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory . getLifecycleStateDAO ( ) ;
//todo applicationUuid and applicationId should be passed and util method has to be changed
ApplicationRelease applicationRelease = validateApplicationRelease ( applicationId , applicationUuid ) ;
ApplicationRelease applicationRelease = validateApplicationRelease ( applicationUuid ) ;
lifecycleState = lifecycleStateDAO . getLatestLifeCycleStateByReleaseID ( applicationRelease . getId ( ) ) ;
lifecycleState = lifecycleStateDAO . getLatestLifeCycleStateByReleaseID ( applicationRelease . getId ( ) ) ;
lifecycleState . setNextStates ( getNextLifecycleStates ( lifecycleState . getCurrentState ( ) ) ) ;
lifecycleState . setNextStates ( getNextLifecycleStates ( lifecycleState . getCurrentState ( ) ) ) ;
} catch ( ApplicationManagementDAOException e ) {
} catch ( ApplicationManagementDAOException e ) {
@ -692,8 +692,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
try {
ConnectionManagerUtil . openDBConnection ( ) ;
ConnectionManagerUtil . openDBConnection ( ) ;
Application application = validateApplication ( applicationId ) ;
Application application = validateApplication ( applicationId ) ;
//todo applicationUuid and applicationId should be passed and util method has to be changed
ApplicationRelease applicationRelease = validateApplicationRelease ( applicationId , applicationUuid ) ;
ApplicationRelease applicationRelease = validateApplicationRelease ( applicationUuid ) ;
LifecycleStateDAO lifecycleStateDAO ;
LifecycleStateDAO lifecycleStateDAO ;
if ( application ! = null ) {
if ( application ! = null ) {