@startuml
title  __DSPA Selfcare PCF: SetMasterPrivileges__ n

actor Client #Magenta

participant SelfCareServiceWSController
participant SelfCareService
participant SelfCareUtil
participant IAMManager
participant IAMDao
participant LdapService
participant IAM_LDAP #DarkSeaGreen
participant CPNI_QUEUE
participant TIBCO_EMS
participant Provisioning as "<b><color:white>Provisioning" #Magenta


Client -> SelfCareServiceWSController: <font color=blue> setMasterPrivileges [[https://servicecatalog.internal.t-mobile.com/servicecat/dspa/2016-10-14/wsdl_api/wsdl/SelfCareService.wsdl WSDL]]\n (JAX-RPC XML Request over Http)

note left
Client: RSP
URI: /webservice/SelfCareService
endnote

alt try
SelfCareServiceWSController->SelfCareService: setMasterPrivileges(msisdn,grantMasterPrivileges,ntID)
SelfCareService-> SelfCareUtil : validateMsisdn(msisdn)
alt msisdn doesn't match msisdnPattern
SelfCareUtil-> SelfCareService : throw InvalidRequestException
SelfCareService-> SelfCareServiceWSController : throw InvalidRequestException
end

SelfCareService->IAMManager: getProfile(msisdn)
IAMManager-> IAMDao: getProfile(msisdn)
IAMDao-> LdapService : ldapSearch(searchCriteria, filterAttributes, searchControls)
note left: with msisdn in searchCriteria
LdapService -> IAM_LDAP : search(rootSuffix, searchCriteria, searchControls, handler)
IAM_LDAP -> LdapService : SearchResult List
LdapService-> IAMDao : SearchResult List

alt searchResult is Empty
IAMDao->IAMManager: throws CustomerNotFoundException
IAMManager->SelfCareService: throws CustomerNotFoundException
SelfCareService->SelfCareServiceWSController: throws NoSuchMsisdnException
else byPassNoAttributesException disabled, filterAttributes length greater than 0 and serachResult size is 0
IAMDao->SelfCareServiceWSController : throws IAMException 
end

alt searchResultList size greater than 1 for a msisdn
IAMDao->IAMDao : Log Error
note left : More than one object found for search criteria
end

IAMDao-> IAMManager : return customerProfile
IAMManager-> SelfCareService : return customerProfile

alt customerProfile.getCustomerType() is PREPAID
SelfCareService->SelfCareServiceWSController: throw InvalidRequestException
end

SelfCareService->SelfCareUtil: isGMPAccountType(customerProfile.getAccountType(), customerProfile.getAccountSubType()) : returns isGMPAccountType
note right
return true if acType+acSubtype is available in allowedGMPAcTypes
endnote

alt isGMPAccountType is false and grantMasterPrivileges is true
SelfCareService->SelfCareServiceWSController: throw InvalidRequestException
end

SelfCareService->IAMManager: setMasterPrivileges(msisdn, grantMasterPrivileges)
IAMManager-> IAMDao: setMasterPrivileges(msisdn, grantMasterPrivileges)
IAMDao-> LdapService : ldapSearch(searchCriteria, filterAttributes, searchControls)
note left: with msisdn in searchCriteria
LdapService -> IAM_LDAP : search(rootSuffix, searchCriteria, searchControls, handler)
IAM_LDAP -> LdapService : SearchResult List
LdapService-> IAMDao : SearchResult List

alt searchResult is Empty
IAMDao->IAMManager: throws CustomerNotFoundException
IAMManager->SelfCareService: throws CustomerNotFoundException
SelfCareService->SelfCareServiceWSController: throws NoSuchMsisdnException
else byPassNoAttributesException disabled, filterAttributes length greater than 0 and serachResult size is 0
IAMDao->SelfCareServiceWSController : throws IAMException 
end

alt searchResultList size greater than 1 for a msisdn
IAMDao->IAMDao : Log Error
note left : More than one object found for search criteria
end
IAMDao-> LdapService:ldapUpdate(dn,modificationItems) updating **tmgrantmasterprivileges**
LdapService->IAM_LDAP: modifyAttributes(dn,modificationItems)
IAM_LDAP-> LdapService: return void
LdapService-->IAMDao: return void
IAMDao-->IAMManager: return void
IAMManager-->SelfCareService: return void

note over SelfCareService #white
If grantMasterPrivileges is true, mlCustType is set to "GMP_M"
otherwise mlCustType is set to "GMP_NM_P"
Set mlCustType to customerProfile.multilineCustomerType
endnote

SelfCareService->IAMManager: setMLCustType(msisdn, mlCustType)
IAMManager-> IAMDao: setMLCustType(msisdn, mlCustType)
IAMDao-> LdapService : ldapSearch(searchCriteria, filterAttributes, searchControls)
note left: with msisdn in searchCriteria
LdapService -> IAM_LDAP : search(rootSuffix, searchCriteria, searchControls, handler)
IAM_LDAP -> LdapService : SearchResult List
LdapService-> IAMDao : SearchResult List

alt searchResult is Empty
IAMDao->IAMManager: throws CustomerNotFoundException
IAMManager->SelfCareService: throws CustomerNotFoundException
SelfCareService->SelfCareServiceWSController: throws NoSuchMsisdnException
else byPassNoAttributesException disabled, filterAttributes length greater than 0 and serachResult size is 0
IAMDao->SelfCareServiceWSController : throws IAMException 
end

alt searchResultList size greater than 1 for a msisdn
IAMDao->IAMDao : Log Error
note left : More than one object found for search criteria
end
IAMDao-> LdapService:ldapUpdate(dn,modificationItems) updating **tmmlcusttype**
LdapService->IAM_LDAP: modifyAttributes(dn,modificationItems)
IAM_LDAP-> LdapService: return void
LdapService-->IAMDao: return void
IAMDao-->IAMManager: return void
IAMManager-->SelfCareService: return void

SelfCareService[#blue]--> TIBCO_EMS : Publish the message with <back:cadetblue><b>event 'setMLType' and msgType='Publish'</back>  to <back:cadetblue><b>PUBLISHTOPIC</back> 
TIBCO_EMS->Provisioning : [[../../provisioningems/ce.dsg.dice.prov.ems.pcf.publishtopic.setmltype.svg Provisioning_AsncFlow_setMLType]]

alt error during posting event
SelfCareService -> SelfCareServiceWSController : throws Exception
end

alt grantMasterPrivileges is true
note left
Create CPNINotification with customerProfile, accType as POSTPAID, eventType as MASTERACCTCHANGE,ntId and GuId
endnote
SelfCareService -> CPNI_QUEUE : Publish the message with <back:cadetblue><b>event 'MASTERACCTCHANGE' and msgType='Publish'</back>
CPNI_QUEUE->Provisioning : [[../../provisioningems/ce.dsg.dice.prov.ems.pcf.queue.cpni.svg Provisioning_AsncFlow_CPNIQueue]]

end

SelfCareService--[#green]>SelfCareServiceWSController : return void
SelfCareServiceWSController--[#green]> Client : return void

else 
 SelfCareServiceWSController-> Client : throws InvalidRequestException
else
SelfCareServiceWSController-> Client : throws NoSuchMsisdnException
else
SelfCareServiceWSController-> Client : throws SelfCareSystemException
end
@enduml