001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2024 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.fhirgw.model; 011 012import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; 013import org.hl7.fhir.instance.model.api.IBaseResource; 014 015import static java.util.Objects.nonNull; 016 017public class OperationResponse extends BaseResponse<OperationResponse> { 018 019 private IBaseResource myResponse; 020 021 private BaseServerResponseException myException; 022 023 /** 024 * Constructor - Create an empty object 025 */ 026 public OperationResponse() { 027 super(); 028 } 029 030 /** 031 * Copy constructor - Creates a shallow copy only 032 */ 033 public OperationResponse(OperationResponse theOperationResponse) { 034 super(theOperationResponse); 035 myResponse = theOperationResponse.getResponse(); 036 myException = theOperationResponse.getException(); 037 } 038 039 public OperationResponse(IBaseResource theResponse) { 040 myResponse = theResponse; 041 } 042 043 public OperationResponse(BaseServerResponseException theServerResponseException) { 044 myException = theServerResponseException; 045 } 046 047 /** 048 * Create a clone of this object using a <b>shallow copy only</b>. Values 049 * are copied by reference only, so things like Resources should only be 050 * modified if you are sure that the changes won't affect the value 051 * stored in cache. 052 */ 053 @Override 054 public OperationResponse clone() { 055 return new OperationResponse(this); 056 } 057 058 public IBaseResource getResponse() { 059 return myResponse; 060 } 061 062 public OperationResponse setResponse(IBaseResource theResponse) { 063 myResponse = theResponse; 064 return this; 065 } 066 067 public boolean hasResponse() { 068 return nonNull(myResponse); 069 } 070 071 public boolean hasException() { 072 return nonNull(myException); 073 } 074 075 public BaseServerResponseException getException() { 076 return myException; 077 } 078}