How to use DataTableInformation class of org.cerberus.util.datatable package

Best Cerberus-source code snippet using org.cerberus.util.datatable.DataTableInformation

Source:TestController.java Github

copy

Full Screen

...17 * You should have received a copy of the GNU General Public License18 * along with Cerberus. If not, see <http://www.gnu.org/licenses/>.19 */20package org.cerberus.controller;21import org.cerberus.util.datatable.DataTableInformation;22import com.google.gson.Gson;23import io.swagger.annotations.ApiImplicitParam;24import io.swagger.annotations.ApiImplicitParams;25import java.util.List;26import javax.servlet.http.HttpServletRequest;27import org.apache.logging.log4j.LogManager;28import org.apache.logging.log4j.Logger;29import org.cerberus.crud.entity.Test;30import org.cerberus.crud.entity.TestCaseExecution;31import org.cerberus.crud.factory.IFactoryLogEvent;32import org.cerberus.crud.factory.IFactoryTest;33import org.cerberus.crud.service.ILogEventService;34import org.cerberus.crud.service.IParameterService;35import org.cerberus.crud.service.ITestService;36import org.cerberus.crud.service.impl.TestCaseExecutionService;37import org.cerberus.engine.entity.MessageEvent;38import org.cerberus.enums.MessageEventEnum;39import org.cerberus.util.ParameterParserUtil;40import org.cerberus.util.answer.Answer;41import org.cerberus.util.answer.AnswerItem;42import org.cerberus.util.answer.AnswerList;43import org.cerberus.util.servlet.ServletUtil;44import org.json.JSONArray;45import org.json.JSONException;46import org.json.JSONObject;47import org.owasp.html.PolicyFactory;48import org.owasp.html.Sanitizers;49import org.springframework.beans.factory.annotation.Autowired;50import org.springframework.web.bind.annotation.DeleteMapping;51import org.springframework.web.bind.annotation.GetMapping;52import org.springframework.web.bind.annotation.PatchMapping;53import org.springframework.web.bind.annotation.PostMapping;54import org.springframework.web.bind.annotation.RequestMapping;55import org.springframework.web.bind.annotation.RestController;56/**57 *58 * @author bcivel59 */60@RestController61@RequestMapping("/test")62public class TestController {63 private static final Logger LOG = LogManager.getLogger(TestCaseExecution.class);64 private final PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);65 @Autowired66 TestCaseExecutionService testCaseExecutionService;67 @Autowired68 ITestService testService;69 @Autowired70 IFactoryTest factoryTest;71 @Autowired72 ILogEventService logEventService;73 @Autowired74 IFactoryLogEvent factoryLogEvent;75 @Autowired76 IParameterService parameterService;77 /**78 * Create Test79 *80 * @param test81 * @param active82 * @param parentTest83 * @param description84 * @param request85 * @return86 */87 @ApiImplicitParams({88 @ApiImplicitParam(dataType = "string", name = "test", value = "This is the test", required = true),89 @ApiImplicitParam(name = "Active", value = "Active", required = false),90 @ApiImplicitParam(name = "ParentTest", value = "ParentTest", required = false),91 @ApiImplicitParam(name = "Description", value = "Description", required = false)92 })93 @PostMapping("/create")94 public String create(String test, String active, String parentTest, String description,95 HttpServletRequest request) {96 JSONObject jsonResponse = new JSONObject();97 try {98 // Calling Servlet Transversal Util.99 ServletUtil.servletStart(request);100 test = policy.sanitize(test);101 boolean isActive = (ParameterParserUtil.parseBooleanParam(policy.sanitize(active), false));102 parentTest = policy.sanitize(parentTest);103 description = policy.sanitize(description);104 Answer ans = new Answer();105 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);106 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));107 ans.setResultMessage(msg);108 Test testData = factoryTest.create(test, description, isActive, parentTest, request.getUserPrincipal().getName(), null, null, null);109 ans = testService.create(testData);110 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {111 /**112 * Object created. Adding Log entry.113 */114 logEventService.createForPrivateCalls("/CreateTest", "CREATE", "Create Test : ['" + test + "']", request);115 }116 /**117 * Formating and returning the json result.118 */119 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());120 jsonResponse.put("message", ans.getResultMessage().getDescription());121 } catch (JSONException ex) {122 LOG.warn(ex);123 }124 return jsonResponse.toString();125 }126 /**127 * Delete Test128 *129 * @param test130 * @param request131 * @return132 */133 @ApiImplicitParams({134 @ApiImplicitParam(required = true, dataType = "string", name = "test", value = "This is the test")})135 @DeleteMapping("/delete")136 public String delete(String test, HttpServletRequest request) {137 JSONObject jsonResponse = new JSONObject();138 try {139 // Calling Servlet Transversal Util.140 ServletUtil.servletStart(request);141 test = policy.sanitize(test);142 Answer ans = testService.deleteIfNotUsed(test);143 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {144 logEventService.createForPrivateCalls("/DeleteTest", "DELETE", "Delete Test : ['" + test + "']", request);145 }146 // Formating and returning the json result.147 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());148 jsonResponse.put("message", ans.getResultMessage().getDescription());149 } catch (JSONException ex) {150 LOG.warn(ex);151 }152 return jsonResponse.toString();153 }154 /**155 * Read By Key156 *157 * @param request158 * @param test159 * @return160 */161 @ApiImplicitParams({162 @ApiImplicitParam(required = true, dataType = "string", name = "test", value = "This is the test")})163 @GetMapping("/readByKey")164 public String readByKey(HttpServletRequest request, String test) {165 JSONObject object = new JSONObject();166 boolean userHasPermissions = request.isUserInRole("TestAdmin");167 try {168 // Calling Servlet Transversal Util.169 ServletUtil.servletStart(request);170 test = policy.sanitize(test);171 AnswerItem<Test> answerTest = testService.readByKey(test);172 if (answerTest.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {173 //if the service returns an OK message then we can get the item and convert it to JSONformat174 Gson gson = new Gson();175 Test testObj = answerTest.getItem();176 object.put("contentTable", new JSONObject(gson.toJson(testObj)));177 }178 object.put("hasPermissions", userHasPermissions);179 } catch (JSONException ex) {180 LOG.warn(ex);181 }182 return object.toString();183 }184 /**185 * Read186 *187 * @param request188 * @return189 */190 @GetMapping("/read")191 public String read(HttpServletRequest request) {192 boolean userHasPermissions = request.isUserInRole("TestAdmin");193 JSONObject object = new JSONObject();194 try {195 AnswerItem<JSONObject> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));196 AnswerList<Test> testList = new AnswerList<>();197 DataTableInformation dti = new DataTableInformation(request, "test,description,active,automated,tdatecrea");198 testList = testService.readByCriteria(dti.getStartPosition(), dti.getLength(), dti.getColumnName(), dti.getSort(), dti.getSearchParameter(), dti.getIndividualSearch());199 JSONArray jsonArray = new JSONArray();200 if (testList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values201 for (Test test : testList.getDataList()) {202 Gson gson = new Gson();203 jsonArray.put(new JSONObject(gson.toJson(test)).put("hasPermissions", userHasPermissions));204 }205 }206 object.put("contentTable", jsonArray);207 object.put("hasPermissions", userHasPermissions);208 object.put("iTotalRecords", testList.getTotalRows());209 object.put("iTotalDisplayRecords", testList.getTotalRows());210 } catch (JSONException ex) {211 LOG.warn(ex);212 }213 return object.toString();214 }215 /**216 * Read By System217 *218 * @param request219 * @param system220 * @return221 */222 @ApiImplicitParams({223 @ApiImplicitParam(required = true, dataType = "string", name = "system", value = "This is the system")})224 @GetMapping("readBySystem")225 public String readBySystem(HttpServletRequest request, String system) {226 JSONObject object = new JSONObject();227 boolean userHasPermissions = request.isUserInRole("TestAdmin");228 try {229 // Calling Servlet Transversal Util.230 ServletUtil.servletStart(request);231 system = policy.sanitize(system);232 AnswerList<Test> testList = testService.readDistinctBySystem(system);233 JSONArray jsonArray = new JSONArray();234 if (testList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values235 for (Test test : testList.getDataList()) {236 Gson gson = new Gson();237 jsonArray.put(new JSONObject(gson.toJson(test)));238 }239 }240 object.put("contentTable", jsonArray);241 object.put("iTotalRecords", testList.getTotalRows());242 object.put("iTotalDisplayRecords", testList.getTotalRows());243 object.put("hasPermissions", userHasPermissions);244 } catch (JSONException ex) {245 LOG.warn(ex);246 }247 return object.toString();248 }249 /**250 * Read Distinct Value Of Column251 *252 * @param request253 * @return254 */255 @GetMapping("readDistinctValueOfColumn")256 public String readDistinctValueOfColumn(HttpServletRequest request) {257 JSONObject object = new JSONObject();258 try {259 DataTableInformation dti = new DataTableInformation(request, "test,description,active,automated,tdatecrea");260 AnswerList testCaseList = testService.readDistinctValuesByCriteria(dti.getSearchParameter(), dti.getIndividualSearch(), dti.getColumnName());261 object.put("distinctValues", testCaseList.getDataList());262 } catch (JSONException ex) {263 LOG.warn(ex);264 }265 return object.toString();266 }267 268 /**269 * Update Test270 * @param request271 * @param originalTest272 * @param test273 * @param active...

