@Override public void removeEndpointRegistrationByEndpointId(String endpointId) throws EndpointRegistrationServiceException { try { Validate.notBlank(endpointId, "Invalid endpoint ID provided!"); this.endpointRegistrationDao.removeByEndpointId(endpointId); } catch (Exception cause) { LOG.error("An unexpected exception occured while removing endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public Optional<EndpointRegistrationDto> findEndpointRegistrationByEndpointId(String endpointId) throws EndpointRegistrationServiceException { try { Validate.notBlank(endpointId, "Invalid endpoint ID provided!"); return this.endpointRegistrationDao.findByEndpointId(endpointId) .map(EndpointRegistration::toDto); } catch (Exception cause) { LOG.error("An unexpected exception occured while searching for endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public void removeEndpointRegistrationById(String registrationId) throws EndpointRegistrationServiceException { try { Validate.notBlank(registrationId, "Invalid registration ID provided!"); this.endpointRegistrationDao.removeById(registrationId); } catch (Exception cause) { LOG.error("An unexpected exception occured while removing endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } } }
@Override public Optional<EndpointRegistrationDto> findEndpointRegistrationByCredentialsId( String credentialsId) throws EndpointRegistrationServiceException { try { Validate.notBlank(credentialsId, "Invalid credentials ID provided!"); return this.endpointRegistrationDao.findByCredentialsId(credentialsId).map( EndpointRegistration::toDto); } catch (Exception cause) { LOG.error("An unexpected exception occured while searching for endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public EndpointRegistrationDto saveEndpointRegistration( EndpointRegistrationDto endpointRegistration) throws EndpointRegistrationServiceException { try { Validate.notNull(endpointRegistration, "Invalid endpoint registration provided!"); String credentialsId = endpointRegistration.getCredentialsId(); Optional<EndpointRegistrationDto> oldRegistration = findEndpointRegistrationByCredentialsId(credentialsId); if (oldRegistration.isPresent()) { EndpointRegistrationDto oldRegistrationDto = oldRegistration.get(); if (oldRegistrationDto.getEndpointId() != null && !oldRegistrationDto.getEndpointId().equals(endpointRegistration.getEndpointId())) { throw new IllegalStateException("The endpoint registration with such credentials " + "already exists!"); } } return this.endpointRegistrationDao.save(endpointRegistration).toDto(); } catch (Exception cause) { LOG.error("An unexpected exception occured while saving endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }