Search in sources :

Example 1 with GetResponse

use of org.opensearch.action.get.GetResponse in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method currentChangeToken.

@Override
public String currentChangeToken() {
    UpdateInfo ui;
    try {
        final GetRequest req = new GetRequest(targetIndex, updateTrackerId).storedFields("esUpdateCount");
        final GetResponse resp = getClient().get(req, RequestOptions.DEFAULT);
        if (!resp.isExists()) {
            return null;
        }
        final EntityBuilder er = getEntityBuilder(resp.getFields());
        ui = er.makeUpdateInfo();
        synchronized (updateInfo) {
            final UpdateInfo fromTbl = updateInfo.get(targetIndex);
            if ((fromTbl == null) || (fromTbl.getCount() < ui.getCount())) {
                updateInfo.put(targetIndex, ui);
            } else {
                ui = fromTbl;
            }
        }
        return ui.getChangeToken();
    } catch (final IOException ie) {
        warn("Exception getting UpdateInfo: " + ie.getLocalizedMessage());
        ui = new UpdateInfo();
    }
    return ui.getChangeToken();
}
Also used : GetRequest(org.opensearch.action.get.GetRequest) IOException(java.io.IOException) GetResponse(org.opensearch.action.get.GetResponse) UpdateInfo(org.bedework.util.opensearch.DocBuilderBase.UpdateInfo)

Example 2 with GetResponse

use of org.opensearch.action.get.GetResponse in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method fetchEntity.

private EntityBuilder fetchEntity(final String docType, final String val, final PropertyInfoIndex... index) throws CalFacadeException {
    requireDocType(docType);
    try {
        fetchStart();
        if ((!docType.equals(docTypeCollection) && !docType.equals(docTypeEvent)) && (index.length == 1) && (index[0] == PropertyInfoIndex.HREF)) {
            // This path avoids the tombstone check.
            final GetRequest req = new GetRequest(targetIndex, val);
            final GetResponse gr = getClient().get(req, RequestOptions.DEFAULT);
            if (!gr.isExists()) {
                return null;
            }
            return getEntityBuilder(gr.getSourceAsMap());
        }
        final SearchHit hit = fetchEntity(docType, getFilters(null).singleEntityQuery(val, index));
        if (hit == null) {
            return null;
        }
        return getEntityBuilder(hit.getSourceAsMap());
    } catch (final IOException ie) {
        throw new CalFacadeException(ie);
    } finally {
        fetchEnd();
    }
}
Also used : SearchHit(org.opensearch.search.SearchHit) GetRequest(org.opensearch.action.get.GetRequest) IOException(java.io.IOException) GetResponse(org.opensearch.action.get.GetResponse) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with GetResponse

use of org.opensearch.action.get.GetResponse in project veilarbportefolje by navikt.

the class RegistreringServiceTest method utdanning_full_integration.

@Test
void utdanning_full_integration() {
    final AktorId aktoerId = randomAktorId();
    populateOpensearch(EnhetId.of("0000"), VeilederId.of(null), aktoerId.get());
    opensearchTestClient.createUserInOpensearch(aktoerId);
    ArbeidssokerRegistrertEvent kafkaMessage = ArbeidssokerRegistrertEvent.newBuilder().setAktorid(aktoerId.toString()).setBrukersSituasjon("Permittert").setUtdanning(UtdanningSvar.GRUNNSKOLE).setUtdanningBestatt(UtdanningBestattSvar.INGEN_SVAR).setUtdanningGodkjent(UtdanningGodkjentSvar.JA).setRegistreringOpprettet(ZonedDateTime.now().format(ISO_ZONED_DATE_TIME)).build();
    registreringService.behandleKafkaMeldingLogikk(kafkaMessage);
    GetResponse getResponse = opensearchTestClient.fetchDocument(aktoerId);
    assertThat(getResponse.isExists()).isTrue();
    String utdanning = (String) getResponse.getSourceAsMap().get("utdanning");
    String situasjon = (String) getResponse.getSourceAsMap().get("brukers_situasjon");
    String utdanningBestatt = (String) getResponse.getSourceAsMap().get("utdanning_bestatt");
    String utdanningGodkjent = (String) getResponse.getSourceAsMap().get("utdanning_godkjent");
    assertThat(utdanning).isEqualTo(UtdanningSvar.GRUNNSKOLE.toString());
    assertThat(situasjon).isEqualTo("Permittert");
    assertThat(utdanningBestatt).isEqualTo(UtdanningBestattSvar.INGEN_SVAR.toString());
    assertThat(utdanningGodkjent).isEqualTo(UtdanningGodkjentSvar.JA.toString());
}
Also used : ArbeidssokerRegistrertEvent(no.nav.arbeid.soker.registrering.ArbeidssokerRegistrertEvent) TestDataUtils.randomAktorId(no.nav.pto.veilarbportefolje.util.TestDataUtils.randomAktorId) AktorId(no.nav.common.types.identer.AktorId) GetResponse(org.opensearch.action.get.GetResponse) EndToEndTest(no.nav.pto.veilarbportefolje.util.EndToEndTest) Test(org.junit.jupiter.api.Test)

