Skip to content

Commit

Permalink
#374 - Extend API to save and load cohort and dataselection
Browse files Browse the repository at this point in the history
- remove some unused imports
- fix some minor potential errors
  • Loading branch information
michael-82 committed Feb 28, 2025
1 parent 2428a6f commit acb10cc
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;

import java.sql.Timestamp;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.numcodex.feasibility_gui_backend.terminology.api;

import de.numcodex.feasibility_gui_backend.common.api.TermCode;
import lombok.Builder;
import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service
@Slf4j
Expand Down Expand Up @@ -74,9 +75,7 @@ private SearchHits<CodeableConceptDocument> findByCodeOrDisplay(String keyword,
if (!filterList.isEmpty()) {
var fieldValues = new ArrayList<FieldValue>();
filterList.forEach(f -> {
f.getSecond().forEach(s -> {
fieldValues.add(new FieldValue.Builder().stringValue(s).build());
});
f.getSecond().forEach(s -> fieldValues.add(new FieldValue.Builder().stringValue(s).build()));
filterTerms.add(new TermsQuery.Builder()
.field(f.getFirst())
.terms(new TermsQueryField.Builder().value(fieldValues).build())
Expand Down Expand Up @@ -135,7 +134,7 @@ private SearchHits<CodeableConceptDocument> findByCodeOrDisplay(String keyword,
.withPageable(pageRequest)
.build();

log.info(query.getQuery().toString());
log.info(Objects.requireNonNull(query.getQuery()).toString());

return operations.search(query, CodeableConceptDocument.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ private SearchHits<OntologyListItemDocument> findByNameOrTermcode(String keyword
if (!filterList.isEmpty()) {
var fieldValues = new ArrayList<FieldValue>();
filterList.forEach(f -> {
f.getSecond().forEach(s -> {
fieldValues.add(new FieldValue.Builder().stringValue(s).build());
});
f.getSecond().forEach(s -> fieldValues.add(new FieldValue.Builder().stringValue(s).build()));
filterTerms.add(new TermsQuery.Builder()
.field(f.getFirst())
.terms(new TermsQueryField.Builder().value(fieldValues).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.Builder;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,19 @@ public void tokenIsDifferentAfterRefreshTimeout() throws InterruptedException {

@Test
public void errorWhenIssuerUrlIsNull() throws InterruptedException {
assertThatThrownBy(() -> {
new OAuthInterceptor(null, "foo", "bar");
}).isInstanceOf(NullPointerException.class)
assertThatThrownBy(() -> new OAuthInterceptor(null, "foo", "bar")).isInstanceOf(NullPointerException.class)
.hasMessageContaining("oauthIssuerUrl");
}

@Test
public void errorWhenClientIdIsNull() throws InterruptedException {
assertThatThrownBy(() -> {
new OAuthInterceptor("http://foo.bar", null, "bar");
}).isInstanceOf(NullPointerException.class)
assertThatThrownBy(() -> new OAuthInterceptor("http://foo.bar", null, "bar")).isInstanceOf(NullPointerException.class)
.hasMessageContaining("oauthClientId");
}

@Test
public void errorWhenClientSecretIsNull() throws InterruptedException {
assertThatThrownBy(() -> {
new OAuthInterceptor("http://foo.bar", "foo", null);
}).isInstanceOf(NullPointerException.class)
assertThatThrownBy(() -> new OAuthInterceptor("http://foo.bar", "foo", null)).isInstanceOf(NullPointerException.class)
.hasMessageContaining("oauthClientSecret");
}

Expand All @@ -120,9 +114,7 @@ public void errorWhenIssuerUrlIsWrong() throws InterruptedException {
String issuerUrl = "http://" + host + "/foo/bar";
OAuthInterceptor interceptor = new OAuthInterceptor(issuerUrl, "foo", "bar");

assertThatThrownBy(() -> {
interceptor.getToken();
}).isInstanceOf(OAuthClientException.class)
assertThatThrownBy(interceptor::getToken).isInstanceOf(OAuthClientException.class)
.hasMessageContaining("Request for OAuth2 access token failed")
.has(new Condition<Throwable>(s -> s.getCause() != null && s.getCause().getMessage().contains(host),
"hostname in error message of cause"));
Expand All @@ -133,9 +125,7 @@ public void errorWhenClientIdIsUnknown() throws InterruptedException {
String issuerUrl = "http://" + keycloak.getHost() + ":" + keycloak.getFirstMappedPort() + "/realms/test";
OAuthInterceptor interceptor = new OAuthInterceptor(issuerUrl, "foo", "test");

assertThatThrownBy(() -> {
interceptor.getToken();
}).isInstanceOf(OAuthClientException.class)
assertThatThrownBy(interceptor::getToken).isInstanceOf(OAuthClientException.class)
.hasMessageContaining("invalid_client");
}

Expand All @@ -144,9 +134,7 @@ public void errorWhenClientSecretIsWrong() throws InterruptedException {
String issuerUrl = "http://" + keycloak.getHost() + ":" + keycloak.getFirstMappedPort() + "/realms/test";
OAuthInterceptor interceptor = new OAuthInterceptor(issuerUrl, "account", "foo");

assertThatThrownBy(() -> {
interceptor.getToken();
}).isInstanceOf(OAuthClientException.class)
assertThatThrownBy(interceptor::getToken).isInstanceOf(OAuthClientException.class)
.hasMessageContaining("unauthorized_client");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,12 @@ public void testGetDataquerySlotsJson() throws JsonProcessingException, Dataquer
}

private Dataquery createDataquery(boolean withResult) {
var testDataquery = Dataquery.builder()
return Dataquery.builder()
.label("test")
.comment("test")
.content(createCrtdl())
.resultSize(withResult ? 123L : null)
.build();
return testDataquery;
}

private Crtdl createCrtdl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@Tag("query")
Expand Down Expand Up @@ -196,7 +195,7 @@ void updateDataquery_throwsOnNoFreeSlots(boolean withResultNew, boolean withResu
var dataqueryEntity = createDataqueryEntity(withResultOld);

lenient().doReturn(Optional.of(dataqueryEntity)).when(dataqueryRepository).findById(any(Long.class));
lenient().doReturn(Long.valueOf(MAX_QUERIES_PER_USER)).when(dataqueryRepository).countByCreatedByWhereResultIsNotNull(any(String.class));
lenient().doReturn((long) MAX_QUERIES_PER_USER).when(dataqueryRepository).countByCreatedByWhereResultIsNotNull(any(String.class));
lenient().doReturn(createDataqueryEntity()).when(dataqueryRepository).save(any(de.numcodex.feasibility_gui_backend.query.persistence.Dataquery.class));

// When the new dataquery has no result, this should never throw. It should only throw if the old had no result and the new has a result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.numcodex.feasibility_gui_backend.terminology.es;

import de.numcodex.feasibility_gui_backend.terminology.es.repository.CodeableConceptEsRepository;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemNotFoundException;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
Expand All @@ -20,8 +19,6 @@
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand Down

0 comments on commit acb10cc

Please sign in to comment.