Search in sources :

Example 1 with DuplicateServerNameNotAllowedException

use of org.hl7.gravity.refimpl.sdohexchange.exception.DuplicateServerNameNotAllowedException in project Gravity-SDOH-Exchange-RI by FHIR.

the class ServerService method createServer.

@Transactional
public ServerDto createServer(NewServerDto newServerDto) throws AuthClientException {
    if (serverRepository.findByServerName(newServerDto.getServerName()).isPresent()) {
        throw new DuplicateServerNameNotAllowedException(newServerDto.getServerName());
    }
    Server server = modelMapper.map(newServerDto, Server.class);
    // Just a validation of credentials.
    authorizationClient.getTokenResponse(URI.create(newServerDto.getAuthServerUrl()), newServerDto.getClientId(), newServerDto.getClientSecret(), SCOPE);
    serverRepository.save(server);
    return modelMapper.map(server, ServerDto.class);
}
Also used : Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) DuplicateServerNameNotAllowedException(org.hl7.gravity.refimpl.sdohexchange.exception.DuplicateServerNameNotAllowedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DuplicateServerNameNotAllowedException

use of org.hl7.gravity.refimpl.sdohexchange.exception.DuplicateServerNameNotAllowedException in project Gravity-SDOH-Exchange-RI by FHIR.

the class ServerService method updateServer.

@Transactional
public ServerDto updateServer(Integer id, NewServerDto newServerDto) throws AuthClientException {
    Server server = serverRepository.findById(id).orElseThrow(() -> new ServerNotFoundException(String.format("No Server was found by id '%s'", id)));
    if (serverRepository.findByServerName(newServerDto.getServerName()).isPresent() && !server.getServerName().equals(newServerDto.getServerName())) {
        throw new DuplicateServerNameNotAllowedException(newServerDto.getServerName());
    }
    // Just a validation of credentials.
    authorizationClient.getTokenResponse(URI.create(newServerDto.getAuthServerUrl()), newServerDto.getClientId(), newServerDto.getClientSecret(), SCOPE);
    modelMapper.map(newServerDto, server);
    return modelMapper.map(server, ServerDto.class);
}
Also used : Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) DuplicateServerNameNotAllowedException(org.hl7.gravity.refimpl.sdohexchange.exception.DuplicateServerNameNotAllowedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DuplicateServerNameNotAllowedException (org.hl7.gravity.refimpl.sdohexchange.exception.DuplicateServerNameNotAllowedException)2 Server (org.hl7.gravity.refimpl.sdohexchange.model.Server)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ServerNotFoundException (org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException)1