Example 4 with GetResponse

use of org.opensearch.action.get.GetResponse in project veilarbportefolje by navikt.

the class SisteEndringIntegrationTest method sisteendring_sortering.

@Test
public void sisteendring_sortering() {
    final AktorId aktoerId_1 = randomAktorId();
    final AktorId aktoerId_2 = randomAktorId();
    final AktorId aktoerId_3 = randomAktorId();
    ZonedDateTime endret_Tid_IJOBB_bruker_1_i_2024 = ZonedDateTime.parse("2024-05-28T09:47:42.480Z");
    ZonedDateTime endret_Tid_IJOBB_bruker_2_i_2025 = ZonedDateTime.parse("2025-05-28T09:47:42.480Z");
    ZonedDateTime endret_Tid_EGEN_bruker_1_i_2021 = ZonedDateTime.parse("2021-05-28T07:47:42.480Z");
    ZonedDateTime endret_Tid_EGEN_bruker_2_i_2020 = ZonedDateTime.parse("2020-05-28T06:47:42.480Z");
    ZonedDateTime endret_Tid_EGEN_bruker_3_i_2019 = ZonedDateTime.parse("2019-05-28T00:47:42.480Z");
    populateOpensearch(testEnhet, veilederId, aktoerId_1.get(), aktoerId_2.get(), aktoerId_3.get());
    pollOpensearchUntil(() -> {
        final BrukereMedAntall brukereMedAntall = opensearchService.hentBrukere(testEnhet.get(), empty(), "asc", "ikke_satt", new Filtervalg(), null, null);
        return brukereMedAntall.getAntall() == 3;
    });
    send_aktvitet_melding(aktoerId_1, endret_Tid_IJOBB_bruker_1_i_2024, KafkaAktivitetMelding.EndringsType.FLYTTET, KafkaAktivitetMelding.AktivitetStatus.FULLFORT, KafkaAktivitetMelding.AktivitetTypeData.IJOBB);
    send_aktvitet_melding(aktoerId_2, endret_Tid_IJOBB_bruker_2_i_2025, KafkaAktivitetMelding.EndringsType.FLYTTET, KafkaAktivitetMelding.AktivitetStatus.FULLFORT, KafkaAktivitetMelding.AktivitetTypeData.IJOBB);
    send_aktvitet_melding(aktoerId_1, endret_Tid_EGEN_bruker_1_i_2021, KafkaAktivitetMelding.EndringsType.FLYTTET, KafkaAktivitetMelding.AktivitetStatus.FULLFORT, KafkaAktivitetMelding.AktivitetTypeData.EGEN);
    send_aktvitet_melding(aktoerId_2, endret_Tid_EGEN_bruker_2_i_2020, KafkaAktivitetMelding.EndringsType.FLYTTET, KafkaAktivitetMelding.AktivitetStatus.FULLFORT, KafkaAktivitetMelding.AktivitetTypeData.EGEN);
    send_aktvitet_melding(aktoerId_3, endret_Tid_EGEN_bruker_3_i_2019, KafkaAktivitetMelding.EndringsType.FLYTTET, KafkaAktivitetMelding.AktivitetStatus.FULLFORT, KafkaAktivitetMelding.AktivitetTypeData.EGEN);
    GetResponse getResponse = opensearchTestClient.fetchDocument(aktoerId_1);
    assertThat(getResponse.isExists()).isTrue();
    pollOpensearchUntil(() -> {
        final BrukereMedAntall brukereMedAntall = opensearchService.hentBrukere(testEnhet.get(), empty(), "ascending", "ikke_satt", getFiltervalg(FULLFORT_IJOBB), null, null);
        return brukereMedAntall.getAntall() == 2;
    });
    pollOpensearchUntil(() -> {
        final BrukereMedAntall brukereMedAntall = opensearchService.hentBrukere(testEnhet.get(), empty(), "ascending", "ikke_satt", getFiltervalg(FULLFORT_EGEN), null, null);
        return brukereMedAntall.getAntall() == 3;
    });
    var responseSortertFULLFORT_IJOBB = opensearchService.hentBrukere(testEnhet.get(), empty(), "descending", "siste_endring_tidspunkt", getFiltervalg(FULLFORT_IJOBB), null, null);
    assertThat(responseSortertFULLFORT_IJOBB.getAntall()).isEqualTo(2);
    assertThat(responseSortertFULLFORT_IJOBB.getBrukere().get(0).getSisteEndringTidspunkt().getYear()).isEqualTo(endret_Tid_IJOBB_bruker_2_i_2025.getYear());
    assertThat(responseSortertFULLFORT_IJOBB.getBrukere().get(1).getSisteEndringTidspunkt().getYear()).isEqualTo(endret_Tid_IJOBB_bruker_1_i_2024.getYear());
    var responseSortertFULLFORT_EGEN = opensearchService.hentBrukere(testEnhet.get(), empty(), "ascending", "siste_endring_tidspunkt", getFiltervalg(FULLFORT_EGEN), null, null);
    assertThat(responseSortertFULLFORT_EGEN.getAntall()).isEqualTo(3);
    assertThat(responseSortertFULLFORT_EGEN.getBrukere().get(0).getSisteEndringTidspunkt().getYear()).isEqualTo(endret_Tid_EGEN_bruker_3_i_2019.getYear());
    assertThat(responseSortertFULLFORT_EGEN.getBrukere().get(1).getSisteEndringTidspunkt().getYear()).isEqualTo(endret_Tid_EGEN_bruker_2_i_2020.getYear());
    assertThat(responseSortertFULLFORT_EGEN.getBrukere().get(2).getSisteEndringTidspunkt().getYear()).isEqualTo(endret_Tid_EGEN_bruker_1_i_2021.getYear());
    var responseSortertTomRes1 = opensearchService.hentBrukere(testEnhet.get(), empty(), "descending", "siste_endring_tidspunkt", getFiltervalg(NY_IJOBB), null, null);
    assertThat(responseSortertTomRes1.getAntall()).isEqualTo(0);
}
Also used : Filtervalg(no.nav.pto.veilarbportefolje.domene.Filtervalg) ZonedDateTime(java.time.ZonedDateTime) BrukereMedAntall(no.nav.pto.veilarbportefolje.domene.BrukereMedAntall) AktorId(no.nav.common.types.identer.AktorId) TestDataUtils.randomAktorId(no.nav.pto.veilarbportefolje.util.TestDataUtils.randomAktorId) GetResponse(org.opensearch.action.get.GetResponse) EndToEndTest(no.nav.pto.veilarbportefolje.util.EndToEndTest) Test(org.junit.jupiter.api.Test)

