Remove ECOMP in headers
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsServiceData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * 
22  */
23
24 package org.onap.clamp.clds.model;
25
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28
29 import java.io.Serializable;
30 import java.util.ArrayList;
31 import java.util.List;
32
33 import javax.ws.rs.NotAuthorizedException;
34
35 import org.onap.clamp.clds.service.CldsService;
36
37 public class CldsServiceData implements Serializable {
38
39     private static final long serialVersionUID = -9153372664377279423L;
40     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsServiceData.class);
41     protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
42     private String serviceInvariantUUID;
43     private String serviceUUID;
44     private Long ageOfRecord;
45     private List<CldsVfData> cldsVfs;
46
47     public String getServiceInvariantUUID() {
48         return serviceInvariantUUID;
49     }
50
51     public void setServiceInvariantUUID(String serviceInvariantUUID) {
52         this.serviceInvariantUUID = serviceInvariantUUID;
53     }
54
55     public List<CldsVfData> getCldsVfs() {
56         return cldsVfs;
57     }
58
59     public void setCldsVfs(List<CldsVfData> cldsVfs) {
60         this.cldsVfs = cldsVfs;
61     }
62
63     public String getServiceUUID() {
64         return serviceUUID;
65     }
66
67     public void setServiceUUID(String serviceUUID) {
68         this.serviceUUID = serviceUUID;
69     }
70
71     public Long getAgeOfRecord() {
72         return ageOfRecord;
73     }
74
75     public void setAgeOfRecord(Long ageOfRecord) {
76         this.ageOfRecord = ageOfRecord;
77     }
78
79     /**
80      * Filter out any VFs that the user is not authorized for. Use the
81      * CldsService to determine if the user is authorized for a VF.
82      *
83      * @param svc
84      */
85     public void filterVfs(CldsService svc) {
86         List<CldsVfData> filteredCldsVfs = new ArrayList<>();
87         if (cldsVfs == null) {
88             logger.debug("cldsVfs == null");
89         } else {
90             for (CldsVfData vf : cldsVfs) {
91                 // if user is authorized for the VF then add it to the filtered
92                 // list
93                 try {
94                     if (svc.isAuthorizedForVf(vf.getVfInvariantResourceUUID())) {
95                         filteredCldsVfs.add(vf);
96                     }
97                 } catch (NotAuthorizedException e) {
98                     logger.error("user not authorized for {}" + vf.getVfInvariantResourceUUID(), e);
99                     // when not NotAuthorizedException - don't add to
100                     // filteredCldsVfs list
101                 }
102             }
103         }
104         // new filtered list replaces the list of VFs for the user
105         cldsVfs = filteredCldsVfs;
106     }
107 }