Search in sources :

Example 41 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class EntrypointServiceImpl method update.

@Override
public EntrypointEntity update(final UpdateEntryPointEntity entrypointEntity, String referenceId, EntrypointReferenceType referenceType) {
    try {
        final Optional<Entrypoint> entrypointOptional = entrypointRepository.findByIdAndReference(entrypointEntity.getId(), referenceId, repoEntrypointReferenceType(referenceType));
        if (entrypointOptional.isPresent()) {
            final Entrypoint entrypoint = convert(entrypointEntity);
            Entrypoint existingEntrypoint = entrypointOptional.get();
            entrypoint.setReferenceId(existingEntrypoint.getReferenceId());
            entrypoint.setReferenceType(existingEntrypoint.getReferenceType());
            final EntrypointEntity savedEntryPoint = convert(entrypointRepository.update(entrypoint));
            auditService.createEnvironmentAuditLog(Collections.singletonMap(ENTRYPOINT, entrypoint.getId()), ENTRYPOINT_UPDATED, new Date(), entrypointOptional.get(), entrypoint);
            return savedEntryPoint;
        } else {
            throw new EntrypointNotFoundException(entrypointEntity.getId());
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to update entrypoint {}", entrypointEntity.getValue(), ex);
        throw new TechnicalManagementException("An error occurs while trying to update entrypoint " + entrypointEntity.getValue(), ex);
    }
}
Also used : EntrypointNotFoundException(io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Entrypoint(io.gravitee.repository.management.model.Entrypoint) EntrypointEntity(io.gravitee.rest.api.model.EntrypointEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 42 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class EventServiceImpl method create.

@Override
public EventEntity create(NewEventEntity newEventEntity) {
    String hostAddress = "";
    try {
        hostAddress = InetAddress.getLocalHost().getHostAddress();
        LOGGER.debug("Create {} for server {}", newEventEntity, hostAddress);
        Event event = convert(newEventEntity);
        event.setId(UuidString.generateRandom());
        event.setEnvironments(Collections.singleton(GraviteeContext.getCurrentEnvironment()));
        // Set origin
        event.getProperties().put(Event.EventProperties.ORIGIN.getValue(), hostAddress);
        // Set date fields
        event.setCreatedAt(new Date());
        event.setUpdatedAt(event.getCreatedAt());
        Event createdEvent = eventRepository.create(event);
        return convert(createdEvent);
    } catch (UnknownHostException e) {
        LOGGER.error("An error occurs while getting the server IP address", e);
        throw new TechnicalManagementException("An error occurs while getting the server IP address", e);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create {} for server {}", newEventEntity, hostAddress, ex);
        throw new TechnicalManagementException("An error occurs while trying create " + newEventEntity + " for server " + hostAddress, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UnknownHostException(java.net.UnknownHostException) Event(io.gravitee.repository.management.model.Event) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 43 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ApiHeaderServiceImpl method update.

@Override
public ApiHeaderEntity update(UpdateApiHeaderEntity updateEntity) {
    try {
        Optional<ApiHeader> optionalApiHeader = apiHeaderRepository.findById(updateEntity.getId());
        if (!optionalApiHeader.isPresent()) {
            throw new ApiHeaderNotFoundException(updateEntity.getId());
        }
        ApiHeader updatedHeader = new ApiHeader(optionalApiHeader.get());
        Date updatedAt = new Date();
        updatedHeader.setName(updateEntity.getName());
        updatedHeader.setValue(updateEntity.getValue());
        updatedHeader.setUpdatedAt(updatedAt);
        if (updatedHeader.getOrder() != updateEntity.getOrder()) {
            updatedHeader.setOrder(updateEntity.getOrder());
            reorderAndSave(updatedHeader);
            return convert(updatedHeader);
        } else {
            ApiHeader header = apiHeaderRepository.update(updatedHeader);
            auditService.createEnvironmentAuditLog(singletonMap(API_HEADER, header.getId()), API_HEADER_UPDATED, header.getUpdatedAt(), optionalApiHeader.get(), header);
            return convert(header);
        }
    } catch (TechnicalException e) {
        LOGGER.error("An error occurs while trying to update header {}", updateEntity, e);
        throw new TechnicalManagementException("An error occurs while trying to update header " + updateEntity, e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApiHeaderNotFoundException(io.gravitee.rest.api.service.exceptions.ApiHeaderNotFoundException) ApiHeader(io.gravitee.repository.management.model.ApiHeader) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 44 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class ApiHeaderServiceImpl method create.

private ApiHeaderEntity create(NewApiHeaderEntity newEntity, String environmentId) {
    try {
        int order = apiHeaderRepository.findAllByEnvironment(environmentId).size() + 1;
        ApiHeader apiHeader = new ApiHeader();
        apiHeader.setId(UuidString.generateRandom());
        apiHeader.setEnvironmentId(environmentId);
        apiHeader.setName(newEntity.getName());
        apiHeader.setValue(newEntity.getValue());
        apiHeader.setOrder(order);
        apiHeader.setCreatedAt(new Date());
        apiHeader.setUpdatedAt(apiHeader.getCreatedAt());
        auditService.createEnvironmentAuditLog(Collections.singletonMap(API_HEADER, apiHeader.getId()), API_HEADER_CREATED, apiHeader.getCreatedAt(), null, apiHeader);
        return convert(apiHeaderRepository.create(apiHeader));
    } catch (TechnicalException e) {
        LOGGER.error("An error occurs while trying to create a header {}", newEntity, e);
        throw new TechnicalManagementException("An error occurs while trying to create a header " + newEntity, e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApiHeader(io.gravitee.repository.management.model.ApiHeader) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 45 with TechnicalManagementException

use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException 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)

Aggregations

TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)149 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)120 UuidString (io.gravitee.rest.api.service.common.UuidString)26 Date (java.util.Date)23 Component (org.springframework.stereotype.Component)18 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)16 Collectors (java.util.stream.Collectors)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 IOException (java.io.IOException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Rating (io.gravitee.repository.management.model.Rating)9 ApiRatingUnavailableException (io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Dictionary (io.gravitee.repository.management.model.Dictionary)8 AuditService (io.gravitee.rest.api.service.AuditService)8 java.util (java.util)8 Theme (io.gravitee.repository.management.model.Theme)6 List (java.util.List)6