Merge "Removing so-monitoring module"
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-bpmn-flows / src / main / java / org / onap / so / etsi / nfvo / ns / lcm / bpmn / flows / nsd / FileEntry.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd;
21
22 import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString;
23 import java.io.ByteArrayInputStream;
24 import java.io.InputStream;
25 import java.util.Arrays;
26 import java.util.Objects;
27
28 /**
29  * @author Waqas Ikram (waqas.ikram@est.tech)
30  *
31  */
32 public class FileEntry {
33
34     private boolean isDirectory;
35     private String filePath;
36     private byte[] fileContent;
37
38     public boolean isDirectory() {
39         return isDirectory;
40     }
41
42     public void setDirectory(final boolean isDirectory) {
43         this.isDirectory = isDirectory;
44     }
45
46     public FileEntry isDirectory(final boolean isDirectory) {
47         this.isDirectory = isDirectory;
48         return this;
49     }
50
51     public String getFilePath() {
52         return filePath;
53     }
54
55     public void setFilename(final String filePath) {
56         this.filePath = filePath;
57     }
58
59     public FileEntry filePath(final String filePath) {
60         this.filePath = filePath;
61         return this;
62     }
63
64     public byte[] getFileContent() {
65         return fileContent;
66     }
67
68     public void setFileContent(final byte[] fileContent) {
69         this.fileContent = fileContent;
70     }
71
72     public FileEntry fileContent(final byte[] fileContent) {
73         this.fileContent = fileContent;
74         return this;
75     }
76
77     public InputStream getFileContentAsStream() {
78         if (fileContent == null || fileContent.length == 0) {
79             return null;
80         }
81         return new ByteArrayInputStream(fileContent);
82     }
83
84     @Override
85     public int hashCode() {
86         return Objects.hash(isDirectory, filePath) + Arrays.hashCode(fileContent);
87     }
88
89     @Override
90     public boolean equals(final Object obj) {
91         if (obj instanceof FileEntry) {
92             final FileEntry other = (FileEntry) obj;
93             return Objects.equals(isDirectory, other.isDirectory) && Objects.equals(filePath, other.filePath)
94                     && Arrays.equals(fileContent, other.fileContent);
95         }
96         return false;
97     }
98
99     @Override
100     public String toString() {
101         final StringBuilder sb = new StringBuilder();
102         sb.append("class FileEntry {\n");
103         sb.append("    isDirectory: ").append(toIndentedString(isDirectory)).append("\n");
104         sb.append("    filePath: ").append(toIndentedString(filePath)).append("\n");
105         sb.append("    fileContent size: ").append(toIndentedString(fileContent != null ? fileContent.length : 0))
106                 .append("\n");
107         sb.append("}");
108         return sb.toString();
109     }
110
111
112 }