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

Atomised usage for matching-ws #1375

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions matching-ws/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ RUN git clone https://github.com/CatalogueOfLife/backend.git
WORKDIR /app/backend
RUN git checkout $GIT_BRANCH

# Build all the CLB modules
RUN mvn clean install package -DskipTests

# Build the Maven project and create a exec file
WORKDIR /app/backend/matching-ws

# Run tests - full backend tests require additional services (e.g. ES)
RUN mvn clean install package
# Build all the CLB modules
RUN mvn clean install package -DskipTests -DskipITs

# Store git commit id and log
RUN curl -o /app/backend/git.json -H "Accept: application/vnd.github+json" "https://api.github.com/repos/catalogueoflife/backend/commits/$(git rev-parse HEAD)"
Expand Down Expand Up @@ -106,4 +103,4 @@ RUN chown -R $USER:$USER /opt/gbif/$APP_ARTIFACT
USER $USER
EXPOSE $SERVER_PORT

CMD java $JVM_OPTIONS -jar app.jar --server.port=$SERVER_PORT --working.dir=/opt/gbif/$APP_ARTIFACT --mode=RUN --spring.cloud.bootstrap.location=/opt/gbif/$APP_ARTIFACT/bootstrap.yaml
CMD java $JVM_OPTIONS -jar app.jar --server.port=$SERVER_PORT --working.dir=/opt/gbif/$APP_ARTIFACT/ --mode=RUN --spring.cloud.bootstrap.location=/opt/gbif/$APP_ARTIFACT/bootstrap.yaml
9 changes: 1 addition & 8 deletions matching-ws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<java.version>11</java.version>
<lucene.version>9.10.0</lucene.version>
<spring-boot.version>2.7.18</spring-boot.version>
<spring-cloud.version>2021.0.9</spring-cloud.version>
<lombok.version>1.18.22</lombok.version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<logback.version>1.2.13</logback.version>
Expand Down Expand Up @@ -355,14 +356,6 @@
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash-logback.version}</version>
</dependency>
<!-- enable for dev -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <version>${spring-boot.version}</version>-->
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void run(ApplicationArguments args) {
}

private void initialiseWebapp() {
Optional<APIMetadata> metadata = matchingService.getAPIMetadata(false);
Optional<APIMetadata> metadata = matchingService.getAPIMetadata(true);
if (metadata.isEmpty()) {
log.error("No main index found. Cannot start web services");
return;
Expand Down Expand Up @@ -136,7 +136,8 @@ private void runIndexingIfRequired(ApplicationArguments args) throws Exception {
indexingService.indexIdentifiers(id);
}

log.info("Indexing completed");
matchingService.getAPIMetadata(true);
log.info("Indexing ready");
}

private ExecutionMode getMode(ApplicationArguments args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.stream.Collectors;
import life.catalogue.matching.model.*;
import life.catalogue.matching.service.MatchingService;
import life.catalogue.matching.util.IUCNUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -112,9 +113,13 @@ public NameUsageMatch matchOldPaths(
HttpServletRequest response) {
return matchV2(
usageKey,
taxonID,taxonConceptID,scientificNameID,
scientificName2, scientificName,
authorship, authorship2,
taxonID,
taxonConceptID,
scientificNameID,
scientificName2,
scientificName,
authorship,
authorship2,
genericName,
specificEpithet,
infraspecificEpithet,
Expand Down Expand Up @@ -677,15 +682,15 @@ public Map<String, Object> iucnRedListV1(@PathVariable(value = "usageKey", requi
return Map.of();
}
NameUsageMatch.Status status = statusList.get(0);
String formatted = formatIucn(status.getStatus());
String formatted = IUCNUtils.formatIucn(status.getStatus());
if (formatted == null || formatted.isEmpty()) {
return Map.of();
}

String scientificName = match.getAcceptedUsage() != null ? match.getAcceptedUsage().getCanonicalName() : match.getUsage().getCanonicalName();

try {
IUCN iucn = IUCN.valueOf(formatted); // throws IllegalArgumentException if not found
IUCNUtils.IUCN iucn = IUCNUtils.IUCN.valueOf(formatted); // throws IllegalArgumentException if not found
watch.stop();
log("v1/species/iucnRedListCategory", usageKey, watch);
return Map.of(
Expand All @@ -695,7 +700,7 @@ public Map<String, Object> iucnRedListV1(@PathVariable(value = "usageKey", requi
"taxonomicStatus", NameUsageMatchV1.TaxonomicStatusV1.convert(
match.getDiagnostics().getStatus()),
"iucnTaxonID", status.getSourceId(),
"code", iucn.code
"code", iucn.getCode()
);
} catch (IllegalArgumentException e) {
log.error("IUCN category not found: {}", formatted, e);
Expand Down Expand Up @@ -757,37 +762,6 @@ private static void addIfNotNull(StringJoiner joiner, Object value) {
}
}

String formatIucn(String original){
if (original == null) {
return null;
}
// Trim the string
String trimmed = original.trim();
// Convert to uppercase
String uppercased = trimmed.toUpperCase();
// Replace any whitespace with a single underscore
return uppercased.replaceAll("\\s+", "_");
}

enum IUCN {
EXTINCT("EX"),
EXTINCT_IN_THE_WILD("EW"),
CRITICALLY_ENDANGERED ("CR"),
ENDANGERED ("EN"),
VULNERABLE ("VU"),
NEAR_THREATENED ("NT"),
CONSERVATION_DEPENDENT ("CD"),
LEAST_CONCERN ("LC"),
DATA_DEFICIENT ("DD"),
NOT_EVALUATED ("NE");

private final String code;

IUCN(String code) {
this.code = code;
}
}

@Data
@Builder
@NoArgsConstructor
Expand Down
Loading