Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/schema search #49

Merged
merged 9 commits into from
Mar 13, 2024
Merged

Enhancement/schema search #49

merged 9 commits into from
Mar 13, 2024

Conversation

iimpulse
Copy link
Member

@iimpulse iimpulse commented Mar 4, 2024

Closes #31
Closes #22

  • hotfixes open api schema bug
  • Jacoco Addition
  • Test cov >90%
  • Translation Definition Exposure

@iimpulse iimpulse requested review from gerring, pnrobinson and ielis March 4, 2024 21:17
Copy link
Collaborator

@gerring gerring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather patching public doc on API disappointing but otherwise good.

afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
"org/jacksonlaboratory/view/*",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why excluded, please tell developers in comment why these should not be tested.

@@ -31,13 +31,13 @@ public SearchController(TermService termService) {
public SearchDto search(
@QueryValue("q") @Schema(minLength = 3, maxLength = 250, type = "string", pattern = ".*") String query,
@QueryValue(value = "page", defaultValue = "0") @Schema(maxLength = 1000, type = "number") int page,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like 0-based pages, it makes the code elegant stream().skip(page).limit(limit) which I do a lot.

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

public class OntologyDataResolver {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for class please

}


public Path dataDirectory() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually put some kind of doc on public ones, I appreciate this is obvious but still.

@@ -20,4 +21,17 @@ public List<OntologyTerm> getTerms() {
public int getTotalCount() {
return totalCount;
}

@Override
public boolean equals(Object o) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fellow implementor of equals and hashcode, I autogenerate assume IntelliJ does too.

@@ -17,7 +18,8 @@ public interface TermRepository {

Optional<List<OntologyTerm>> findByTermIdIn(@NotEmpty List<TermId> ids);

List<OntologyTerm> search(@NotBlank String query);
@Transactional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface methods must all be documented please.

@@ -17,7 +18,8 @@ public interface TermRepository {

Optional<List<OntologyTerm>> findByTermIdIn(@NotEmpty List<TermId> ids);

List<OntologyTerm> search(@NotBlank String query);
@Transactional
List<OntologyTerm> search(String searchTerm, boolean prefixSearch);

void saveAll(@NotEmpty List<OntologyTerm> terms);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc

@@ -1,6 +1,8 @@
micronaut:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good micronaut uses application yaml too.

@@ -47,6 +47,7 @@ jackson:

api-url:
prefix: /api
ontology: ${ONTOLOGY}
ontology: ${ONTOLOGY:unknown}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume unknown is a real empty ontology which will cause less errors later, otherwise not defaulting to 'unknown' seems wrong.

Copy link

@ielis ielis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @iimpulse
nice work, pls consider looking at my comments.
Cheers :)

*/
@Get(uri="/{id}/descendants", produces="application/json")
public List<SimpleOntologyTerm> descendants(@Schema(minLength = 1, maxLength = 20, type = "string", pattern = ".*") @PathVariable String id){
TermId termId = TermId.of(id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can explode if id is not a good CURIE. I assume the framework handles runtime exceptions, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handle in the global exception handler.

@@ -17,7 +18,8 @@ public interface TermRepository {

Optional<List<OntologyTerm>> findByTermIdIn(@NotEmpty List<TermId> ids);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an Optional<List<T>> but on line 22 you return just List<T>?

I think it may be a bit better to just return List<T> everywhere, especially on line 16, where wrapping the list in Optional seems IMO unnecessary. I would use Optional if there was an extra situation that could occur during the lookup. However, failures are probably better modeled with an exception, and missing results for a query can also be represented by an empty list.

Unless you know about some framework semantics which I do not know about..

if (q.toUpperCase().startsWith(String.format("%s:", ontologyName.toUpperCase()))){
return this.termRepository.search(q, true).stream()
.sorted((a, b) -> {
int c = Integer.parseInt(a.getTermId().getId());
Copy link

@ielis ielis Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail for some ontology classes where id is not an integer, e.g. NCIT:C2852 for Adenocarcinoma (if you think of this serving such an ontology).

To best of my knowledge, both CURIE prefix and id are strings, but some ids are strings of int values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your reccomendation here string compare?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String compare is probably the simplest solution. Any other sorting strategy should be motivated by a specific requirements. Therefore, if you are aware of no such requirements (I am not), doing string comparison sounds OK to me.

@iimpulse iimpulse merged commit 15eedc2 into main Mar 13, 2024
1 check passed
@iimpulse iimpulse deleted the enhancement/schema-search branch May 2, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Definition Translations Full Integration Tests
3 participants