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.openecomp.sdc.validation.tos;
23 import org.apache.commons.collections4.MapUtils;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
31 public class ContrailResourcesMappingTo {
32 private Map<String, List<String>> contrailV1Resources;
33 private Map<String, List<String>> contrailV2Resources;
36 * Add ContrailV1Resource.
38 * @param fileName the file name
39 * @param resourceName the resource name
41 public void addContrailV1Resource(String fileName, String resourceName) {
42 if (MapUtils.isEmpty(contrailV1Resources)) {
43 contrailV1Resources = new HashMap<>();
45 contrailV1Resources.putIfAbsent(fileName, new ArrayList<>());
46 contrailV1Resources.get(fileName).add(resourceName);
50 * Add ContrailV1Resource.
52 * @param fileName the file name
53 * @param resourceName the resource name
55 public void addContrailV2Resource(String fileName, String resourceName) {
56 if (MapUtils.isEmpty(contrailV2Resources)) {
57 contrailV2Resources = new HashMap<>();
59 contrailV2Resources.putIfAbsent(fileName, new ArrayList<>());
60 contrailV2Resources.get(fileName).add(resourceName);
63 public void addAll(ContrailResourcesMappingTo contrailResourcesMappingTo) {
64 addContrailV1Resources(contrailResourcesMappingTo.getContrailV1Resources());
65 addContrailV2Resources(contrailResourcesMappingTo.getContrailV2Resources());
68 public String fetchContrailV1Resources() {
69 return fetchContrailResources(contrailV1Resources);
72 public String fetchContrailV2Resources() {
73 return fetchContrailResources(contrailV2Resources);
76 private void addContrailV1Resources(Map<String, List<String>> contrailV1Resources) {
77 if (!MapUtils.isEmpty(contrailV1Resources)) {
78 for (Map.Entry<String, List<String>> fileResourcesEntry : contrailV1Resources.entrySet()) {
79 for (String resourceName : fileResourcesEntry.getValue()) {
80 this.addContrailV1Resource(fileResourcesEntry.getKey(), resourceName);
86 private void addContrailV2Resources(Map<String, List<String>> contrailV2Resources) {
87 if (!MapUtils.isEmpty(contrailV2Resources)) {
88 for (Map.Entry<String, List<String>> fileResourcesEntry : contrailV2Resources.entrySet()) {
89 for (String resourceName : fileResourcesEntry.getValue()) {
90 this.addContrailV2Resource(fileResourcesEntry.getKey(), resourceName);
96 private String fetchContrailResources(Map<String, List<String>> contrailResources) {
97 StringBuilder buffer = new StringBuilder();
98 if (MapUtils.isEmpty(contrailResources)) {
101 for (Map.Entry<String, List<String>> fileResourcesEntry : contrailResources.entrySet()) {
102 buffer.append(" file '").append(fileResourcesEntry.getKey()).append("' , resources :");
103 for (String resourceName : fileResourcesEntry.getValue()) {
104 buffer.append("'").append(resourceName).append("', ");
107 buffer.deleteCharAt(buffer.lastIndexOf(","));
108 return buffer.toString();
111 public Map<String, List<String>> getContrailV1Resources() {
112 return contrailV1Resources;
115 public Map<String, List<String>> getContrailV2Resources() {
116 return contrailV2Resources;