Change the header to SO
[so.git] / mso-api-handlers / mso-requests-db / src / main / java / org / openecomp / mso / requestsdb / MockRequestsDatabase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.requestsdb;
22
23
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 public class MockRequestsDatabase {
29         
30         private Map<String, InfraActiveRequests> activeRequests;
31         
32         public MockRequestsDatabase() {
33                 activeRequests = new HashMap<String, InfraActiveRequests>();
34         }
35         
36         public void addRecord(InfraActiveRequests record) {
37                 String serviceType = record.getServiceType();
38                 String serviceInstanceId = record.getServiceInstanceId();
39                 String key = serviceType + "::" + serviceInstanceId;
40                 activeRequests.put(key, record);
41         }
42         
43         public void deleteRecord(String serviceType, String serviceInstanceId) {
44                 String key = serviceType + "::" + serviceInstanceId;
45                 activeRequests.remove(key);
46         }
47         
48         public InfraActiveRequests getRecord(String serviceType, String serviceInstanceId) {
49                 String key = serviceType + "::" + serviceInstanceId;
50                 InfraActiveRequests record = activeRequests.get(key);
51                 return record;
52         }
53         
54         public InfraActiveRequests checkDuplicate(String serviceType, String serviceInstanceId) {
55                 return getRecord(serviceType, serviceInstanceId);
56         }
57         
58         public InfraActiveRequests checkRetry(String serviceType, String serviceInstanceId) {
59                 InfraActiveRequests record = getRecord(serviceType, serviceInstanceId);
60                 InfraActiveRequests returnRecord = null;
61                 if (record != null) {
62                         String requestAction = record.getRequestAction();
63                         if (requestAction == null || !requestAction.equals("GetLayer3ServiceDetailsRequest")) {
64                                 String status = record.getRequestStatus();
65                                 if (status != null && status.equals("COMPLETED")) {
66                                         return returnRecord = record;
67                                 }
68                         }
69                 }
70                 return returnRecord;
71         }
72 }