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