From the above description given by you I have understood the task as following:
We have to prepare two lists in the service which will be returned as Output Parameters:
1) A list of glAccountId's that needs to be associated with the organizationPartyId in GlAccountOrganization Entity. Following is the step to do that:
a) Get a list of global glAccountId's from the following entities (which has "overrideGlAccountId" attribute): (InvoiceItem, Payment, PaymentApplication, OrderAdjustment, OrderItem, QuoteAdjustment, ReturnAdjustment).
b) Iterate the list and for each global glAccountId:
i) Get a list of organization specific mappings with different accounts and for each of them verify the corresponding entry in GlAccountOrganization
ii) Verify the corresponding entry in the GlAccointOrganization.
iii) Add the global glAccountId and all the related glAccountId's with organization specific mappings, for which entry is not found in the GlAccountOrganization to the returnable list.
2) A list of glAccountTypeId's that needs to be associated with organizationPartyId in GlAccountTypeDefault Entity. Following is the step to do that:
a) Get a list of mapped glAccountId's for the organizationPartyId from the entities specified by you above like InvoiceItemTypeGlAccount, etc. and others if needed.
b) For each glAccountId and corresponding glAccountTypeId, verify if there is corresponding entry in GlAccountTypeDefault.
c) Add the glAccountId and corresponding glAccountTypeId, for which entry is not found in GlAccountTypeDefault to the returnable list.
Am I on the right track? Please suggest if any improvements are needed in this part of the task.
And I have one question related to this part which is: How to find organization specific mappings to different accounts for a globalGlAccount?
Please help us with some more info if needed and the above question to proceed further.