Best Cerberus-source code snippet using org.cerberus.util.answer.AnswerItem.AnswerItem
Source:ReadTestCaseV2.java
...59import org.cerberus.engine.entity.MessageEvent;60import org.cerberus.enums.MessageEventEnum;61import org.cerberus.exception.CerberusException;62import org.cerberus.util.ParameterParserUtil;63import org.cerberus.util.answer.AnswerItem;64import org.cerberus.util.answer.AnswerList;65import org.cerberus.util.answer.AnswerUtil;66import org.cerberus.util.servlet.ServletUtil;67import org.json.JSONArray;68import org.json.JSONException;69import org.json.JSONObject;70import org.owasp.html.PolicyFactory;71import org.owasp.html.Sanitizers;72import org.springframework.beans.factory.annotation.Autowired;73/**74 *75 * @author mlombard76 */77@WebServlet(name = "ReadTestCaseV2", urlPatterns = {"/ReadTestCaseV2"})78public class ReadTestCaseV2 extends AbstractCrudTestCase {79 @Autowired80 private ITestCaseService testCaseService;81 @Autowired82 private ITestCaseCountryService testCaseCountryService;83 @Autowired84 private ITestCaseDepService testCaseDepService;85 @Autowired86 private ITestCaseStepService testCaseStepService;87 @Autowired88 private ITestCaseStepActionService testCaseStepActionService;89 @Autowired90 private ITestCaseStepActionControlService testCaseStepActionControlService;91 @Autowired92 private ITestCaseLabelService testCaseLabelService;93 @Autowired94 private ICampaignParameterService campaignParameterService;95 @Autowired96 private ITestCaseCountryPropertiesService testCaseCountryPropertiesService;97 @Autowired98 private ILabelService labelService;99 @Autowired100 private IInvariantService invariantService;101 @Autowired102 private IApplicationService applicationService;103 private static final Logger LOG = LogManager.getLogger(ReadTestCase.class);104 private AnswerList<TestCaseCountry> answerTestCaseCountries;105 private List<TestCaseDep> testCaseDependencies;106 private AnswerList<TestCaseLabel> answerTestCaseLabels;107 private List<Invariant> countryInvariants;108 /**109 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>110 * methods.111 *112 * @param request servlet request113 * @param response servlet response114 * @throws ServletException if a servlet-specific error occurs115 * @throws IOException if an I/O error occurs116 */117 protected void processRequest(HttpServletRequest request, HttpServletResponse response)118 throws ServletException, IOException {119 int sEcho = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("sEcho"), "0"));120 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);121 response.setContentType("application/json");122 response.setCharacterEncoding("utf8");123 // Calling Servlet Transversal Util.124 ServletUtil.servletStart(request);125 // Default message to unexpected error.126 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);127 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));128 //Parsing and securing all required parameters.129 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");130 List<String> system = ParameterParserUtil.parseListParamAndDecodeAndDeleteEmptyValue(request.getParameterValues("system"), Arrays.asList("DEFAULT"), "UTF-8");131 String testCase = ParameterParserUtil.parseStringParam(request.getParameter("testCase"), null);132 String campaign = ParameterParserUtil.parseStringParam(request.getParameter("campaign"), "");133 boolean getMaxTC = ParameterParserUtil.parseBooleanParam(request.getParameter("getMaxTC"), false);134 boolean filter = ParameterParserUtil.parseBooleanParam(request.getParameter("filter"), false);135 boolean withSteps = ParameterParserUtil.parseBooleanParam(request.getParameter("withSteps"), false);136 String columnName = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");137 // Init Answer with potencial error from Parsing parameter.138 AnswerItem answer = new AnswerItem<>(msg);139 JSONObject jsonResponse = new JSONObject();140 try {141 if (!Strings.isNullOrEmpty(test) && testCase != null) {142 answer = findTestCaseByTestTestCase(test, testCase, request, withSteps);143 } else if (!Strings.isNullOrEmpty(test) && getMaxTC) {144 String max = testCaseService.getMaxNumberTestCase(test) == null ? "0" : testCaseService.getMaxNumberTestCase(test);145 jsonResponse.put("maxTestCase", Integer.valueOf(max));146 answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));147 } else if (filter) {148 answer = findTestCaseByVarious(request);149 } else if (!Strings.isNullOrEmpty(campaign)) {150 answer = findTestCaseByCampaign(campaign, withSteps);151 } else if (!Strings.isNullOrEmpty(columnName)) {152 //If columnName is present, then return the distinct value of this column.153 answer = findDistinctValuesOfColumn(system, test, request, columnName);154 } else {155 // Page TestCaseList156 answer = findTestCaseByTest(system, test, request, withSteps);157 }158 if (!getMaxTC) {159 jsonResponse = answer.getItem() == null ? new JSONObject() : (JSONObject) answer.getItem();160 }161 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());162 jsonResponse.put("message", answer.getResultMessage().getDescription());163 jsonResponse.put("sEcho", sEcho);164 response.getWriter().print(jsonResponse.toString());165 } catch (JSONException e) {166 LOG.warn(e, e);167 //returns a default error message with the json format that is able to be parsed by the client-side168 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());169 } catch (CerberusException | IOException | NumberFormatException ex) {170 LOG.error(ex, ex);171 // TODO return to the gui172 }173 // TODO return to the gui174 }175 private AnswerItem<JSONObject> findTestCaseByTest(List<String> system, String test, HttpServletRequest request, boolean withSteps) throws JSONException, CerberusException {176 AnswerItem<JSONObject> answerItem = new AnswerItem<>();177 JSONObject jsonResponse = new JSONObject();178 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));179 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));180 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");181 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "tec.test,tec.testcase,tec.application,project,ticket,description,detailedDescription,readonly,bugtrackernewurl,deploytype,mavengroupid");182 String columnToSort[] = sColumns.split(",");183 List<String> individualLike = new ArrayList<>(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));184 StringBuilder sortInformation = getSortingInformation(columnToSort, request);185 Map<String, List<String>> individualSearch = getIndivualSearch(request, columnToSort, individualLike);186 AnswerList<TestCase> testCases = testCaseService.readByTestByCriteria(system, test, startPosition, length, sortInformation.toString(), searchParameter, individualSearch);187 this.answerTestCaseCountries = testCaseCountryService.readByTestTestCase(system, test, null, testCases.getDataList());188 this.testCaseDependencies = testCaseDepService.readByTestAndTestCase(testCases.getDataList());189 this.answerTestCaseLabels = testCaseLabelService.readByTestTestCase(test, null, testCases.getDataList());190 this.countryInvariants = invariantService.readByIdName("COUNTRY");191 //jsonResponse.put("contentTable", getTestCases(testCases.getDataList(), withSteps));192 jsonResponse.put("hasPermissionsCreate", testCaseService.hasPermissionsCreate(null, request));193 jsonResponse.put("iTotalRecords", testCases.getTotalRows());194 jsonResponse.put("iTotalDisplayRecords", testCases.getTotalRows());195 answerItem.setItem(jsonResponse);196 answerItem.setResultMessage(testCases.getResultMessage());197 return answerItem;198 }199 private AnswerItem<JSONObject> findTestCaseByTestTestCase(String test, String testCase, HttpServletRequest request, boolean withSteps) throws JSONException, CerberusException {200 AnswerItem<JSONObject> answerItem = new AnswerItem<>();201 JSONObject jsonResponse = new JSONObject();202 AnswerItem<TestCase> answerTestCase;203 answerTestCase = testCaseService.findTestCaseByKeyWithDependencies(test, testCase, withSteps);204 if (answerTestCase.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerTestCase.getItem() != null) {205 TestCase tc = answerTestCase.getItem();206 if (withSteps) {207 jsonResponse.put("hasPermissionsStepLibrary", (request.isUserInRole("TestStepLibrary")));208 }209 jsonResponse.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(tc, request));210 jsonResponse.put("hasPermissionsDelete", testCaseService.hasPermissionsDelete(tc, request));211 jsonResponse.put("contentTable", new JSONArray().put(tc.toJson()));212 } else {213 answerItem.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_NOT_FOUND_OR_NOT_AUTHORIZE));214 return answerItem;215 }216 answerItem.setItem(jsonResponse);217 answerItem.setResultMessage(answerTestCase.getResultMessage());218 return answerItem;219 }220 private AnswerItem findTestCaseByCampaign(String campaign, boolean withSteps) throws JSONException, CerberusException {221 AnswerItem<JSONObject> answerItem = new AnswerItem<>();222 JSONObject jsonResponse = new JSONObject();223 final AnswerItem<Map<String, List<String>>> parsedCampaignParameters = campaignParameterService.parseParametersByCampaign(campaign);224 List<String> countries = parsedCampaignParameters.getItem().get(CampaignParameter.COUNTRY_PARAMETER);225 AnswerList<TestCase> testCases = null;226 if (countries != null && !countries.isEmpty()) {227 testCases = testCaseService.findTestCaseByCampaignNameAndCountries(campaign, countries.toArray(new String[countries.size()]));228 } else {229 testCases = testCaseService.findTestCaseByCampaignNameAndCountries(campaign, null);230 }231 if (testCases.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values232 //jsonResponse.put("contentTable", getTestCases(testCases.getDataList(), withSteps));233 }234 answerItem.setItem(jsonResponse);235 answerItem.setResultMessage(testCases.getResultMessage());236 return answerItem;237 }238 private AnswerItem<JSONObject> findTestCaseByVarious(HttpServletRequest request) throws JSONException {239 AnswerItem<JSONObject> item = new AnswerItem<>();240 JSONObject object = new JSONObject();241 JSONArray dataArray = new JSONArray();242 String[] test = request.getParameterValues("test");243 String[] idProject = request.getParameterValues("project");244 String[] app = request.getParameterValues("application");245 String[] creator = request.getParameterValues("creator");246 String[] implementer = request.getParameterValues("implementer");247 String[] system = request.getParameterValues("system");248 String[] campaign = request.getParameterValues("campaign");249 String[] priority = request.getParameterValues("priority");250 String[] type = request.getParameterValues("type");251 String[] status = request.getParameterValues("status");252 String[] labelid = request.getParameterValues("labelid");253 List<Integer> labels = new ArrayList<>();254 if (labelid != null) {255 for (int i = 0; i < labelid.length; i++) {256 String string = labelid[i];257 labels.add(Integer.valueOf(string));258 }259 labels = labelService.enrichWithChild(labels);260 }261 int length = ParameterParserUtil.parseIntegerParam(request.getParameter("length"), -1);262 AnswerList<TestCase> answer = testCaseService.readByVarious(test, app, creator, implementer, system, campaign, labels, priority, type, status, length);263 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {264 for (TestCase tc : (List<TestCase>) answer.getDataList()) {265 JSONObject value = tc.toJson();266 dataArray.put(value);267 }268 }269 object.put("contentTable", dataArray);270 item.setItem(object);271 item.setResultMessage(answer.getResultMessage());272 return item;273 }274 private AnswerItem<JSONObject> findDistinctValuesOfColumn(List<String> system, String test, HttpServletRequest request, String columnName) throws JSONException {275 AnswerItem<JSONObject> answerItem = new AnswerItem<>();276 JSONObject jsonResponse = new JSONObject();277 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");278 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "tec.test,tec.testcase,application,project,ticket,description,detailedDescription,readonly,bugtrackernewurl,deploytype,mavengroupid");279 String columnToSort[] = sColumns.split(",");280 List<String> individualLike = new ArrayList<>(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));281 Map<String, List<String>> individualSearch = getIndivualSearch(request, columnToSort, individualLike);282 AnswerList testCases = testCaseService.readDistinctValuesByCriteria(system, test, searchParameter, individualSearch, columnName);283 jsonResponse.put("distinctValues", testCases.getDataList());284 answerItem.setItem(jsonResponse);285 answerItem.setResultMessage(testCases.getResultMessage());286 return answerItem;287 }288 private StringBuilder getSortingInformation(String columnToSort[], HttpServletRequest request) {289 int numberOfColumnToSort = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortingCols"), "1"));...
Source:ReadTestCase.java
...36import org.cerberus.engine.entity.MessageEvent;37import org.cerberus.enums.MessageEventEnum;38import org.cerberus.exception.CerberusException;39import org.cerberus.util.ParameterParserUtil;40import org.cerberus.util.answer.AnswerItem;41import org.cerberus.util.answer.AnswerList;42import org.cerberus.util.answer.AnswerUtil;43import org.cerberus.util.servlet.ServletUtil;44import org.json.JSONArray;45import org.json.JSONException;46import org.json.JSONObject;47import org.springframework.beans.factory.annotation.Autowired;48/**49 * @author cerberus50 */51@WebServlet(name = "ReadTestCase", urlPatterns = {"/ReadTestCase"})52public class ReadTestCase extends AbstractCrudTestCase {53 @Autowired54 private ITestCaseService testCaseService;55 @Autowired56 private ILabelService labelService;57 private static final Logger LOG = LogManager.getLogger(ReadTestCase.class);58 /**59 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>60 * methods.61 *62 * @param request servlet request63 * @param response servlet response64 * @throws ServletException if a servlet-specific error occurs65 * @throws IOException if an I/O error occurs66 */67 @Override68 protected void processRequest(HttpServletRequest request, HttpServletResponse response)69 throws ServletException, IOException {70 71 response.setContentType("application/json");72 response.setCharacterEncoding("utf8");73 // Calling Servlet Transversal Util.74 ServletUtil.servletStart(request);75 // Default message to unexpected error.76 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);77 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));78 /**79 * Parsing and securing all required parameters.80 */81 int sEcho = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("sEcho"), "0"));82 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");83 List<String> system = ParameterParserUtil.parseListParamAndDecodeAndDeleteEmptyValue(request.getParameterValues("system"), Arrays.asList("DEFAULT"), "UTF-8");84 String testCase = ParameterParserUtil.parseStringParam(request.getParameter("testCase"), null);85 String campaign = ParameterParserUtil.parseStringParam(request.getParameter("campaign"), "");86 boolean getMaxTC = ParameterParserUtil.parseBooleanParam(request.getParameter("getMaxTC"), false);87 boolean filter = ParameterParserUtil.parseBooleanParam(request.getParameter("filter"), false);88 boolean withSteps = ParameterParserUtil.parseBooleanParam(request.getParameter("withSteps"), false);89 String columnName = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");90 // Init Answer with potencial error from Parsing parameter.91 AnswerItem<JSONObject> answer = new AnswerItem<>(msg);92 JSONObject jsonResponse = new JSONObject();93 try {94 if (!Strings.isNullOrEmpty(test) && testCase != null) {95 answer = findTestCaseByTestTestCase(test, testCase, request, withSteps);96 } else if (!Strings.isNullOrEmpty(test) && getMaxTC) {97 String max = testCaseService.getNextAvailableTestcaseId(test);98 jsonResponse.put("nextAvailableTestcaseId", max);99 answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));100 } else if (filter) {101 answer = findTestCaseByVarious(request);102 } else if (!Strings.isNullOrEmpty(campaign)) {103 answer = findTestCaseByCampaign(campaign);104 } else if (!Strings.isNullOrEmpty(columnName)) {105 //If columnName is present, then return the distinct value of this column.106 answer = findDistinctValuesOfColumn(system, test, request, columnName);107 } else {108 // Page TestCaseList109 answer = findTestCaseByTest(system, test, request);110 }111 if (!getMaxTC) {112 jsonResponse = (answer.getItem() == null) ? new JSONObject() : answer.getItem();113 }114 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());115 jsonResponse.put("message", answer.getResultMessage().getDescription());116 jsonResponse.put("sEcho", sEcho);117 response.getWriter().print(jsonResponse.toString());118 } catch (JSONException e) {119 LOG.warn(e, e);120 //returns a default error message with the json format that is able to be parsed by the client-side121 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());122 } catch (CerberusException ex) {123 LOG.error(ex, ex);124 // TODO return to the gui125 } catch (Exception ex) {126 LOG.error(ex, ex);127 // TODO return to the gui128 }129 }130 private AnswerItem<JSONObject> findTestCaseByTest(List<String> system, String test, HttpServletRequest request) throws JSONException, CerberusException {131 AnswerItem<JSONObject> answer = new AnswerItem<>();132 JSONObject object = new JSONObject();133 boolean isCalledFromListPage = (request.getParameter("sColumns") != null);134 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));135 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));136 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");137 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "tec.test,tec.testcase,tec.application,project,ticket,description,detailedDescription,readonly,bugtrackernewurl,deploytype,mavengroupid");138 String columnToSort[] = sColumns.split(",");139 List<String> individualLike = new ArrayList<>(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));140 StringBuilder sortInformation = getSortingInformation(columnToSort, request);141 Map<String, List<String>> individualSearch = getIndivualSearch(request, columnToSort, individualLike);142 AnswerList<TestCase> testCases = testCaseService.findTestCasesByTestByCriteriaWithDependencies(system, test, startPosition, length, sortInformation.toString(), searchParameter, individualSearch, isCalledFromListPage);143 JSONArray jsonArray = new JSONArray();144 for (TestCase testCase : testCases.getDataList()) {145 JSONObject jsonTestCase = testCase.toJson();146 jsonTestCase.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(testCase, request));147 jsonTestCase.put("hasPermissionsDelete", testCaseService.hasPermissionsDelete(testCase, request));148 jsonArray.put(jsonTestCase);149 }150 object.put("hasPermissionsCreate", testCaseService.hasPermissionsCreate(null, request));151 object.put("contentTable", jsonArray);152 object.put("iTotalRecords", testCases.getTotalRows());153 object.put("iTotalDisplayRecords", testCases.getTotalRows());154 answer.setItem(object);155 answer.setResultMessage(testCases.getResultMessage());156 return answer;157 }158 private AnswerItem<JSONObject> findTestCaseByTestTestCase(String test, String testCase, HttpServletRequest request, boolean withSteps) throws JSONException, CerberusException {159 AnswerItem<JSONObject> answerItem = new AnswerItem<>();160 JSONObject jsonResponse = new JSONObject();161 AnswerItem<TestCase> answerTestCase;162 answerTestCase = testCaseService.findTestCaseByKeyWithDependencies(test, testCase, withSteps);163 if (answerTestCase.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerTestCase.getItem() != null) {164 TestCase tc = answerTestCase.getItem();165 if (withSteps) {166 jsonResponse.put("hasPermissionsStepLibrary", (request.isUserInRole("TestStepLibrary")));167 }168 jsonResponse.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(tc, request));169 jsonResponse.put("hasPermissionsDelete", testCaseService.hasPermissionsDelete(tc, request));170 jsonResponse.put("contentTable", new JSONArray().put(tc.toJson()));171 } else {172 answerItem.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_NOT_FOUND_OR_NOT_AUTHORIZE));173 return answerItem;174 }175 answerItem.setItem(jsonResponse);176 answerItem.setResultMessage(answerTestCase.getResultMessage());177 LOG.debug(answerItem.getItem());178 return answerItem;179 }180 private AnswerItem<JSONObject> findTestCaseByVarious(HttpServletRequest request) throws JSONException {181 AnswerItem<JSONObject> item = new AnswerItem<>();182 JSONObject object = new JSONObject();183 JSONArray dataArray = new JSONArray();184 String[] test = request.getParameterValues("test");185 String[] idProject = request.getParameterValues("project");186 String[] app = request.getParameterValues("application");187 String[] creator = request.getParameterValues("creator");188 String[] implementer = request.getParameterValues("implementer");189 String[] system = request.getParameterValues("system");190 String[] campaign = request.getParameterValues("campaign");191 String[] priority = request.getParameterValues("priority");192 String[] type = request.getParameterValues("type");193 String[] status = request.getParameterValues("status");194 String[] labelid = request.getParameterValues("labelid");195 List<Integer> labels = new ArrayList<>();196 if (labelid != null) {197 for (int i = 0; i < labelid.length; i++) {198 String string = labelid[i];199 labels.add(Integer.valueOf(string));200 }201 labels = labelService.enrichWithChild(labels);202 }203 int length = ParameterParserUtil.parseIntegerParam(request.getParameter("length"), -1);204 AnswerList<TestCase> answer = testCaseService.readByVarious(test, app, creator, implementer, system, campaign, labels, priority, type, status, length);205 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {206 for (TestCase tc : answer.getDataList()) {207 JSONObject value = tc.toJson();208 dataArray.put(value);209 }210 }211 object.put("contentTable", dataArray);212 item.setItem(object);213 item.setResultMessage(answer.getResultMessage());214 return item;215 }216 private AnswerItem<JSONObject> findTestCaseByCampaign(String campaign) throws JSONException {217 AnswerItem<JSONObject> answerItem = new AnswerItem<>();218 JSONObject jsonResponse = new JSONObject();219 JSONArray dataArray = new JSONArray();220 AnswerList<TestCase> testCases = testCaseService.findTestCaseByCampaign(campaign);221 if (testCases.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values222 for (TestCase testCase : testCases.getDataList()) {223 JSONObject jsonTestCase = testCase.toJson();224 dataArray.put(jsonTestCase);225 }226 }227 jsonResponse.put("contentTable", dataArray);228 answerItem.setItem(jsonResponse);229 answerItem.setResultMessage(testCases.getResultMessage());230 return answerItem;231 }232 private AnswerItem<JSONObject> findDistinctValuesOfColumn(List<String> system, String test, HttpServletRequest request, String columnName) throws JSONException {233 AnswerItem<JSONObject> answerItem = new AnswerItem<>();234 JSONObject jsonResponse = new JSONObject();235 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");236 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "tec.test,tec.testcase,application,project,ticket,description,detailedDescription,readonly,bugtrackernewurl,deploytype,mavengroupid");237 String columnToSort[] = sColumns.split(",");238 List<String> individualLike = new ArrayList<>(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));239 Map<String, List<String>> individualSearch = getIndivualSearch(request, columnToSort, individualLike);240 AnswerList testCaseList = testCaseService.readDistinctValuesByCriteria(system, test, searchParameter, individualSearch, columnName);241 jsonResponse.put("distinctValues", testCaseList.getDataList());242 answerItem.setItem(jsonResponse);243 answerItem.setResultMessage(testCaseList.getResultMessage());244 return answerItem;245 }246 private StringBuilder getSortingInformation(String columnToSort[], HttpServletRequest request) {247 int numberOfColumnToSort = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortingCols"), "1"));...
Source:ICampaignService.java
...23import org.cerberus.crud.entity.Campaign;24import org.cerberus.crud.entity.CampaignParameter;25import org.cerberus.exception.CerberusException;26import org.cerberus.util.answer.Answer;27import org.cerberus.util.answer.AnswerItem;28import org.cerberus.util.answer.AnswerList;29/**30 * @author memiks31 */32public interface ICampaignService {33 List<CampaignParameter> findCampaignParametersByCampaignName(String campaign) throws CerberusException;34 /**35 * Get the {@link Campaign} List of the given {@link System} with the given36 * Criteria37 *38 * @param startPosition the start index to look for39 * @param length the number of {@link Campaign} to get40 * @param columnName the Column name to sort41 * @param sort42 * @param searchParameter the string to search in the {@link Campaign}43 * @param individualSearch the string to search for each column44 * @return45 */46 AnswerList readByCriteria(int startPosition, int length, String columnName, String sort, String searchParameter, Map<String, List<String>> individualSearch);47 /**48 * Get the {@link Campaign} with the given {@link System} and the given key49 *50 * @param key the key of the {@link Campaign}51 * @return52 */53 AnswerItem readByKey(String key);54 /**55 * Get the {@link Campaign} with the given {@link System} and the given key56 *57 * @param key the key of the {@link Campaign}58 * @return59 */60 AnswerItem readByKeyTech(int key);61 /**62 * @param searchParameter63 * @param individualSearch64 * @param columnName65 * @return66 */67 public AnswerList<String> readDistinctValuesByCriteria(String searchParameter, Map<String, List<String>> individualSearch, String columnName);68 /**69 * @param object the {@link Campaign} to Create70 * @return {@link AnswerItem}71 */72 Answer create(Campaign object);73 /**74 * @param object the {@link Campaign} to Update75 * @return {@link AnswerItem}76 */77 Answer update(Campaign object);78 /**79 * @param object the {@link Campaign} to Delete80 * @return {@link AnswerItem}81 */82 Answer delete(Campaign object);83 /**84 *85 * @param answerItem86 * @return87 * @throws CerberusException88 */89 Campaign convert(AnswerItem answerItem) throws CerberusException;90 /**91 *92 * @param answerList93 * @return94 * @throws CerberusException95 */96 List<Campaign> convert(AnswerList answerList) throws CerberusException;97 /**98 *99 * @param answer100 * @throws CerberusException101 */102 void convert(Answer answer) throws CerberusException;103}...
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2public class AnswerItem<T> {3 private T item;4 private MessageEvent message;5 public AnswerItem(T item) {6 this.item = item;7 this.message = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);8 }9 public AnswerItem(MessageEvent message) {10 this.message = message;11 }12 public AnswerItem(T item, MessageEvent message) {13 this.item = item;14 this.message = message;15 }16 public T getItem() {17 return item;18 }19 public void setItem(T item) {20 this.item = item;21 }22 public MessageEvent getMessage() {23 return message;24 }25 public void setMessage(MessageEvent message) {26 this.message = message;27 }28}29package org.cerberus.util.answer;30import java.util.ArrayList;31import java.util.List;32public class AnswerList<T> {33 private List<T> dataList;34 private MessageEvent message;35 public AnswerList() {36 this.dataList = new ArrayList<T>();37 this.message = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);38 }39 public AnswerList(List<T> dataList) {40 this.dataList = dataList;41 this.message = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);42 }43 public AnswerList(MessageEvent message) {44 this.dataList = new ArrayList<T>();45 this.message = message;46 }47 public AnswerList(List<T> dataList, MessageEvent message) {48 this.dataList = dataList;49 this.message = message;50 }51 public List<T> getDataList() {52 return dataList;53 }54 public void setDataList(List<T> dataList) {55 this.dataList = dataList;56 }57 public MessageEvent getMessage() {58 return message;59 }60 public void setMessage(MessageEvent message) {61 this.message = message;62 }63}64package org.cerberus.util.answer;65public class AnswerItem<T> {66 private T item;67 private MessageEvent message;68 public AnswerItem(T item) {69 this.item = item;70 this.message = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);71 }
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2import java.util.HashMap;3import java.util.Map;4public class AnswerItem {5 private final Map<String, MessageEvent> messages = new HashMap<String, MessageEvent>();6 private final Map<String, MessageGeneral> messagesGeneral = new HashMap<String, MessageGeneral>();7 private final Map<String, Object> object = new HashMap<String, Object>();8 private boolean code = false;9 private String description = "";10 private String message = "";11 public AnswerItem() {12 super();13 }14 public AnswerItem(boolean code, String description) {15 this.code = code;16 this.description = description;17 }18 public AnswerItem(boolean code, String description, String message) {19 this.code = code;20 this.description = description;21 this.message = message;22 }23 public boolean isCodeEquals(MessageGeneralEnum message) {24 return this.code && this.message.equals(message.getCodeString());25 }26 public boolean isCodeEquals(MessageGeneralEnum message, String description) {27 return this.code && this.message.equals(message.getCodeString()) && this.description.equals(description);28 }29 public boolean isCodeEquals(MessageGeneralEnum message, String description, String object) {30 return this.code && this.message.equals(message.getCodeString()) && this.description.equals(description) && this.object.get(object) != null;31 }32 public boolean isCodeEquals(MessageGeneralEnum message, String description, String object, String object2) {33 return this.code && this.message.equals(message.getCodeString()) && this.description.equals(description) && this.object.get(object) != null && this.object.get(object2) != null;34 }35 public boolean isCodeEquals(MessageGeneralEnum message, String description, String object, String object2, String object3) {36 return this.code && this.message.equals(message.getCodeString()) && this.description.equals(description) && this.object.get(object) != null && this.object.get(object2) != null && this.object.get(object3) != null;37 }38 public boolean isCodeEquals(MessageGeneralEnum message, String description, String object, String object2, String object3, String object4) {39 return this.code && this.message.equals(message.getCodeString()) && this.description.equals(description) && this.object.get(object) != null && this.object.get(object2) != null && this.object.get(object3) != null && this.object.get(object4) != null;40 }
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2import org.cerberus.util.answer.AnswerItem;3public class AnswerItemTest {4 public static void main(String[] args) {5 AnswerItem item = new AnswerItem();6 item.setItem("hello");7 System.out.println(item.getItem());8 }9}10package org.cerberus.util.answer;11import org.cerberus.util.answer.AnswerList;12public class AnswerListTest {13 public static void main(String[] args) {14 AnswerList list = new AnswerList();15 list.setDataList("hello");16 System.out.println(list.getDataList());17 }18}19package org.cerberus.util.answer;20import org.cerberus.util.answer.Answer;21public class AnswerTest {22 public static void main(String[] args) {23 Answer answer = new Answer();24 answer.setResultMessage("hello");25 System.out.println(answer.getResultMessage());26 }27}28package org.cerberus.util.answer;29import org.cerberus.util.answer.AnswerUtil;30public class AnswerUtilTest {31 public static void main(String[] args) {32 String message = "hello";33 System.out.println(AnswerUtil.createMessageAnswer(message));34 }35}36package org.cerberus.util.answer;37import org.cerberus.util.answer.AnswerUtil;38public class AnswerUtilTest2 {
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2import org.cerberus.util.answer.AnswerItem;3import java.util.*;4public class AnswerItemDemo {5 public static void main(String[] args) {6 AnswerItem ai = new AnswerItem();7 ai.setItem("Hello");8 ai.setTotalRows(1);9 ai.setDataLength(1);10 ai.setFetchSize(1);11 ai.setStartIndex(0);12 ai.setHasData(true);13 ai.setHasMoreData(false);14 ai.setTotalRows(1);15 ai.setTotalPages(1);16 ai.setPageNumber(1);17 ai.setPageSize(1);18 ai.setSort("Hello");19 ai.setSortParameter("Hello");20 ai.setSortParameter("H
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2import java.util.logging.Level;3import java.util.logging.Logger;4public class AnswerItem {5 private String message;6 private boolean code;7 public AnswerItem() {8 this.message = "";9 this.code = false;10 }11 public AnswerItem(String message, boolean code) {12 this.message = message;13 this.code = code;14 }15 public String getMessage() {16 return message;17 }18 public void setMessage(String message) {19 this.message = message;20 }21 public boolean getCode() {22 return code;23 }24 public void setCode(boolean code) {25 this.code = code;26 }27 public String toString() {28 return "AnswerItem{" + "message=" + message + ", code=" + code + '}';29 }30 public String toJson() {31 String result = "";32 result = "{\"message\" : \"" + message + "\", \"code\" : " + code + "}";33 return result;34 }35}36package org.cerberus.util.answer;37import java.util.ArrayList;38import java.util.List;39import java.util.logging.Level;40import java.util.logging.Logger;41public class AnswerList<T> {42 private List<T> list;43 private String message;44 private boolean code;45 public AnswerList() {46 this.list = new ArrayList<T>();47 this.message = "";48 this.code = false;49 }50 public AnswerList(List<T> list, String message, boolean code) {51 this.list = list;52 this.message = message;53 this.code = code;54 }55 public List<T> getList() {56 return list;57 }58 public void setList(List<T> list) {59 this.list = list;60 }61 public String getMessage() {62 return message;63 }64 public void setMessage(String message) {65 this.message = message;66 }67 public boolean getCode() {68 return code;69 }70 public void setCode(boolean code) {71 this.code = code;72 }73 public String toString() {74 return "AnswerList{" + "list=" + list + ", message=" + message + ", code=" + code + '}';75 }76 public String toJson() {77 String result = "";78 result = "{\"list\"
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2public class AnswerItem {3 private MessageEvent message;4 private Object object;5 private String messageString;6 private Integer id;7 public AnswerItem(Object object, MessageEvent message) {8 this.message = message;9 this.object = object;10 }11 public AnswerItem(Object object, Integer id, MessageEvent message) {12 this.message = message;13 this.object = object;14 this.id = id;15 }16 public AnswerItem(Object object, Integer id, String message) {17 this.messageString = message;18 this.object = object;19 this.id = id;20 }21 public AnswerItem(Object object, String message) {22 this.messageString = message;23 this.object = object;24 }25 public AnswerItem(MessageEvent message) {26 this.message = message;27 }28 public AnswerItem(String message) {29 this.messageString = message;30 }31 public MessageEvent getMessage() {32 return message;33 }34 public void setMessage(MessageEvent message) {35 this.message = message;36 }37 public Object getObject() {38 return object;39 }40 public void setObject(Object object) {41 this.object = object;42 }43 public String getMessageString() {44 return messageString;45 }46 public void setMessageString(String messageString) {47 this.messageString = messageString;48 }49 public Integer getId() {50 return id;51 }52 public void setId(Integer id) {53 this.id = id;54 }55}56package org.cerberus.util.answer;57import java.util.ArrayList;58import java.util.List;59public class AnswerList<T> extends Answer {60 private List<T> objectList;61 public AnswerList() {62 objectList = new ArrayList<T>();63 }64 public AnswerList(List<T> objectList, MessageEvent message) {65 super(message);66 this.objectList = objectList;67 }68 public AnswerList(List<T> objectList, String message) {69 super(message);70 this.objectList = objectList;71 }72 public AnswerList(List<T> objectList) {73 this.objectList = objectList;74 }75 public List<T> getObjectList() {76 return objectList;77 }78 public void setObjectList(List<T> objectList) {
AnswerItem
Using AI Code Generation
1package org.cerberus.util.answer;2public class AnswerItemTest {3 public static void main(String[] args) {4 AnswerItem answerItem = new AnswerItem("Message", "Object", false);5 System.out.println(answerItem.getMessage());6 }7}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!