Search in sources :

Example 1 with Documentation

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

the class DocumentationDAO method findAllWithEmptyDocValue.

@Override
public List<Documentation> findAllWithEmptyDocValue(String lang) {
    List<Documentation> result = new ArrayList<Documentation>();
    final String query = "SELECT DocTable, DocField, DocValue, DocLabel, DocDesc, DocAnchor FROM documentation where Lang = ? and docValue='' ORDER BY DocTable, DocField, DocValue asc";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, lang);
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    String table = resultSet.getString("DocTable");
                    String field = resultSet.getString("DocField");
                    String value = resultSet.getString("DocValue");
                    String label = resultSet.getString("DocLabel");
                    String description = resultSet.getString("DocDesc");
                    String anchor = resultSet.getString("DocAnchor");
                    result.add(factoryDocumentation.create(table, field, value, label, description, anchor));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) IFactoryDocumentation(org.cerberus.crud.factory.IFactoryDocumentation) Documentation(org.cerberus.crud.entity.Documentation) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Documentation

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

the class DocumentationDAO method findDocumentationsWithNotEmptyValueAndDescription.

@Override
public List<Documentation> findDocumentationsWithNotEmptyValueAndDescription(String docTable, String docField, String lang) {
    List<Documentation> result = new ArrayList<Documentation>();
    final String query = "SELECT DocValue, DocDesc, DocLabel, DocAnchor FROM documentation where DocTable = ? and docfield = ? and Lang = ? and docValue IS NOT NULL and length(docValue) > 1 AND length(docdesc) > 1";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, docTable);
            preStat.setString(2, docField);
            preStat.setString(3, lang);
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    String docLabel = resultSet.getString("DocLabel");
                    String description = resultSet.getString("DocDesc");
                    String docValue = resultSet.getString("DocValue");
                    String docAnchor = resultSet.getString("DocAnchor");
                    result.add(factoryDocumentation.create(docTable, docField, docValue, docLabel, description, docAnchor));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) IFactoryDocumentation(org.cerberus.crud.factory.IFactoryDocumentation) Documentation(org.cerberus.crud.entity.Documentation) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with Documentation

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

the class DocumentationDAO method findDocumentationsWithEmptyValueAndNotEmptyDescription.

@Override
public List<Documentation> findDocumentationsWithEmptyValueAndNotEmptyDescription(String docTable, String docField, String lang) {
    List<Documentation> result = new ArrayList<Documentation>();
    final String query = "SELECT DocDesc, DocLabel FROM documentation where DocTable = ? and docfield = ? and Lang = ? and length(docvalue)=0 and length(docdesc) > 1";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, docTable);
            preStat.setString(2, docField);
            preStat.setString(3, lang);
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    String docLabel = resultSet.getString("DocLabel");
                    String description = resultSet.getString("DocDesc");
                    String docAnchor = resultSet.getString("DocAnchor");
                    result.add(factoryDocumentation.create(docTable, docField, "", docLabel, description, docAnchor));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) IFactoryDocumentation(org.cerberus.crud.factory.IFactoryDocumentation) Documentation(org.cerberus.crud.entity.Documentation) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with Documentation

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

the class ReadDocumentation method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) throws ServletException, IOException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IDocumentationService docService = appContext.getBean(IDocumentationService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    JSONObject jsonResponse = new JSONObject();
    List<Documentation> result = new ArrayList<Documentation>();
    JSONObject format = new JSONObject();
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    String lang = ParameterParserUtil.parseStringParamAndSanitize(httpServletRequest.getParameter("lang"), "en");
    result = docService.findAllWithEmptyDocLabel(lang);
    format = docService.formatGroupByDocTable(result);
    try {
        jsonResponse.put("labelTable", format);
    } catch (JSONException ex) {
        LOG.warn(ex);
    }
    response.getWriter().print(jsonResponse.toString());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) PolicyFactory(org.owasp.html.PolicyFactory) JSONObject(org.json.JSONObject) Documentation(org.cerberus.crud.entity.Documentation) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IDocumentationService(org.cerberus.crud.service.IDocumentationService)

Example 5 with Documentation

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

the class DocumentationService method formatGroupByDocTable.

@Override
public JSONObject formatGroupByDocTable(List<Documentation> docList) {
    JSONObject result = new JSONObject();
    for (Documentation doc : docList) {
        String docTable = doc.getDocTable();
        if (result.has(docTable)) {
            try {
                result.getJSONObject(docTable).put(doc.getDocField(), convertDocToJSONObject(doc));
            } catch (JSONException ex) {
                LOG.warn(ex);
            }
        } else {
            try {
                result.put(docTable, new JSONObject());
                result.getJSONObject(docTable).put(doc.getDocField(), convertDocToJSONObject(doc));
            } catch (JSONException ex) {
                LOG.warn(ex);
            }
        }
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) Documentation(org.cerberus.crud.entity.Documentation) JSONException(org.json.JSONException)

Aggregations

Documentation (org.cerberus.crud.entity.Documentation)10 IFactoryDocumentation (org.cerberus.crud.factory.IFactoryDocumentation)6 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)5 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 IDocumentationService (org.cerberus.crud.service.IDocumentationService)1 PolicyFactory (org.owasp.html.PolicyFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1