2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
23 package org.openecomp.sdc.asdctool.main;
25 import org.openecomp.sdc.asdctool.impl.GraphJsonValidator;
26 import org.openecomp.sdc.asdctool.impl.GraphMLConverter;
27 import org.openecomp.sdc.asdctool.impl.GraphMLDataAnalyzer;
29 import java.io.IOException;
30 import java.util.Arrays;
31 import java.util.List;
32 import java.util.stream.Collectors;
34 public class ExportImportMenu {
36 enum ExportImportEnum {
37 DATA_REPORT("Usage: get-data-report-from-graph-ml <full path of .graphml file>", "get-data-report-from-graph-ml"){
39 void handle(String[] args) {
40 if (verifyParamsLength(args, 2)) {
44 String[] dataArgs = new String[] { args[1] };
45 if (new GraphMLDataAnalyzer().analyzeGraphMLData(dataArgs) == null) {
50 EXPORT("Usage: export <janusgraph.properties> <output directory>", "export"){
52 void handle(String[] args) {
53 if (verifyParamsLength(args, 3)) {
58 if (!GRAPH_ML_CONVERTER.exportGraph(args)) {
62 },EXPORT_AS_GRAPH("Usage: export-as-graph-ml <janusgraph.properties> <output directory>", "export-as-graph-ml"){
64 void handle(String[] args) {
65 if (verifyParamsLength(args, 3)) {
69 if (GRAPH_ML_CONVERTER.exportGraphMl(args) == null) {
73 },EXPORT_USERS("Usage: exportusers <janusgraph.properties> <output directory>", "exportusers"){
75 void handle(String[] args) {
76 if (verifyParamsLength(args, 3)) {
80 if (!GRAPH_ML_CONVERTER.exportUsers(args)) {
84 },EXPORT_WITH_REPORT("Usage: export-as-graph-ml-with-data-report <janusgraph.properties> <output directory>", "export-as-graph-ml-with-data-report"){
86 void handle(String[] args) {
87 if (verifyParamsLength(args, 3)) {
91 if (GRAPH_ML_CONVERTER.exportGraphMl(args) == null) {
94 String[] dataArgs = new String[] {GRAPH_ML_CONVERTER.exportGraphMl(args)};
95 if (new GraphMLDataAnalyzer().analyzeGraphMLData(dataArgs) == null) {
99 },FIND_PROBLEM("Usage: findproblem <janusgraph.properties> <graph file location>", "findproblem"){
101 void handle(String[] args) {
102 if (verifyParamsLength(args, 3)) {
106 if (!GRAPH_ML_CONVERTER.findErrorInJsonGraph(args)) {
110 },IMPORT("Usage: import <janusgraph.properties> <graph file location>", "import"){
112 void handle(String[] args) {
113 if (verifyParamsLength(args, 3)) {
117 if (!GRAPH_ML_CONVERTER.importGraph(args)) {
121 },VALIDATE_JSON("Usage: validate-json <export graph path>", "validate-json"){
123 void handle(String[] args) throws IOException {
124 if (verifyParamsLength(args, 2)) {
128 String jsonFilePath = args[1];
129 GraphJsonValidator graphJsonValidator = new GraphJsonValidator();
130 if (graphJsonValidator.verifyJanusGraphJson(jsonFilePath)) {
136 void handle(String[] args) {
142 Arrays.stream(ExportImportEnum.values()).filter(type -> type != NONE).forEach(ExportImportEnum::usage);
146 private static final GraphMLConverter GRAPH_ML_CONVERTER = new GraphMLConverter();
147 private String usage;
148 private String keyword;
150 ExportImportEnum(String usage, String keyword) {
152 this.keyword = keyword;
155 ExportImportEnum() {}
158 System.out.println(usage);
161 static ExportImportEnum getByKeyword(String keyword) {
162 List<ExportImportEnum> collected = Arrays.stream(ExportImportEnum.values())
163 .filter(type -> type != NONE)
164 .filter(type -> type.keyword.equals(keyword))
165 .collect(Collectors.toList());
166 return collected.isEmpty() ? NONE : collected.get(0);
169 abstract void handle(String[] args) throws IOException;
171 private static boolean verifyParamsLength(String[] args, int i) {
175 return args.length < i;
179 public static void main(String[] args) throws Exception {
180 ExportImportEnum type;
181 if (args == null || args.length < 1) {
182 type = ExportImportEnum.NONE;
184 type = ExportImportEnum.getByKeyword(getOperation(args).toLowerCase());
189 private static String getOperation(String[] args) {
190 String operation = null;