Search in sources :

Example 1 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApiDAOImpl method deleteComment.

@Override
public void deleteComment(String commentId, String apiId) throws APIMgtDAOException {
    final String deleteCommentQuery = "DELETE FROM AM_API_COMMENTS WHERE UUID = ? AND API_ID = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(deleteCommentQuery)) {
        try {
            connection.setAutoCommit(false);
            statement.setString(1, commentId);
            statement.setString(2, apiId);
            statement.execute();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApiDAOImpl method updateComment.

@Override
public void updateComment(Comment comment, String commentId, String apiId) throws APIMgtDAOException {
    final String updateCommentQuery = "UPDATE AM_API_COMMENTS SET COMMENT_TEXT = ? " + ", UPDATED_BY = ? , LAST_UPDATED_TIME = ?" + " WHERE UUID = ? AND API_ID = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(updateCommentQuery)) {
        try {
            connection.setAutoCommit(false);
            statement.setString(1, comment.getCommentText());
            statement.setString(2, comment.getUpdatedUser());
            statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()));
            statement.setString(4, commentId);
            statement.setString(5, apiId);
            statement.execute();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String errorMessage = "updating comment for API " + apiId + ", Comment " + commentId;
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String errorMessage = "updating comment for API " + apiId + ", Comment " + commentId;
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 3 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testUpdateComment.

@Test
public void testUpdateComment() throws Exception {
    String newCommentText = "updated comment";
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
    apiDAO.addComment(comment1, api.getId());
    String lastUpdatedTime1 = apiDAO.getLastUpdatedTimeOfComment(comment1.getUuid());
    // Keep at least millisecond difference between the two timestamps
    Thread.sleep(1);
    Comment comment2 = SampleTestObjectCreator.createDefaultComment(api.getId());
    comment2.setCommentText(newCommentText);
    apiDAO.updateComment(comment2, comment1.getUuid(), api.getId());
    Comment commentFromDB = apiDAO.getCommentByUUID(comment1.getUuid(), api.getId());
    String lastUpdatedTimeAfterUpdating = apiDAO.getLastUpdatedTimeOfComment(comment1.getUuid());
    Assert.assertNotNull(commentFromDB);
    Assert.assertNotNull(lastUpdatedTime1);
    Assert.assertNotNull(lastUpdatedTimeAfterUpdating);
    Assert.assertNotEquals(lastUpdatedTime1, lastUpdatedTimeAfterUpdating);
    Assert.assertEquals(newCommentText, commentFromDB.getCommentText());
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 4 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testDeleteComment.

@Test
public void testDeleteComment() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
    apiDAO.addComment(comment, api.getId());
    apiDAO.deleteComment(comment.getUuid(), api.getId());
    Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
    Assert.assertNull(commentFromDB);
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 5 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testAddGetComment.

@Test
public void testAddGetComment() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
    apiDAO.addComment(comment, api.getId());
    Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
    Assert.assertNotNull(commentFromDB);
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

Comment (org.wso2.carbon.apimgt.core.models.Comment)36 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)28 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)23 Test (org.testng.annotations.Test)22 SQLException (java.sql.SQLException)18 BeforeTest (org.testng.annotations.BeforeTest)18 API (org.wso2.carbon.apimgt.core.models.API)17 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 Comment (org.wso2.carbon.apimgt.api.model.Comment)16 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)15 PreparedStatement (java.sql.PreparedStatement)13 Connection (java.sql.Connection)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 ArrayList (java.util.ArrayList)10 CommentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO)9 URI (java.net.URI)8 URISyntaxException (java.net.URISyntaxException)8 Test (org.junit.Test)8