Search in sources :

Example 36 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class LabelDAO method delete.

@Override
public Answer delete(Label object) {
    Answer response = new Answer();
    MessageEvent msg = null;
    final String query = "DELETE FROM label WHERE id = ? ";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        preStat.setInt(1, object.getId());
        preStat.executeUpdate();
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));
    } catch (Exception e) {
        LOG.warn("Unable to delete label: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        response.setResultMessage(msg);
    }
    return response;
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 37 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class LabelDAO method update.

@Override
public Answer update(Label object) {
    Answer response = new Answer();
    MessageEvent msg = null;
    final String query = "UPDATE label SET `system` = ?, `label` = ?, `type` = ?, `color` = ?, `parentLabel` = ?, `usrModif` = ?, `dateModif` = ?, `description` = ?" + ", `LongDesc` = ?, `ReqType` = ?, `ReqStatus` = ?, `ReqCriticity` = ?  WHERE id = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        int i = 1;
        preStat.setString(i++, object.getSystem());
        preStat.setString(i++, object.getLabel());
        preStat.setString(i++, object.getType());
        preStat.setString(i++, object.getColor());
        preStat.setString(i++, object.getParentLabel());
        preStat.setString(i++, object.getUsrModif());
        preStat.setTimestamp(i++, object.getDateModif());
        preStat.setString(i++, object.getDescription());
        preStat.setString(i++, object.getLongDesc());
        preStat.setString(i++, object.getReqType());
        preStat.setString(i++, object.getReqStatus());
        preStat.setString(i++, object.getReqCriticity());
        preStat.setInt(i++, object.getId());
        preStat.executeUpdate();
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
    } catch (Exception e) {
        LOG.warn("Unable to update label: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        response.setResultMessage(msg);
    }
    return response;
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 38 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class LabelDAO method create.

@Override
public Answer create(Label object) {
    Answer response = new Answer();
    MessageEvent msg = null;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO label (`system`, `label`, `type`, `color`, `parentLabel`, `ReqType`, `ReqStatus`, `ReqCriticity`, `description`, `longdesc`, `usrCreated`, `dateCreated`, `usrModif`, `dateModif` ) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        int i = 1;
        preStat.setString(i++, object.getSystem());
        preStat.setString(i++, object.getLabel());
        preStat.setString(i++, object.getType());
        preStat.setString(i++, object.getColor());
        preStat.setString(i++, object.getParentLabel());
        preStat.setString(i++, object.getReqType());
        preStat.setString(i++, object.getReqStatus());
        preStat.setString(i++, object.getReqCriticity());
        preStat.setString(i++, object.getDescription());
        preStat.setString(i++, object.getLongDesc());
        preStat.setString(i++, object.getUsrCreated());
        preStat.setTimestamp(i++, object.getDateCreated());
        preStat.setString(i++, object.getUsrModif());
        preStat.setTimestamp(i++, object.getDateModif());
        preStat.executeUpdate();
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
    } catch (Exception e) {
        LOG.warn("Unable to create label: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        response.setResultMessage(msg);
    }
    return response;
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 39 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class ParameterDAO method create.

@Override
public Answer create(Parameter object) {
    Answer ans = new Answer();
    MessageEvent msg = null;
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(Query.CREATE)) {
        // Prepare and execute query
        preStat.setString(1, object.getSystem());
        preStat.setString(2, object.getParam());
        preStat.setString(3, object.getValue());
        preStat.setString(4, object.getDescription());
        preStat.executeUpdate();
        // Set the final message
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "CREATE");
    } catch (Exception e) {
        LOG.warn("Unable to create robot capability: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) CerberusException(org.cerberus.exception.CerberusException)

Example 40 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class ParameterDAO method delete.

@Override
public Answer delete(Parameter object) {
    Answer ans = new Answer();
    MessageEvent msg = null;
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(Query.DELETE)) {
        // Prepare and execute query
        preStat.setString(1, object.getSystem());
        preStat.setString(2, object.getParam());
        preStat.executeUpdate();
        // Set the final message
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "DELETE");
    } catch (Exception e) {
        LOG.warn("Unable to delete parameter: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) CerberusException(org.cerberus.exception.CerberusException)

Aggregations

Answer (org.cerberus.util.answer.Answer)241 MessageEvent (org.cerberus.engine.entity.MessageEvent)227 Connection (java.sql.Connection)127 PreparedStatement (java.sql.PreparedStatement)127 SQLException (java.sql.SQLException)127 ApplicationContext (org.springframework.context.ApplicationContext)77 JSONObject (org.json.JSONObject)75 ILogEventService (org.cerberus.crud.service.ILogEventService)74 PolicyFactory (org.owasp.html.PolicyFactory)60 AnswerItem (org.cerberus.util.answer.AnswerItem)53 CerberusException (org.cerberus.exception.CerberusException)45 ArrayList (java.util.ArrayList)35 JSONException (org.json.JSONException)26 IOException (java.io.IOException)23 ServletException (javax.servlet.ServletException)19 JSONArray (org.json.JSONArray)15 LogEventService (org.cerberus.crud.service.impl.LogEventService)13 TestCase (org.cerberus.crud.entity.TestCase)10 ITestCaseService (org.cerberus.crud.service.ITestCaseService)10 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)8