{"action":"created","issue":{"url":"https://api.github.com/repos/fabric8-services/fabric8-auth/issues/456","repository_url":"https://api.github.com/repos/fabric8-services/fabric8-auth","labels_url":"https://api.github.com/repos/fabric8-services/fabric8-auth/issues/456/labels{/name}","comments_url":"https://api.github.com/repos/fabric8-services/fabric8-auth/issues/456/comments","events_url":"https://api.github.com/repos/fabric8-services/fabric8-auth/issues/456/events","html_url":"https://github.com/fabric8-services/fabric8-auth/pull/456","id":316550851,"number":456,"title":"Introduce service layer","user":{"login":"sbryzak","id":165507,"avatar_url":"https://avatars0.githubusercontent.com/u/165507?v=4","gravatar_id":"","url":"https://api.github.com/users/sbryzak","html_url":"https://github.com/sbryzak","followers_url":"https://api.github.com/users/sbryzak/followers","following_url":"https://api.github.com/users/sbryzak/following{/other_user}","gists_url":"https://api.github.com/users/sbryzak/gists{/gist_id}","starred_url":"https://api.github.com/users/sbryzak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbryzak/subscriptions","organizations_url":"https://api.github.com/users/sbryzak/orgs","repos_url":"https://api.github.com/users/sbryzak/repos","events_url":"https://api.github.com/users/sbryzak/events{/privacy}","received_events_url":"https://api.github.com/users/sbryzak/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"sbryzak","id":165507,"avatar_url":"https://avatars0.githubusercontent.com/u/165507?v=4","gravatar_id":"","url":"https://api.github.com/users/sbryzak","html_url":"https://github.com/sbryzak","followers_url":"https://api.github.com/users/sbryzak/followers","following_url":"https://api.github.com/users/sbryzak/following{/other_user}","gists_url":"https://api.github.com/users/sbryzak/gists{/gist_id}","starred_url":"https://api.github.com/users/sbryzak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbryzak/subscriptions","organizations_url":"https://api.github.com/users/sbryzak/orgs","repos_url":"https://api.github.com/users/sbryzak/repos","events_url":"https://api.github.com/users/sbryzak/events{/privacy}","received_events_url":"https://api.github.com/users/sbryzak/received_events","type":"User","site_admin":false},"assignees":[{"login":"sbryzak","id":165507,"avatar_url":"https://avatars0.githubusercontent.com/u/165507?v=4","gravatar_id":"","url":"https://api.github.com/users/sbryzak","html_url":"https://github.com/sbryzak","followers_url":"https://api.github.com/users/sbryzak/followers","following_url":"https://api.github.com/users/sbryzak/following{/other_user}","gists_url":"https://api.github.com/users/sbryzak/gists{/gist_id}","starred_url":"https://api.github.com/users/sbryzak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbryzak/subscriptions","organizations_url":"https://api.github.com/users/sbryzak/orgs","repos_url":"https://api.github.com/users/sbryzak/repos","events_url":"https://api.github.com/users/sbryzak/events{/privacy}","received_events_url":"https://api.github.com/users/sbryzak/received_events","type":"User","site_admin":false}],"milestone":null,"comments":10,"created_at":"2018-04-22T05:34:39Z","updated_at":"2018-04-23T03:54:26Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/fabric8-services/fabric8-auth/pulls/456","html_url":"https://github.com/fabric8-services/fabric8-auth/pull/456","diff_url":"https://github.com/fabric8-services/fabric8-auth/pull/456.diff","patch_url":"https://github.com/fabric8-services/fabric8-auth/pull/456.patch"},"body":"What this pull request does:\r\n\r\n# Refactoring of application package\r\n\r\n- Repositories interface extracted into repository subpackage\r\n\r\nThis provides a global fix for import cycle issues, solving the problem of having to create a separate repositories interfaces for the service layer\r\n\r\n- Services interface introduced.\r\n\r\nProvides a convenient way for controllers to access the service layer\r\n\r\n# Decouple transaction control from the application package\r\n\r\n## Transaction-related functionality moved to application/transaction package\r\n\r\n- Allows transactions to be managed without introducing import cycle issues with application package\r\n- Transactional method refactored:\r\n`      func Transactional(tm TransactionManager, todo func(f TransactionalResources) error) error`\r\n      \r\nThe `tm` parameter is used by the `Transactional` method to initiate the transaction.  Code executed within the transaction block (i.e. the `todo` function) may interact with transactional resources (e.g. repositories) via the `TransactionalResources` parameter.\r\n      \r\n**Some notes:**\r\n\r\nThe `Application` object implements `TransactionManager`, so transactions can continue to be conveniently managed inside the controller package:\r\n        \r\n```\r\n        \terr := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {\r\n        \t// transactional code\r\n        \t}\r\n```\r\n        \t\r\n`TransactionalResources` implements the `Repositories` interface, providing convenient access to repository types:\r\n        \r\n```\r\n        err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {\r\n        \ttr.ResourceRepository().Delete(ctx, ctx.ResourceID)\r\n        }\r\n```\r\n        \r\nThe scope of `TransactionalResources` may be easily extended in the future to include other transactional resources, not just repositories.\r\n\r\n# Introduction of service layer\r\n\r\n- Transaction control moved to service layer\r\n\r\nSince the service layer is responsible for the atomic integrity of the operation, transaction control was moved to the service layer where required.\r\n\r\n- Extracted db-specific code from service layer to repository layer\r\n\r\nThis leaves the service layer as a purely business logic layer.  In many cases, this has left the service layer as a thin facade over the repository layer, which is exactly what the Service Layer design pattern recommends.  For example, `RoleManagementService` which was previously over 300 lines of code is now only about 40 lines.\r\n\r\n- Fixed Preload issues\r\n\r\nMany hours was spent deep inside the Gorm source code to determine why `Preload()` was failing, and I'm pleased to report that I was able to identify the issue and rectify it in our code.  As a result, I was able to do some extensive code refactoring to significantly reduce the number of lines of code required to execute some queries and get the results we required.  For example, I was able to reduce the methods in `RoleManagementService` (some of them around 70 lines of code) significantly (in some cases just over 10 lines of code) in the `IdentityRole` repository.\r\n\r\n**Still TO DO:**\r\n\r\n- [x] Evaluate code coverage once report is available\r\n- [x] Review services for transaction control, decoupling of database-specific code\r\n\r\nFixes #446 "},"comment":{"url":"https://api.github.com/repos/fabric8-services/fabric8-auth/issues/comments/383447220","html_url":"https://github.com/fabric8-services/fabric8-auth/pull/456#issuecomment-383447220","issue_url":"https://api.github.com/repos/fabric8-services/fabric8-auth/issues/456","id":383447220,"user":{"login":"fabric8cd","id":26630553,"avatar_url":"https://avatars2.githubusercontent.com/u/26630553?v=4","gravatar_id":"","url":"https://api.github.com/users/fabric8cd","html_url":"https://github.com/fabric8cd","followers_url":"https://api.github.com/users/fabric8cd/followers","following_url":"https://api.github.com/users/fabric8cd/following{/other_user}","gists_url":"https://api.github.com/users/fabric8cd/gists{/gist_id}","starred_url":"https://api.github.com/users/fabric8cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabric8cd/subscriptions","organizations_url":"https://api.github.com/users/fabric8cd/orgs","repos_url":"https://api.github.com/users/fabric8cd/repos","events_url":"https://api.github.com/users/fabric8cd/events{/privacy}","received_events_url":"https://api.github.com/users/fabric8cd/received_events","type":"User","site_admin":false},"created_at":"2018-04-23T03:54:26Z","updated_at":"2018-04-23T03:54:26Z","author_association":"NONE","body":"@sbryzak snapshot fabric8-auth image is available for testing.  `docker pull docker.io/fabric8/fabric8-auth:SNAPSHOT-PR-456-9`"}}
{"actor":{"display_login":"fabric8cd"}}