Skip to content

Commit

Permalink
Merge branch 'main' into ARKIV-297
Browse files Browse the repository at this point in the history
  • Loading branch information
oleanders authored Oct 29, 2024
2 parents 3dd33a4 + e927e59 commit 3212ab3
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 83 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Limit branch name
id: branch
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "shortname=$(echo "$BRANCH_NAME" | cut -c1-40)" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch,suffix=-{{sha}}
type=ref,event=pr,suffix=-{{sha}}
type=raw,value=${{ steps.branch.outputs.shortname }}-{{sha}}
type=sha,prefix={{date 'YYYY-MM-DD-'}},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
Expand All @@ -47,13 +52,8 @@ jobs:
strategy:
fail-fast: false
matrix:
org: [ fintlabs-no, ofk-no, tromsfylke-no, bfk-no, afk-no, vlfk-no, rogfk-no, innlandetfylke-no, mrfylke-no ]
org: [ fintlabs-no, ofk-no, tromsfylke-no, bfk-no, afk-no, vlfk-no, rogfk-no, innlandetfylke-no, agderfk-no, mrfylke-no ]
cluster: [ aks-beta-fint-2021-11-23, aks-api-fint-2022-02-08 ]
include:
- cluster: aks-beta-fint-2021-11-23
org: bfk-no
deploy-every-branch: true

