Skip to content

Commit

Permalink
Arbeid i gang for elastisk soek
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Oct 18, 2023
1 parent 08bb9e4 commit aeb06d4
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 74 deletions.
6 changes: 6 additions & 0 deletions apps/dolly-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ DOCKER_HOST=unix://${HOME}/.colima/default/docker.sock
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
TESTCONTAINERS_RYUK_DISABLED=true
```

For å kjøre lokalt med elastic search:

```
docker run -d --name es762 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2
```
5 changes: 5 additions & 0 deletions apps/dolly-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'org.springframework.retry:spring-retry:2.0.0'

// implementation 'org.opensearch.client:spring-data-opensearch:1.1.0'
// implementation 'com.fasterxml.jackson.core:jackson-core:2.15.2'
// implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.16.1'

implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'com.github.ben-manes.caffeine:caffeine'
Expand Down
3 changes: 3 additions & 0 deletions apps/dolly-backend/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ spec:
enabled: true
tenant: nav.no
image: {{image}}
openSearch:
instance: dolly-bestilling-test
access: admin
env:
- name: SPRING_PROFILES_ACTIVE
value: dev
Expand Down
3 changes: 3 additions & 0 deletions apps/dolly-backend/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ spec:
enabled: true
tenant: nav.no
image: {{image}}
openSearch:
instance: dolly-bestilling
access: admin
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected RsDollyBestillingRequest getDollyBestillingRequest(Bestilling bestilli
bestKriterier.setNavSyntetiskIdent(bestilling.getNavSyntetiskIdent());
bestKriterier.setEnvironments(getEnvironments(bestilling.getMiljoer()));
bestKriterier.setBeskrivelse(bestilling.getBeskrivelse());

return bestKriterier;

} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService;
import no.nav.dolly.domain.jpa.Bestilling;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyBestilling;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.metrics.CounterCustomRegistry;
import no.nav.dolly.repository.IdentRepository.GruppeBestillingIdent;
Expand Down Expand Up @@ -105,7 +104,7 @@ public void executeAsync(Bestilling bestilling) {
.flatMapSequential(cobestilling -> createBestilling(bestilling, cobestilling)
.filter(bestillingRequest -> bestillingRequest.getId() ==
isFirstBestilling(coBestillinger, cobestilling.getIdent()) ||
RsDollyBestilling.isNonEmpty(bestillingRequest))
bestillingRequest.isNonEmpty())
.doOnNext(request -> log.info("Startet gjenopprett bestilling {} for ident: {}",
request.getId(), testident.getIdent()))
.flatMapSequential(bestillingRequest -> Flux.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService;
import no.nav.dolly.domain.jpa.Bestilling;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyBestilling;
import no.nav.dolly.domain.resultset.RsDollyBestillingRequest;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.metrics.CounterCustomRegistry;
Expand Down Expand Up @@ -106,7 +105,7 @@ public void executeAsync(Bestilling bestilling) {
.filter(cobestilling -> ident.equals(cobestilling.getIdent()))
.flatMap(cobestilling -> createBestilling(bestilling, cobestilling)
.filter(bestillingRequest -> countEmptyBestillinger.getAndIncrement() == 0 ||
RsDollyBestilling.isNonEmpty(bestillingRequest))
bestillingRequest.isNonEmpty())
.doOnNext(request ->
log.info("Startet gjenopprett bestilling {} for ident: {}",
request.getId(), testident.getIdent()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.nav.dolly.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchConfiguration;

import java.time.Duration;

@Profile({"prod", "dev"})
@Configuration
public class ElasticSearchConfig extends ReactiveElasticsearchConfiguration {

@Value("${OPEN_SEARCH_USERNAME}")
private String username;

@Value("${OPEN_SEARCH_PASSWORD}")
private String password;

@Value("${OPEN_SEARCH_URI}")
private String uri;

@Override
public ClientConfiguration clientConfiguration() {
return ClientConfiguration.builder()
.connectedTo(uri.replace("https://", ""))
.usingSsl()
.withBasicAuth(username, password)
.withConnectTimeout(Duration.ofSeconds(10))
.withSocketTimeout(Duration.ofSeconds(5))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package no.nav.dolly.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchConfiguration;
import org.springframework.data.elasticsearch.config.EnableElasticsearchAuditing;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

@Profile("local")
@Configuration
@EnableElasticsearchRepositories
@EnableElasticsearchAuditing
public class ElasticSearchLocalConfig extends ReactiveElasticsearchConfiguration {

@Override
public ClientConfiguration clientConfiguration() {
return ClientConfiguration.builder()
.connectedTo("localhost:9200")
.usingSsl()
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ public List<RsInstdata> getInstdata() {
return instdata;
}

public static boolean isNonEmpty(RsDollyBestilling bestilling) {
@JsonIgnore
public boolean isNonEmpty() {

return Arrays.stream(RsDollyBestilling.class.getMethods())
.filter(method -> "get".equals(method.getName().substring(0, 3)))
.filter(method -> !EXCLUDE_METHODS.contains(method.getName()))
.anyMatch(method -> {
try {
var object = method.invoke(bestilling);
var object = method.invoke(this);
return nonNull(object) && (!(object instanceof List) || !((List<?>) object).isEmpty());
} catch (IllegalAccessException | InvocationTargetException e) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package no.nav.dolly.elastic;

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface BestillingElasticRepository extends ElasticsearchRepository<ElasticBestilling, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package no.nav.dolly.elastic;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import no.nav.dolly.domain.resultset.aareg.RsAareg;
import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata;
import no.nav.dolly.domain.resultset.breg.RsBregdata;
import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv;
import no.nav.dolly.domain.resultset.histark.RsHistark;
import no.nav.dolly.domain.resultset.inntektsmeldingstub.RsInntektsmelding;
import no.nav.dolly.domain.resultset.inntektstub.InntektMultiplierWrapper;
import no.nav.dolly.domain.resultset.inst.RsInstdata;
import no.nav.dolly.domain.resultset.kontoregister.BankkontoData;
import no.nav.dolly.domain.resultset.krrstub.RsDigitalKontaktdata;
import no.nav.dolly.domain.resultset.medl.RsMedl;
import no.nav.dolly.domain.resultset.pdldata.PdlPersondata;
import no.nav.dolly.domain.resultset.pensjon.PensjonData;
import no.nav.dolly.domain.resultset.sigrunstub.RsLignetInntekt;
import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden;
import no.nav.dolly.domain.resultset.skjerming.RsSkjerming;
import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding;
import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging;
import no.nav.dolly.domain.resultset.udistub.model.RsUdiPerson;
import no.nav.testnav.libs.dto.arbeidsplassencv.v1.ArbeidsplassenCVDTO;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Persistable;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static java.util.Objects.isNull;

@Document(indexName = "bestilling")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ElasticBestilling implements Persistable<String> {

@JsonIgnore
@Id
private String id;

@Field
private Set<String> environments;
@Field
private String malBestillingNavn;
@Field
private PdlPersondata pdldata;
@Field
private RsDigitalKontaktdata krrstub;
@Field
private RsMedl medl;
@Field
private List<RsInstdata> instdata;
@Field
private List<RsAareg> aareg;
@Field
private List<RsLignetInntekt> sigrunstub;
@Field
private List<RsPensjonsgivendeForFolketrygden> sigrunstubPensjonsgivende;
@Field
private InntektMultiplierWrapper inntektstub;
@Field
private Arenadata arenaforvalter;
@Field
private RsUdiPerson udistub;
@Field
private PensjonData pensjonforvalter;
@Field
private RsInntektsmelding inntektsmelding;
@Field
private RsBregdata brregstub;
@Field
private RsDokarkiv dokarkiv;
@Field
private RsHistark histark;
@Field
private RsSykemelding sykemelding;
@Field
private RsTpsMessaging tpsMessaging;
@Field
private BankkontoData bankkonto;
@Field
private RsSkjerming skjerming;
@Field
private ArbeidsplassenCVDTO arbeidsplassenCV;
@Field
private List<String> identer;

public List<RsAareg> getAareg() {
if (isNull(aareg)) {
aareg = new ArrayList<>();
}
return aareg;
}

public Set<String> getEnvironments() {
if (isNull(environments)) {
environments = new HashSet<>();
}
return environments;
}

public List<RsLignetInntekt> getSigrunstub() {
if (isNull(sigrunstub)) {
sigrunstub = new ArrayList<>();
}
return sigrunstub;
}

public List<RsPensjonsgivendeForFolketrygden> getSigrunstubPensjonsgivende() {
if (isNull(sigrunstubPensjonsgivende)) {
sigrunstubPensjonsgivende = new ArrayList<>();
}
return sigrunstubPensjonsgivende;
}

public List<RsInstdata> getInstdata() {
if (isNull(instdata)) {
instdata = new ArrayList<>();
}
return instdata;
}

public List<String> getIdenter() {
if (isNull(identer)) {
identer = new ArrayList<>();
}
return identer;
}

@Override
@JsonIgnore
public boolean isNew() {

return true;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit aeb06d4

Please sign in to comment.