Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/navikt/etterlevelse into …
Browse files Browse the repository at this point in the history
…rediger_krav_modal
  • Loading branch information
PaulMartinKokseter committed Nov 16, 2023
2 parents da005de + 09b170f commit 49606b9
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 11 deletions.
6 changes: 3 additions & 3 deletions apps/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
<msal4j.version>1.14.0</msal4j.version>

<!-- transitive versions -->
<commons-compress.version>1.24.0</commons-compress.version>
<commons-compress.version>1.25.0</commons-compress.version>
<commons-io.version>2.15.0</commons-io.version>
<guava.version>32.1.3-jre</guava.version>
<jna.version>5.13.0</jna.version>
<jetbrains.annotation.version>24.0.1</jetbrains.annotation.version>
<jetbrains.annotation.version>24.1.0</jetbrains.annotation.version>
<stax2-api.version>4.2.2</stax2-api.version>

<!-- Test -->
<testcontainers.version>1.19.1</testcontainers.version>
<testcontainers.version>1.19.2</testcontainers.version>
<wiremock.version>2.27.2</wiremock.version>
<docx4j.version>11.4.9</docx4j.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,11 @@ public EtterlevelseDokumentasjonStats stats(EtterlevelseDokumentasjonResponse et
}
});


var fylt = filter(krav, k -> etterlevelser.stream().anyMatch(e -> e.isEtterleves() && e.kravId().equals(k.kravId())));
var ikkeFylt = filter(krav, k -> !fylt.contains(k));

var irrelevant = filter(irrelevantKrav, i -> !fylt.contains(i) && !ikkeFylt.contains(i));

//filtering for only newest version for utgaatt krav