exclude:
- cluster: aks-api-fint-2022-02-08
org: fintlabs-no
Expand Down
7 changes: 7 additions & 0 deletions bruno/environments/api: agderfk-no.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vars {
org: agderfk-no
env:
}
vars:secret [
user_session
]
7 changes: 7 additions & 0 deletions bruno/environments/beta: agderfk-no.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vars {
org: agderfk-no
env: beta/
}
vars:secret [
user_session
]
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ dependencies {
implementation 'no.fintlabs:fint-kafka:4.0.1'
implementation 'no.fintlabs:fint-flyt-kafka:3.1.1'

implementation 'no.fintlabs:fint-flyt-instance-gateway:5.0.5'
implementation 'no.fintlabs:fint-flyt-resource-server:2.1.0'
implementation 'no.fintlabs:fint-flyt-instance-gateway:6.0.0'
implementation 'no.fintlabs:fint-flyt-resource-server:5.0.0'

runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
Expand Down
33 changes: 33 additions & 0 deletions kustomize/overlays/agderfk-no/api/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: agderfk-no

resources:
- ../../../base

commonLabels:
app.kubernetes.io/instance: fint-flyt-vigo-gateway_agderfk_no
fintlabs.no/org-id: agderfk.no

patches:
- patch: |-
- op: replace
path: "/spec/kafka/acls/0/topic"
value: "agderfk-no.flyt.*"
- op: replace
path: "/spec/orgId"
value: "agderfk.no"
- op: add
path: "/spec/url/basePath"
value: "/agderfk-no"
- op: replace
path: "/spec/ingress/basePath"
value: "/agderfk-no/api/vigo"
- op: add
path: "/spec/env/-"
value:
name: "logging.level.no.fintlabs.instance.gateway"
value: "INFO"
target:
kind: Application
name: fint-flyt-vigo-gateway
33 changes: 33 additions & 0 deletions kustomize/overlays/agderfk-no/beta/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: agderfk-no

resources:
- ../../../base

commonLabels:
app.kubernetes.io/instance: fint-flyt-vigo-gateway_agderfk_no
fintlabs.no/org-id: agderfk.no

patches:
- patch: |-
- op: replace
path: "/spec/kafka/acls/0/topic"
value: "agderfk-no.flyt.*"
- op: replace
path: "/spec/orgId"
value: "agderfk.no"
- op: add
path: "/spec/url/basePath"
value: "/beta/agderfk-no"
- op: replace
path: "/spec/ingress/basePath"
value: "/beta/agderfk-no/api/vigo"
- op: add
path: "/spec/env/-"
value:
name: "logging.level.no.fintlabs.instance.gateway"
value: "DEBUG"
target:
kind: Application
name: fint-flyt-vigo-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import no.fintlabs.gateway.instance.InstanceMapper;
import no.fintlabs.gateway.instance.model.File;
import no.fintlabs.gateway.instance.model.instance.InstanceObject;
import no.fintlabs.gateway.instance.web.FileClient;
import no.fintlabs.instance.gateway.model.vigo.IncomingInstance;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
Expand All @@ -15,29 +14,26 @@
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
@Slf4j
public class IncomingInstanceMappingService implements InstanceMapper<IncomingInstance> {

private final FileClient fileClient;

public IncomingInstanceMappingService(
FileClient fileClient
) {
this.fileClient = fileClient;
}

@Override
public Mono<InstanceObject> map(Long sourceApplicationId, IncomingInstance incomingInstance) {
public Mono<InstanceObject> map(
Long sourceApplicationId,
IncomingInstance incomingInstance,
Function<File, Mono<UUID>> persistFile
) {
if (incomingInstance.getDokument() == null) {
return Mono.just(InstanceObject.builder()
.valuePerKey(toValuePerKey(incomingInstance, null))
.build());
} else {
return postFile(sourceApplicationId, incomingInstance)
return postFile(sourceApplicationId, incomingInstance, persistFile)
.map(uuid -> InstanceObject.builder()
.valuePerKey(toValuePerKey(incomingInstance, uuid))
.build());
Expand All @@ -57,22 +53,22 @@ private static Map<String, String> toValuePerKey(IncomingInstance incomingInstan

entries.add(Map.entry("tilpassetNavn1",
Stream.of(incomingInstance.getPersonalia().getFornavn(),
incomingInstance.getPersonalia().getMellomnavn(),
incomingInstance.getPersonalia().getEtternavn())
.filter(s -> StringUtils.hasLength(s))
.collect(Collectors.joining(" "))
incomingInstance.getPersonalia().getMellomnavn(),
incomingInstance.getPersonalia().getEtternavn())
.filter(s -> StringUtils.hasLength(s))
.collect(Collectors.joining(" "))
));

entries.add(Map.entry("tilpassetNavn2",
Stream.of(incomingInstance.getPersonalia().getEtternavn(),
incomingInstance.getPersonalia().getFornavn(),
incomingInstance.getPersonalia().getMellomnavn())
.filter(s -> StringUtils.hasLength(s))
.collect(Collectors.joining(" "))
incomingInstance.getPersonalia().getFornavn(),
incomingInstance.getPersonalia().getMellomnavn())
.filter(s -> StringUtils.hasLength(s))
.collect(Collectors.joining(" "))
));

entries.add(Map.entry("tilpassetNavn3",
Stream.of(incomingInstance.getPersonalia().getEtternavn() +",",
Stream.of(incomingInstance.getPersonalia().getEtternavn() + ",",
incomingInstance.getPersonalia().getFornavn(),
incomingInstance.getPersonalia().getMellomnavn())
.filter(s -> StringUtils.hasLength(s))
Expand All @@ -88,7 +84,7 @@ private static Map<String, String> toValuePerKey(IncomingInstance incomingInstan

Optional.ofNullable(formatedDate(fodselsdato, "dd.MM.yyyy")).ifPresent(formatedFodselsdato ->
entries.add(Map.entry("tilpassetFodselsdato2", formatedFodselsdato)));

});

entries.add(Map.entry("kontaktinformasjonTelefonnummer", incomingInstance.getKontaktinformasjon().getTelefonnummer()));
Expand Down Expand Up @@ -142,15 +138,19 @@ private static String formatedDate(String fodselsdato, String format) {
}


private Mono<UUID> postFile(Long sourceApplicationId, IncomingInstance incomingInstance) {
return fileClient.postFile(
private Mono<UUID> postFile(
Long sourceApplicationId,
IncomingInstance incomingInstance,
Function<File, Mono<UUID>> persistFile
) {
return persistFile.apply(
File.builder()
.name(incomingInstance.getDokument().getFilnavn())
.type(MediaType.parseMediaType(incomingInstance.getDokument().getFormat()))
.sourceApplicationId(sourceApplicationId)
.sourceApplicationInstanceId(incomingInstance.getInstansId())
.encoding("UTF-8")
.base64Contents(incomingInstance.getDokument().getFil())
.build());
.name(incomingInstance.getDokument().getFilnavn())
.type(MediaType.parseMediaType(incomingInstance.getDokument().getFormat()))
.sourceApplicationId(sourceApplicationId)
.sourceApplicationInstanceId(incomingInstance.getInstansId())
.encoding("UTF-8")
.base64Contents(incomingInstance.getDokument().getFil())
.build());
}
}
24 changes: 15 additions & 9 deletions src/main/java/no/fintlabs/instance/gateway/InstanceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import no.fintlabs.gateway.instance.kafka.ArchiveCaseIdRequestService;
import no.fintlabs.instance.gateway.model.Status;
import no.fintlabs.instance.gateway.model.vigo.IncomingInstance;
import no.fintlabs.resourceserver.security.client.sourceapplication.SourceApplicationAuthorizationUtil;
import no.fintlabs.resourceserver.security.client.sourceapplication.SourceApplicationAuthorizationService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -23,10 +23,16 @@ public class InstanceController {

private final ArchiveCaseIdRequestService archiveCaseIdRequestService;

public InstanceController(InstanceProcessor<IncomingInstance> instanceProcessor,
ArchiveCaseIdRequestService archiveCaseIdRequestService) {
private final SourceApplicationAuthorizationService sourceApplicationAuthorizationService;

public InstanceController(
InstanceProcessor<IncomingInstance> instanceProcessor,
ArchiveCaseIdRequestService archiveCaseIdRequestService,
SourceApplicationAuthorizationService sourceApplicationAuthorizationService
) {
this.instanceProcessor = instanceProcessor;
this.archiveCaseIdRequestService = archiveCaseIdRequestService;
this.sourceApplicationAuthorizationService = sourceApplicationAuthorizationService;
}

@PostMapping("instance")
Expand All @@ -51,22 +57,22 @@ public Mono<ResponseEntity<Status>> getInstanceStatus(
) {
return authenticationMono.map(authentication ->
{
Long applicationId = SourceApplicationAuthorizationUtil.getSourceApplicationId(authentication);
Long applicationId = sourceApplicationAuthorizationService.getSourceApplicationId(authentication);

log.debug("Get status for instance: {} in sourceApplication: {}", instanceId, applicationId);

return archiveCaseIdRequestService.getArchiveCaseId(applicationId, instanceId)
.map(caseId -> ResponseEntity.ok(Status.builder()
.instansId(instanceId)
.destinasjonsId(caseId)
.status("Instans godtatt av destinasjon").build()
.instansId(instanceId)
.destinasjonsId(caseId)
.status("Instans godtatt av destinasjon").build()
)
)
.orElse(ResponseEntity
.badRequest()
.body(Status.builder()
.instansId(instanceId)
.status("Ukjent status").build()
.instansId(instanceId)
.status("Ukjent status").build()
)
);
}
Expand Down
Loading

0 comments on commit 3212ab3

Please sign in to comment.