Search in sources :

Example 1 with FactoryTestCaseCountryProperties

use of org.cerberus.crud.factory.impl.FactoryTestCaseCountryProperties in project cerberus-source by cerberustesting.

the class CreateNotDefinedProperty method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    JSONObject jsonResponse = new JSONObject();
    MessageEvent rs = null;
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(TestCaseCountryPropertiesService.class);
    ITestCaseCountryService testCaseCountryService = appContext.getBean(TestCaseCountryService.class);
    IFactoryTestCaseCountryProperties factoryTestCaseCountryProperties = appContext.getBean(FactoryTestCaseCountryProperties.class);
    try {
        String propertyName = request.getParameter("property");
        if (propertyName != null) {
            propertyName = propertyName.replace("%", "");
        }
        String toTest = request.getParameter("totest");
        String toTestCase = request.getParameter("totestcase");
        String propertyType = request.getParameter("propertyType");
        String userLanguage = request.getParameter("userLanguage");
        // We retrieve all country of the destination TestCase
        List<String> toCountriesAll = testCaseCountryService.findListOfCountryByTestTestCase(toTest, toTestCase);
        if (toCountriesAll != null && toCountriesAll.size() > 0) {
            // Variable for the properties list of the destination TestCase
            List<TestCaseCountryProperties> listOfPropertiesToInsert = new ArrayList<TestCaseCountryProperties>();
            // Variable for the countries of a property of the destination TestCase
            List<String> toCountriesProp;
            IDocumentationService docService = appContext.getBean(DocumentationService.class);
            String notDefinedProperty = docService.findLabel("page_testcase", "txt_property_not_defined", "** Property not defined **", userLanguage);
            // List of all country of the destination test for the current property
            List<String> toCountries = new ArrayList<String>();
            toCountries.addAll(toCountriesAll);
            // Retrieve the country of the destination TestCase for the property,
            // if not empty remove it (property aleady exists for these countries)
            toCountriesProp = testCaseCountryPropertiesService.findCountryByPropertyNameAndTestCase(toTest, toTestCase, propertyName);
            if (toCountriesProp != null && toCountriesProp.size() > 0) {
                toCountries.removeAll(toCountriesProp);
            }
            for (String country : toCountries) {
                listOfPropertiesToInsert.add(factoryTestCaseCountryProperties.create(toTest, toTestCase, country, propertyName, "", propertyType, "---", notDefinedProperty, "", "0", 0, "STATIC", 0, 10000, 0));
            }
            Answer answer = testCaseCountryPropertiesService.createListTestCaseCountryPropertiesBatch(listOfPropertiesToInsert);
            rs = answer.getResultMessage();
            // then a new entry should be added by the log service
            if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // Adding Log entry.
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/CreateNotDefinedProperty", "CREATE", "Create NotDefinedProperty:" + " " + propertyName, request);
            }
        } else {
            rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            rs.setDescription(rs.getDescription().replace("%ITEM%", "Property ").replace("%OPERATION%", "CREATE").replace("%REASON%", "No countries were defined for the test case."));
        }
        // sets the message returned by the operations
        jsonResponse.put("messageType", rs.getMessage().getCodeString());
        jsonResponse.put("message", rs.getDescription());
        response.setContentType("application/json");
        response.getWriter().print(jsonResponse);
        response.getWriter().flush();
    } catch (JSONException ex) {
        LOG.warn(ex);
        // returns a default error message with the json format that is able to be parsed by the client-side
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
    }
}
Also used : FactoryTestCaseCountryProperties(org.cerberus.crud.factory.impl.FactoryTestCaseCountryProperties) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) ILogEventService(org.cerberus.crud.service.ILogEventService) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) IDocumentationService(org.cerberus.crud.service.IDocumentationService)

Aggregations

ArrayList (java.util.ArrayList)1 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)1 IFactoryTestCaseCountryProperties (org.cerberus.crud.factory.IFactoryTestCaseCountryProperties)1 FactoryTestCaseCountryProperties (org.cerberus.crud.factory.impl.FactoryTestCaseCountryProperties)1 IDocumentationService (org.cerberus.crud.service.IDocumentationService)1 ILogEventService (org.cerberus.crud.service.ILogEventService)1 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)1 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)1 MessageEvent (org.cerberus.engine.entity.MessageEvent)1 Answer (org.cerberus.util.answer.Answer)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 ApplicationContext (org.springframework.context.ApplicationContext)1