2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License ati
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.openecomp.sa.searchdbabstraction.elasticsearch.dao;
27 import org.openecomp.sa.rest.ApiUtils;
29 public class ElasticSearchResultItem {
31 public static final String REQUEST_URL = "REQUEST_URL";
33 private ElasticSearchOperationStatus create;
34 private ElasticSearchOperationStatus index;
35 private ElasticSearchOperationStatus delete;
37 public ElasticSearchOperationStatus getCreate() {
41 public void setCreate(ElasticSearchOperationStatus index) {
45 public ElasticSearchOperationStatus getIndex() {
49 public void setIndex(ElasticSearchOperationStatus index) {
53 public ElasticSearchOperationStatus getDelete() {
57 public void setDelete(ElasticSearchOperationStatus delete) {
61 public String operationType() {
76 public ElasticSearchOperationStatus operationStatus() {
92 public String toJson() {
93 StringBuilder sb = new StringBuilder();
97 sb.append("\"operation\": \"").append(operationType()).append("\", ");
99 if (operationStatus().getAdditionalProperties().containsKey(REQUEST_URL)) {
100 sb.append("\"url\": \"").append(operationStatus().getAdditionalProperties()
101 .get(REQUEST_URL)).append("\", ");
103 sb.append("\"url\": \"").append(ApiUtils.buildDocumentUri(operationStatus()
104 .getIndex(), operationStatus().getId())).append("\", ");
107 // We don't want to include an etag field in the response in
108 // the case of a delete, since that would imply that the client
109 // could still access that version of the file in some manner
110 // (which we are not supporting).
111 if (!operationType().equals("delete")) {
112 sb.append("\"etag\": \"").append(operationStatus().getVersion()).append("\", ");
114 sb.append("\"status-code\": \"").append(operationStatus().getStatus()).append("\", ");
116 sb.append("\"status-message\": \"");
118 if ((operationStatus().getStatus() >= 200) && (operationStatus().getStatus() < 300)) {
121 // Sometimes the error object doesn't get populated, so check
122 // before we try to reference it...
123 if (operationStatus().getError() != null) {
124 sb.append(operationStatus().getError().getReason());
132 return sb.toString();
137 public String toString() {
138 StringBuilder sb = new StringBuilder();
140 sb.append("ElasticSearchItemStatus [");
141 if (create != null) {
142 sb.append("create " + create);
143 } else if (index != null) {
144 sb.append("index " + index);
145 } else if (delete != null) {
146 sb.append("delete " + index);
149 return sb.toString();