All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ch.export.service.ExportService Maven / Gradle / Ivy

Go to download

The Charles Hudson Java SDK wraps the REST API in a lightweight library. The Java SDK enables you to develop a fast, flexible, and customized integration with CH cloud solution.

There is a newer version: 1.0.7
Show newest version
package com.ch.export.service;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.lang3.StringUtils;

import com.ch.config.ConfigProperties;
import com.ch.exception.PropertyNotFoundException;
import com.ch.model.ExecutionReport;
import com.ch.model.Report;
import com.ch.model.TestReport;
import com.ch.service.TestReportService;
import com.ch.service.exception.ServiceException;
import com.ch.utils.PropertyCache;
import com.ch.utils.PropertyReader;

public class ExportService {
	private static final Logger LOGGER = Logger.getLogger(ExportService.class.getName());
	private TestReportService detailService;
	private ConfigProperties properties = null;
	private String defaultServiceClass = "com.ch.export.service.NoOpsExportService";

	public ExportService(String serviceConfigPath) throws ServiceException {
		initPropertyCache(serviceConfigPath);
		String serviceClass = null;
		try {
			serviceClass = PropertyCache.getProperty("SERVICE_CLASS");
		} catch (PropertyNotFoundException e) {
			LOGGER.log(Level.WARNING, "Property SERVICE_CLASS  not found in file " + serviceConfigPath);
			LOGGER.log(Level.WARNING, "Initializing default NoOps service " + defaultServiceClass);
			serviceClass = defaultServiceClass;
		}
		if(StringUtils.isAllEmpty(serviceClass)) {
			serviceClass = defaultServiceClass;
			LOGGER.log(Level.WARNING, "Initializing default NoOps service");
		}
		initExportService(serviceClass);
		properties = new ConfigProperties(PropertyReader.getAllProperties());
	}

	public void exportExecutionReport(ExecutionReport executionReport) throws ServiceException {
		detailService.exportExecutionReport(executionReport, properties);
	}

	public void exportTestReport(TestReport testReport) throws ServiceException {
		
		detailService.exportTestReport(testReport, properties);
	}

	public void exportReport(Report report) throws ServiceException {
		detailService.exportReport(report, properties);
	}

	private void initExportService(String serviceClass) throws ServiceException {
		if (serviceClass != null) {
			try {
				detailService = (TestReportService) Class.forName(serviceClass).newInstance();
			} catch (Exception e) {
				LOGGER.log(Level.SEVERE, e.getMessage(), e);
				throw new ServiceException("Unable to initialize report Service with " + serviceClass);
			}
		} else {
			LOGGER.warning("Default NoOpsExportService service configured. Report will NOT be uploaded");
			detailService = new NoOpsExportService();
		}
	}

	private void initPropertyCache(String filePatch) throws ServiceException {
		PropertyReader.getInstance(filePatch);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy