com.ch.export.service.ExportService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ch-java-sdk Show documentation
Show all versions of ch-java-sdk Show documentation
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.
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);
}
}