private void removeIncomingPhoneNumbers ( Sid accountSid , IncomingPhoneNumbersDao dao ) { List < IncomingPhoneNumber > numbers = dao . getIncomingPhoneNumbers ( accountSid ) ; if ( numbers != null && numbers . size ( ) > 0 ) { // manager is retrieved in a lazy way. If any number needs it, it will be first retrieved // from the servlet context. If not there it will be created, stored in context and returned. boolean managerQueried = false ; PhoneNumberProvisioningManager manager = null ; for ( IncomingPhoneNumber number : numbers ) { // if this is not just a SIP number try to release it by contacting the provider if ( number . isPureSip ( ) == null || ! number . isPureSip ( ) ) { if ( ! managerQueried ) manager = new PhoneNumberProvisioningManagerProvider ( rootConfiguration , context ) . get ( ) ; // try to retrieve/build manager only once if ( manager != null ) { try { if ( ! manager . cancelNumber ( IncomingPhoneNumbersEndpoint . convertIncomingPhoneNumbertoPhoneNumber ( number ) ) ) { logger . error ( "Number cancelation failed for provided number '" + number . getPhoneNumber ( ) + "'. Number entity " + number . getSid ( ) + " will stay in database" ) ; } else { dao . removeIncomingPhoneNumber ( number . getSid ( ) ) ; } } catch ( Exception e ) { logger . error ( "Number cancelation failed for provided number '" + number . getPhoneNumber ( ) + "'" , e ) ; } } else logger . error ( "Number cancelation failed for provided number '" + number . getPhoneNumber ( ) + "'. Provisioning Manager was null. " + "Number entity " + number . getSid ( ) + " will stay in database" ) ; } else { // pureSIP numbers only to be removed from database. No need to contact provider dao . removeIncomingPhoneNumber ( number . getSid ( ) ) ; } } } }
Removes incoming phone numbers that belong to an account from the database . For provided numbers the provider is also contacted to get them released .