e86d7bd049f381146b0b6cd6a41f90f0c35fb33a
[aai/search-data-service.git] / src / main / java / org / onap / aai / sa / rest / BulkRequest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.sa.rest;
22
23
24 /**
25  * This class represents a single instance of a request from the search client
26  * that would be part of a bundle of such operations sent in a single bulk
27  * request.
28  */
29 public class BulkRequest {
30
31   public enum OperationType {
32     CREATE,
33     UPDATE,
34     DELETE
35   }
36
37   private BulkOperation create;
38   private BulkOperation update;
39   private BulkOperation delete;
40
41   public BulkOperation getCreate() {
42     return create;
43   }
44
45   public void setCreate(BulkOperation create) {
46     this.create = create;
47   }
48
49   public BulkOperation getUpdate() {
50     return update;
51   }
52
53   public void setUpdate(BulkOperation update) {
54     this.update = update;
55   }
56
57   public BulkOperation getDelete() {
58     return delete;
59   }
60
61   public void setDelete(BulkOperation delete) {
62     this.delete = delete;
63   }
64
65   public OperationType getOperationType() {
66
67     if (create != null) {
68       return OperationType.CREATE;
69     } else if (update != null) {
70       return OperationType.UPDATE;
71     } else if (delete != null) {
72       return OperationType.DELETE;
73     } else {
74       return null;
75     }
76   }
77
78   public BulkOperation getOperation() {
79     if (create != null) {
80       return create;
81     } else if (update != null) {
82       return update;
83     } else if (delete != null) {
84       return delete;
85     } else {
86       return null;
87     }
88   }
89
90   public String getIndex() {
91     return ApiUtils.extractIndexFromUri(getOperation().getMetaData().getUrl());
92   }
93
94   public String getId() {
95     return ApiUtils.extractIdFromUri(getOperation().getMetaData().getUrl());
96   }
97
98   @Override
99   public String toString() {
100
101     if (create != null) {
102       return "create: [" + create.toString() + "]\n";
103     } else if (update != null) {
104       return "update: [" + update.toString() + "]\n";
105     } else if (delete != null) {
106       return "delete: [" + delete.toString() + "]\n";
107     } else {
108       return "UNDEFINED";
109     }
110   }
111 }