Example 5 with GetResponse

use of org.opensearch.action.get.GetResponse in project veilarbportefolje by navikt.

the class SisteEndringIntegrationTest method sisteendring_filtrering.

@Test
public void sisteendring_filtrering() {
    final AktorId aktoerId = randomAktorId();
    ZonedDateTime zonedDateTime = ZonedDateTime.parse("2019-05-28T09:47:42.48+02:00");
    ZonedDateTime zonedDateTime_NY_IJOBB = ZonedDateTime.parse("2020-05-28T09:47:42.48+02:00");
    populateOpensearch(testEnhet, veilederId, aktoerId.toString());
    pollOpensearchUntil(() -> {
        final BrukereMedAntall brukereMedAntall = opensearchService.hentBrukere(testEnhet.get(), empty(), "asc", "ikke_satt", new Filtervalg(), null, null);
        return brukereMedAntall.getAntall() == 1;
    });
    send_aktvitet_melding(aktoerId, zonedDateTime_NY_IJOBB, KafkaAktivitetMelding.EndringsType.OPPRETTET, KafkaAktivitetMelding.AktivitetStatus.PLANLAGT, KafkaAktivitetMelding.AktivitetTypeData.IJOBB);
    send_aktvitet_melding(aktoerId, zonedDateTime, KafkaAktivitetMelding.EndringsType.FLYTTET, KafkaAktivitetMelding.AktivitetStatus.FULLFORT, KafkaAktivitetMelding.AktivitetTypeData.IJOBB);
    GetResponse getResponse = opensearchTestClient.fetchDocument(aktoerId);
    assertThat(getResponse.isExists()).isTrue();
    pollOpensearchUntil(() -> {
        final BrukereMedAntall brukereMedAntall = opensearchService.hentBrukere(testEnhet.get(), empty(), "asc", "ikke_satt", getFiltervalg(FULLFORT_IJOBB), null, null);
        return brukereMedAntall.getAntall() == 1;
    });
    var responseBrukere = opensearchService.hentBrukere(testEnhet.get(), empty(), "asc", "ikke_satt", getFiltervalg(FULLFORT_IJOBB), null, null);
    assertThat(responseBrukere.getAntall()).isEqualTo(1);
    assertThat(responseBrukere.getBrukere().get(0).getSisteEndringTidspunkt()).isEqualTo(zonedDateTime.toLocalDateTime());
}
Also used : Filtervalg(no.nav.pto.veilarbportefolje.domene.Filtervalg) ZonedDateTime(java.time.ZonedDateTime) BrukereMedAntall(no.nav.pto.veilarbportefolje.domene.BrukereMedAntall) AktorId(no.nav.common.types.identer.AktorId) TestDataUtils.randomAktorId(no.nav.pto.veilarbportefolje.util.TestDataUtils.randomAktorId) GetResponse(org.opensearch.action.get.GetResponse) EndToEndTest(no.nav.pto.veilarbportefolje.util.EndToEndTest) Test(org.junit.jupiter.api.Test)

Aggregations

GetResponse (org.opensearch.action.get.GetResponse)71 Matchers.containsString (org.hamcrest.Matchers.containsString)15 IndexResponse (org.opensearch.action.index.IndexResponse)14 MultiGetResponse (org.opensearch.action.get.MultiGetResponse)12 EndToEndTest (no.nav.pto.veilarbportefolje.util.EndToEndTest)10 Test (org.junit.jupiter.api.Test)10 GetRequest (org.opensearch.action.get.GetRequest)10 Script (org.opensearch.script.Script)10 SearchResponse (org.opensearch.action.search.SearchResponse)9 IOException (java.io.IOException)8 AktorId (no.nav.common.types.identer.AktorId)8 Alias (org.opensearch.action.admin.indices.alias.Alias)8 DeleteResponse (org.opensearch.action.delete.DeleteResponse)8 IndexRequest (org.opensearch.action.index.IndexRequest)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 OpenSearchException (org.opensearch.OpenSearchException)7 UpdateResponse (org.opensearch.action.update.UpdateResponse)7 BytesArray (org.opensearch.common.bytes.BytesArray)7 Settings (org.opensearch.common.settings.Settings)7