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