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;
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;
41 public class DcaeLocationService {
43 private Map<String, DcaeLocation> dcaeLocations = DatabaseClass.getDcaeLocations();
45 public Map<String, DcaeLocation> getDcaeLocations() {
49 public List<DcaeLocation> getAllDcaeLocations() {
50 return new ArrayList<DcaeLocation>(dcaeLocations.values());
53 public DcaeLocation getDcaeLocation( String name ) {
54 return dcaeLocations.get(name);
57 public DcaeLocation addDcaeLocation( DcaeLocation location ) {
58 location.setLastMod();
59 location.setStatus(DmaapObject_Status.VALID);
60 dcaeLocations.put( location.getDcaeLocationName(), location );
64 public DcaeLocation updateDcaeLocation( DcaeLocation location ) {
65 if ( location.getDcaeLocationName().isEmpty()) {
68 location.setLastMod();
69 dcaeLocations.put( location.getDcaeLocationName(), location );
73 public DcaeLocation removeDcaeLocation( String locationName ) {
74 return dcaeLocations.remove(locationName);
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();
86 return "aCentralLocation"; // default value that is obvious to see is wrong
89 public boolean isEdgeLocation(String aName) {
90 DcaeLocation loc = dcaeLocations.get(aName);
94 if ( ! loc.isCentral() ) {