23d44d16bf9c7723883a86e859c94fc68318bcb7
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / service / DcaeLocationService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
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.onap.dmaap.dbcapi.service;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30
31
32
33
34
35
36
37 import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass;
38 import org.onap.dmaap.dbcapi.model.DcaeLocation;
39 import org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status;
40
41 public class DcaeLocationService {
42         
43         private Map<String, DcaeLocation> dcaeLocations = DatabaseClass.getDcaeLocations();
44         
45         public Map<String, DcaeLocation> getDcaeLocations() {
46                 return dcaeLocations;
47         }
48         
49         public List<DcaeLocation> getAllDcaeLocations() {
50                 return new ArrayList<DcaeLocation>(dcaeLocations.values());
51         }
52         
53         public DcaeLocation getDcaeLocation( String name ) {
54                 return dcaeLocations.get(name);
55         }
56
57         public DcaeLocation addDcaeLocation( DcaeLocation location ) {
58                 location.setLastMod();
59                 location.setStatus(DmaapObject_Status.VALID);
60                 dcaeLocations.put( location.getDcaeLocationName(), location );
61                 return location;
62         }
63         
64         public DcaeLocation updateDcaeLocation( DcaeLocation location ) {
65                 if ( location.getDcaeLocationName().isEmpty()) {
66                         return null;
67                 }
68                 location.setLastMod();
69                 dcaeLocations.put( location.getDcaeLocationName(), location );
70                 return location;
71         }
72         
73         public DcaeLocation removeDcaeLocation( String locationName ) {
74                 return dcaeLocations.remove(locationName);
75         }
76
77         public String getCentralLocation() {
78                 for( Map.Entry<String, DcaeLocation> entry: dcaeLocations.entrySet() ) {
79                         DcaeLocation loc = entry.getValue();
80                         if ( loc.isCentral() ) {
81                                 // use the name of the first central location we hit
82                                 return loc.getDcaeLocationName();
83                         }
84                         
85                 }
86                 return "aCentralLocation";  // default value that is obvious to see is wrong
87         }       
88         
89         public boolean isEdgeLocation(String aName) {
90                 DcaeLocation loc = dcaeLocations.get(aName);
91                 if ( loc == null ) {
92                         return false;
93                 }
94                 if ( ! loc.isCentral() ) {
95                                 return true;
96                 }
97                 return false;
98         }       
99
100 }