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.util;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
29 import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass;
30 import org.onap.dmaap.dbcapi.model.DcaeLocation;
31 import org.onap.dmaap.dbcapi.model.MR_Client;
35 private HashMap<String, String> graph;
36 private boolean hasCentral;
38 private Map<String, DcaeLocation> locations = DatabaseClass.getDcaeLocations();
40 //TODO add to properties file
41 private static String centralDcaeLayerName = "central";
44 public Graph(HashMap<String, String> graph) {
49 public Graph( List<MR_Client> clients, boolean strict ) {
50 if ( clients == null )
52 this.graph = new HashMap<String, String>();
53 this.hasCentral = false;
54 for( MR_Client client: clients ) {
55 if ( ! strict || client.isStatusValid()) {
56 String loc = client.getDcaeLocationName();
57 for( String action : client.getAction() ){
58 DcaeLocation dcaeLoc = locations.get(loc);
59 if ( ! action.equals("view") && dcaeLoc != null ) {
60 graph.put(loc, dcaeLoc.getDcaeLayer());
63 String layer = graph.get(loc);
64 if ( layer != null && layer.contains(centralDcaeLayerName) ) {
65 this.hasCentral = true;
72 public HashMap<String, String> getGraph() {
76 public void setGraph(HashMap<String, String> graph) {
80 public String put( String key, String val ) {
81 return graph.put(key, val);
84 public String get( String key ) {
85 return graph.get(key);
88 public Collection<String> getKeys() {
89 return graph.keySet();
91 public boolean isHasCentral() {
94 public void setHasCentral(boolean hasCentral) {
95 this.hasCentral = hasCentral;
98 public String getCentralLoc() {
102 for( String loc : graph.keySet()) {
103 if ( graph.get(loc).contains(centralDcaeLayerName)) {