use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class TestDataLibDataDAO method readAll.
@Override
public AnswerList<TestDataLibData> readAll() {
AnswerList answerList = new AnswerList();
List<TestDataLibData> list = new ArrayList<TestDataLibData>();
MessageEvent msg;
final String query = "SELECT * FROM testdatalibdata";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
list.add(this.loadFromResultSet(resultSet));
}
if (list.isEmpty()) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
list.clear();
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
list.clear();
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
list.clear();
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to close connection : " + ex.toString());
}
}
answerList.setDataList(list);
answerList.setTotalRows(list.size());
answerList.setResultMessage(msg);
return answerList;
}
use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class TestDataLibDataDAO method readByKeyTech.
@Override
public AnswerItem readByKeyTech(Integer testDataLibDataID) {
AnswerItem answer = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
TestDataLibData result = null;
final String query = "SELECT * FROM testdatalibdata where `testdatalibdataid`=? ";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.testDataLibDataID : " + testDataLibDataID);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
preStat.setInt(1, testDataLibDataID);
try {
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = this.loadFromResultSet(resultSet);
} else {
// specific message for gefromdatalib
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to close connection : " + ex.toString());
}
}
answer.setResultMessage(msg);
answer.setItem(result);
return answer;
}
use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class DataLibService method getSubDataFromType.
/**
* Get the list of subData
*
* @param lib
* @return
*/
private AnswerItem<HashMap<String, String>> getSubDataFromType(TestDataLib lib) {
AnswerList answerData = new AnswerList();
AnswerItem<HashMap<String, String>> result = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
List<TestDataLibData> objectDataList = new ArrayList<TestDataLibData>();
HashMap<String, String> row = new HashMap<String, String>();
switch(lib.getType()) {
case TestDataLib.TYPE_CSV:
answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), null, null, "N");
if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {
objectDataList = answerData.getDataList();
boolean missingKey = true;
for (TestDataLibData tdld : objectDataList) {
row.put(tdld.getSubData(), tdld.getColumnPosition());
if (tdld.getSubData().equalsIgnoreCase("")) {
missingKey = false;
}
}
result.setItem(row);
if (missingKey) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATACSVNOKEY);
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));
result.setResultMessage(msg);
}
} else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATACSV);
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATACSV);
result.setResultMessage(msg);
}
break;
case TestDataLib.TYPE_SQL:
answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), "N", null, null);
if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {
objectDataList = answerData.getDataList();
boolean missingKey = true;
for (TestDataLibData tdld : objectDataList) {
row.put(tdld.getSubData(), tdld.getColumn());
if (tdld.getSubData().equalsIgnoreCase("")) {
missingKey = false;
}
}
result.setItem(row);
if (missingKey) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASQLNOKEY);
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));
result.setResultMessage(msg);
}
} else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATASQL);
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASQL);
result.setResultMessage(msg);
}
break;
case TestDataLib.TYPE_SERVICE:
answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), null, "N", null);
if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {
objectDataList = answerData.getDataList();
boolean missingKey = true;
for (TestDataLibData tdld : objectDataList) {
row.put(tdld.getSubData(), tdld.getParsingAnswer());
if (tdld.getSubData().equalsIgnoreCase("")) {
missingKey = false;
}
}
result.setItem(row);
if (missingKey) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASOAPNOKEY);
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);
msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));
result.setResultMessage(msg);
}
} else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATASOAP);
result.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASOAP);
result.setResultMessage(msg);
}
break;
case TestDataLib.TYPE_INTERNAL:
// For static Type, there is no need to fetch the subdata as subdata are loaded at the same time of the data.
msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);
result.setResultMessage(msg);
result.setItem(null);
break;
}
return result;
}
use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class CreateTestDataLib method getSubDataFromParameter.
private List<TestDataLibData> getSubDataFromParameter(HttpServletRequest request, ApplicationContext appContext, int testDataLibId, JSONArray json) throws JSONException {
List<TestDataLibData> tdldList = new ArrayList();
IFactoryTestDataLibData tdldFactory = appContext.getBean(IFactoryTestDataLibData.class);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String charset = request.getCharacterEncoding();
for (int i = 0; i < json.length(); i++) {
JSONObject objectJson = json.getJSONObject(i);
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
boolean delete = objectJson.getBoolean("toDelete");
Integer testDataLibDataId = objectJson.getInt("testDataLibDataID");
// Parameter that needs to be secured --> We SECURE+DECODE them
// NONE
// Parameter that we cannot secure as we need the html --> We DECODE them
String subdata = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("subData"), "", charset);
String value = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("value"), "", charset);
String column = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("column"), "", charset);
String parsingAnswer = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("parsingAnswer"), "", charset);
String columnPosition = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("columnPosition"), "", charset);
String description = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("description"), "", charset);
if (!delete) {
TestDataLibData tdld = tdldFactory.create(testDataLibDataId, testDataLibId, subdata, value, column, parsingAnswer, columnPosition, description);
tdldList.add(tdld);
}
}
return tdldList;
}
use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class UpdateTestDataLib method getSubDataFromParameter.
private List<TestDataLibData> getSubDataFromParameter(HttpServletRequest request, ApplicationContext appContext, int testDataLibId, JSONArray json) throws JSONException {
List<TestDataLibData> tdldList = new ArrayList();
IFactoryTestDataLibData tdldFactory = appContext.getBean(IFactoryTestDataLibData.class);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String charset = request.getCharacterEncoding();
for (int i = 0; i < json.length(); i++) {
JSONObject objectJson = json.getJSONObject(i);
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
boolean delete = objectJson.getBoolean("toDelete");
Integer testDataLibDataId = objectJson.getInt("testDataLibDataID");
// Parameter that needs to be secured --> We SECURE+DECODE them
// NONE
// Parameter that we cannot secure as we need the html --> We DECODE them
String subdata = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("subData"), "", charset);
String value = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("value"), "", charset);
String column = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("column"), "", charset);
String parsingAnswer = ParameterParserUtil.parseStringParam(objectJson.getString("parsingAnswer"), "");
String columnPosition = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("columnPosition"), "", charset);
String description = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("description"), "", charset);
if (!delete) {
TestDataLibData tdld = tdldFactory.create(testDataLibDataId, testDataLibId, subdata, value, column, parsingAnswer, columnPosition, description);
tdldList.add(tdld);
}
}
return tdldList;
}
Aggregations