Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / backend / ResourceCreationResult.java
1 /*******************************************************************************
2  * Copyright (c) 2012-2013 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.backend;
13
14 import java.net.URI;
15
16 import javax.ws.rs.core.Response;
17 import javax.ws.rs.core.Response.Status;
18
19 import org.eclipse.winery.common.ids.GenericId;
20
21 public class ResourceCreationResult {
22         
23         private Status status = null;
24         private URI uri = null;
25         private GenericId id = null;
26         
27         
28         public ResourceCreationResult() {
29         }
30         
31         public ResourceCreationResult(Status status) {
32                 this.setStatus(status);
33         }
34
35         public ResourceCreationResult(Status status, URI uri, GenericId id) {
36                 this.setStatus(status);
37                 this.setId(id);
38                 this.setUri(uri);
39         }
40         
41         public Status getStatus() {
42                 return this.status;
43         }
44         
45         public void setStatus(Status status) {
46                 this.status = status;
47         }
48         
49         public URI getUri() {
50                 return this.uri;
51         }
52         
53         public void setUri(URI uri) {
54                 this.uri = uri;
55         }
56         
57         public GenericId getId() {
58                 return this.id;
59         }
60         
61         public void setId(GenericId id) {
62                 this.id = id;
63         }
64         
65         public boolean isSuccess() {
66                 return this.getStatus() == Status.CREATED;
67         }
68         
69         /**
70          * The possibly existing URI is used as location in Response.created
71          * 
72          * @return a Response created based on the contained data
73          */
74         public Response getResponse() {
75                 Response res;
76                 if (this.getUri() == null) {
77                         res = Response.status(this.getStatus()).build();
78                 } else {
79                         assert (this.getStatus().equals(Status.CREATED));
80                         res = Response.created(this.getUri()).build();
81                 }
82                 return res;
83         }
84 }