[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-heat-lib / src / main / java / org / openecomp / sdc / heat / datatypes / structure / Artifact.java
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.structure;
22
23
24 import org.openecomp.sdc.datatypes.error.ErrorMessage;
25 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 public class Artifact implements Comparable<Artifact> {
31
32   private String fileName;
33   private FileData.Type type;
34   private List<ErrorMessage> errors;
35
36   public Artifact(String fileName, FileData.Type type) {
37     this.fileName = fileName;
38     this.type = type;
39   }
40
41
42   public String getFileName() {
43     return fileName;
44   }
45
46   public void setFileName(String name) {
47     this.fileName = name;
48   }
49
50
51   public FileData.Type getType() {
52     return type;
53   }
54
55   public List<ErrorMessage> getErrors() {
56     return errors;
57   }
58
59   public void setErrors(List<ErrorMessage> errors) {
60     this.errors = errors;
61   }
62
63   /**
64    * Add error to error list.
65    *
66    * @param error the error
67    */
68   public void addErrorToErrorList(ErrorMessage error) {
69     if (this.errors == null || this.errors.isEmpty()) {
70       this.errors = new ArrayList<>();
71     }
72
73     this.errors.add(error);
74   }
75
76   @Override
77   public int hashCode() {
78     int result = fileName.hashCode();
79     return result;
80   }
81
82   @Override
83   public boolean equals(Object obj) {
84     if (this == obj) {
85       return true;
86     }
87     if (obj == null || getClass() != obj.getClass()) {
88       return false;
89     }
90
91     Artifact artifact = (Artifact) obj;
92
93     if (!fileName.equals(artifact.fileName)) {
94       return false;
95     }
96     return true;
97
98   }
99
100   @Override
101   public int compareTo(Artifact artifact) {
102     return artifact.getFileName().compareTo(this.getFileName());
103   }
104 }