Search in sources :

Example 1 with UpdateApiHeaderEntity

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

the class ApiHeaderServiceImpl method delete.

@Override
public void delete(String apiHeaderId) {
    try {
        Optional<ApiHeader> optionalApiHeader = apiHeaderRepository.findById(apiHeaderId);
        if (!optionalApiHeader.isPresent()) {
            throw new ApiHeaderNotFoundException(apiHeaderId);
        }
        apiHeaderRepository.delete(apiHeaderId);
        auditService.createEnvironmentAuditLog(Collections.singletonMap(API_HEADER, apiHeaderId), API_HEADER_DELETED, new Date(), optionalApiHeader.get(), null);
        // reorder headers
        int currentOrder = 1;
        for (ApiHeaderEntity apiHeaderEntity : this.findAll()) {
            if (apiHeaderEntity.getOrder() != currentOrder) {
                UpdateApiHeaderEntity updateEntity = convert(apiHeaderEntity);
                updateEntity.setOrder(currentOrder);
                this.update(updateEntity);
                break;
            }
            currentOrder++;
        }
    } catch (TechnicalException e) {
        LOGGER.error("An error occurs while trying to delete a header {}", apiHeaderId, e);
        throw new TechnicalManagementException("An error occurs while trying to delete a header " + apiHeaderId, e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UpdateApiHeaderEntity(io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity) NewApiHeaderEntity(io.gravitee.rest.api.model.api.header.NewApiHeaderEntity) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) ApiHeaderNotFoundException(io.gravitee.rest.api.service.exceptions.ApiHeaderNotFoundException) ApiHeader(io.gravitee.repository.management.model.ApiHeader) UpdateApiHeaderEntity(io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with UpdateApiHeaderEntity

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

the class ApiHeaderServiceImpl method convert.

private UpdateApiHeaderEntity convert(ApiHeaderEntity entity) {
    UpdateApiHeaderEntity updateApiHeaderEntity = new UpdateApiHeaderEntity();
    updateApiHeaderEntity.setId(entity.getId());
    updateApiHeaderEntity.setName(entity.getName());
    updateApiHeaderEntity.setOrder(entity.getOrder());
    updateApiHeaderEntity.setValue(entity.getValue());
    return updateApiHeaderEntity;
}
Also used : UpdateApiHeaderEntity(io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity)

Aggregations

UpdateApiHeaderEntity (io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 ApiHeader (io.gravitee.repository.management.model.ApiHeader)1 ApiHeaderEntity (io.gravitee.rest.api.model.api.header.ApiHeaderEntity)1 NewApiHeaderEntity (io.gravitee.rest.api.model.api.header.NewApiHeaderEntity)1 ApiHeaderNotFoundException (io.gravitee.rest.api.service.exceptions.ApiHeaderNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1