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     * Patch defaults to a sparql update
052     */
053    public PatchBuilder body(final InputStream stream) {
054        return (PatchBuilder) super.body(stream, SPARQL_UPDATE);
055    }
056
057    @Override
058    public PatchBuilder ifMatch(final String etag) {
059        return (PatchBuilder) super.ifMatch(etag);
060    }
061
062    @Override
063    public PatchBuilder ifUnmodifiedSince(final String modified) {
064        return (PatchBuilder) super.ifUnmodifiedSince(modified);
065    }
066
067    @Deprecated
068    @Override
069    public PatchBuilder digest(final String digest) {
070        return (PatchBuilder) super.digest(digest);
071    }
072
073    @Override
074    public PatchBuilder digest(final String digest, final String alg) {
075        return (PatchBuilder) super.digest(digest, alg);
076    }
077
078    @Override
079    public PatchBuilder digestMd5(final String digest) {
080        return (PatchBuilder) super.digestMd5(digest);
081    }
082
083    @Override
084    public PatchBuilder digestSha1(final String digest) {
085        return (PatchBuilder) super.digestSha1(digest);
086    }
087
088    @Override
089    public PatchBuilder digestSha256(final String digest) {
090        return (PatchBuilder) super.digestSha256(digest);
091    }
092}