001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.fcrepo.client;
018
019import java.io.InputStream;
020import java.net.URI;
021
022import org.apache.http.client.methods.HttpRequestBase;
023
024/**
025 * Builds a PUT request for interacting with the Fedora HTTP API in order to modify the triples associated with a
026 * resource with SPARQL-Update.
027 * 
028 * @author bbpennel
029 */
030public class PatchBuilder extends BodyRequestBuilder {
031
032    private static final String SPARQL_UPDATE = "application/sparql-update";
033
034    /**
035     * Instantiate builder
036     * 
037     * @param uri uri of the resource this request is being made to
038     * @param client the client
039     */
040    public PatchBuilder(final URI uri, final FcrepoClient client) {
041        super(uri, client);
042    }
043
044    @Override
045    protected HttpRequestBase createRequest() {
046        return HttpMethods.PATCH.createRequest(targetUri);
047    }
048
049    /**
050     * Patch defaults to a sparql update
051     */
052    public PatchBuilder body(final InputStream stream) {
053        return (PatchBuilder) super.body(stream, SPARQL_UPDATE);
054    }
055
056    @Override
057    public PatchBuilder ifMatch(final String etag) {
058        return (PatchBuilder) super.ifMatch(etag);
059    }
060
061    @Override
062    public PatchBuilder ifUnmodifiedSince(final String modified) {
063        return (PatchBuilder) super.ifUnmodifiedSince(modified);
064    }
065}