Skip to content

Commit

Permalink
removing retrofit client from registry-search
Browse files Browse the repository at this point in the history
  • Loading branch information
fmendezh committed Mar 25, 2024
1 parent 087d914 commit 7bcaeb2
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 220 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<gbif-postal-service.version>1.8.0</gbif-postal-service.version>
<xoai.version>4.1.0-gbif-4</xoai.version>
<gbif-occurrence.version>0.195.1</gbif-occurrence.version>
<checklistbank.version>2.125</checklistbank.version>

<!-- Third party -->
<commons-digester.version>3.2</commons-digester.version>
Expand Down Expand Up @@ -361,6 +362,11 @@
<artifactId>occurrence-ws-client</artifactId>
<version>${gbif-occurrence.version}</version>
</dependency>
<dependency>
<groupId>org.gbif.checklistbank</groupId>
<artifactId>checklistbank-ws-client</artifactId>
<version>${checklistbank.version}</version>
</dependency>
<dependency>
<groupId>org.gbif</groupId>
<artifactId>gbif-doi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.gbif.registry.search.dataset.indexing.es.EsClient;
import org.gbif.registry.search.dataset.indexing.es.EsConfiguration;
import org.gbif.registry.search.dataset.indexing.ws.GbifApiServiceConfig;
import org.gbif.registry.search.dataset.indexing.ws.GbifWsRetrofitClient;
import org.gbif.registry.search.dataset.indexing.ws.GbifWsWrapperClient;
import org.gbif.registry.search.dataset.indexing.ws.JacksonObjectMapper;
import org.gbif.registry.ws.client.DatasetClient;
import org.gbif.registry.ws.client.InstallationClient;
Expand Down Expand Up @@ -93,7 +93,7 @@ private static AnnotationConfigApplicationContext commonContext(
"DatasetIndexConfiguration", DatasetIndexConfiguration.class, () -> configuration);
ctx.register(DatasetBatchIndexer.class);
ctx.register(GbifApiServiceConfig.class);
ctx.register(GbifWsRetrofitClient.class);
ctx.register(GbifWsWrapperClient.class);
ctx.register(JacksonObjectMapper.class);
ctx.register(EsConfiguration.class);
ctx.register(EsClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,22 @@
*/
package org.gbif.registry.search;

import org.gbif.api.model.checklistbank.DatasetMetrics;
import org.gbif.api.model.checklistbank.NameUsage;
import org.gbif.api.model.checklistbank.search.NameUsageSearchParameter;
import org.gbif.api.model.common.search.SearchResponse;
import org.gbif.api.model.occurrence.Occurrence;
import org.gbif.api.model.occurrence.search.OccurrenceSearchParameter;
import org.gbif.api.service.registry.DatasetService;
import org.gbif.api.service.registry.InstallationService;
import org.gbif.api.service.registry.NetworkService;
import org.gbif.api.service.registry.OrganizationService;
import org.gbif.registry.search.dataset.indexing.ws.GbifApiService;
import org.gbif.checklistbank.ws.client.DatasetMetricsClient;
import org.gbif.checklistbank.ws.client.SpeciesResourceClient;
import org.gbif.metrics.ws.client.CubeWsClient;
import org.gbif.occurrence.ws.client.OccurrenceWsSearchClient;
import org.gbif.registry.search.dataset.indexing.ws.GbifWsClient;
import org.gbif.registry.search.dataset.indexing.ws.GbifWsRetrofitClient;

import java.util.Map;
import org.gbif.registry.search.dataset.indexing.ws.GbifWsWrapperClient;

import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import retrofit2.Call;
import retrofit2.mock.Calls;

@Configuration(proxyBeanMethods = false)
public class SearchTestConfiguration {

Expand All @@ -46,38 +39,14 @@ public GbifWsClient gbifWsClient(
OrganizationService organizationService,
DatasetService datasetService,
NetworkService networkService) {
return new GbifWsRetrofitClient(
gbifApiService(), installationService, organizationService, datasetService, networkService);
return new GbifWsWrapperClient(installationService,
organizationService,
datasetService,
networkService,
Mockito.mock(OccurrenceWsSearchClient.class),
Mockito.mock(SpeciesResourceClient.class),
Mockito.mock(CubeWsClient.class),
Mockito.mock(DatasetMetricsClient.class));
}

public GbifApiService gbifApiService() {
return new GbifApiService() {
@Override
public Call<Long> getDatasetRecordCount(String datasetKey) {
return Calls.response(1L);
}

@Override
public Call<Long> getOccurrenceRecordCount() {
return Calls.response(1L);
}

@Override
public Call<DatasetMetrics> getDatasetSpeciesMetrics(String datasetKey) {
return Calls.response(new DatasetMetrics());
}

@Override
public Call<SearchResponse<NameUsage, NameUsageSearchParameter>> speciesSearch(
Map<String, Object> options) {
return Calls.response(new SearchResponse<>());
}

@Override
public Call<SearchResponse<Occurrence, OccurrenceSearchParameter>> occurrenceSearch(
Map<String, Object> options) {
return Calls.response(new SearchResponse<>());
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.gbif.api.model.occurrence.DownloadFormat;
import org.gbif.api.model.occurrence.DownloadType;
import org.gbif.api.model.occurrence.PredicateDownloadRequest;
import org.gbif.api.model.predicate.EqualsPredicate;
import org.gbif.api.model.occurrence.search.OccurrenceSearchParameter;
import org.gbif.api.model.predicate.EqualsPredicate;
import org.gbif.api.model.registry.CountryOccurrenceDownloadUsage;
import org.gbif.api.model.registry.Dataset;
import org.gbif.api.model.registry.DatasetOccurrenceDownloadUsage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/
package org.gbif.registry.ws.it.collections.service;

import org.gbif.api.model.collections.Address;
import org.gbif.api.model.collections.*;
import org.gbif.api.model.collections.Address;
import org.gbif.api.model.collections.lookup.*;
import org.gbif.api.model.registry.*;
import org.gbif.api.service.collections.CollectionService;
Expand All @@ -27,15 +27,16 @@
import org.gbif.registry.database.TestCaseDatabaseInitializer;
import org.gbif.registry.service.collections.lookup.LookupService;
import org.gbif.ws.client.filter.SimplePrincipalProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;
import java.util.UUID;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
import org.dspace.xoai.dataprovider.repository.ItemRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.LinkedMultiValueMap;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;

import static org.gbif.registry.oaipmh.OaipmhSetRepository.SetType.COUNTRY;
import static org.gbif.registry.oaipmh.OaipmhSetRepository.SetType.DATASET_TYPE;
Expand Down Expand Up @@ -297,8 +297,9 @@ private OaipmhItem toOaipmhItem(Dataset dataset) throws IOException {
ReadBuilder readBuilder = new ReadBuilder();
readBuilder.at(OccurrenceCube.DATASET_KEY, dataset.getKey());
try {
Long occurrenceCount =
metricsClient.count(ImmutableMap.of("datasetKey", dataset.getKey().toString()));
LinkedMultiValueMap<String,String> params = new LinkedMultiValueMap<>();
params.add("datasetKey", dataset.getKey().toString());
long occurrenceCount = metricsClient.get(params);
if (occurrenceCount > 0) {
additionalProperties.put(DublinCoreWriter.ADDITIONAL_PROPERTY_OCC_COUNT, occurrenceCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.gbif.api.model.occurrence.DownloadRequest;
import org.gbif.api.model.occurrence.PredicateDownloadRequest;
import org.gbif.api.model.occurrence.SqlDownloadRequest;
import org.gbif.api.model.predicate.Predicate;
import org.gbif.api.model.pipelines.PipelineExecution;
import org.gbif.api.model.pipelines.PipelineProcess;
import org.gbif.api.model.pipelines.PipelineStep;
import org.gbif.api.model.predicate.Predicate;
import org.gbif.api.model.registry.Citation;
import org.gbif.api.model.registry.Comment;
import org.gbif.api.model.registry.Contact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
*/
package org.gbif.registry.persistence.mapper;

import org.apache.ibatis.annotations.Param;
import org.gbif.api.model.common.paging.Pageable;
import org.gbif.api.model.crawler.DatasetProcessStatus;
import org.gbif.api.model.crawler.FinishReason;
import org.springframework.stereotype.Repository;

import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID;

import javax.annotation.Nullable;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

/** Mapper that perform operations on {@link DatasetProcessStatus} instances. */
@Repository
public interface DatasetProcessStatusMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
import org.gbif.registry.persistence.mapper.DatasetMapper;
import org.gbif.registry.persistence.mapper.DatasetProcessStatusMapper;
import org.gbif.registry.persistence.mapper.pipelines.PipelineProcessMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.springframework.stereotype.Service;

@Service
public class DefaultRegistryIngestionHistoryService implements RegistryIngestionHistoryService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import org.gbif.api.model.crawler.FinishReason;
import org.gbif.api.model.pipelines.IngestionProcess;

import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID;

import javax.annotation.Nullable;

public interface RegistryIngestionHistoryService {

PagingResponse<IngestionProcess> ingestionHistory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
*/
package org.gbif.registry.pipelines.issues;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@
*/
package org.gbif.registry.pipelines.issues;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.avro.file.DataFileReader;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.AvroFSInput;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.RemoteIterator;
import org.gbif.api.model.common.search.SearchResponse;
import org.gbif.api.model.occurrence.Occurrence;
import org.gbif.api.model.occurrence.search.OccurrenceSearchParameter;
Expand All @@ -44,11 +29,6 @@
import org.gbif.registry.persistence.mapper.pipelines.PipelineProcessMapper;
import org.gbif.ws.client.ClientBuilder;
import org.gbif.ws.json.JacksonJsonObjectMapperProvider;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -60,6 +40,29 @@
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

import org.apache.avro.file.DataFileReader;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.AvroFSInput;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.RemoteIterator;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import static org.gbif.registry.pipelines.issues.GithubApiService.Issue;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*/
package org.gbif.registry.pipelines.issues;

import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotEmpty;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;

@Component
@Getter
Expand Down
Loading

0 comments on commit 7bcaeb2

Please sign in to comment.