Reformat asdctool
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / impl / internal / tool / CommonInternalTool.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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 package org.openecomp.sdc.asdctool.impl.internal.tool;
21
22 import java.io.IOException;
23 import java.util.Map;
24 import org.openecomp.sdc.asdctool.utils.ConsoleWriter;
25 import org.openecomp.sdc.asdctool.utils.ReportWriter;
26 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
27
28 public abstract class CommonInternalTool {
29
30     protected ReportWriter reportWriter;
31     private String reportType;
32
33     CommonInternalTool(String reportType) {
34         this.reportType = reportType;
35     }
36
37     protected ReportWriter getReportWriter() throws IOException {
38         if (reportWriter == null) {
39             reportWriter = new ReportWriter(reportType);
40         }
41         return reportWriter;
42     }
43
44     public void closeAll() {
45         try {
46             getReportWriter().close();
47         } catch (IOException e) {
48             ConsoleWriter.dataLine("\nFailed to close report file.");
49         }
50     }
51
52     protected void printComponentInfo(Map<GraphPropertyEnum, Object> metadataProperties) {
53         ConsoleWriter.dataLine("component from type", metadataProperties.get(GraphPropertyEnum.COMPONENT_TYPE));
54         ConsoleWriter.dataLine("component name", metadataProperties.get(GraphPropertyEnum.NAME));
55         ConsoleWriter.dataLine("component version", metadataProperties.get(GraphPropertyEnum.VERSION));
56         ConsoleWriter.dataLine("component state", metadataProperties.get(GraphPropertyEnum.STATE));
57         ConsoleWriter.dataLine("component is highest", metadataProperties.get(GraphPropertyEnum.IS_HIGHEST_VERSION));
58         ConsoleWriter.dataLine("component is archived", metadataProperties.get(GraphPropertyEnum.IS_ARCHIVED));
59     }
60 }