{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/53181798","id":53181798,"diff_hunk":"@@ -0,0 +1,141 @@\n+/**\n+ * Copyright (c) Codice Foundation\n+ * <p/>\n+ * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser\n+ * General Public License as published by the Free Software Foundation, either version 3 of the\n+ * License, or any later version.\n+ * <p/>\n+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\n+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details. A copy of the GNU Lesser General Public License\n+ * is distributed along with this program and can be found at\n+ * <http://www.gnu.org/licenses/lgpl.html>.\n+ */\n+\n+package org.codice.ddf.persistence.attributes.internal;\n+\n+import java.util.List;\n+import java.util.Map;\n+import java.util.concurrent.locks.ReadWriteLock;\n+import java.util.concurrent.locks.ReentrantReadWriteLock;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.codice.ddf.persistence.PersistenceException;\n+import org.codice.ddf.persistence.PersistentItem;\n+import org.codice.ddf.persistence.PersistentStore;\n+import org.codice.ddf.persistence.attributes.AttributesStore;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+public class AttributesStoreImpl implements AttributesStore {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(AttributesStoreImpl.class);\n+\n+    private PersistentStore persistentStore;\n+\n+    private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();\n+\n+    private static final String EMPTY_USERNAME_ERROR = \"Empty username specified\";\n+\n+    public AttributesStoreImpl(PersistentStore persistentStore) {\n+        this.persistentStore = persistentStore;\n+    }\n+\n+    @Override\n+    public long getCurrentDataUsageByUser(final String username) throws PersistenceException {\n+        long currentDataUsage = 0L;\n+\n+        if (StringUtils.isEmpty(username)) {\n+            throw new PersistenceException(EMPTY_USERNAME_ERROR);\n+        }\n+\n+        try {\n+            readWriteLock.readLock()\n+                    .lock();\n+            currentDataUsage = getCurrentDataUsageByUserNoLock(username);\n+        } finally {\n+            readWriteLock.readLock()\n+                    .unlock();\n+        }\n+\n+        return currentDataUsage;\n+    }\n+\n+    @Override\n+    public void updateUserDataUsage(final String username, final long newDataUsage)\n+            throws PersistenceException {\n+        if (StringUtils.isEmpty(username)) {\n+            throw new PersistenceException(EMPTY_USERNAME_ERROR);\n+        }\n+\n+        if (newDataUsage > 0) {\n+            try {\n+                readWriteLock.writeLock()\n+                        .lock();\n+                long dataUsage = getCurrentDataUsageByUserNoLock(username);\n+                dataUsage += newDataUsage;\n+\n+                // add to usage and store\n+                PersistentItem item = new PersistentItem();\n+                item.addIdProperty(username);\n+                item.addProperty(USER_KEY, username);\n+                item.addProperty(DATA_USAGE_KEY, dataUsage);\n+\n+                LOGGER.debug(\"Updating user {} data usage to {}\", username, dataUsage);\n+                persistentStore.add(PersistentStore.USER_ATTRIBUTE_TYPE, item);\n+            } finally {\n+                readWriteLock.writeLock()\n+                        .unlock();\n+\n+            }\n+        }\n+    }\n+\n+    @Override\n+    public void setDataUsage(final String username, final long dataUsage)\n+            throws PersistenceException {\n+\n+        if (StringUtils.isEmpty(username)) {\n+            throw new PersistenceException(EMPTY_USERNAME_ERROR);\n+        }\n+        if (dataUsage >= 0) {\n+            try {\n+                readWriteLock.writeLock()\n+                        .lock();\n+\n+                // add to usage and store\n+                PersistentItem item = new PersistentItem();","path":"platform/persistence/platform-persistence-core-attributes-impl/src/main/java/org/codice/ddf/persistence/attributes/internal/AttributesStoreImpl.java","position":107,"original_position":107,"commit_id":"ecd42af7c697eb2028c7fae0999a6d9981e8f5b0","original_commit_id":"ecd42af7c697eb2028c7fae0999a6d9981e8f5b0","user":{"login":"jrnorth","id":4495447,"avatar_url":"https://avatars.githubusercontent.com/u/4495447?v=3","gravatar_id":"","url":"https://api.github.com/users/jrnorth","html_url":"https://github.com/jrnorth","followers_url":"https://api.github.com/users/jrnorth/followers","following_url":"https://api.github.com/users/jrnorth/following{/other_user}","gists_url":"https://api.github.com/users/jrnorth/gists{/gist_id}","starred_url":"https://api.github.com/users/jrnorth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrnorth/subscriptions","organizations_url":"https://api.github.com/users/jrnorth/orgs","repos_url":"https://api.github.com/users/jrnorth/repos","events_url":"https://api.github.com/users/jrnorth/events{/privacy}","received_events_url":"https://api.github.com/users/jrnorth/received_events","type":"User","site_admin":false},"body":"This code is identical to the code in `updateUserDataUsage()`.","created_at":"2016-02-17T15:41:19Z","updated_at":"2016-02-17T15:41:19Z","html_url":"https://github.com/codice/ddf/pull/545#discussion_r53181798","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/545","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/53181798"},"html":{"href":"https://github.com/codice/ddf/pull/545#discussion_r53181798"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/545"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/545","id":59646429,"html_url":"https://github.com/codice/ddf/pull/545","diff_url":"https://github.com/codice/ddf/pull/545.diff","patch_url":"https://github.com/codice/ddf/pull/545.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/545","number":545,"state":"open","locked":false,"title":"DDF-1852: Added data usage tracking on resource requests","user":{"login":"jlcsmith","id":4503545,"avatar_url":"https://avatars.githubusercontent.com/u/4503545?v=3","gravatar_id":"","url":"https://api.github.com/users/jlcsmith","html_url":"https://github.com/jlcsmith","followers_url":"https://api.github.com/users/jlcsmith/followers","following_url":"https://api.github.com/users/jlcsmith/following{/other_user}","gists_url":"https://api.github.com/users/jlcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/jlcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlcsmith/subscriptions","organizations_url":"https://api.github.com/users/jlcsmith/orgs","repos_url":"https://api.github.com/users/jlcsmith/repos","events_url":"https://api.github.com/users/jlcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/jlcsmith/received_events","type":"User","site_admin":false},"body":"- Added a PreResourcePlugin to keep track of data usage per user\r\n- Added a new solr core for user attributes\r\n- Added persistent store interface for attributes\r\n\r\n@jrnorth ","created_at":"2016-02-17T13:53:40Z","updated_at":"2016-02-17T15:41:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"201795fbc84993351129a8f053f404595f51ab90","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/545/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/545/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/545/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/ecd42af7c697eb2028c7fae0999a6d9981e8f5b0","head":{"label":"jlcsmith:DDF-1852-resource-tracking","ref":"DDF-1852-resource-tracking","sha":"ecd42af7c697eb2028c7fae0999a6d9981e8f5b0","user":{"login":"jlcsmith","id":4503545,"avatar_url":"https://avatars.githubusercontent.com/u/4503545?v=3","gravatar_id":"","url":"https://api.github.com/users/jlcsmith","html_url":"https://github.com/jlcsmith","followers_url":"https://api.github.com/users/jlcsmith/followers","following_url":"https://api.github.com/users/jlcsmith/following{/other_user}","gists_url":"https://api.github.com/users/jlcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/jlcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlcsmith/subscriptions","organizations_url":"https://api.github.com/users/jlcsmith/orgs","repos_url":"https://api.github.com/users/jlcsmith/repos","events_url":"https://api.github.com/users/jlcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/jlcsmith/received_events","type":"User","site_admin":false},"repo":{"id":40322675,"name":"ddf","full_name":"jlcsmith/ddf","owner":{"login":"jlcsmith","id":4503545,"avatar_url":"https://avatars.githubusercontent.com/u/4503545?v=3","gravatar_id":"","url":"https://api.github.com/users/jlcsmith","html_url":"https://github.com/jlcsmith","followers_url":"https://api.github.com/users/jlcsmith/followers","following_url":"https://api.github.com/users/jlcsmith/following{/other_user}","gists_url":"https://api.github.com/users/jlcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/jlcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlcsmith/subscriptions","organizations_url":"https://api.github.com/users/jlcsmith/orgs","repos_url":"https://api.github.com/users/jlcsmith/repos","events_url":"https://api.github.com/users/jlcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/jlcsmith/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jlcsmith/ddf","description":"The Distributed Data Framework - Distribution, SDK, and Test","fork":true,"url":"https://api.github.com/repos/jlcsmith/ddf","forks_url":"https://api.github.com/repos/jlcsmith/ddf/forks","keys_url":"https://api.github.com/repos/jlcsmith/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jlcsmith/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jlcsmith/ddf/teams","hooks_url":"https://api.github.com/repos/jlcsmith/ddf/hooks","issue_events_url":"https://api.github.com/repos/jlcsmith/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/jlcsmith/ddf/events","assignees_url":"https://api.github.com/repos/jlcsmith/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/jlcsmith/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/jlcsmith/ddf/tags","blobs_url":"https://api.github.com/repos/jlcsmith/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jlcsmith/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jlcsmith/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/jlcsmith/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jlcsmith/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/jlcsmith/ddf/languages","stargazers_url":"https://api.github.com/repos/jlcsmith/ddf/stargazers","contributors_url":"https://api.github.com/repos/jlcsmith/ddf/contributors","subscribers_url":"https://api.github.com/repos/jlcsmith/ddf/subscribers","subscription_url":"https://api.github.com/repos/jlcsmith/ddf/subscription","commits_url":"https://api.github.com/repos/jlcsmith/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/jlcsmith/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/jlcsmith/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/jlcsmith/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/jlcsmith/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/jlcsmith/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jlcsmith/ddf/merges","archive_url":"https://api.github.com/repos/jlcsmith/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jlcsmith/ddf/downloads","issues_url":"https://api.github.com/repos/jlcsmith/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/jlcsmith/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/jlcsmith/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/jlcsmith/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jlcsmith/ddf/labels{/name}","releases_url":"https://api.github.com/repos/jlcsmith/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/jlcsmith/ddf/deployments","created_at":"2015-08-06T19:17:14Z","updated_at":"2016-02-08T21:38:24Z","pushed_at":"2016-02-16T22:45:59Z","git_url":"git://github.com/jlcsmith/ddf.git","ssh_url":"git@github.com:jlcsmith/ddf.git","clone_url":"https://github.com/jlcsmith/ddf.git","svn_url":"https://github.com/jlcsmith/ddf","homepage":"","size":131064,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codice:master","ref":"master","sha":"d1583084aa7a2abe147dd4e929238e245d8d4d38","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15173563,"name":"ddf","full_name":"codice/ddf","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf","description":"The Distributed Data Framework - Federated Open Geospatial Consortium (OGC) filter powered metadata catalog with SAML Web SSO secured container","fork":false,"url":"https://api.github.com/repos/codice/ddf","forks_url":"https://api.github.com/repos/codice/ddf/forks","keys_url":"https://api.github.com/repos/codice/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf/teams","hooks_url":"https://api.github.com/repos/codice/ddf/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf/events","assignees_url":"https://api.github.com/repos/codice/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf/tags","blobs_url":"https://api.github.com/repos/codice/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf/languages","stargazers_url":"https://api.github.com/repos/codice/ddf/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf/subscription","commits_url":"https://api.github.com/repos/codice/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf/merges","archive_url":"https://api.github.com/repos/codice/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf/downloads","issues_url":"https://api.github.com/repos/codice/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/codice/ddf/deployments","created_at":"2013-12-13T20:38:28Z","updated_at":"2016-02-02T16:34:27Z","pushed_at":"2016-02-17T15:29:43Z","git_url":"git://github.com/codice/ddf.git","ssh_url":"git@github.com:codice/ddf.git","clone_url":"https://github.com/codice/ddf.git","svn_url":"https://github.com/codice/ddf","homepage":"","size":138457,"stargazers_count":32,"watchers_count":32,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":69,"mirror_url":null,"open_issues_count":19,"forks":69,"open_issues":19,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/545"},"html":{"href":"https://github.com/codice/ddf/pull/545"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/545"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/545/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/545/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/545/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/ecd42af7c697eb2028c7fae0999a6d9981e8f5b0"}}}}