Search in sources :

Example 1 with ArtifactDetails

use of org.wso2.ei.dashboard.core.rest.model.ArtifactDetails in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method getArtifactDetails.

private List<ArtifactDetails> getArtifactDetails(String getServicesQuery, String artifactName, String groupId, List<String> nodeList) {
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(getServicesQuery)) {
        statement.setString(1, artifactName);
        statement.setString(2, groupId);
        for (int i = 0, j = 3; i < nodeList.size(); i++, j++) {
            statement.setString(j, nodeList.get(i));
        }
        ResultSet resultSet = statement.executeQuery();
        List<ArtifactDetails> artifactDetailsList = new ArrayList<>();
        while (resultSet.next()) {
            ArtifactDetails artifactDetails = new ArtifactDetails();
            String nodeId = resultSet.getString("NODE_ID");
            String details = resultSet.getString("DETAILS");
            artifactDetails.setNodeId(nodeId);
            artifactDetails.setDetails(details);
            artifactDetailsList.add(artifactDetails);
        }
        return artifactDetailsList;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred while retrieving next row.", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ArtifactDetails(org.wso2.ei.dashboard.core.rest.model.ArtifactDetails) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 2 with ArtifactDetails

use of org.wso2.ei.dashboard.core.rest.model.ArtifactDetails in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method fetchArtifacts.

@Override
public Artifacts fetchArtifacts(String artifactType, String groupId, List<String> nodeList) {
    Artifacts artifacts = new Artifacts();
    String nodeSearch = "";
    String nodeSearchTmp = nodeSearch;
    nodeList.forEach(node -> nodeSearchTmp.concat("NODE_ID=? OR "));
    nodeSearch = nodeSearchTmp;
    for (int i = 0; i < nodeList.size(); i++) {
        nodeSearch = nodeSearch.concat("NODE_ID=? OR ");
    }
    if (!nodeSearch.equals("")) {
        nodeSearch = nodeSearch.substring(0, nodeSearch.length() - 4);
    }
    String tableName = getTableName(artifactType);
    String getDistinctNamesQuery = "SELECT DISTINCT NAME FROM " + tableName + " WHERE GROUP_ID=? " + "AND (" + nodeSearch + ");";
    String getDetailsQuery = "SELECT NODE_ID, DETAILS FROM " + tableName + " WHERE NAME=? AND GROUP_ID=? AND " + "(" + nodeSearch + ");";
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(getDistinctNamesQuery)) {
        statement.setString(1, groupId);
        for (int i = 0, j = 2; i < nodeList.size(); i++, j++) {
            statement.setString(j, nodeList.get(i));
        }
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            ArtifactsInner artifactsInner = new ArtifactsInner();
            String artifactName = resultSet.getString("NAME");
            artifactsInner.setName(artifactName);
            List<ArtifactDetails> artifactDetails = getArtifactDetails(getDetailsQuery, artifactName, groupId, nodeList);
            artifactsInner.setNodes(artifactDetails);
            artifacts.add(artifactsInner);
        }
        return artifacts;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred fetching " + artifactType, e);
    }
}
Also used : Artifacts(org.wso2.ei.dashboard.core.rest.model.Artifacts) SQLException(java.sql.SQLException) ArtifactsInner(org.wso2.ei.dashboard.core.rest.model.ArtifactsInner) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArtifactDetails(org.wso2.ei.dashboard.core.rest.model.ArtifactDetails) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 3 with ArtifactDetails

use of org.wso2.ei.dashboard.core.rest.model.ArtifactDetails in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method insertArtifact.

@Override
public boolean insertArtifact(String groupId, String nodeId, String artifactType, String artifactName, String artifactDetails) {
    String query = "INSERT INTO " + getTableName(artifactType) + " VALUES (?,?,?,?);";
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(query)) {
        statement.setString(1, groupId);
        statement.setString(2, nodeId);
        statement.setString(3, artifactName);
        statement.setString(4, artifactDetails);
        return statement.executeUpdate() > 0;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred while inserting " + artifactName + " information.", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Aggregations

Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 DashboardServerException (org.wso2.ei.dashboard.core.exception.DashboardServerException)3 ResultSet (java.sql.ResultSet)2 ArtifactDetails (org.wso2.ei.dashboard.core.rest.model.ArtifactDetails)2 ArrayList (java.util.ArrayList)1 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)1 ArtifactsInner (org.wso2.ei.dashboard.core.rest.model.ArtifactsInner)1