001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.client;
019
020import java.io.InputStream;
021import java.net.URI;
022
023import org.apache.http.client.methods.HttpRequestBase;
024
025/**
026 * Builds a PUT request for interacting with the Fedora HTTP API in order to modify the triples associated with a
027 * resource with SPARQL-Update.
028 *
029 * @author bbpennel
030 */
031public class PatchBuilder extends BodyRequestBuilder {
032
033    private static final String SPARQL_UPDATE = "application/sparql-update";
034
035    /**
036     * Instantiate builder
037     *
038     * @param uri uri of the resource this request is being made to
039     * @param client the client
040     */
041    public PatchBuilder(final URI uri, final FcrepoClient client) {
042        super(uri, client);
043    }
044
045    @Override
046    protected HttpRequestBase createRequest() {
047        return HttpMethods.PATCH.createRequest(targetUri);
048    }
049
050    /**
051     * Add a body to this request from a stream, with application/sparql-update as its content type
052     *
053     * @param stream InputStream of the content to be sent to the server
054     * @return this builder
055     */
056    @Override
057    public PatchBuilder body(final InputStream stream) {
058        return (PatchBuilder) super.body(stream, SPARQL_UPDATE);
059    }
060
061    @Override
062    public PatchBuilder body(final InputStream stream, final String contentType) {
063        return (PatchBuilder) super.body(stream, contentType);
064    }
065
066    @Override
067    public PatchBuilder ifMatch(final String etag) {
068        return (PatchBuilder) super.ifMatch(etag);
069    }
070
071    @Override
072    public PatchBuilder ifUnmodifiedSince(final String modified) {
073        return (PatchBuilder) super.ifUnmodifiedSince(modified);
074    }
075
076    @Override
077    public PatchBuilder ifStateToken(final String token) {
078        return (PatchBuilder) super.ifStateToken(token);
079    }
080
081    @Deprecated
082    @Override
083    public PatchBuilder digest(final String digest) {
084        return (PatchBuilder) super.digest(digest);
085    }
086
087    @Override
088    public PatchBuilder digest(final String digest, final String alg) {
089        return (PatchBuilder) super.digest(digest, alg);
090    }
091
092    @Override
093    public PatchBuilder digestMd5(final String digest) {
094        return (PatchBuilder) super.digestMd5(digest);
095    }
096
097    @Override
098    public PatchBuilder digestSha1(final String digest) {
099        return (PatchBuilder) super.digestSha1(digest);
100    }
101
102    @Override
103    public PatchBuilder digestSha256(final String digest) {
104        return (PatchBuilder) super.digestSha256(digest);
105    }
106
107    @Override
108    public PatchBuilder addHeader(final String name, final String value) {
109        return (PatchBuilder) super.addHeader(name, value);
110    }
111
112    @Override
113    public PatchBuilder addLinkHeader(final FcrepoLink linkHeader) {
114        return (PatchBuilder) super.addLinkHeader(linkHeader);
115    }
116}