Search in sources :

Example 1 with EntrypointNotFoundException

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

the class EntrypointServiceImpl method findByIdAndReference.

@Override
public EntrypointEntity findByIdAndReference(final String entrypointId, String referenceId, EntrypointReferenceType referenceType) {
    try {
        LOGGER.debug("Find by id {}", entrypointId);
        final Optional<Entrypoint> optionalEntryPoint = entrypointRepository.findByIdAndReference(entrypointId, referenceId, repoEntrypointReferenceType(referenceType));
        if (!optionalEntryPoint.isPresent()) {
            throw new EntrypointNotFoundException(entrypointId);
        }
        return convert(optionalEntryPoint.get());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find all entrypoints", ex);
        throw new TechnicalManagementException("An error occurs while trying to find all entrypoints", ex);
    }
}
Also used : EntrypointNotFoundException(io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Entrypoint(io.gravitee.repository.management.model.Entrypoint) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with EntrypointNotFoundException

use of io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException 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 3 with EntrypointNotFoundException

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

the class EntrypointServiceImpl method delete.

@Override
public void delete(final String entrypointId, String referenceId, EntrypointReferenceType referenceType) {
    try {
        Optional<Entrypoint> entrypointOptional = entrypointRepository.findByIdAndReference(entrypointId, referenceId, repoEntrypointReferenceType(referenceType));
        if (entrypointOptional.isPresent()) {
            entrypointRepository.delete(entrypointId);
            auditService.createEnvironmentAuditLog(Collections.singletonMap(ENTRYPOINT, entrypointId), ENTRYPOINT_DELETED, new Date(), null, entrypointOptional.get());
        } else {
            throw new EntrypointNotFoundException(entrypointId);
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete entrypoint {}", entrypointId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete entrypoint " + entrypointId, ex);
    }
}
Also used : EntrypointNotFoundException(io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Entrypoint(io.gravitee.repository.management.model.Entrypoint) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 Entrypoint (io.gravitee.repository.management.model.Entrypoint)3 EntrypointNotFoundException (io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 EntrypointEntity (io.gravitee.rest.api.model.EntrypointEntity)1