Full Screen

Full Screen

DataTableInformation

Using AI Code Generation

copy

Full Screen

1DataTableInformation dataTableInformation = new DataTableInformation();2dataTableInformation.setTableName("mytable");3dataTableInformation.setTableKey("id");4dataTableInformation.setTableValue("name");5dataTableInformation.setTableColumn("id, name");6DataTableService dataTableService = new DataTableService();7dataTableService.setMyTable(dataTableInformation);8List<String> myTable = dataTableService.getMyTable();9DataTableService dataTableService = new DataTableService();10dataTableService.setMyTable(dataTableInformation);11List<String> myTable = dataTableService.getMyTable();12DataTableInformation dataTableInformation = new DataTableInformation();13dataTableInformation.setTableName("mytable");14dataTableInformation.setTableKey("id");15dataTableInformation.setTableValue("name");16dataTableInformation.setTableColumn("id, name");17DataTableService dataTableService = new DataTableService();18dataTableService.setMyTable(dataTableInformation);19List<String> myTable = dataTableService.getMyTable();20DataTableInformation dataTableInformation = new DataTableInformation();21dataTableInformation.setTableName("mytable");22dataTableInformation.setTableKey("id");23dataTableInformation.setTableValue("name");24dataTableInformation.setTableColumn("id, name");25DataTableService dataTableService = new DataTableService();26dataTableService.setMyTable(dataTableInformation);27List<String> myTable = dataTableService.getMyTable();28DataTableInformation dataTableInformation = new DataTableInformation();29dataTableInformation.setTableName("mytable");30dataTableInformation.setTableKey("id");31dataTableInformation.setTableValue("name");32dataTableInformation.setTableColumn("id, name");33DataTableService dataTableService = new DataTableService();34dataTableService.setMyTable(dataTableInformation);35List<String> myTable = dataTableService.getMyTable();36DataTableInformation dataTableInformation = new DataTableInformation();37dataTableInformation.setTableName("mytable");38dataTableInformation.setTableKey("id");39dataTableInformation.setTableValue("name");40dataTableInformation.setTableColumn("id, name");41DataTableService dataTableService = new DataTableService();42dataTableService.setMyTable(dataTableInformation);43List<String> myTable = dataTableService.getMyTable();44DataTableInformation dataTableInformation = new DataTableInformation();45dataTableInformation.setTableName("mytable");46dataTableInformation.setTableKey("id");47dataTableInformation.setTableValue("name");48dataTableInformation.setTableColumn("id, name");49DataTableService dataTableService = new DataTableService();50dataTableService.setMyTable(dataTableInformation);

