Even another batch of sonar fixes

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-10 00:38:13 +02:00
parent 5cbbbfed31
commit 483a42b1e0
8 changed files with 19 additions and 16 deletions

View file

@ -99,7 +99,7 @@ public class AutomationController {
req.getScenes()
.stream()
.map(AutomationFastUpdateRequest.ScenePriorityDTO::toModel)
.peek(
.map(
t -> {
t.setAutomationId(a.getId());
@ -107,6 +107,7 @@ public class AutomationController {
// please do not replicate unless the quality gate sees
// it as a bug
t.setAutomation(a);
return t;
})
.collect(Collectors.toList()));

View file

@ -53,7 +53,7 @@ public class ConfirmationToken {
}
public Date getCreatedDate() {
return createdDate;
return (Date) createdDate.clone();
}
public User getUser() {
@ -69,7 +69,7 @@ public class ConfirmationToken {
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
this.createdDate = (Date) createdDate.clone();
}
public void setUser(User user) {

View file

@ -75,7 +75,7 @@ public class DeviceService {
sceneRepository
.findById(t.getSceneId())
.orElseThrow(IllegalStateException::new))
.forEach((s) -> sceneService.apply(s, username, true));
.forEach(s -> sceneService.apply(s, username, true));
}
public List<Device> findAll(Long hostId, String username) throws NotFoundException {
@ -123,7 +123,7 @@ public class DeviceService {
List<T> toReturn =
devicePropagationService.saveAllAsOwner(devices, username, fromScene, fromTrigger);
if (!fromScene) {
toReturn.forEach((d) -> this.triggerTriggers(d, username));
toReturn.forEach(d -> this.triggerTriggers(d, username));
}
return toReturn;
}
@ -170,6 +170,10 @@ public class DeviceService {
devicePopulationService.populateComputedFields(devices);
return filterOutCamerasIfNeeded(host, devices);
}
private List<Device> filterOutCamerasIfNeeded(User host, Iterable<Device> devices) {
if (host != null && !host.isCameraEnabled()) {
return StreamSupport.stream(devices.spliterator(), true)
.filter(d -> !(d instanceof SecurityCamera))

View file

@ -15,7 +15,7 @@ public class JWTUserDetailsService implements UserDetailsService {
@Autowired private UserRepository repository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
public UserDetails loadUserByUsername(String username) {
User toReturn = repository.findByUsername(username);
if (toReturn != null && toReturn.getEnabled()) {
return new org.springframework.security.core.userdetails.User(

View file

@ -42,8 +42,8 @@ public class SensorSocketConfig extends ServerEndpointConfig.Configurator {
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
try {
@SuppressWarnings("unchecked")
final T instance = (T) this.instance;
return instance;
final T thaInstance = (T) this.instance;
return thaInstance;
} catch (ClassCastException e) {
final var e2 =
new InstantiationException("Cannot cast SensorSocketEndpoint to desired type");

View file

@ -122,7 +122,8 @@ public class SensorSocketEndpoint extends Endpoint {
} else {
try {
session.close();
} catch (IOException ignored) {
} catch (IOException e) {
logger.warn(e.getLocalizedMessage(), e);
}
}
}

View file

@ -41,7 +41,7 @@ public abstract class SmartHutTest {
final ConfirmationTokenRepository tokenRepository) {
final ResponseEntity<Object> res2 =
restTemplate.postForEntity(this.url("/register"), enabledUser, Object.class);
assertThat(res2.getStatusCode().equals(HttpStatus.OK));
assertThat(res2.getStatusCode()).isEqualTo(HttpStatus.OK);
final User persistedEnabledUser = userRepository.findByUsername("enabled");
final ConfirmationToken token = tokenRepository.findByUser(persistedEnabledUser);

View file

@ -16,11 +16,8 @@ public class SmarthutApplicationTests extends SmartHutTest {
@Autowired private TestRestTemplate restTemplate;
@Test
public void anonymousGreetingShouldNotBeAuthorized() throws Exception {
assertThat(
this.restTemplate
.getForEntity(getBaseURL(), Void.class)
.getStatusCode()
.equals(HttpStatus.UNAUTHORIZED));
public void anonymousGreetingShouldNotBeAuthorized() {
assertThat(this.restTemplate.getForEntity(getBaseURL(), Void.class).getStatusCode())
.isEqualTo(HttpStatus.UNAUTHORIZED);
}
}