Search in sources :

Example 1 with EventType

use of io.gravitee.rest.api.model.EventType in project gravitee-management-rest-api by gravitee-io.

the class ApiServiceImpl method updateLifecycle.

private ApiEntity updateLifecycle(String apiId, LifecycleState lifecycleState, String username) throws TechnicalException {
    Optional<Api> optApi = apiRepository.findById(apiId);
    if (optApi.isPresent()) {
        Api api = optApi.get();
        Api previousApi = new Api(api);
        api.setUpdatedAt(new Date());
        api.setLifecycleState(lifecycleState);
        ApiEntity apiEntity = convert(apiRepository.update(api), getPrimaryOwner(api), null);
        // Audit
        auditService.createApiAuditLog(apiId, Collections.emptyMap(), API_UPDATED, api.getUpdatedAt(), previousApi, api);
        EventType eventType = null;
        switch(lifecycleState) {
            case STARTED:
                eventType = EventType.START_API;
                break;
            case STOPPED:
                eventType = EventType.STOP_API;
                break;
            default:
                break;
        }
        final ApiEntity deployedApi = deployLastPublishedAPI(apiId, username, eventType);
        if (deployedApi != null) {
            return deployedApi;
        }
        return apiEntity;
    } else {
        throw new ApiNotFoundException(apiId);
    }
}
Also used : EventType(io.gravitee.rest.api.model.EventType) Api(io.gravitee.repository.management.model.Api)

Aggregations

Api (io.gravitee.repository.management.model.Api)1 EventType (io.gravitee.rest.api.model.EventType)1