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());
}
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());
}
}
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());
}
}
Aggregations