Search in sources :

Example 1 with LifeCycleEvent

use of org.wso2.carbon.apimgt.api.model.LifeCycleEvent in project carbon-apimgt by wso2.

the class ApiMgtDAO method getLifeCycleEvents.

public List<LifeCycleEvent> getLifeCycleEvents(String uuid) throws APIManagementException {
    Connection connection = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlQuery = SQLConstants.GET_LIFECYCLE_EVENT_SQL;
    int apiOrApiProductId = getAPIID(uuid);
    List<LifeCycleEvent> events = new ArrayList<LifeCycleEvent>();
    try {
        connection = APIMgtDBUtil.getConnection();
        prepStmt = connection.prepareStatement(sqlQuery);
        prepStmt.setInt(1, apiOrApiProductId);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            LifeCycleEvent event = new LifeCycleEvent();
            String oldState = rs.getString("PREVIOUS_STATE");
            // event.setOldStatus(oldState != null ? APIStatus.valueOf(oldState) : null);
            event.setOldStatus(oldState);
            // event.setNewStatus(APIStatus.valueOf(rs.getString("NEW_STATE")));
            event.setNewStatus(rs.getString("NEW_STATE"));
            event.setUserId(rs.getString("USER_ID"));
            event.setDate(rs.getTimestamp("EVENT_DATE"));
            events.add(event);
        }
        Collections.sort(events, (o1, o2) -> o1.getDate().compareTo(o2.getDate()));
    } catch (SQLException e) {
        handleException("Error when executing the SQL : " + sqlQuery, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
    }
    return events;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) LifeCycleEvent(org.wso2.carbon.apimgt.api.model.LifeCycleEvent)

Example 2 with LifeCycleEvent

use of org.wso2.carbon.apimgt.api.model.LifeCycleEvent in project carbon-apimgt by wso2.

the class APIMappingUtil method fromLifecycleHistoryModelToDTO.

/**
 * Return the REST API DTO representation of API Lifecycle history information.
 *
 * @param lifeCycleEvents API lifecycle history information
 * @return REST API DTO representation of API Lifecycle history information
 */
public static LifecycleHistoryDTO fromLifecycleHistoryModelToDTO(List<LifeCycleEvent> lifeCycleEvents) {
    LifecycleHistoryDTO historyDTO = new LifecycleHistoryDTO();
    historyDTO.setCount(lifeCycleEvents.size());
    for (LifeCycleEvent event : lifeCycleEvents) {
        LifecycleHistoryItemDTO historyItemDTO = new LifecycleHistoryItemDTO();
        historyItemDTO.setPostState(event.getNewStatus());
        historyItemDTO.setPreviousState(event.getOldStatus());
        historyItemDTO.setUser(event.getUserId());
        String updatedTime = RestApiCommonUtil.getRFC3339Date(event.getDate());
        historyItemDTO.setUpdatedTime(updatedTime);
        historyDTO.getList().add(historyItemDTO);
    }
    return historyDTO;
}
Also used : LifecycleHistoryDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleHistoryDTO) LifecycleHistoryItemDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleHistoryItemDTO) LifeCycleEvent(org.wso2.carbon.apimgt.api.model.LifeCycleEvent)

Aggregations

LifeCycleEvent (org.wso2.carbon.apimgt.api.model.LifeCycleEvent)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 LifecycleHistoryDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleHistoryDTO)1 LifecycleHistoryItemDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleHistoryItemDTO)1