{"action":"created","comment":{"url":"https://api.github.com/repos/is51/catan/pulls/comments/42546167","id":42546167,"diff_hunk":"@@ -0,0 +1,135 @@\n+package catan.services.util.play;\n+\n+import catan.domain.exception.GameException;\n+import catan.domain.model.game.GameBean;\n+import catan.domain.model.game.GameUserBean;\n+import catan.domain.model.game.types.GameStage;\n+import catan.domain.model.game.types.GameUserActions;\n+import catan.domain.transfer.output.game.AllAvailableActionsDetails;\n+import com.google.gson.Gson;\n+import com.google.gson.reflect.TypeToken;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+import org.springframework.beans.factory.annotation.Autowired;\n+import org.springframework.stereotype.Component;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import static catan.services.impl.GameServiceImpl.ERROR_CODE_ERROR;\n+\n+@Component\n+public class PlayUtil {\n+    private Logger log = LoggerFactory.getLogger(PlayUtil.class);\n+\n+    private EndTurnUtil endTurnUtil;\n+\n+    private static final Gson GSON = new Gson();\n+\n+    public List<List<String>> getInitialBuildingsSetFromJson(String json) {\n+        return GSON.fromJson(json, new TypeToken<List<List<String>>>() {\n+        }.getType());\n+    }\n+\n+    public AllAvailableActionsDetails getAllAvailableActions(String json) {\n+        return GSON.fromJson(json, AllAvailableActionsDetails.class);\n+    }\n+\n+    public void updateNextMoveOrder(GameBean game) throws GameException {\n+        Integer nextMoveNumber;\n+        switch (game.getStage()) {\n+            case PREPARATION:\n+                List<List<String>> initialBuildingsSet = getInitialBuildingsSetFromJson(game.getInitialBuildingsSet());\n+                nextMoveNumber = endTurnUtil.endTurnImplInPreparationStage(game, initialBuildingsSet);\n+                break;\n+            case MAIN:\n+                nextMoveNumber = endTurnUtil.endTurnImplInMainStage(game);\n+                break;\n+            default:\n+                log.debug(\"Cannot recognize current game stage: {}\", game.getStage());\n+                throw new GameException(ERROR_CODE_ERROR);\n+        }\n+\n+        log.debug(\"Next move order in {} stage is changing from {} to {}\", game.getStage(), game.getCurrentMove(), nextMoveNumber);\n+        game.setCurrentMove(nextMoveNumber);\n+    }\n+\n+    public void updateCurrentCycleBuildingNumber(GameBean game) {\n+        if (game.getStage().equals(GameStage.PREPARATION)) {\n+            List<List<String>> initialBuildingsSet = getInitialBuildingsSetFromJson(game.getInitialBuildingsSet());\n+            if (game.getCurrentCycleBuildingNumber() > initialBuildingsSet.get(game.getPreparationCycle() - 1).size()) {\n+                game.setCurrentCycleBuildingNumber(1);\n+            } else {\n+                game.setCurrentCycleBuildingNumber(game.getCurrentCycleBuildingNumber() + 1);\n+            }\n+        }\n+    }\n+    public void updateAvailableUserActions(GameBean game) throws GameException {\n+        boolean isMandatory = false;\n+        List<String> actionsList = new ArrayList<String>();\n+        List<GameUserActions> actionCode = new ArrayList<GameUserActions>();\n+        switch (game.getStage()) {\n+            case PREPARATION:\n+                List<List<String>> initialBuildingsSet = getInitialBuildingsSetFromJson(game.getInitialBuildingsSet());\n+                for (GameUserBean gameUser : game.getGameUsers()) {\n+                    if (gameUser.getMoveOrder() == game.getCurrentMove()) {\n+                        actionCode = getActionCodeInPreparationStage(game, initialBuildingsSet);\n+                    }\n+                    if (!actionCode.isEmpty()) {\n+                        actionsList.add(\"{\\\"code\\\": \\\"\" + actionCode.get(0).toString() + \"\\\", \\\"params\\\": {}}\");\n+                        gameUser.setAvailableActions(\"{\\\"list\\\": [\" + actionsList.get(0) + \"], \\\"isMandatory\\\": true}\");","path":"src/main/java/catan/services/util/play/PlayUtil.java","position":80,"original_position":80,"commit_id":"0770173fa29c3c350920a1fe0dec60dbc1b4f19f","original_commit_id":"0770173fa29c3c350920a1fe0dec60dbc1b4f19f","user":{"login":"andrii-r","id":5818527,"avatar_url":"https://avatars.githubusercontent.com/u/5818527?v=3","gravatar_id":"","url":"https://api.github.com/users/andrii-r","html_url":"https://github.com/andrii-r","followers_url":"https://api.github.com/users/andrii-r/followers","following_url":"https://api.github.com/users/andrii-r/following{/other_user}","gists_url":"https://api.github.com/users/andrii-r/gists{/gist_id}","starred_url":"https://api.github.com/users/andrii-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrii-r/subscriptions","organizations_url":"https://api.github.com/users/andrii-r/orgs","repos_url":"https://api.github.com/users/andrii-r/repos","events_url":"https://api.github.com/users/andrii-r/events{/privacy}","received_events_url":"https://api.github.com/users/andrii-r/received_events","type":"User","site_admin":false},"body":"you should iterate by all values, not only the first one","created_at":"2015-10-20T20:04:21Z","updated_at":"2015-10-20T20:04:21Z","html_url":"https://github.com/is51/catan/pull/23#discussion_r42546167","pull_request_url":"https://api.github.com/repos/is51/catan/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/is51/catan/pulls/comments/42546167"},"html":{"href":"https://github.com/is51/catan/pull/23#discussion_r42546167"},"pull_request":{"href":"https://api.github.com/repos/is51/catan/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/is51/catan/pulls/23","id":47986156,"html_url":"https://github.com/is51/catan/pull/23","diff_url":"https://github.com/is51/catan/pull/23.diff","patch_url":"https://github.com/is51/catan/pull/23.patch","issue_url":"https://api.github.com/repos/is51/catan/issues/23","number":23,"state":"open","locked":false,"title":"Us 51 provide information about currently available actions for user","user":{"login":"andrii-r","id":5818527,"avatar_url":"https://avatars.githubusercontent.com/u/5818527?v=3","gravatar_id":"","url":"https://api.github.com/users/andrii-r","html_url":"https://github.com/andrii-r","followers_url":"https://api.github.com/users/andrii-r/followers","following_url":"https://api.github.com/users/andrii-r/following{/other_user}","gists_url":"https://api.github.com/users/andrii-r/gists{/gist_id}","starred_url":"https://api.github.com/users/andrii-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrii-r/subscriptions","organizations_url":"https://api.github.com/users/andrii-r/orgs","repos_url":"https://api.github.com/users/andrii-r/repos","events_url":"https://api.github.com/users/andrii-r/events{/privacy}","received_events_url":"https://api.github.com/users/andrii-r/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-17T13:02:02Z","updated_at":"2015-10-20T20:04:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ec5e92a66d20ab93392cb86919a55e82b3bec225","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/is51/catan/pulls/23/commits","review_comments_url":"https://api.github.com/repos/is51/catan/pulls/23/comments","review_comment_url":"https://api.github.com/repos/is51/catan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/is51/catan/issues/23/comments","statuses_url":"https://api.github.com/repos/is51/catan/statuses/0770173fa29c3c350920a1fe0dec60dbc1b4f19f","head":{"label":"is51:US-51_Provide_information_about_currently_available_actions_for_user","ref":"US-51_Provide_information_about_currently_available_actions_for_user","sha":"0770173fa29c3c350920a1fe0dec60dbc1b4f19f","user":{"login":"is51","id":13038634,"avatar_url":"https://avatars.githubusercontent.com/u/13038634?v=3","gravatar_id":"","url":"https://api.github.com/users/is51","html_url":"https://github.com/is51","followers_url":"https://api.github.com/users/is51/followers","following_url":"https://api.github.com/users/is51/following{/other_user}","gists_url":"https://api.github.com/users/is51/gists{/gist_id}","starred_url":"https://api.github.com/users/is51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/is51/subscriptions","organizations_url":"https://api.github.com/users/is51/orgs","repos_url":"https://api.github.com/users/is51/repos","events_url":"https://api.github.com/users/is51/events{/privacy}","received_events_url":"https://api.github.com/users/is51/received_events","type":"Organization","site_admin":false},"repo":{"id":38006336,"name":"catan","full_name":"is51/catan","owner":{"login":"is51","id":13038634,"avatar_url":"https://avatars.githubusercontent.com/u/13038634?v=3","gravatar_id":"","url":"https://api.github.com/users/is51","html_url":"https://github.com/is51","followers_url":"https://api.github.com/users/is51/followers","following_url":"https://api.github.com/users/is51/following{/other_user}","gists_url":"https://api.github.com/users/is51/gists{/gist_id}","starred_url":"https://api.github.com/users/is51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/is51/subscriptions","organizations_url":"https://api.github.com/users/is51/orgs","repos_url":"https://api.github.com/users/is51/repos","events_url":"https://api.github.com/users/is51/events{/privacy}","received_events_url":"https://api.github.com/users/is51/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/is51/catan","description":"","fork":false,"url":"https://api.github.com/repos/is51/catan","forks_url":"https://api.github.com/repos/is51/catan/forks","keys_url":"https://api.github.com/repos/is51/catan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/is51/catan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/is51/catan/teams","hooks_url":"https://api.github.com/repos/is51/catan/hooks","issue_events_url":"https://api.github.com/repos/is51/catan/issues/events{/number}","events_url":"https://api.github.com/repos/is51/catan/events","assignees_url":"https://api.github.com/repos/is51/catan/assignees{/user}","branches_url":"https://api.github.com/repos/is51/catan/branches{/branch}","tags_url":"https://api.github.com/repos/is51/catan/tags","blobs_url":"https://api.github.com/repos/is51/catan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/is51/catan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/is51/catan/git/refs{/sha}","trees_url":"https://api.github.com/repos/is51/catan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/is51/catan/statuses/{sha}","languages_url":"https://api.github.com/repos/is51/catan/languages","stargazers_url":"https://api.github.com/repos/is51/catan/stargazers","contributors_url":"https://api.github.com/repos/is51/catan/contributors","subscribers_url":"https://api.github.com/repos/is51/catan/subscribers","subscription_url":"https://api.github.com/repos/is51/catan/subscription","commits_url":"https://api.github.com/repos/is51/catan/commits{/sha}","git_commits_url":"https://api.github.com/repos/is51/catan/git/commits{/sha}","comments_url":"https://api.github.com/repos/is51/catan/comments{/number}","issue_comment_url":"https://api.github.com/repos/is51/catan/issues/comments{/number}","contents_url":"https://api.github.com/repos/is51/catan/contents/{+path}","compare_url":"https://api.github.com/repos/is51/catan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/is51/catan/merges","archive_url":"https://api.github.com/repos/is51/catan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/is51/catan/downloads","issues_url":"https://api.github.com/repos/is51/catan/issues{/number}","pulls_url":"https://api.github.com/repos/is51/catan/pulls{/number}","milestones_url":"https://api.github.com/repos/is51/catan/milestones{/number}","notifications_url":"https://api.github.com/repos/is51/catan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/is51/catan/labels{/name}","releases_url":"https://api.github.com/repos/is51/catan/releases{/id}","created_at":"2015-06-24T19:28:17Z","updated_at":"2015-06-26T22:01:06Z","pushed_at":"2015-10-20T17:52:48Z","git_url":"git://github.com/is51/catan.git","ssh_url":"git@github.com:is51/catan.git","clone_url":"https://github.com/is51/catan.git","svn_url":"https://github.com/is51/catan","homepage":null,"size":3632,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"is51:master","ref":"master","sha":"a61195d0c30291c64d87ce37d4bd19e80ad1b789","user":{"login":"is51","id":13038634,"avatar_url":"https://avatars.githubusercontent.com/u/13038634?v=3","gravatar_id":"","url":"https://api.github.com/users/is51","html_url":"https://github.com/is51","followers_url":"https://api.github.com/users/is51/followers","following_url":"https://api.github.com/users/is51/following{/other_user}","gists_url":"https://api.github.com/users/is51/gists{/gist_id}","starred_url":"https://api.github.com/users/is51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/is51/subscriptions","organizations_url":"https://api.github.com/users/is51/orgs","repos_url":"https://api.github.com/users/is51/repos","events_url":"https://api.github.com/users/is51/events{/privacy}","received_events_url":"https://api.github.com/users/is51/received_events","type":"Organization","site_admin":false},"repo":{"id":38006336,"name":"catan","full_name":"is51/catan","owner":{"login":"is51","id":13038634,"avatar_url":"https://avatars.githubusercontent.com/u/13038634?v=3","gravatar_id":"","url":"https://api.github.com/users/is51","html_url":"https://github.com/is51","followers_url":"https://api.github.com/users/is51/followers","following_url":"https://api.github.com/users/is51/following{/other_user}","gists_url":"https://api.github.com/users/is51/gists{/gist_id}","starred_url":"https://api.github.com/users/is51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/is51/subscriptions","organizations_url":"https://api.github.com/users/is51/orgs","repos_url":"https://api.github.com/users/is51/repos","events_url":"https://api.github.com/users/is51/events{/privacy}","received_events_url":"https://api.github.com/users/is51/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/is51/catan","description":"","fork":false,"url":"https://api.github.com/repos/is51/catan","forks_url":"https://api.github.com/repos/is51/catan/forks","keys_url":"https://api.github.com/repos/is51/catan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/is51/catan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/is51/catan/teams","hooks_url":"https://api.github.com/repos/is51/catan/hooks","issue_events_url":"https://api.github.com/repos/is51/catan/issues/events{/number}","events_url":"https://api.github.com/repos/is51/catan/events","assignees_url":"https://api.github.com/repos/is51/catan/assignees{/user}","branches_url":"https://api.github.com/repos/is51/catan/branches{/branch}","tags_url":"https://api.github.com/repos/is51/catan/tags","blobs_url":"https://api.github.com/repos/is51/catan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/is51/catan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/is51/catan/git/refs{/sha}","trees_url":"https://api.github.com/repos/is51/catan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/is51/catan/statuses/{sha}","languages_url":"https://api.github.com/repos/is51/catan/languages","stargazers_url":"https://api.github.com/repos/is51/catan/stargazers","contributors_url":"https://api.github.com/repos/is51/catan/contributors","subscribers_url":"https://api.github.com/repos/is51/catan/subscribers","subscription_url":"https://api.github.com/repos/is51/catan/subscription","commits_url":"https://api.github.com/repos/is51/catan/commits{/sha}","git_commits_url":"https://api.github.com/repos/is51/catan/git/commits{/sha}","comments_url":"https://api.github.com/repos/is51/catan/comments{/number}","issue_comment_url":"https://api.github.com/repos/is51/catan/issues/comments{/number}","contents_url":"https://api.github.com/repos/is51/catan/contents/{+path}","compare_url":"https://api.github.com/repos/is51/catan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/is51/catan/merges","archive_url":"https://api.github.com/repos/is51/catan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/is51/catan/downloads","issues_url":"https://api.github.com/repos/is51/catan/issues{/number}","pulls_url":"https://api.github.com/repos/is51/catan/pulls{/number}","milestones_url":"https://api.github.com/repos/is51/catan/milestones{/number}","notifications_url":"https://api.github.com/repos/is51/catan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/is51/catan/labels{/name}","releases_url":"https://api.github.com/repos/is51/catan/releases{/id}","created_at":"2015-06-24T19:28:17Z","updated_at":"2015-06-26T22:01:06Z","pushed_at":"2015-10-20T17:52:48Z","git_url":"git://github.com/is51/catan.git","ssh_url":"git@github.com:is51/catan.git","clone_url":"https://github.com/is51/catan.git","svn_url":"https://github.com/is51/catan","homepage":null,"size":3632,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/is51/catan/pulls/23"},"html":{"href":"https://github.com/is51/catan/pull/23"},"issue":{"href":"https://api.github.com/repos/is51/catan/issues/23"},"comments":{"href":"https://api.github.com/repos/is51/catan/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/is51/catan/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/is51/catan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/is51/catan/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/is51/catan/statuses/0770173fa29c3c350920a1fe0dec60dbc1b4f19f"}}}}