Search in sources :

Example 6 with CountryEnvironmentDatabase

use of org.cerberus.crud.entity.CountryEnvironmentDatabase 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());
        }
    }
}
Also used : AppService(org.cerberus.crud.entity.AppService) CerberusException(org.cerberus.exception.CerberusException) PolicyFactory(org.owasp.html.PolicyFactory) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) SqlLibrary(org.cerberus.crud.entity.SqlLibrary) JSONException(org.json.JSONException) IAppServiceService(org.cerberus.crud.service.IAppServiceService) IParameterService(org.cerberus.crud.service.IParameterService) CerberusEventException(org.cerberus.exception.CerberusEventException) ApplicationContext(org.springframework.context.ApplicationContext) ISQLService(org.cerberus.service.sql.ISQLService) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) JSONObject(org.json.JSONObject) ISoapService(org.cerberus.service.soap.ISoapService) TestCase(org.cerberus.crud.entity.TestCase) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ISqlLibraryService(org.cerberus.crud.service.ISqlLibraryService) ICountryEnvironmentDatabaseService(org.cerberus.crud.service.ICountryEnvironmentDatabaseService) UUID(java.util.UUID) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) IXmlUnitService(org.cerberus.service.xmlunit.IXmlUnitService) IApplicationService(org.cerberus.crud.service.IApplicationService) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase)

Example 7 with CountryEnvironmentDatabase

use of org.cerberus.crud.entity.CountryEnvironmentDatabase in project cerberus-source by cerberustesting.

the class SQLService method calculateOnDatabase.

@Override
public TestCaseExecutionData calculateOnDatabase(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseProperties, TestCaseExecution tCExecution) {
    String sql = testCaseExecutionData.getValue1();
    String db = testCaseProperties.getDatabase();
    String connectionName;
    CountryEnvironmentDatabase countryEnvironmentDatabase;
    MessageEvent mes = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SQL);
    try {
        String system = tCExecution.getApplicationObj().getSystem();
        String country = testCaseProperties.getCountry();
        String environment = tCExecution.getEnvironmentData();
        countryEnvironmentDatabase = this.countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system, country, environment, db));
        if (countryEnvironmentDatabase == null) {
            mes = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_DATABASENOTCONFIGURED);
            mes.setDescription(mes.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));
        } else {
            connectionName = countryEnvironmentDatabase.getConnectionPoolName();
            if (!(StringUtil.isNullOrEmpty(connectionName))) {
                try {
                    Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);
                    List<String> list = this.queryDatabase(connectionName, sql, testCaseProperties.getRowLimit(), sqlTimeout);
                    if (list != null && !list.isEmpty()) {
                        if (testCaseProperties.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_STATIC)) {
                            testCaseExecutionData.setValue(list.get(0));
                        } else if (testCaseProperties.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_RANDOM)) {
                            testCaseExecutionData.setValue(this.getRandomStringFromList(list));
                            mes = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SQL_RANDOM);
                        } else if (testCaseProperties.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_RANDOMNEW)) {
                            testCaseExecutionData.setValue(this.calculateNatureRandomNew(list, testCaseProperties.getProperty(), tCExecution));
                            mes = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NATURERANDOMNEW_NOTIMPLEMENTED);
                        } else if (testCaseProperties.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_NOTINUSE)) {
                            mes = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NATURENOTINUSE_NOTIMPLEMENTED);
                        }
                    } else {
                        mes = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NODATA);
                    }
                    mes.setDescription(mes.getDescription().replace("%DATABASE%", db));
                    mes.setDescription(mes.getDescription().replace("%SQL%", sql));
                    mes.setDescription(mes.getDescription().replace("%JDBCPOOLNAME%", connectionName));
                    testCaseExecutionData.setPropertyResultMessage(mes);
                } catch (CerberusEventException ex) {
                    mes = ex.getMessageError();
                }
            } else {
                mes = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_EMPTYJDBCPOOL);
                mes.setDescription(mes.getDescription().replace("%SYSTEM%", tCExecution.getApplicationObj().getSystem()));
                mes.setDescription(mes.getDescription().replace("%COUNTRY%", testCaseProperties.getCountry()));
                mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironmentData()));
                mes.setDescription(mes.getDescription().replace("%DATABASE%", db));
            }
        }
    } catch (CerberusException ex) {
        mes = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_JDBCPOOLNOTCONFIGURED);
        mes.setDescription(mes.getDescription().replace("%SYSTEM%", tCExecution.getApplicationObj().getSystem()));
        mes.setDescription(mes.getDescription().replace("%COUNTRY%", testCaseProperties.getCountry()));
        mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironmentData()));
        mes.setDescription(mes.getDescription().replace("%DATABASE%", db));
    }
    testCaseExecutionData.setPropertyResultMessage(mes);
    return testCaseExecutionData;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase)