Full Screen

Full Screen

DataTableInformation

Using AI Code Generation

copy

Full Screen

1DataTableInformation dti = new DataTableInformation();2dti.setDatatable(datatable);3List<DataTableColumn> dtcList = dti.getColumns();4List<DataTableColumn> dtcListVisible = dti.getVisibleColumns();5List<DataTableColumn> dtcListNotVisible = dti.getNotVisibleColumns();6List<DataTableColumn> dtcListSortable = dti.getSortableColumns();7List<DataTableColumn> dtcListNotSortable = dti.getNotSortableColumns();8List<DataTableColumn> dtcListSearchable = dti.getSearchableColumns();9List<DataTableColumn> dtcListNotSearchable = dti.getNotSearchableColumns();10List<DataTableColumn> dtcListOrderable = dti.getOrderableColumns();

Full Screen

Full Screen

DataTableInformation

Using AI Code Generation

copy

Full Screen

1var dtId = $(this).closest('.dataTable').attr('id');2var dtInfo = new DataTableInformation(dtId);3var nbRows = dtInfo.getNbRows();4var nbColumns = dtInfo.getNbColumns();5var nbVisibleColumns = dtInfo.getNbVisibleColumns();6var nbHiddenColumns = dtInfo.getNbHiddenColumns();7var nbVisibleRows = dtInfo.getNbVisibleRows();8var nbHiddenRows = dtInfo.getNbHiddenRows();9var nbRowsPerPage = dtInfo.getNbRowsPerPage();10var nbPages = dtInfo.getNbPages();11var nbVisiblePages = dtInfo.getNbVisiblePages();12var nbHiddenPages = dtInfo.getNbHiddenPages();13var currentPage = dtInfo.getCurrentPage();14var currentRow = dtInfo.getCurrentRow();15var currentColumn = dtInfo.getCurrentColumn();16var currentCell = dtInfo.getCurrentCell();17var currentCellValue = dtInfo.getCurrentCellValue();18var currentCellPosition = dtInfo.getCurrentCellPosition();19var currentRowPosition = dtInfo.getCurrentRowPosition();20var currentColumnPosition = dtInfo.getCurrentColumnPosition();21var currentPagePosition = dtInfo.getCurrentPagePosition();22var currentCellPosition = dtInfo.getCurrentCellPosition();23var currentRowPosition = dtInfo.getCurrentRowPosition();

