use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class TestCaseLabelService method compareListAndUpdateInsertDeleteElements.
@Override
public Answer compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseLabel> newList) {
Answer ans = new Answer(null);
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
List<TestCaseLabel> oldList = new ArrayList();
try {
oldList = this.convert(this.readByTestTestCase(test, testCase));
} catch (CerberusException ex) {
LOG.error(ex);
}
/**
* Update and Create all objects database Objects from newList
*/
List<TestCaseLabel> listToUpdateOrInsert = new ArrayList(newList);
listToUpdateOrInsert.removeAll(oldList);
List<TestCaseLabel> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
for (TestCaseLabel objectDifference : listToUpdateOrInsertToIterate) {
for (TestCaseLabel objectInDatabase : oldList) {
if (objectDifference.hasSameKey(objectInDatabase)) {
ans = this.update(objectDifference);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
listToUpdateOrInsert.remove(objectDifference);
}
}
}
/**
* Delete all objects database Objects that do not exist from newList
*/
List<TestCaseLabel> listToDelete = new ArrayList(oldList);
listToDelete.removeAll(newList);
List<TestCaseLabel> listToDeleteToIterate = new ArrayList(listToDelete);
for (TestCaseLabel tcsDifference : listToDeleteToIterate) {
for (TestCaseLabel tcsInPage : newList) {
if (tcsDifference.hasSameKey(tcsInPage)) {
listToDelete.remove(tcsDifference);
}
}
}
if (!listToDelete.isEmpty()) {
ans = this.deleteList(listToDelete);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
if (!listToUpdateOrInsert.isEmpty()) {
ans = this.createList(listToUpdateOrInsert);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
return finalAnswer;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class ReadTestCaseLabel method findTestCaseLabelList.
// </editor-fold>
private AnswerItem findTestCaseLabelList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
/*int sEcho = Integer.valueOf(request.getParameter("sEcho"));*/
String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "Label,Description,sort,type,system,subsystem,svnurl,bugtrackerurl,bugtrackernewurl,deploytype,mavengroupid");
String[] columnToSort = sColumns.split(",");
String columnName = columnToSort[columnToSortParameter];
String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
Map<String, List<String>> individualSearch = new HashMap<>();
for (int a = 0; a < columnToSort.length; a++) {
if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
individualSearch.put(columnToSort[a], search);
}
}
AnswerList resp = testCaseLabelService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
JSONArray jsonArray = new JSONArray();
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (TestCaseLabel label : (List<TestCaseLabel>) resp.getDataList()) {
jsonArray.put(convertTestCaseLabelToJSONObject(label));
}
}
object.put("hasPermissions", userHasPermissions);
object.put("contentTable", jsonArray);
object.put("iTotalRecords", resp.getTotalRows());
object.put("iTotalDisplayRecords", resp.getTotalRows());
item.setItem(object);
item.setResultMessage(resp.getResultMessage());
return item;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class ReadTestCaseLabel method findByTestTestCase.
private AnswerItem findByTestTestCase(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
String test = request.getParameter("test");
String testcase = request.getParameter("testcase");
AnswerList resp = testCaseLabelService.readByTestTestCase(test, testcase);
JSONArray jsonArray = new JSONArray();
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (TestCaseLabel label : (List<TestCaseLabel>) resp.getDataList()) {
jsonArray.put(convertTestCaseLabelToJSONObject(label));
}
}
object.put("hasPermissions", userHasPermissions);
object.put("contentTable", jsonArray);
object.put("iTotalRecords", resp.getTotalRows());
object.put("iTotalDisplayRecords", resp.getTotalRows());
item.setItem(object);
item.setResultMessage(resp.getResultMessage());
return item;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class ReadTestCaseLabel method findLabelByKey.
private AnswerItem findLabelByKey(Integer id, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
ITestCaseLabelService labelService = appContext.getBean(ITestCaseLabelService.class);
// finds the project
AnswerItem answer = labelService.readByKeyTech(id);
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// if the service returns an OK message then we can get the item and convert it to JSONformat
TestCaseLabel label = (TestCaseLabel) answer.getItem();
JSONObject response = convertTestCaseLabelToJSONObject(label);
object.put("contentTable", response);
}
object.put("hasPermissions", userHasPermissions);
item.setItem(object);
item.setResultMessage(answer.getResultMessage());
return item;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class SaveTestCaseLabel 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, CerberusException, JSONException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
String charset = request.getCharacterEncoding();
String usr = request.getUserPrincipal().getName();
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
testCaseLabelFactory = appContext.getBean(IFactoryTestCaseLabel.class);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
String test = policy.sanitize(request.getParameter("test"));
String testcase = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testcase"), "", charset);
String[] labelIdList = request.getParameterValues("labelid");
/**
* Checking all constrains before calling the services.
*/
if (test.isEmpty() || testcase.isEmpty()) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseLabel").replace("%OPERATION%", "Save").replace("%REASON%", "Mandatory parameter is missing. [test|testcase]"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
List<TestCaseLabel> toSave = new ArrayList();
if (null != labelIdList && labelIdList.length != 0) {
Timestamp creationDate = new Timestamp(new Date().getTime());
for (String lableId : labelIdList) {
toSave.add(testCaseLabelFactory.create(0, test, testcase, Integer.valueOf(lableId), usr, creationDate, usr, creationDate, null));
}
}
List<TestCaseLabel> existingList = testCaseLabelService.readByTestTestCase(test, testcase).getDataList();
testCaseLabelService.compareListAndUpdateInsertDeleteElements(test, testcase, toSave);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseLabel").replace("%OPERATION%", "Save"));
ans.setResultMessage(msg);
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
Aggregations