Example 8 with CountryEnvironmentDatabase

use of org.cerberus.crud.entity.CountryEnvironmentDatabase in project cerberus-source by cerberustesting.

the class ReadCountryEnvironmentDatabase method findCountryEnvDatabaseList.

// </editor-fold>
private AnswerItem findCountryEnvDatabaseList(String system, String country, String environment, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    cedService = appContext.getBean(ICountryEnvironmentDatabaseService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "system,country,Environment,database,connectionpoolname");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    AnswerList resp = cedService.readByVariousByCriteria(system, country, environment, startPosition, length, columnName, sort, searchParameter, "");
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (CountryEnvironmentDatabase ced : (List<CountryEnvironmentDatabase>) resp.getDataList()) {
            jsonArray.put(convertToJSONObject(ced));
        }
    }
    object.put("hasPermissions", userHasPermissions);
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", resp.getTotalRows());
    object.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(object);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ICountryEnvironmentDatabaseService(org.cerberus.crud.service.ICountryEnvironmentDatabaseService) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase)

Example 9 with CountryEnvironmentDatabase

use of org.cerberus.crud.entity.CountryEnvironmentDatabase in project cerberus-source by cerberustesting.

the class UpdateCountryEnvParam method getCountryEnvironmentDatabaseFromParameter.

private List<CountryEnvironmentDatabase> getCountryEnvironmentDatabaseFromParameter(HttpServletRequest request, ApplicationContext appContext, String system, String country, String environment, JSONArray json) throws JSONException {
    List<CountryEnvironmentDatabase> cebList = new ArrayList();
    IFactoryCountryEnvironmentDatabase cebFactory = appContext.getBean(IFactoryCountryEnvironmentDatabase.class);
    for (int i = 0; i < json.length(); i++) {
        JSONObject tcsaJson = json.getJSONObject(i);
        boolean delete = tcsaJson.getBoolean("toDelete");
        String database = tcsaJson.getString("database");
        String connectionPool = tcsaJson.getString("connectionPoolName");
        String soapUrl = tcsaJson.getString("soapUrl");
        String csvUrl = tcsaJson.getString("csvUrl");
        if (!delete) {
            CountryEnvironmentDatabase ceb = cebFactory.create(system, country, environment, database, connectionPool, soapUrl, csvUrl);
            cebList.add(ceb);
        }
    }
    return cebList;
}
Also used : IFactoryCountryEnvironmentDatabase(org.cerberus.crud.factory.IFactoryCountryEnvironmentDatabase) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase) IFactoryCountryEnvironmentDatabase(org.cerberus.crud.factory.IFactoryCountryEnvironmentDatabase)

Example 10 with CountryEnvironmentDatabase

use of org.cerberus.crud.entity.CountryEnvironmentDatabase in project cerberus-source by cerberustesting.

the class FactoryCountryEnvironmentDatabase method create.

@Override
public CountryEnvironmentDatabase create(String system, String country, String environment, String database, String connectionPoolName, String soapUrl, String csvUrl) {
    CountryEnvironmentDatabase ced = new CountryEnvironmentDatabase();
    ced.setSystem(system);
    ced.setCountry(country);
    ced.setEnvironment(environment);
    ced.setDatabase(database);
    ced.setConnectionPoolName(connectionPoolName);
    ced.setSoapUrl(soapUrl);
    ced.setCsvUrl(csvUrl);
    return ced;
}
Also used : CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase) IFactoryCountryEnvironmentDatabase(org.cerberus.crud.factory.IFactoryCountryEnvironmentDatabase)

Aggregations

CountryEnvironmentDatabase (org.cerberus.crud.entity.CountryEnvironmentDatabase)13 MessageEvent (org.cerberus.engine.entity.MessageEvent)9 CerberusException (org.cerberus.exception.CerberusException)7 ArrayList (java.util.ArrayList)5 IFactoryCountryEnvironmentDatabase (org.cerberus.crud.factory.IFactoryCountryEnvironmentDatabase)5 AnswerItem (org.cerberus.util.answer.AnswerItem)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 CerberusEventException (org.cerberus.exception.CerberusEventException)4 JSONObject (org.json.JSONObject)4 PreparedStatement (java.sql.PreparedStatement)3 List (java.util.List)3 AppService (org.cerberus.crud.entity.AppService)3 ICountryEnvironmentDatabaseService (org.cerberus.crud.service.ICountryEnvironmentDatabaseService)3 ResultSet (java.sql.ResultSet)2 SQLTimeoutException (java.sql.SQLTimeoutException)2 IFactoryAppService (org.cerberus.crud.factory.IFactoryAppService)2 AnswerList (org.cerberus.util.answer.AnswerList)2 PolicyFactory (org.owasp.html.PolicyFactory)2 ApplicationContext (org.springframework.context.ApplicationContext)2