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);
}
}
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);
}
}
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);
}
}
Aggregations