use of org.cerberus.crud.entity.ApplicationObject in project cerberus-source by cerberustesting.
the class ApplicationObjectDAO method readByKeyTech.
@Override
public AnswerItem readByKeyTech(int id) {
AnswerItem ans = new AnswerItem();
MessageEvent msg = null;
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_KEY)) {
// Prepare and execute query
preStat.setInt(1, id);
ResultSet rs = preStat.executeQuery();
ApplicationObject ao = loadFromResultSet(rs);
ans.setItem(ao);
// Set the final message
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "READ_BY_KEY");
} catch (Exception e) {
LOG.warn("Unable to read by key: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.crud.entity.ApplicationObject in project cerberus-source by cerberustesting.
the class ApplicationObjectDAO method readByKey.
@Override
public AnswerItem readByKey(String application, String object) {
AnswerItem ans = new AnswerItem();
MessageEvent msg = null;
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_KEY1)) {
ApplicationObject ao = null;
// Prepare and execute query
preStat.setString(1, application);
preStat.setString(2, object);
ResultSet rs = preStat.executeQuery();
try {
while (rs.next()) {
ao = loadFromResultSet(rs);
}
ans.setItem(ao);
// Set the final message
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "READ_BY_KEY");
} catch (Exception e) {
LOG.warn("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
if (rs != null) {
rs.close();
}
}
} catch (Exception e) {
LOG.warn("Unable to read by key: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.crud.entity.ApplicationObject in project cerberus-source by cerberustesting.
the class ApplicationObjectDAO method readByCriteria.
@Override
public AnswerList readByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<ApplicationObject> objectList = new ArrayList<ApplicationObject>();
StringBuilder searchSQL = new StringBuilder();
List<String> individalColumnSearchValues = new ArrayList<String>();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM applicationobject ");
searchSQL.append(" where 1=1 ");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (`Application` like ?");
searchSQL.append(" or `Object` like ?");
searchSQL.append(" or `Value` like ?");
searchSQL.append(" or `ScreenshotFileName` like ?");
searchSQL.append(" or `UsrCreated` like ?");
searchSQL.append(" or `DateCreated` like ?");
searchSQL.append(" or `UsrModif` like ?");
searchSQL.append(" or `DateModif` like ?)");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
searchSQL.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
searchSQL.append(" and ");
searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
searchSQL.append(" )");
}
query.append(searchSQL);
if (!StringUtil.isNullOrEmpty(column)) {
query.append(" order by `").append(column).append("` ").append(dir);
}
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString());
Statement stm = connection.createStatement()) {
int i = 1;
if (!StringUtil.isNullOrEmpty(searchTerm)) {
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
try (ResultSet resultSet = preStat.executeQuery();
ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
// gets the data
while (resultSet.next()) {
objectList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
int nrTotalRows = 0;
if (rowSet != null && rowSet.next()) {
nrTotalRows = rowSet.getInt(1);
}
if (objectList.size() >= MAX_ROW_SELECTED) {
// Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(objectList, nrTotalRows);
} else if (objectList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(objectList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList(objectList, nrTotalRows);
}
} 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()));
}
} 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()));
}
response.setResultMessage(msg);
response.setDataList(objectList);
return response;
}
use of org.cerberus.crud.entity.ApplicationObject in project cerberus-source by cerberustesting.
the class FactoryApplicationObject method create.
@Override
public ApplicationObject create(int ID, String application, String object, String value, String screenshotfilename, String usrcreated, String datecreated, String usrmodif, String datemodif) {
ApplicationObject ao = new ApplicationObject();
ao.setID(ID);
ao.setApplication(application);
ao.setObject(object);
ao.setValue(value);
ao.setScreenShotFileName(screenshotfilename);
ao.setUsrCreated(usrcreated);
ao.setDateCreated(datecreated);
ao.setUsrModif(usrmodif);
ao.setDateModif(datemodif);
return ao;
}
use of org.cerberus.crud.entity.ApplicationObject in project cerberus-source by cerberustesting.
the class ApplicationObjectVariableService method decodeStringWithApplicationObject.
@Override
public String decodeStringWithApplicationObject(String stringToDecode, TestCaseExecution tCExecution, boolean forceCalculation) throws CerberusEventException {
String application = tCExecution.getApplicationObj().getApplication();
String stringToDecodeInit = stringToDecode;
if (LOG.isDebugEnabled()) {
LOG.debug("Starting to decode string (application Object) : " + stringToDecode);
}
/**
* Look at all the potencial properties still contained in
* StringToDecode (considering that properties are between %).
*/
List<String> internalAppObjectsFromStringToDecode = this.getApplicationObjectsStringListFromString(stringToDecode);
if (LOG.isDebugEnabled()) {
LOG.debug("Internal potencial application objects still found inside String '" + stringToDecode + "' : " + internalAppObjectsFromStringToDecode);
}
if (internalAppObjectsFromStringToDecode.isEmpty()) {
// We escape if no property found on the string to decode
if (LOG.isDebugEnabled()) {
LOG.debug("Finished to decode (no application objects detected in string). Result : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");
}
return stringToDecode;
}
Iterator i = internalAppObjectsFromStringToDecode.iterator();
while (i.hasNext()) {
String value = (String) i.next();
String[] valueA = value.split("\\.");
if (valueA.length >= 3) {
AnswerItem ans = applicationObjectService.readByKey(application, valueA[1]);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && ans.getItem() != null) {
ApplicationObject ao = (ApplicationObject) ans.getItem();
String val = null;
if ("picturepath".equals(valueA[2])) {
val = parameterService.getParameterStringByKey("cerberus_applicationobject_path", "", "") + File.separator + ao.getID() + File.separator + ao.getScreenShotFileName();
} else if ("pictureurl".equals(valueA[2])) {
val = parameterService.getParameterStringByKey("cerberus_url", "", "") + "/ReadApplicationObjectImage?application=" + ao.getApplication() + "&object=" + ao.getObject();
} else if ("value".equals(valueA[2])) {
val = ao.getValue();
}
if (val != null) {
stringToDecode = stringToDecode.replace("%" + value + "%", val);
}
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Finished to decode String (application Object) : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");
}
return stringToDecode;
}
Aggregations