Search in sources :

Example 16 with TestDataLibData

use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.

the class TestDataLibDataDAO method readByVarious.

@Override
public AnswerList<TestDataLibData> readByVarious(Integer testDataLibID, String columnEmpty, String parsingAnswerEmpty, String columnPositionEmpty) {
    List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();
    AnswerList answer = new AnswerList();
    MessageEvent msg;
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testdatalibdata where `testDataLibID` = ? ");
    if ("Y".equalsIgnoreCase(columnEmpty)) {
        query.append(" and `Column`='' ");
    } else if ("N".equalsIgnoreCase(columnEmpty)) {
        query.append(" and `Column`!='' ");
    }
    if ("Y".equalsIgnoreCase(parsingAnswerEmpty)) {
        query.append(" and `ParsingAnswer`='' ");
    } else if ("N".equalsIgnoreCase(parsingAnswerEmpty)) {
        query.append(" and `ParsingAnswer`!='' ");
    }
    if ("Y".equalsIgnoreCase(columnPositionEmpty)) {
        query.append(" and `columnPosition`='' ");
    } else if ("N".equalsIgnoreCase(columnPositionEmpty)) {
        query.append(" and `columnPosition`!='' ");
    }
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.testDataLibID : " + testDataLibID);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setInt(1, testDataLibID);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testDataLibListData.add(this.loadFromResultSet(resultSet));
                }
                if (testDataLibListData.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()));
                testDataLibListData.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()));
            testDataLibListData.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()));
        testDataLibListData.clear();
    } finally {
        try {
            if (!this.databaseSpring.isOnTransaction()) {
                if (connection != null) {
                    connection.close();
                }
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to close connection : " + ex.toString());
        }
    }
    answer.setDataList(testDataLibListData);
    answer.setTotalRows(testDataLibListData.size());
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryTestDataLibData(org.cerberus.crud.factory.IFactoryTestDataLibData) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Example 17 with TestDataLibData

use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.

the class TestDataLibDataDAO method readByName.

@Override
public AnswerList readByName(String testDataLibName) {
    AnswerList answer = new AnswerList();
    MessageEvent msg;
    List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();
    StringBuilder query = new StringBuilder();
    query.append("SELECT tdld.*, tdl.`name`, tdl.type, tdl.system, tdl.country, tdl.environment FROM testdatalibdata tdld ");
    query.append("inner join testdatalib tdl ");
    query.append("on tdld.testDataLibID = tdl.testDataLibID ");
    query.append("and tdl.`name` LIKE ? ");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.testDataLibName : " + testDataLibName);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, testDataLibName);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testDataLibListData.add(this.loadFromResultSet(resultSet));
                }
                if (testDataLibListData.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()));
            } 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.setDataList(testDataLibListData);
    // all lines are retrieved
    answer.setTotalRows(testDataLibListData.size());
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryTestDataLibData(org.cerberus.crud.factory.IFactoryTestDataLibData) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Example 18 with TestDataLibData

use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.

the class XMLTestDataLibHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    if (qName.equalsIgnoreCase(TESTDATALIB)) {
        dataItem = new TestDataLib();
        // temporary ID
        dataItem.setTestDataLibID(dataFromFile.size());
    } else if (qName.equalsIgnoreCase(TESTDATALIBDATASET)) {
        currentList = new ArrayList<TestDataLibData>();
    } else if (qName.equalsIgnoreCase(TESTDATALIBDATA)) {
        subDataItem = new TestDataLibData();
        subDataItem.setTestDataLibID(dataFromFile.size());
    }
    currentElement = qName;
}
Also used : TestDataLib(org.cerberus.crud.entity.TestDataLib) ArrayList(java.util.ArrayList) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Aggregations

TestDataLibData (org.cerberus.crud.entity.TestDataLibData)18 ArrayList (java.util.ArrayList)12 IFactoryTestDataLibData (org.cerberus.crud.factory.IFactoryTestDataLibData)12 MessageEvent (org.cerberus.engine.entity.MessageEvent)11 AnswerList (org.cerberus.util.answer.AnswerList)9 AnswerItem (org.cerberus.util.answer.AnswerItem)8 JSONObject (org.json.JSONObject)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 ITestDataLibDataService (org.cerberus.crud.service.ITestDataLibDataService)5 JSONArray (org.json.JSONArray)5 HashMap (java.util.HashMap)4 List (java.util.List)4 TestDataLib (org.cerberus.crud.entity.TestDataLib)4 PolicyFactory (org.owasp.html.PolicyFactory)4 Answer (org.cerberus.util.answer.Answer)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2