2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sa.searchdbabstraction.elasticsearch.dao;
23 import org.onap.aai.sa.rest.ApiUtils;
25 public class ElasticSearchResultItem {
27 public static final String REQUEST_URL = "REQUEST_URL";
29 private ElasticSearchOperationStatus create;
30 private ElasticSearchOperationStatus index;
31 private ElasticSearchOperationStatus delete;
33 public ElasticSearchOperationStatus getCreate() {
37 public void setCreate(ElasticSearchOperationStatus index) {
41 public ElasticSearchOperationStatus getIndex() {
45 public void setIndex(ElasticSearchOperationStatus index) {
49 public ElasticSearchOperationStatus getDelete() {
53 public void setDelete(ElasticSearchOperationStatus delete) {
57 public String operationType() {
72 public ElasticSearchOperationStatus operationStatus() {
88 public String toJson() {
89 StringBuilder sb = new StringBuilder();
93 sb.append("\"operation\": \"").append(operationType()).append("\", ");
95 if (operationStatus().getAdditionalProperties().containsKey(REQUEST_URL)) {
96 sb.append("\"url\": \"").append(operationStatus().getAdditionalProperties().get(REQUEST_URL))
99 sb.append("\"url\": \"")
100 .append(ApiUtils.buildDocumentUri(operationStatus().getIndex(), operationStatus().getId()))
104 // We don't want to include an etag field in the response in
105 // the case of a delete, since that would imply that the client
106 // could still access that version of the file in some manner
107 // (which we are not supporting).
108 if (!operationType().equals("delete")) {
109 sb.append("\"etag\": \"").append(operationStatus().getVersion()).append("\", ");
111 sb.append("\"status-code\": \"").append(operationStatus().getStatus()).append("\", ");
113 sb.append("\"status-message\": \"");
115 if (ApiUtils.isSuccessStatusCode(operationStatus().getStatus())) {
118 // Sometimes the error object doesn't get populated, so check
119 // before we try to reference it...
120 if (operationStatus().getError() != null) {
121 sb.append(operationStatus().getError().getReason());
129 return sb.toString();
134 public String toString() {
135 StringBuilder sb = new StringBuilder();
137 sb.append("ElasticSearchItemStatus [");
138 if (create != null) {
139 sb.append("create " + create);
140 } else if (index != null) {
141 sb.append("index " + index);
142 } else if (delete != null) {
143 sb.append("delete " + index);
146 return sb.toString();