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