{"action":"created","comment":{"url":"https://api.github.com/repos/lookout/deploydb/pulls/comments/24929652","id":24929652,"diff_hunk":"@@ -0,0 +1,81 @@\n+package deploydb.resources\n+\n+import java.io.File\n+import java.util.*\n+import java.io.IOException\n+import javax.validation.Validation\n+import javax.validation.Validator\n+import io.dropwizard.jackson.Jackson\n+import com.google.common.io.Resources;\n+import io.dropwizard.configuration.ConfigurationFactory\n+import com.fasterxml.jackson.annotation.JsonProperty\n+import io.dropwizard.configuration.ConfigurationException\n+import io.dropwizard.configuration.ConfigurationParsingException\n+import io.dropwizard.configuration.ConfigurationValidationException\n+import java.util.concurrent.ConcurrentHashMap\n+import java.lang.IllegalArgumentException\n+\n+/**\n+ * Model Registry object\n+ *\n+ * It creates the configuration driven model objects. The key for Model \n+ * instances is String. Objects are stored in hashMap for later retrieval.\n+ */\n+class ModelRegistry<T> {\n+    private final ConcurrentHashMap<String, T> modelTable\n+    private final Validator validator\n+    private final ConfigurationFactory<T> factory\n+\n+   /**\n+    * Creates a new Model Registry for the given class.\n+    *\n+    * @param klass          the Model class\n+    */\n+    public ModelRegistry(Class<T> klass) {\n+        this.validator = Validation.buildDefaultValidatorFactory().getValidator()\n+        this.factory = new ConfigurationFactory<>(klass,\n+                                                  validator,\n+                                                  Jackson.newObjectMapper(), \"\")\n+        this.modelTable = new ConcurrentHashMap<String, T>()\n+    }\n+\n+    /**\n+     * Insert an extant model in the table\n+     *\n+     * @param model          the Model instance\n+     */\n+    void insert(T model) throws IllegalArgumentException {\n+        //if (model.name == null) throw IllegalArgumentException\n+        modelTable.put(model.name, model)\n+    }\n+    \n+    /**\n+     * Instantiate a new Model object by parsing contents of the input file (T) \n+     *\n+     * @param File name, file is present in the resources directory\n+     */\n+    T createFromFile(String filename)\n+        throws Exception, ConfigurationParsingException,\n+               ConfigurationValidationException {\n+        File inputFile = new File(Resources.getResource(filename).toURI())\n+        T model = factory.build(inputFile)\n+        this.insert(model)\n+        return model\n+    }\n+\n+    /**\n+     * Return list of all model objects\n+     */\n+    List<T> getAllModels() {\n+        return new ArrayList<T>(modelTable.values())","path":"src/main/groovy/deploydb/resources/ModelRegistry.groovy","position":70,"original_position":70,"commit_id":"bc2a042bb8978faea82ec4fbd851cb0fa393e73f","original_commit_id":"bc2a042bb8978faea82ec4fbd851cb0fa393e73f","user":{"login":"rtyler","id":26594,"avatar_url":"https://avatars.githubusercontent.com/u/26594?v=3","gravatar_id":"","url":"https://api.github.com/users/rtyler","html_url":"https://github.com/rtyler","followers_url":"https://api.github.com/users/rtyler/followers","following_url":"https://api.github.com/users/rtyler/following{/other_user}","gists_url":"https://api.github.com/users/rtyler/gists{/gist_id}","starred_url":"https://api.github.com/users/rtyler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtyler/subscriptions","organizations_url":"https://api.github.com/users/rtyler/orgs","repos_url":"https://api.github.com/users/rtyler/repos","events_url":"https://api.github.com/users/rtyler/events{/privacy}","received_events_url":"https://api.github.com/users/rtyler/received_events","type":"User","site_admin":false},"body":"I think it is safe for the type to be `Collection<T>`, look at the javadocs, Collection is a superinterface of List","created_at":"2015-02-18T19:01:48Z","updated_at":"2015-02-18T19:01:48Z","html_url":"https://github.com/lookout/deploydb/pull/51#discussion_r24929652","pull_request_url":"https://api.github.com/repos/lookout/deploydb/pulls/51","_links":{"self":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/comments/24929652"},"html":{"href":"https://github.com/lookout/deploydb/pull/51#discussion_r24929652"},"pull_request":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/51"}}},"pull_request":{"url":"https://api.github.com/repos/lookout/deploydb/pulls/51","id":29542795,"html_url":"https://github.com/lookout/deploydb/pull/51","diff_url":"https://github.com/lookout/deploydb/pull/51.diff","patch_url":"https://github.com/lookout/deploydb/pull/51.patch","issue_url":"https://api.github.com/repos/lookout/deploydb/issues/51","number":51,"state":"open","locked":false,"title":"Expose Services via read API","user":{"login":"maheshkelkar","id":10839177,"avatar_url":"https://avatars.githubusercontent.com/u/10839177?v=3","gravatar_id":"","url":"https://api.github.com/users/maheshkelkar","html_url":"https://github.com/maheshkelkar","followers_url":"https://api.github.com/users/maheshkelkar/followers","following_url":"https://api.github.com/users/maheshkelkar/following{/other_user}","gists_url":"https://api.github.com/users/maheshkelkar/gists{/gist_id}","starred_url":"https://api.github.com/users/maheshkelkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maheshkelkar/subscriptions","organizations_url":"https://api.github.com/users/maheshkelkar/orgs","repos_url":"https://api.github.com/users/maheshkelkar/repos","events_url":"https://api.github.com/users/maheshkelkar/events{/privacy}","received_events_url":"https://api.github.com/users/maheshkelkar/received_events","type":"User","site_admin":false},"body":"Added a ModelRegistry to manage config driven data objects (e.g. Service)\r\nin the memory. Added an REST API to return all or a specific by name\r\nService instance. Added cucumber and spock unit tests.\r\n\r\nFixes #43","created_at":"2015-02-18T17:03:16Z","updated_at":"2015-02-18T19:01:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"989f17017310a7cac0f9c4da3714e393edc5dc80","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lookout/deploydb/pulls/51/commits","review_comments_url":"https://api.github.com/repos/lookout/deploydb/pulls/51/comments","review_comment_url":"https://api.github.com/repos/lookout/deploydb/pulls/comments/{number}","comments_url":"https://api.github.com/repos/lookout/deploydb/issues/51/comments","statuses_url":"https://api.github.com/repos/lookout/deploydb/statuses/bc2a042bb8978faea82ec4fbd851cb0fa393e73f","head":{"label":"maheshkelkar:issues/43-service-api","ref":"issues/43-service-api","sha":"bc2a042bb8978faea82ec4fbd851cb0fa393e73f","user":{"login":"maheshkelkar","id":10839177,"avatar_url":"https://avatars.githubusercontent.com/u/10839177?v=3","gravatar_id":"","url":"https://api.github.com/users/maheshkelkar","html_url":"https://github.com/maheshkelkar","followers_url":"https://api.github.com/users/maheshkelkar/followers","following_url":"https://api.github.com/users/maheshkelkar/following{/other_user}","gists_url":"https://api.github.com/users/maheshkelkar/gists{/gist_id}","starred_url":"https://api.github.com/users/maheshkelkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maheshkelkar/subscriptions","organizations_url":"https://api.github.com/users/maheshkelkar/orgs","repos_url":"https://api.github.com/users/maheshkelkar/repos","events_url":"https://api.github.com/users/maheshkelkar/events{/privacy}","received_events_url":"https://api.github.com/users/maheshkelkar/received_events","type":"User","site_admin":false},"repo":{"id":30329363,"name":"deploydb","full_name":"maheshkelkar/deploydb","owner":{"login":"maheshkelkar","id":10839177,"avatar_url":"https://avatars.githubusercontent.com/u/10839177?v=3","gravatar_id":"","url":"https://api.github.com/users/maheshkelkar","html_url":"https://github.com/maheshkelkar","followers_url":"https://api.github.com/users/maheshkelkar/followers","following_url":"https://api.github.com/users/maheshkelkar/following{/other_user}","gists_url":"https://api.github.com/users/maheshkelkar/gists{/gist_id}","starred_url":"https://api.github.com/users/maheshkelkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maheshkelkar/subscriptions","organizations_url":"https://api.github.com/users/maheshkelkar/orgs","repos_url":"https://api.github.com/users/maheshkelkar/repos","events_url":"https://api.github.com/users/maheshkelkar/events{/privacy}","received_events_url":"https://api.github.com/users/maheshkelkar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/maheshkelkar/deploydb","description":"Your deployments: who, what, where and when.","fork":true,"url":"https://api.github.com/repos/maheshkelkar/deploydb","forks_url":"https://api.github.com/repos/maheshkelkar/deploydb/forks","keys_url":"https://api.github.com/repos/maheshkelkar/deploydb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maheshkelkar/deploydb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maheshkelkar/deploydb/teams","hooks_url":"https://api.github.com/repos/maheshkelkar/deploydb/hooks","issue_events_url":"https://api.github.com/repos/maheshkelkar/deploydb/issues/events{/number}","events_url":"https://api.github.com/repos/maheshkelkar/deploydb/events","assignees_url":"https://api.github.com/repos/maheshkelkar/deploydb/assignees{/user}","branches_url":"https://api.github.com/repos/maheshkelkar/deploydb/branches{/branch}","tags_url":"https://api.github.com/repos/maheshkelkar/deploydb/tags","blobs_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/refs{/sha}","trees_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maheshkelkar/deploydb/statuses/{sha}","languages_url":"https://api.github.com/repos/maheshkelkar/deploydb/languages","stargazers_url":"https://api.github.com/repos/maheshkelkar/deploydb/stargazers","contributors_url":"https://api.github.com/repos/maheshkelkar/deploydb/contributors","subscribers_url":"https://api.github.com/repos/maheshkelkar/deploydb/subscribers","subscription_url":"https://api.github.com/repos/maheshkelkar/deploydb/subscription","commits_url":"https://api.github.com/repos/maheshkelkar/deploydb/commits{/sha}","git_commits_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/commits{/sha}","comments_url":"https://api.github.com/repos/maheshkelkar/deploydb/comments{/number}","issue_comment_url":"https://api.github.com/repos/maheshkelkar/deploydb/issues/comments/{number}","contents_url":"https://api.github.com/repos/maheshkelkar/deploydb/contents/{+path}","compare_url":"https://api.github.com/repos/maheshkelkar/deploydb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maheshkelkar/deploydb/merges","archive_url":"https://api.github.com/repos/maheshkelkar/deploydb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maheshkelkar/deploydb/downloads","issues_url":"https://api.github.com/repos/maheshkelkar/deploydb/issues{/number}","pulls_url":"https://api.github.com/repos/maheshkelkar/deploydb/pulls{/number}","milestones_url":"https://api.github.com/repos/maheshkelkar/deploydb/milestones{/number}","notifications_url":"https://api.github.com/repos/maheshkelkar/deploydb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maheshkelkar/deploydb/labels{/name}","releases_url":"https://api.github.com/repos/maheshkelkar/deploydb/releases{/id}","created_at":"2015-02-05T00:36:28Z","updated_at":"2015-02-05T00:36:29Z","pushed_at":"2015-02-18T17:01:29Z","git_url":"git://github.com/maheshkelkar/deploydb.git","ssh_url":"git@github.com:maheshkelkar/deploydb.git","clone_url":"https://github.com/maheshkelkar/deploydb.git","svn_url":"https://github.com/maheshkelkar/deploydb","homepage":"http://hackers.lookout.com/deploydb/","size":562,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lookout:master","ref":"master","sha":"b34fe4d23c1c1dc649b345673c7b8a854b373e63","user":{"login":"lookout","id":47237,"avatar_url":"https://avatars.githubusercontent.com/u/47237?v=3","gravatar_id":"","url":"https://api.github.com/users/lookout","html_url":"https://github.com/lookout","followers_url":"https://api.github.com/users/lookout/followers","following_url":"https://api.github.com/users/lookout/following{/other_user}","gists_url":"https://api.github.com/users/lookout/gists{/gist_id}","starred_url":"https://api.github.com/users/lookout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lookout/subscriptions","organizations_url":"https://api.github.com/users/lookout/orgs","repos_url":"https://api.github.com/users/lookout/repos","events_url":"https://api.github.com/users/lookout/events{/privacy}","received_events_url":"https://api.github.com/users/lookout/received_events","type":"Organization","site_admin":false},"repo":{"id":28099382,"name":"deploydb","full_name":"lookout/deploydb","owner":{"login":"lookout","id":47237,"avatar_url":"https://avatars.githubusercontent.com/u/47237?v=3","gravatar_id":"","url":"https://api.github.com/users/lookout","html_url":"https://github.com/lookout","followers_url":"https://api.github.com/users/lookout/followers","following_url":"https://api.github.com/users/lookout/following{/other_user}","gists_url":"https://api.github.com/users/lookout/gists{/gist_id}","starred_url":"https://api.github.com/users/lookout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lookout/subscriptions","organizations_url":"https://api.github.com/users/lookout/orgs","repos_url":"https://api.github.com/users/lookout/repos","events_url":"https://api.github.com/users/lookout/events{/privacy}","received_events_url":"https://api.github.com/users/lookout/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lookout/deploydb","description":"Your deployments: who, what, where and when.","fork":false,"url":"https://api.github.com/repos/lookout/deploydb","forks_url":"https://api.github.com/repos/lookout/deploydb/forks","keys_url":"https://api.github.com/repos/lookout/deploydb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lookout/deploydb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lookout/deploydb/teams","hooks_url":"https://api.github.com/repos/lookout/deploydb/hooks","issue_events_url":"https://api.github.com/repos/lookout/deploydb/issues/events{/number}","events_url":"https://api.github.com/repos/lookout/deploydb/events","assignees_url":"https://api.github.com/repos/lookout/deploydb/assignees{/user}","branches_url":"https://api.github.com/repos/lookout/deploydb/branches{/branch}","tags_url":"https://api.github.com/repos/lookout/deploydb/tags","blobs_url":"https://api.github.com/repos/lookout/deploydb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lookout/deploydb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lookout/deploydb/git/refs{/sha}","trees_url":"https://api.github.com/repos/lookout/deploydb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lookout/deploydb/statuses/{sha}","languages_url":"https://api.github.com/repos/lookout/deploydb/languages","stargazers_url":"https://api.github.com/repos/lookout/deploydb/stargazers","contributors_url":"https://api.github.com/repos/lookout/deploydb/contributors","subscribers_url":"https://api.github.com/repos/lookout/deploydb/subscribers","subscription_url":"https://api.github.com/repos/lookout/deploydb/subscription","commits_url":"https://api.github.com/repos/lookout/deploydb/commits{/sha}","git_commits_url":"https://api.github.com/repos/lookout/deploydb/git/commits{/sha}","comments_url":"https://api.github.com/repos/lookout/deploydb/comments{/number}","issue_comment_url":"https://api.github.com/repos/lookout/deploydb/issues/comments/{number}","contents_url":"https://api.github.com/repos/lookout/deploydb/contents/{+path}","compare_url":"https://api.github.com/repos/lookout/deploydb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lookout/deploydb/merges","archive_url":"https://api.github.com/repos/lookout/deploydb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lookout/deploydb/downloads","issues_url":"https://api.github.com/repos/lookout/deploydb/issues{/number}","pulls_url":"https://api.github.com/repos/lookout/deploydb/pulls{/number}","milestones_url":"https://api.github.com/repos/lookout/deploydb/milestones{/number}","notifications_url":"https://api.github.com/repos/lookout/deploydb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lookout/deploydb/labels{/name}","releases_url":"https://api.github.com/repos/lookout/deploydb/releases{/id}","created_at":"2014-12-16T18:04:06Z","updated_at":"2015-02-17T23:39:03Z","pushed_at":"2015-02-17T23:39:09Z","git_url":"git://github.com/lookout/deploydb.git","ssh_url":"git@github.com:lookout/deploydb.git","clone_url":"https://github.com/lookout/deploydb.git","svn_url":"https://github.com/lookout/deploydb","homepage":"http://hackers.lookout.com/deploydb/","size":1031,"stargazers_count":33,"watchers_count":33,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":24,"forks":5,"open_issues":24,"watchers":33,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/51"},"html":{"href":"https://github.com/lookout/deploydb/pull/51"},"issue":{"href":"https://api.github.com/repos/lookout/deploydb/issues/51"},"comments":{"href":"https://api.github.com/repos/lookout/deploydb/issues/51/comments"},"review_comments":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/51/comments"},"review_comment":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/51/commits"},"statuses":{"href":"https://api.github.com/repos/lookout/deploydb/statuses/bc2a042bb8978faea82ec4fbd851cb0fa393e73f"}}}}