use of org.cerberus.service.sql.ISQLService in project cerberus-source by cerberustesting.
the class CalculatePropertyForTestCase method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);
String type = policy.sanitize(httpServletRequest.getParameter("type"));
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
String result = null;
String description = null;
String system = "";
String property = httpServletRequest.getParameter("property");
String testName = policy.sanitize(httpServletRequest.getParameter("test"));
String testCaseName = policy.sanitize(httpServletRequest.getParameter("testCase"));
String country = policy.sanitize(httpServletRequest.getParameter("country"));
String environment = policy.sanitize(httpServletRequest.getParameter("environment"));
try {
if (type.equals("executeSoapFromLib")) {
IAppServiceService appServiceService = appContext.getBean(AppServiceService.class);
ISoapService soapService = appContext.getBean(ISoapService.class);
IXmlUnitService xmlUnitService = appContext.getBean(IXmlUnitService.class);
AppService appService = appServiceService.findAppServiceByKey(property);
if (appService != null) {
ExecutionUUID executionUUIDObject = appContext.getBean(ExecutionUUID.class);
UUID executionUUID = UUID.randomUUID();
executionUUIDObject.setExecutionUUID(executionUUID.toString(), null);
soapService.callSOAP(appService.getServiceRequest(), appService.getServicePath(), appService.getOperation(), appService.getAttachementURL(), null, null, 60000, system);
result = xmlUnitService.getFromXml(executionUUID.toString(), appService.getAttachementURL());
description = appService.getDescription();
executionUUIDObject.removeExecutionUUID(executionUUID.toString());
LOG.debug("Clean ExecutionUUID");
}
} else {
try {
ITestCaseService testCaseService = appContext.getBean(TestCaseService.class);
IApplicationService applicationService = appContext.getBean(ApplicationService.class);
TestCase testCase = testCaseService.findTestCaseByKey(testName, testCaseName);
if (testCase != null) {
system = applicationService.convert(applicationService.readByKey(testCase.getApplication())).getSystem();
} else {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
} catch (CerberusException ex) {
LOG.warn(ex);
}
if (system != null) {
String database = policy.sanitize(httpServletRequest.getParameter("database"));
ICountryEnvironmentDatabaseService countryEnvironmentDatabaseService = appContext.getBean(CountryEnvironmentDatabaseService.class);
CountryEnvironmentDatabase countryEnvironmentDatabase;
countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(countryEnvironmentDatabaseService.readByKey(system, country, environment, database));
String connectionName = countryEnvironmentDatabase.getConnectionPoolName();
if (type.equals("executeSqlFromLib")) {
ISqlLibraryService sqlLibraryService = appContext.getBean(SqlLibraryService.class);
SqlLibrary sl = sqlLibraryService.findSqlLibraryByKey(policy.sanitize(property));
property = sl.getScript();
if (!(StringUtil.isNullOrEmpty(connectionName)) && !(StringUtil.isNullOrEmpty(policy.sanitize(property)))) {
ISQLService sqlService = appContext.getBean(ISQLService.class);
IParameterService parameterService = appContext.getBean(IParameterService.class);
Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);
result = sqlService.queryDatabase(connectionName, policy.sanitize(property), 1, sqlTimeout).get(0);
description = sl.getDescription();
}
}
}
}
} catch (CerberusException ex) {
LOG.warn(ex);
result = ex.getMessageError().getDescription();
description = ex.getMessageError().getDescription();
} catch (CerberusEventException ex) {
LOG.warn(ex);
result = ex.getMessageError().getDescription();
description = ex.getMessageError().getDescription();
}
if (result != null) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("resultList", result);
jsonObject.put("description", description);
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().print(jsonObject.toString());
} catch (JSONException exception) {
LOG.warn(exception.toString());
}
}
}
Aggregations