Full Screen

Full Screen

DataTableInformation

Using AI Code Generation

copy

Full Screen

1package org.cerberus.util.datatable;2import java.util.List;3import cucumber.api.DataTable;4public class DataTableInformation {5 public static String getColumnName(DataTable datatable, int columnIndex) {6 String columnName = datatable.getGherkinRows().get(0).getCells().get(columnIndex);7 return columnName;8 }9 public static int getColumnIndex(DataTable datatable, String columnName) {10 int columnIndex = 0;11 List<String> list = datatable.getGherkinRows().get(0).getCells();12 for (int i = 0; i < list.size(); i++) {13 if (list.get(i).equals(columnName)) {14 columnIndex = i;15 }16 }17 return columnIndex;18 }19 public static String getCellValue(DataTable datatable, String columnName, int rowIndex) {20 int columnIndex = getColumnIndex(datatable, columnName);21 String cellValue = datatable.getGherkinRows().get(rowIndex).getCells().get(columnIndex);22 return cellValue;23 }24 public static String getCellValue(DataTable datatable, int columnIndex, int rowIndex) {25 String cellValue = datatable.getGherkinRows().get(rowIndex).getCells().get(columnIndex);26 return cellValue;27 }28}29package org.cerberus.util.datatable;30import cucumber.api.DataTable;31public class DataTableInformation {32 public static String getColumnName(DataTable datatable, int columnIndex) {33 String columnName = datatable.getGherkinRows().get(0).getCells().get(columnIndex);34 return columnName;35 }36 public static int getColumnIndex(DataTable datatable, String columnName) {37 int columnIndex = 0;

Full Screen

Full Screen

DataTableInformation

Using AI Code Generation

copy

Full Screen

1String columnName = "Country";2DataTableInformation dti = new DataTableInformation();3dti = dti.getDataTableInformation(table);4int columnIdx = dti.getColumnIndex(columnName);5System.out.println(columnIdx);6System.out.println(dti.getColumnName(columnIdx));7System.out.println(dti.getColumnCount());8System.out.println(dti.getRowCount());9System.out.println(dti.toString());10System.out.println(dti.toJson());11System.out.println(dti.toXml());12System.out.println(dti.toYaml());13System.out.println(dti.toCsv());14System.out.println(dti.toTsv());15System.out.println(dti.toHtml());16System.out.println(dti.toMarkdown());17System.out.println(dti.toText());18System.out.println(dti.toSql());19System.out.println(dti.toJava());20System.out.println(dti.toCSharp());21System.out.println(dti.toPhp());22System.out.println(dti.toPython());23System.out.println(dti.toRuby());

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful