@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); } }
/** * Constructs an endpoint registration with the information provided and * saves it to the database. * * @param applicationId The application ID * @param endpointId The endpoint ID * @param credentialsId The credentials ID * @return The endpoint registration saved */ protected EndpointRegistrationDto generateEndpointRegistration(String applicationId, String endpointId, String credentialsId) { EndpointRegistrationDto endpointRegistration = new EndpointRegistrationDto(applicationId, endpointId, credentialsId, null, null); return this.endpointRegistrationDao.save(endpointRegistration).toDto(); }
protected EndpointRegistrationDto generateEndpointRegistration( String applicationId, String endpointId, String credentialsId, Integer serverProfileVersion, String serverProfileBody) { EndpointRegistrationDto endpointRegistration = new EndpointRegistrationDto(); endpointRegistration.setApplicationId(applicationId); endpointRegistration.setEndpointId(endpointId); endpointRegistration.setCredentialsId(credentialsId); endpointRegistration.setServerProfileVersion(serverProfileVersion); endpointRegistration.setServerProfileBody(serverProfileBody); return this.endpointRegistrationDao.save(endpointRegistration).toDto(); }