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