return EtterlevelseDokumentasjonStats.builder()
.fyltKrav(fylt)
.ikkeFyltKrav(ikkeFylt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import no.nav.data.common.rest.RestResponsePage;
import no.nav.data.etterlevelse.codelist.CodelistService;
import no.nav.data.etterlevelse.codelist.domain.ListName;
import no.nav.data.etterlevelse.krav.domain.KravStatus;
import no.nav.data.etterlevelse.kravprioritering.domain.KravPrioritering;
import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringFilter;
import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringRequest;
import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringResponse;
import org.springframework.data.domain.Page;
Expand All @@ -24,6 +26,7 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
Expand Down Expand Up @@ -80,6 +83,28 @@ public ResponseEntity<RestResponsePage<KravPrioriteringResponse>> getByTemaCode(
return ResponseEntity.ok(new RestResponsePage<>(kravPrioriteringList).convert(KravPrioritering::toResponse));
}

@Operation(summary = "Get krav prioritering by filter")
@ApiResponse(description = "ok")
@GetMapping("/filter")
public ResponseEntity<RestResponsePage<KravPrioriteringResponse>> getByFilter(
@RequestParam(name="id",required = false) String id,
@RequestParam(name="kravNummer",required = false) Integer kravNummer,
@RequestParam(name="temaCode",required = false) String temaCode,
@RequestParam(name="kravStatus",required = false) KravStatus kravStatus
) {
KravPrioriteringFilter filter = KravPrioriteringFilter.builder()
.id(id)
.kravNummer(kravNummer)
.temaCode(temaCode)
.kravStatus(kravStatus)
.build();
log.info("Get krav prioritering with filter={}", filter);
if(filter.getTemaCode() != null) {
codelistService.validateListNameAndCode(ListName.TEMA.name(), filter.getTemaCode());
}
return ResponseEntity.ok(new RestResponsePage<>(service.getByFilter(filter)));
}

@Operation(summary = "Get one krav prioritering")
@ApiResponse(description = "ok")
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@
import no.nav.data.common.rest.PageParameters;
import no.nav.data.common.storage.domain.GenericStorage;
import no.nav.data.etterlevelse.common.domain.DomainService;
import no.nav.data.etterlevelse.krav.KravService;
import no.nav.data.etterlevelse.krav.domain.Krav;
import no.nav.data.etterlevelse.krav.domain.KravStatus;
import no.nav.data.etterlevelse.kravprioritering.domain.KravPrioritering;
import no.nav.data.etterlevelse.kravprioritering.domain.KravPrioriteringRepo;
import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringFilter;
import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringRequest;
import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Service
public class KravPrioriteringService extends DomainService<KravPrioritering> {

private final KravPrioriteringRepo repo;
private final KravService kravService;

public KravPrioriteringService(KravPrioriteringRepo repo) {
public KravPrioriteringService(KravPrioriteringRepo repo, KravService kravService) {
super(KravPrioritering.class);
this.repo = repo;
this.kravService = kravService;
}

public Page<KravPrioritering> getAll(PageParameters pageParameters) {
Expand All @@ -42,6 +51,47 @@ public List<KravPrioritering> getByTema(String tema) {
return GenericStorage.to(repo.findByTema(tema.substring(0, 3)), KravPrioritering.class);
}

public List<KravPrioriteringResponse> getByFilter(KravPrioriteringFilter filter) {
if (!StringUtils.isBlank(filter.getId())) {
KravPrioritering kravPrioritering = storage.get(UUID.fromString(filter.getId()), KravPrioritering.class);
if (kravPrioritering != null) {
KravPrioriteringResponse kravPrioriteringResponse = kravPrioritering.toResponse();
setKravStatus(kravPrioriteringResponse);
return List.of(kravPrioriteringResponse);
}
return List.of();
} else if (filter.getKravNummer() != null) {
List<KravPrioriteringResponse> kravPrioriteringList = GenericStorage.to(repo.findByKravNummer(filter.getKravNummer()), KravPrioritering.class).stream().map(KravPrioritering::toResponse).toList();
kravPrioriteringList.forEach(this::setKravStatus);
return filterForKravStatus(kravPrioriteringList, filter);
} else if(filter.getTemaCode() != null) {
List<KravPrioriteringResponse> kravPrioriteringerResp = GenericStorage.to(repo.findByTema(filter.getTemaCode().substring(0, 3)), KravPrioritering.class).stream().map(KravPrioritering::toResponse).toList();
kravPrioriteringerResp.forEach(this::setKravStatus);
return filterForKravStatus(kravPrioriteringerResp, filter);
}

List<KravPrioriteringResponse> kravPrioriteringer = GenericStorage.to(repo.getAll(),KravPrioritering.class).stream().map(KravPrioritering::toResponse).toList();
kravPrioriteringer.forEach(this::setKravStatus);

return filterForKravStatus(kravPrioriteringer, filter);
}

private List<KravPrioriteringResponse> filterForKravStatus(List<KravPrioriteringResponse> kravPrioriteringResponse, KravPrioriteringFilter filter) {
if(filter.getKravStatus() != null) {
return kravPrioriteringResponse.stream().filter(kp-> kp.getKravStatus().equals(filter.getKravStatus())).toList();
}
return kravPrioriteringResponse;
}

private void setKravStatus(KravPrioriteringResponse kravPrioriteringResponse) {
Optional<Krav> krav = kravService.getByKravNummer(kravPrioriteringResponse.getKravNummer(), kravPrioriteringResponse.getKravVersjon());
if(krav.isPresent()) {
kravPrioriteringResponse.setKravStatus(krav.get().getStatus());
} else {
kravPrioriteringResponse.setKravStatus(KravStatus.UTGAATT);
}
}

public KravPrioritering save(KravPrioriteringRequest request) {

var kravprioritering = request.isUpdate() ? storage.get(request.getIdAsUUID(), KravPrioritering.class) : new KravPrioritering();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public interface KravPrioriteringRepo extends JpaRepository<GenericStorage, UUID
@Query(value = "select * from generic_storage where data ->> 'prioriteringsId' ilike %?1% and type = 'KravPrioritering'", nativeQuery = true)
List<GenericStorage> findByTema(String tema);

@Query(value = "select * from generic_storage where type = 'KravPrioritering'", nativeQuery = true)
List<GenericStorage> getAll();

@Modifying(clearAutomatically = true)
@Transactional
@Query(value = "update generic_storage set DATA = jsonb_set(DATA, '{kravVersjon}', to_jsonb(?1) , false ) where data -> 'kravNummer' = to_jsonb(?2) and type = 'KravPrioritering'", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package no.nav.data.etterlevelse.kravprioritering.dto;

import graphql.schema.DataFetchingEnvironment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import no.nav.data.etterlevelse.krav.domain.KravStatus;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

import static no.nav.data.etterlevelse.graphql.support.GraphQlResolverUtil.getFilter;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@FieldNameConstants
public class KravPrioriteringFilter {

private String id;
private Integer kravNummer;
private String temaCode;
private KravStatus kravStatus;

public boolean isEmpty() {
return StringUtils.isBlank(id)
&& kravNummer == null
&& kravStatus == null
&& temaCode == null;
}

public static <T> T get(DataFetchingEnvironment env, String field) {
Map<String, T> vars = getFilter(env.getExecutionStepInfo());
return vars.get(field);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import no.nav.data.common.rest.ChangeStampResponse;
import no.nav.data.etterlevelse.krav.domain.KravStatus;

import java.util.UUID;

Expand All @@ -22,4 +23,6 @@ public class KravPrioriteringResponse {
private Integer kravVersjon;
private String prioriteringsId;

private KravStatus kravStatus;

}
61 changes: 60 additions & 1 deletion apps/frontend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,68 @@
### Requires node 17

### Install deps

`yarn install`

### Login with Google Cloud with @nav.no user

Do this in Google Chrome as it doesn't work in Firefox on Mac

`gcloud auth login`

Remember to flush sockets when you can't login

`chrome://net-internals/#sockets`

### Run local, with port forward to dev-gcp

`kubectl port-forward deployment/etterlevelse-backend`

`yarn run start`
`yarn run start`

## Other

### To use Yarn you need to

1. `brew install yarn`
2. `brew install node`

## Common errors

###

#### Kubernetes error

```
frontend git:(master) ✗ kubectl port-forward deployment/etterlevelse-backend
error: TYPE/NAME and list of ports are required for port-forward
See 'kubectl port-forward -h' for help and examples
```

1. You need to add config (see below) in `.zshrc`.
2. Run `gcloud auth login`
3. Run `kpfe`
4. Then run in separate window `yarn run start`
5. Go to `http://localhost:3000/`
6. Done!

##### `.bashrc` or `.zshrc` config

```
# etterlevelse-back end proxy connection
kpfe() {
while true; do
kubectl port-forward deployment/etterlevelse-backend 8080 --namespace teamdatajegerne;
done
}
# behandlingskatalog-backend proxy connection
kpfb() {
while true; do
kubectl port-forward deployment/behandlingskatalog-backend 8080 --namespace teamdatajegerne;
done
}
# logge inn i gcloud for å ha tilgang til gcp clusters
alias gli="gcloud auth login"
```
34 changes: 34 additions & 0 deletions apps/frontend/src/api/KravApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export const kravMapToFormVal = (krav: Partial<KravQL>): KravQL => ({
etterlevelser: [],
kravIdRelasjoner: [],
aktivertDato: krav.aktivertDato || '',
prioriteringsId: ''
})

export const kravFullQuery = gql`
Expand Down Expand Up @@ -301,6 +302,7 @@ export const etterlevelseDokumentasjonKravQuery = gql`
status
aktivertDato
kravIdRelasjoner
prioriteringsId
kravRelasjoner {
id
kravNummer
Expand Down Expand Up @@ -341,6 +343,38 @@ export const etterlevelseDokumentasjonKravQuery = gql`
}
`

export const KravMedPrioriteringOgEtterlevelseQuery = gql`
query getKravByFilter($etterlevelseDokumentasjonId: String, $lover: [String!], $gjeldendeKrav: Boolean, $etterlevelseDokumentasjonIrrevantKrav: Boolean, $status: [String!]) {
krav(
filter: {
etterlevelseDokumentasjonId: $etterlevelseDokumentasjonId
lover: $lover
gjeldendeKrav: $gjeldendeKrav
etterlevelseDokumentasjonIrrevantKrav: $etterlevelseDokumentasjonIrrevantKrav
status: $status
}
) {
content {
navn
kravNummer
kravVersjon
status
prioriteringsId
etterlevelser(onlyForEtterlevelseDokumentasjon: true) {
id
etterleves
fristForFerdigstillelse
status
changeStamp {
lastModifiedBy
lastModifiedDate
}
}
}
}
}
`

export const statsQuery = gql`
query getBehandlingStats($behandlingId: ID) {
behandling(filter: { id: $behandlingId }) {
Expand Down
11 changes: 11 additions & 0 deletions apps/frontend/src/api/KravPriorityApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ export const getKravPriorityByKravNumberAndVersion = async (kravNummer: number |
})
}

export const getKravPriorityByTemaCode = async (temaCode: string) => {
return await axios
.get<KravPrioritering>(`${env.backendBaseUrl}/kravprioritering/tema/${temaCode}`)
.then((resp) => {
return resp.data
})
.catch(() => {
return undefined
})
}

export const getKravPriorityByKravNummer = async (kravNummer: number | string) => {
return (await axios.get<PageResponse<KravPrioritering>>(`${env.backendBaseUrl}/kravprioritering/kravnummer/${kravNummer}`)).data
}
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export type KravQL = Replace<
begreper: Begrep[]
virkemidler: Virkemiddel[]
kravRelasjoner: Krav[]
prioriteringsId: string
}
>

Expand Down
Loading

0 comments on commit 49606b9

Please sign in to comment.