2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.model;
26 import org.onap.clamp.clds.dao.CldsDao;
27 import org.onap.clamp.clds.service.CldsService;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import javax.ws.rs.NotAuthorizedException;
32 import java.io.Serializable;
33 import java.util.ArrayList;
34 import java.util.List;
36 public class CldsServiceData implements Serializable {
37 private static final Logger logger = LoggerFactory.getLogger(CldsServiceData.class);
39 private static final long serialVersionUID = 1L;
41 private String serviceInvariantUUID;
42 private String serviceUUID;
43 private Long ageOfRecord;
44 private List<CldsVfData> cldsVfs;
46 public String getServiceInvariantUUID() {
47 return serviceInvariantUUID;
50 public void setServiceInvariantUUID(String serviceInvariantUUID) {
51 this.serviceInvariantUUID = serviceInvariantUUID;
54 public List<CldsVfData> getCldsVfs() {
58 public void setCldsVfs(List<CldsVfData> cldsVfs) {
59 this.cldsVfs = cldsVfs;
62 public String getServiceUUID() {
66 public void setServiceUUID(String serviceUUID) {
67 this.serviceUUID = serviceUUID;
70 public CldsServiceData getCldsServiceCache(CldsDao cldsDao, String invariantServiceUUID) throws Exception {
71 return cldsDao.getCldsServiceCache(invariantServiceUUID);
74 public void setCldsServiceCache(CldsDao cldsDao, CldsDBServiceCache cldsDBServiceCache) throws Exception {
75 cldsDao.setCldsServiceCache(cldsDBServiceCache);
78 public Long getAgeOfRecord() {
82 public void setAgeOfRecord(Long ageOfRecord) {
83 this.ageOfRecord = ageOfRecord;
87 * Filter out any VFs that the user is not authorized for.
88 * Use the CldsService to determine if the user is authorized for a VF.
92 public void filterVfs(CldsService svc) {
93 List<CldsVfData> filteredCldsVfs = new ArrayList<>();
94 if (cldsVfs == null) {
95 logger.debug("cldsVfs == null");
97 for (CldsVfData vf : cldsVfs) {
98 // if user is authorized for the VF then add it to the filtered list
100 if (svc.isAuthorizedForVf(vf.getVfInvariantResourceUUID())) {
101 filteredCldsVfs.add(vf);
103 } catch (NotAuthorizedException e) {
104 logger.debug("user not authorized for {}", vf.getVfInvariantResourceUUID());
105 // when not NotAuthorizedException - don't add to filteredCldsVfs list
109 // new filtered list replaces the list of VFs for the user
110 cldsVfs = filteredCldsVfs;