View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.responses;
17  
18  import lombok.EqualsAndHashCode;
19  import lombok.ToString;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  import java.io.Serializable;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Basic response information.
32   * <p>
33   * All non-list members of this class are allowed to be <code>null</code>.
34   * The lists are pre-created and can therefore never be <code>null</code>.
35   * @author Jens Riemschneider
36   */
37  @XmlAccessorType(XmlAccessType.FIELD)
38  @XmlType(name = "Response", propOrder = {"status", "errors"})
39  @XmlRootElement(name = "response")
40  @EqualsAndHashCode(doNotUseGetters = true)
41  @ToString(doNotUseGetters = true)
42  public class Response implements Serializable {
43      private static final long serialVersionUID = -6370795461214680771L;
44      
45      private Status status;
46      @XmlElement(name = "error")
47      private List<ErrorInfo> errors = new ArrayList<>();
48      
49      /**
50       * Constructs the response.
51       */
52      public Response() {}
53      
54      /**
55       * Constructs the response.
56       * @param status
57       *          the status of the request execution.
58       */
59      public Response(Status status) {        
60          this.status = status;
61      }
62      
63      /**
64       * Constructs an error response object with the data from an exception.
65       * @param throwable
66       *          the exception that occurred.
67       * @param defaultMetaDataError
68       *          the default error code for
69       *          {@link org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException}.
70       * @param defaultError
71       *          the default error code for any other exception.
72       * @param location
73       *          error location.
74       */
75      public Response(
76              Throwable throwable,
77              ErrorCode defaultMetaDataError,
78              ErrorCode defaultError,
79              String location)
80      {
81          this.status = Status.FAILURE;
82          this.errors.add(new ErrorInfo(throwable, defaultMetaDataError, defaultError, location));
83      }
84  
85      /**
86       * @return the status of the request execution.
87       */
88      public Status getStatus() {
89          return status;
90      }
91      
92      /**
93       * @param status
94       *          the status of the request execution.
95       */
96      public void setStatus(Status status) {
97          this.status = status;
98      }
99  
100     /**
101      * @return the list of errors that occurred.
102      */
103     public List<ErrorInfo> getErrors() {
104         return errors;
105     }
106 
107     /**
108      * @param errors
109      *          the list of errors that occurred.
110      */
111     public void setErrors(List<ErrorInfo> errors) {
112         this.errors = errors;
113     }
114 
115 
116 }