2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.dbcapi.service;
23 import java.util.ArrayList;
24 import java.util.List;
27 import org.onap.dmaap.dbcapi.database.DatabaseClass;
28 import org.onap.dmaap.dbcapi.model.DcaeLocation;
29 import org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status;
31 public class DcaeLocationService {
33 private Map<String, DcaeLocation> dcaeLocations = DatabaseClass.getDcaeLocations();
35 public Map<String, DcaeLocation> getDcaeLocations() {
39 public List<DcaeLocation> getAllDcaeLocations() {
40 return new ArrayList<DcaeLocation>(dcaeLocations.values());
43 public DcaeLocation getDcaeLocation( String name ) {
44 return dcaeLocations.get(name);
47 public DcaeLocation addDcaeLocation( DcaeLocation location ) {
48 location.setLastMod();
49 location.setStatus(DmaapObject_Status.VALID);
50 dcaeLocations.put( location.getDcaeLocationName(), location );
54 public DcaeLocation updateDcaeLocation( DcaeLocation location ) {
55 if ( location.getDcaeLocationName().isEmpty()) {
58 location.setLastMod();
59 dcaeLocations.put( location.getDcaeLocationName(), location );
63 public DcaeLocation removeDcaeLocation( String locationName ) {
64 return dcaeLocations.remove(locationName);
67 public String getCentralLocation() {
68 for( Map.Entry<String, DcaeLocation> entry: dcaeLocations.entrySet() ) {
69 DcaeLocation loc = entry.getValue();
70 if ( loc.isCentral() ) {
71 // use the name of the first central location we hit
72 return loc.getDcaeLocationName();
76 return "aCentralLocation"; // default value that is obvious to see is wrong
79 public boolean isEdgeLocation(String aName) {
80 DcaeLocation loc = dcaeLocations.get(aName);
84 if ( ! loc.isCentral() ) {