Rename restconf-nb-rfc8040 to restconf-nb
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / ResponseFactory.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
9
10 import java.net.URI;
11 import javax.ws.rs.core.Response;
12 import javax.ws.rs.core.Response.ResponseBuilder;
13 import javax.ws.rs.core.Response.Status;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.mdsal.common.api.CommitInfo;
16
17 final class ResponseFactory extends FutureDataFactory<CommitInfo> {
18     private ResponseBuilder responseBuilder;
19
20     ResponseFactory() {
21     }
22
23     ResponseFactory(final Status status) {
24         responseBuilder = Response.status(status);
25     }
26
27     ResponseFactory status(final Status status) {
28         responseBuilder = Response.status(status);
29         return this;
30     }
31
32     ResponseFactory location(final URI location) {
33         responseBuilder.location(location);
34         return this;
35     }
36
37     public @NonNull Response build() {
38         if (getFailureStatus()) {
39             responseBuilder = responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR);
40         }
41         return responseBuilder.build();
42     }
43 }