2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sa.searchdbabstraction.elasticsearch.dao;
25 import org.openecomp.sa.rest.ApiUtils;
27 public class ElasticSearchResultItem {
29 public static final String REQUEST_URL = "REQUEST_URL";
31 private ElasticSearchOperationStatus create;
32 private ElasticSearchOperationStatus index;
33 private ElasticSearchOperationStatus delete;
35 public ElasticSearchOperationStatus getCreate() {
39 public void setCreate(ElasticSearchOperationStatus index) {
43 public ElasticSearchOperationStatus getIndex() {
47 public void setIndex(ElasticSearchOperationStatus index) {
51 public ElasticSearchOperationStatus getDelete() {
55 public void setDelete(ElasticSearchOperationStatus delete) {
59 public String operationType() {
74 public ElasticSearchOperationStatus operationStatus() {
90 public String toJson() {
91 StringBuilder sb = new StringBuilder();
95 sb.append("\"operation\": \"").append(operationType()).append("\", ");
97 if (operationStatus().getAdditionalProperties().containsKey(REQUEST_URL)) {
98 sb.append("\"url\": \"").append(operationStatus().getAdditionalProperties()
99 .get(REQUEST_URL)).append("\", ");
101 sb.append("\"url\": \"").append(ApiUtils.buildDocumentUri(operationStatus()
102 .getIndex(), operationStatus().getId())).append("\", ");
105 // We don't want to include an etag field in the response in
106 // the case of a delete, since that would imply that the client
107 // could still access that version of the file in some manner
108 // (which we are not supporting).
109 if (!operationType().equals("delete")) {
110 sb.append("\"etag\": \"").append(operationStatus().getVersion()).append("\", ");
112 sb.append("\"status-code\": \"").append(operationStatus().getStatus()).append("\", ");
114 sb.append("\"status-message\": \"");
116 if ((operationStatus().getStatus() >= 200) && (operationStatus().getStatus() < 300)) {
119 // Sometimes the error object doesn't get populated, so check
120 // before we try to reference it...
121 if (operationStatus().getError() != null) {
122 sb.append(operationStatus().getError().getReason());
130 return sb.toString();
135 public String toString() {
136 StringBuilder sb = new StringBuilder();
138 sb.append("ElasticSearchItemStatus [");
139 if (create != null) {
140 sb.append("create " + create);
141 } else if (index != null) {
142 sb.append("index " + index);
143 } else if (delete != null) {
144 sb.append("delete " + index);
147 return sb.toString();