/*- * ============LICENSE_START======================================================= * appc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.policy.appc; import com.google.gson.annotations.SerializedName; import java.io.Serializable; import java.util.HashMap; import java.util.Map; public class Response implements Serializable { private static final long serialVersionUID = 434953706339865151L; @SerializedName("CommonHeader") private CommonHeader commonHeader; @SerializedName("Status") private ResponseStatus status = new ResponseStatus(); @SerializedName("Payload") private HashMap payload = new HashMap<>(); public Response() { } /** * Construct an instance from an existing instance. * * @param request the existing instance */ public Response(Request request) { if (request.getCommonHeader() != null) { this.commonHeader = new CommonHeader(request.getCommonHeader()); } if (request.getPayload() != null) { this.payload.putAll(request.getPayload()); } } public CommonHeader getCommonHeader() { return commonHeader; } public void setCommonHeader(CommonHeader commonHeader) { this.commonHeader = commonHeader; } public ResponseStatus getStatus() { return status; } public void setStatus(ResponseStatus status) { this.status = status; } public Map getPayload() { return payload; } public void setPayload(Map payload) { this.payload = new HashMap<>(payload); } @Override public String toString() { return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); result = prime * result + ((payload == null) ? 0 : payload.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Response other = (Response) obj; if (commonHeader == null) { if (other.commonHeader != null) { return false; } } else if (!commonHeader.equals(other.commonHeader)) { return false; } if (payload == null) { if (other.payload != null) { return false; } } else if (!payload.equals(other.payload)) { return false; } if (status == null) { if (other.status != null) { return false; } } else if (!status.equals(other.status)) { return false; } return true; } }