package com.aventstack.extentreports.convert;

import java.io.File;
import java.io.IOException;
import java.util.List;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.model.Test;

public class TestModelReportBuilder {

	public void recreateModelFromJson(ExtentReports extent, File jsonFile) throws IOException {
		extent.setReportUsesManualConfiguration(true);
		List<Test> tests = JsonDeserializer.deserialize(jsonFile);
		for (Test test : tests) {
			recreateTest(test, extent.createTest(test.getName() + "json", test.getDescription()));
		}
		extent.setReportUsesManualConfiguration(false);
	}

	public void recreateTest(Test test, ExtentTest extentTest) {
		// create events
		test.getLogContext().getAll().forEach(x -> extentTest.log(x.getStatus(), x.getDetails()));

		// assign attributes
		test.getAuthorContext().getAll().forEach(x -> extentTest.assignAuthor(x.getName()));
		test.getCategoryContext().getAll().forEach(x -> extentTest.assignCategory(x.getName()));
		test.getDeviceContext().getAll().forEach(x -> extentTest.assignDevice(x.getName()));

		// handle nodes
		for (Test node : test.getNodeContext().getAll()) {
			ExtentTest extentNode = extentTest.createNode(node.getName());
			recreateTest(node, extentNode);
		}
	}

}

@@ -393,16 +393,59 @@
 ption %7B%0A
+%09%09if (!jsonFile.exists()) %7B%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09extent

exit if the json file is not found