Search in sources :

Example 1 with IDocumentationService

use of org.cerberus.crud.service.IDocumentationService in project cerberus-source by cerberustesting.

the class ReadDocumentation method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) throws ServletException, IOException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IDocumentationService docService = appContext.getBean(IDocumentationService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    JSONObject jsonResponse = new JSONObject();
    List<Documentation> result = new ArrayList<Documentation>();
    JSONObject format = new JSONObject();
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    String lang = ParameterParserUtil.parseStringParamAndSanitize(httpServletRequest.getParameter("lang"), "en");
    result = docService.findAllWithEmptyDocLabel(lang);
    format = docService.formatGroupByDocTable(result);
    try {
        jsonResponse.put("labelTable", format);
    } catch (JSONException ex) {
        LOG.warn(ex);
    }
    response.getWriter().print(jsonResponse.toString());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) PolicyFactory(org.owasp.html.PolicyFactory) JSONObject(org.json.JSONObject) Documentation(org.cerberus.crud.entity.Documentation) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IDocumentationService(org.cerberus.crud.service.IDocumentationService)

Example 2 with IDocumentationService

use of org.cerberus.crud.service.IDocumentationService 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)

Example 3 with IDocumentationService

use of org.cerberus.crud.service.IDocumentationService in project cerberus-source by cerberustesting.

the class DocumentationField method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IDocumentationService docService = appContext.getBean(IDocumentationService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String result = "";
    String docTable = policy.sanitize(httpServletRequest.getParameter("docTable"));
    String docField = policy.sanitize(httpServletRequest.getParameter("docField"));
    String docLabel = policy.sanitize(httpServletRequest.getParameter("docLabel"));
    String lang = ParameterParserUtil.parseStringParamAndSanitize(httpServletRequest.getParameter("lang"), "en");
    result = docService.findLabelHTML(docTable, docField, docLabel, lang);
    try {
        httpServletResponse.setContentType("text/html");
        httpServletResponse.getWriter().print(result);
    } catch (Exception exception) {
        LOG.warn(exception.toString());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) PolicyFactory(org.owasp.html.PolicyFactory) IDocumentationService(org.cerberus.crud.service.IDocumentationService) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

IDocumentationService (org.cerberus.crud.service.IDocumentationService)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 PolicyFactory (org.owasp.html.PolicyFactory)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 Documentation (org.cerberus.crud.entity.Documentation)1 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)1 IFactoryTestCaseCountryProperties (org.cerberus.crud.factory.IFactoryTestCaseCountryProperties)1 FactoryTestCaseCountryProperties (org.cerberus.crud.factory.impl.FactoryTestCaseCountryProperties)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