2bc549c05804b6ea79cc725c0498233a264fb0be
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.heat.datatypes.manifest;
22
23 import org.apache.commons.collections4.CollectionUtils;
24
25 import java.util.*;
26 import java.util.function.Predicate;
27
28 public class FileData {
29
30     protected static final Set<Type> heatFileTypes =
31         new HashSet<>(Arrays.asList(Type.HEAT, Type.HEAT_NET, Type.HEAT_VOL));
32     private Boolean isBase;
33     private String parentFile;
34     private String file;
35     private Type type;
36     private List<FileData> data;
37
38     public static Predicate<FileData> buildFileDataPredicateByType(Type... types) {
39         return fileData -> Arrays.asList(types).contains(fileData.getType());
40     }
41
42     public static boolean isHeatFile(Type type) {
43     return heatFileTypes.contains(type);
44   }
45
46     public Boolean getBase() {
47         return isBase;
48     }
49
50     public void setBase(Boolean base) {
51         isBase = base;
52     }
53
54     public String getFile() {
55         return file;
56     }
57
58     public void setFile(String file) {
59         this.file = file;
60     }
61
62     public String getParentFile() {
63         return parentFile;
64     }
65
66     public void setParentFile(String parentFile) {
67     this.parentFile = parentFile;
68   }
69
70     public Type getType() {
71     return type;
72   }
73
74     public void setType(Type type) {
75     this.type = type;
76   }
77
78     public List<FileData> getData() {
79         return data;
80     }
81
82     public void setData(List<FileData> data) {
83         this.data = data;
84     }
85
86     /**
87     * Add file data.
88     *
89     * @param data the data
90     */
91     public void addFileData(FileData data) {
92         if (CollectionUtils.isEmpty(this.data)) {
93             this.data = new ArrayList<>();
94         }
95         this.data.add(data);
96     }
97
98     public enum Type {
99
100     HEAT("HEAT"),
101     HEAT_ENV("HEAT_ENV"),
102     HEAT_NET("HEAT_NET"),
103     HEAT_VOL("HEAT_VOL"),
104     CHEF("CHEF"),
105     PUPPET("PUPPET"),
106     SHELL("SHELL"),
107     YANG("YANG"),
108     YANG_XML("YANG_XML"),
109     BPEL("BPEL"),
110     DG_XML("DG_XML"),
111     MURANO_PKG("MURANO_PKG"),
112     VENDOR_LICENSE("VENDOR_LICENSE"),
113     VF_LICENSE("VF_LICENSE"),
114     OTHER("OTHER");
115
116         private String displayName;
117
118         Type(String displayName) {
119             this.displayName = displayName;
120         }
121
122         public String getDisplayName() {
123             return displayName;
124         }
125
126         public static boolean isArtifact(Type fileType) {
127             return !Arrays.asList(HEAT,HEAT_ENV, HEAT_VOL).contains(fileType);
128         }
129
130         public static boolean canBeAssociated(Type fileType)
131         {
132             return HEAT_VOL == fileType;
133         }
134     }
135 }