Adding Basic NSD parser
[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 Ericsson. All rights reserved.
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.Objects;
26
27 /**
28  * @author Waqas Ikram (waqas.ikram@est.tech)
29  *
30  */
31 public class FileEntry {
32
33     private boolean isDirectory;
34     private String filePath;
35     private byte[] fileContent;
36
37     public boolean isDirectory() {
38         return isDirectory;
39     }
40
41     public void setDirectory(final boolean isDirectory) {
42         this.isDirectory = isDirectory;
43     }
44
45     public FileEntry isDirectory(final boolean isDirectory) {
46         this.isDirectory = isDirectory;
47         return this;
48     }
49
50     public String getFilePath() {
51         return filePath;
52     }
53
54     public void setFilename(final String filePath) {
55         this.filePath = filePath;
56     }
57
58     public FileEntry filePath(final String filePath) {
59         this.filePath = filePath;
60         return this;
61     }
62
63     public byte[] getFileContent() {
64         return fileContent;
65     }
66
67     public void setFileContent(final byte[] fileContent) {
68         this.fileContent = fileContent;
69     }
70
71     public FileEntry fileContent(final byte[] fileContent) {
72         this.fileContent = fileContent;
73         return this;
74     }
75
76     public InputStream getFileContentAsStream() {
77         if (fileContent == null || fileContent.length == 0) {
78             return null;
79         }
80         return new ByteArrayInputStream(fileContent);
81     }
82
83     @Override
84     public int hashCode() {
85         return Objects.hash(isDirectory, filePath, fileContent);
86     }
87
88     @Override
89     public boolean equals(final Object obj) {
90         if (obj instanceof FileEntry) {
91             final FileEntry other = (FileEntry) obj;
92             return Objects.equals(isDirectory, other.isDirectory) && Objects.equals(filePath, other.filePath)
93                     && Objects.equals(fileContent, other.fileContent);
94         }
95         return false;
96     }
97
98     @Override
99     public String toString() {
100         final StringBuilder sb = new StringBuilder();
101         sb.append("class FileEntry {\n");
102         sb.append("    isDirectory: ").append(toIndentedString(isDirectory)).append("\n");
103         sb.append("    filePath: ").append(toIndentedString(filePath)).append("\n");
104         sb.append("    fileContent size: ").append(toIndentedString(fileContent != null ? fileContent.length : 0))
105                 .append("\n");
106         sb.append("}");
107         return sb.toString();
108     }
109
110
111 }