{"action":"created","comment":{"url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/comments/66122946","id":66122946,"diff_hunk":"@@ -0,0 +1,144 @@\n+/**\n+ * Copyright 2015 DuraSpace, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.fcrepo.client;\n+\n+import static org.fcrepo.client.FedoraHeaderConstants.CONTENT_TYPE;\n+import static org.fcrepo.client.FedoraHeaderConstants.DIGEST;\n+import static org.fcrepo.client.FedoraHeaderConstants.IF_MATCH;\n+import static org.fcrepo.client.FedoraHeaderConstants.IF_UNMODIFIED_SINCE;\n+import static org.slf4j.LoggerFactory.getLogger;\n+\n+import java.io.File;\n+import java.io.FileInputStream;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.net.URI;\n+\n+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;\n+import org.apache.http.client.methods.HttpRequestBase;\n+import org.apache.http.entity.InputStreamEntity;\n+import org.slf4j.Logger;\n+\n+/**\n+ * Request builder which includes a body component\n+ * \n+ * @author bbpennel\n+ */\n+public abstract class BodyRequestBuilder<T extends BodyRequestBuilder<T>> extends\n+        RequestBuilder<BodyRequestBuilder<T>> {\n+\n+    private static final Logger LOGGER = getLogger(PatchBuilder.class);\n+\n+    protected InputStream bodyStream;\n+\n+    protected String contentType;\n+\n+    protected String digest;\n+\n+    protected String etag;\n+\n+    protected String unmodifiedSince;\n+\n+    /**\n+     * Instantiate builder\n+     * \n+     * @param uri uri request will be issued to\n+     * @param client the client\n+     */\n+    protected BodyRequestBuilder(final URI uri, final FcrepoClient client) {\n+        super(uri, client);\n+    }\n+\n+    protected abstract T self();\n+\n+    @Override\n+    protected void populateRequest(final HttpRequestBase request) throws FcrepoOperationFailedException {\n+        addBody((HttpEntityEnclosingRequestBase) request);\n+\n+        addIfUnmodifiedSince(request);\n+        addIfMatch(request);\n+\n+        addDigest(request);\n+\n+        LOGGER.debug(\"Fcrepo {} request headers: {}\", request.getMethod(), (Object[]) request.getAllHeaders());\n+    }\n+\n+    /**\n+     * Add a body to this request from a stream, with application/octet-stream as its content type\n+     * \n+     * @param stream InputStream of the content to be sent to the server\n+     * @return this builder\n+     */\n+    public T body(final InputStream stream) {\n+        return body(stream, null);\n+    }\n+\n+    /**\n+     * Add a body to this request as a stream with the given content type\n+     * \n+     * @param stream InputStream of the content to be sent to the server\n+     * @param contentType the Content-Type of the body\n+     * @return this builder\n+     */\n+    public T body(final InputStream stream, final String contentType) {\n+        this.bodyStream = stream;\n+        if (contentType == null) {\n+            this.contentType = \"application/octet-stream\";\n+        } else {\n+            this.contentType = contentType;\n+        }\n+\n+        return self();\n+    }\n+\n+    /**\n+     * Add the given file as the body for this request with the provided content type\n+     * \n+     * @param file File containing the content to be sent to the server\n+     * @param contentType the Content-Type of the body\n+     * @return this builder\n+     * @throws IOException when unable to stream the body file\n+     */\n+    public T body(final File file, final String contentType) throws IOException {\n+        return body(new FileInputStream(file), contentType);\n+    }\n+\n+    protected void addBody(final HttpEntityEnclosingRequestBase request) {","path":"src/main/java/org/fcrepo/client/BodyRequestBuilder.java","position":123,"original_position":120,"commit_id":"fc22d3d8f13658b47af746d1865befbbe4962cd2","original_commit_id":"1eec23ad3a720b36bf2f658204f729c0db06d3b7","user":{"login":"bbpennel","id":969810,"avatar_url":"https://avatars.githubusercontent.com/u/969810?v=3","gravatar_id":"","url":"https://api.github.com/users/bbpennel","html_url":"https://github.com/bbpennel","followers_url":"https://api.github.com/users/bbpennel/followers","following_url":"https://api.github.com/users/bbpennel/following{/other_user}","gists_url":"https://api.github.com/users/bbpennel/gists{/gist_id}","starred_url":"https://api.github.com/users/bbpennel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbpennel/subscriptions","organizations_url":"https://api.github.com/users/bbpennel/orgs","repos_url":"https://api.github.com/users/bbpennel/repos","events_url":"https://api.github.com/users/bbpennel/events{/privacy}","received_events_url":"https://api.github.com/users/bbpennel/received_events","type":"User","site_admin":false},"body":"After considering a couple ways of trying to make this fluent, I wonder if it would make more sense for the RequestBuilder objects to immediately instantiate a HttpRequestBase rather than requiring the use of addBlah methods later, and remove populateRequest:\r\n\r\n```java\r\npublic class PostBuilder... {\r\n    protected HttpRequestBuilder request;\r\n\r\n    public PostBuilder(...) {\r\n        super(...);\r\n        this.request = HttpMethods.POST.createRequest(targetUri);\r\n    }\r\n\r\n    public PostBuilder<T> slug(final String slug) {\r\n        if (slug != null) {\r\n            request.addHeader(SLUG, slug);\r\n        }\r\n        return self();\r\n    }\r\n}\r\n\r\npublic abstract class BodyRequestBuilder... {\r\n    public T body(final InputStream stream, final String contentType) {\r\n        if (bodyStream != null) {\r\n            request.setEntity(new InputStreamEntity(bodyStream));\r\n            request.addHeader(CONTENT_TYPE, contentType);\r\n        }\r\n        return self();\r\n    }\r\n```","created_at":"2016-06-07T18:08:44Z","updated_at":"2016-06-07T18:08:44Z","html_url":"https://github.com/fcrepo4-exts/fcrepo-java-client/pull/12#discussion_r66122946","pull_request_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/comments/66122946"},"html":{"href":"https://github.com/fcrepo4-exts/fcrepo-java-client/pull/12#discussion_r66122946"},"pull_request":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12","id":72763664,"html_url":"https://github.com/fcrepo4-exts/fcrepo-java-client/pull/12","diff_url":"https://github.com/fcrepo4-exts/fcrepo-java-client/pull/12.diff","patch_url":"https://github.com/fcrepo4-exts/fcrepo-java-client/pull/12.patch","issue_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues/12","number":12,"state":"open","locked":false,"title":"Fluent API","user":{"login":"bbpennel","id":969810,"avatar_url":"https://avatars.githubusercontent.com/u/969810?v=3","gravatar_id":"","url":"https://api.github.com/users/bbpennel","html_url":"https://github.com/bbpennel","followers_url":"https://api.github.com/users/bbpennel/followers","following_url":"https://api.github.com/users/bbpennel/following{/other_user}","gists_url":"https://api.github.com/users/bbpennel/gists{/gist_id}","starred_url":"https://api.github.com/users/bbpennel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbpennel/subscriptions","organizations_url":"https://api.github.com/users/bbpennel/orgs","repos_url":"https://api.github.com/users/bbpennel/repos","events_url":"https://api.github.com/users/bbpennel/events{/privacy}","received_events_url":"https://api.github.com/users/bbpennel/received_events","type":"User","site_admin":false},"body":"Changed client methods over to a fluent approach to adding headers and other request components.","created_at":"2016-06-06T19:28:14Z","updated_at":"2016-06-07T18:08:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"42ec14b809df1a70098ee9cdf6f53bf0e8caef62","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12/commits","review_comments_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12/comments","review_comment_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues/12/comments","statuses_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/statuses/fc22d3d8f13658b47af746d1865befbbe4962cd2","head":{"label":"bbpennel:fluent","ref":"fluent","sha":"fc22d3d8f13658b47af746d1865befbbe4962cd2","user":{"login":"bbpennel","id":969810,"avatar_url":"https://avatars.githubusercontent.com/u/969810?v=3","gravatar_id":"","url":"https://api.github.com/users/bbpennel","html_url":"https://github.com/bbpennel","followers_url":"https://api.github.com/users/bbpennel/followers","following_url":"https://api.github.com/users/bbpennel/following{/other_user}","gists_url":"https://api.github.com/users/bbpennel/gists{/gist_id}","starred_url":"https://api.github.com/users/bbpennel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbpennel/subscriptions","organizations_url":"https://api.github.com/users/bbpennel/orgs","repos_url":"https://api.github.com/users/bbpennel/repos","events_url":"https://api.github.com/users/bbpennel/events{/privacy}","received_events_url":"https://api.github.com/users/bbpennel/received_events","type":"User","site_admin":false},"repo":{"id":59321899,"name":"fcrepo-java-client","full_name":"bbpennel/fcrepo-java-client","owner":{"login":"bbpennel","id":969810,"avatar_url":"https://avatars.githubusercontent.com/u/969810?v=3","gravatar_id":"","url":"https://api.github.com/users/bbpennel","html_url":"https://github.com/bbpennel","followers_url":"https://api.github.com/users/bbpennel/followers","following_url":"https://api.github.com/users/bbpennel/following{/other_user}","gists_url":"https://api.github.com/users/bbpennel/gists{/gist_id}","starred_url":"https://api.github.com/users/bbpennel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbpennel/subscriptions","organizations_url":"https://api.github.com/users/bbpennel/orgs","repos_url":"https://api.github.com/users/bbpennel/repos","events_url":"https://api.github.com/users/bbpennel/events{/privacy}","received_events_url":"https://api.github.com/users/bbpennel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bbpennel/fcrepo-java-client","description":"A Fedora 4 client library written in Java.","fork":true,"url":"https://api.github.com/repos/bbpennel/fcrepo-java-client","forks_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/forks","keys_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/teams","hooks_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/hooks","issue_events_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/issues/events{/number}","events_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/events","assignees_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/assignees{/user}","branches_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/branches{/branch}","tags_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/tags","blobs_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/statuses/{sha}","languages_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/languages","stargazers_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/stargazers","contributors_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/contributors","subscribers_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/subscribers","subscription_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/subscription","commits_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/contents/{+path}","compare_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/merges","archive_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/downloads","issues_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/issues{/number}","pulls_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/pulls{/number}","milestones_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/milestones{/number}","notifications_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/labels{/name}","releases_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/releases{/id}","deployments_url":"https://api.github.com/repos/bbpennel/fcrepo-java-client/deployments","created_at":"2016-05-20T19:45:31Z","updated_at":"2016-05-20T19:45:32Z","pushed_at":"2016-06-07T17:43:35Z","git_url":"git://github.com/bbpennel/fcrepo-java-client.git","ssh_url":"git@github.com:bbpennel/fcrepo-java-client.git","clone_url":"https://github.com/bbpennel/fcrepo-java-client.git","svn_url":"https://github.com/bbpennel/fcrepo-java-client","homepage":null,"size":511,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"fcrepo4-exts:master","ref":"master","sha":"625b6141016f1f374def314417b5be3caa1556e4","user":{"login":"fcrepo4-exts","id":13263222,"avatar_url":"https://avatars.githubusercontent.com/u/13263222?v=3","gravatar_id":"","url":"https://api.github.com/users/fcrepo4-exts","html_url":"https://github.com/fcrepo4-exts","followers_url":"https://api.github.com/users/fcrepo4-exts/followers","following_url":"https://api.github.com/users/fcrepo4-exts/following{/other_user}","gists_url":"https://api.github.com/users/fcrepo4-exts/gists{/gist_id}","starred_url":"https://api.github.com/users/fcrepo4-exts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fcrepo4-exts/subscriptions","organizations_url":"https://api.github.com/users/fcrepo4-exts/orgs","repos_url":"https://api.github.com/users/fcrepo4-exts/repos","events_url":"https://api.github.com/users/fcrepo4-exts/events{/privacy}","received_events_url":"https://api.github.com/users/fcrepo4-exts/received_events","type":"Organization","site_admin":false},"repo":{"id":47417411,"name":"fcrepo-java-client","full_name":"fcrepo4-exts/fcrepo-java-client","owner":{"login":"fcrepo4-exts","id":13263222,"avatar_url":"https://avatars.githubusercontent.com/u/13263222?v=3","gravatar_id":"","url":"https://api.github.com/users/fcrepo4-exts","html_url":"https://github.com/fcrepo4-exts","followers_url":"https://api.github.com/users/fcrepo4-exts/followers","following_url":"https://api.github.com/users/fcrepo4-exts/following{/other_user}","gists_url":"https://api.github.com/users/fcrepo4-exts/gists{/gist_id}","starred_url":"https://api.github.com/users/fcrepo4-exts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fcrepo4-exts/subscriptions","organizations_url":"https://api.github.com/users/fcrepo4-exts/orgs","repos_url":"https://api.github.com/users/fcrepo4-exts/repos","events_url":"https://api.github.com/users/fcrepo4-exts/events{/privacy}","received_events_url":"https://api.github.com/users/fcrepo4-exts/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fcrepo4-exts/fcrepo-java-client","description":"A Fedora 4 client library written in Java.","fork":false,"url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client","forks_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/forks","keys_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/teams","hooks_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/hooks","issue_events_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues/events{/number}","events_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/events","assignees_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/assignees{/user}","branches_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/branches{/branch}","tags_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/tags","blobs_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/statuses/{sha}","languages_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/languages","stargazers_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/stargazers","contributors_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/contributors","subscribers_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/subscribers","subscription_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/subscription","commits_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/contents/{+path}","compare_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/merges","archive_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/downloads","issues_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues{/number}","pulls_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls{/number}","milestones_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/milestones{/number}","notifications_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/labels{/name}","releases_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/releases{/id}","deployments_url":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/deployments","created_at":"2015-12-04T16:59:23Z","updated_at":"2016-05-20T19:45:49Z","pushed_at":"2016-06-07T17:43:36Z","git_url":"git://github.com/fcrepo4-exts/fcrepo-java-client.git","ssh_url":"git@github.com:fcrepo4-exts/fcrepo-java-client.git","clone_url":"https://github.com/fcrepo4-exts/fcrepo-java-client.git","svn_url":"https://github.com/fcrepo4-exts/fcrepo-java-client","homepage":null,"size":479,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":6,"mirror_url":null,"open_issues_count":2,"forks":6,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12"},"html":{"href":"https://github.com/fcrepo4-exts/fcrepo-java-client/pull/12"},"issue":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues/12"},"comments":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/fcrepo4-exts/fcrepo-java-client/statuses/fc22d3d8f13658b47af746d1865befbbe4962cd2"}}}}
{"actor":{"display_login":"bbpennel"}}