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=========================================================
21 package org.openecomp.sdc.asdctool.impl;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.openecomp.sdc.common.log.wrappers.Logger;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.concurrent.atomic.AtomicInteger;
35 * simple util class to verify that the titan export json graph is not corrupted
37 public class GraphJsonValidator {
39 private static Logger log = Logger.getLogger(GraphJsonValidator.class.getName());
41 public boolean verifyTitanJson(String filePath) throws IOException {
42 ObjectMapper objectMapper = new ObjectMapper();
43 List<Integer> invalidRows = new ArrayList<>();
44 AtomicInteger atomicInteger = new AtomicInteger(1);
45 Files.lines(Paths.get(filePath)).forEach(line -> {
47 verifyJsonLine(objectMapper, atomicInteger, line);
48 } catch (RuntimeException | IOException e) {
49 logInvalidJsonRow(atomicInteger, line, e);
50 invalidRows.add(atomicInteger.get());
53 return verificationResult(invalidRows);
56 private void verifyJsonLine(ObjectMapper objectMapper, AtomicInteger atomicInteger, String line) throws IOException {
57 log.info("verifying line: " + atomicInteger.get());
58 objectMapper.readTree(line);
59 atomicInteger.incrementAndGet();
62 private void logInvalidJsonRow(AtomicInteger atomicInteger, String line, Exception e) {
63 log.error("Invalid Json!!!!!!!!!!!!!!!!!!!!", e);
64 log.info("line number: " + atomicInteger.get());
65 log.info("line value: " + line);
68 private boolean verificationResult(List<Integer> invalidRows) {
69 if (!invalidRows.isEmpty()) {
70 log.info("the following lines are not valid: " + invalidRows);