Skip to content

Commit

Permalink
resolve complex code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jan 7, 2025
1 parent ba6283b commit 0f7fa6f
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ch.puzzle.okr.ErrorKey;
import ch.puzzle.okr.dto.ErrorDto;
import java.util.List;
import java.util.Objects;

import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

Expand Down Expand Up @@ -57,4 +59,17 @@ public OkrResponseStatusException(HttpStatus status, List<ErrorDto> errors) {
public List<ErrorDto> getErrors() {
return errors;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof OkrResponseStatusException that)) {
return false;
}
return Objects.equals(getErrors(), that.getErrors());
}

@Override
public int hashCode() {
return Objects.hashCode(getErrors());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,40 @@ public Optional<String> getJwkSetUri(String tenantId) {

public record TenantConfig(String tenantId, String[] okrChampionEmails, String jwkSetUri, String issuerUrl,
String clientId, DataSourceConfig dataSourceConfig) {
}

public record DataSourceConfig(String driverClassName, String url, String name, String password, String schema) {
@Override
public boolean equals(Object o) {
if (!(o instanceof TenantConfig that)) {
return false;
}
return Objects.equals(tenantId(), that.tenantId()) && Objects.equals(clientId(), that.clientId()) &&
Objects.equals(jwkSetUri(), that.jwkSetUri()) && Objects.equals(issuerUrl(), that.issuerUrl()) &&
Objects.deepEquals(okrChampionEmails(), that.okrChampionEmails()) &&
Objects.equals(dataSourceConfig(), that.dataSourceConfig());
}

}
@Override
public int hashCode() {
return Objects.hash(tenantId(),
Arrays.hashCode(okrChampionEmails()),
jwkSetUri(),
issuerUrl(),
clientId(),
dataSourceConfig());
}

public record OauthConfig(String jwkSetUri, String frontendClientIssuerUrl, String frontendClientId) {
@Override
public String toString() {
return "TenantConfig{" + "tenantId='" + tenantId + '\'' + ", okrChampionEmails=" +
Arrays.toString(okrChampionEmails) + ", jwkSetUri='" + jwkSetUri + '\'' + ", issuerUrl='" +
issuerUrl + '\'' + ", clientId='" + clientId + '\'' + ", dataSourceConfig=" + dataSourceConfig + '}';
}
}

@Override
public String toString() {
return "TenantConfigProvider{" + "tenantConfigs=" + tenantConfigs + ", env=" + env + '}';
}
public record DataSourceConfig(String driverClassName, String url, String name, String password, String schema) {

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
TenantConfigProvider that = (TenantConfigProvider) o;
return Objects.equals(getTenantConfigs(), that.getTenantConfigs()) && Objects.equals(env, that.env);
}

@Override
public int hashCode() {
return Objects.hash(getTenantConfigs(), env);
public record OauthConfig(String jwkSetUri, String frontendClientIssuerUrl, String frontendClientId) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ public void hasRoleDeleteByCheckInId(Long checkInId, AuthorizationUser authoriza
OkrResponseStatusException.of(NOT_AUTHORIZED_TO_DELETE, CHECK_IN));
}

private void hasRoleWriteForTeam(AuthorizationUser authorizationUser, Team team,
protected void hasRoleWriteForTeam(AuthorizationUser authorizationUser, Team team,
OkrResponseStatusException notAuthorizedException) {
if (hasRoleWriteForTeam(authorizationUser, team)) {
return;
}
throw notAuthorizedException;
}

private boolean hasRoleWriteForTeam(AuthorizationUser authorizationUser, Team team) {
protected boolean hasRoleWriteForTeam(AuthorizationUser authorizationUser, Team team) {
return hasRoleWriteForTeam(authorizationUser, team.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void checkAtLeastOneOkrChampionExists(User user) {

if (optionalUser.isEmpty()){
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST,
ErrorKey.TRIED_TO_REMOVE_LAST_OKR_CHAMPION)
ErrorKey.TRIED_TO_REMOVE_LAST_OKR_CHAMPION);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.puzzle.okr.deserializer;

import static ch.puzzle.okr.Constants.*;
import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -144,10 +145,10 @@ void deserializeShouldThrowResponseStatusExceptionIfJsonHasNoKeyResultType() thr
when(deserializer.getKeyResultType(any())).thenReturn(null);

JsonParser jsonParser = objectMapper.getFactory().createParser(jsonMetric);

Map<String, Class<? extends CheckInDto>> CHECK_IN_MAP = Map.of("", CheckInOrdinalDto.class);
// act + assert
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () ->
deserializerHelper.deserializeMetricOrdinal(jsonParser, Map.of("", CheckInOrdinalDto.class), deserializer)
deserializerHelper.deserializeMetricOrdinal(jsonParser, CHECK_IN_MAP, deserializer)
);

assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
Expand Down
Loading

0 comments on commit 0f7fa6f

Please sign in to comment.