Skip to content

Commit

Permalink
returns exception if you put resource that does not excist in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander14121 committed Dec 17, 2024
1 parent 6dc30ad commit 4b3d14b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/main/java/no/fintlabs/NotInDataBaseException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package no.fintlabs;

public class NotInDataBaseException extends RuntimeException {
public NotInDataBaseException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.fint.model.resource.personvern.kodeverk.PersonopplysningResource;
import no.fintlabs.NotInDataBaseException;
import no.fintlabs.adapter.events.WriteableResourceRepository;
import no.fintlabs.adapter.models.event.RequestFintEvent;
import no.fintlabs.adapter.operation.OperationType;
import no.fintlabs.model.personopplysning.model.PersonopplysningEntity;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -32,10 +34,13 @@ public List<PersonopplysningResource> getUpdatedResources() {

@Override
public PersonopplysningResource saveResources(PersonopplysningResource personopplysningResource, RequestFintEvent requestFintEvent) {
if (requestFintEvent.getOperationType().equals(OperationType.UPDATE) && !personopplysningJpaRepository.existsById(personopplysningResource.getSystemId().getIdentifikatorverdi())) {
throw new NotInDataBaseException("Can not update resource that is not in the database");
}

PersonopplysningEntity personopplysningEntity = PersonopplysningMappingService.toEntity(personopplysningResource);
log.info("Save personopplysning {}", personopplysningResource.getNavn());
personopplysningJpaRepository.save(personopplysningEntity);
return personopplysningResource;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void doCheckForNewEvents() {
}

@Override
protected void handleEvent(RequestFintEvent requestFintEvent, PersonopplysningResource personopplysningResource) {
public void handleEvent(RequestFintEvent requestFintEvent, PersonopplysningResource personopplysningResource) {
ResponseFintEvent response = createResponse(requestFintEvent);
response.setOperationType(requestFintEvent.getOperationType());

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application-db.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
spring:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
jdbc:
time_zone: UTC
lob:
non_contextual_creation: true
dialect: org.hibernate.dialect.PostgreSQLDialect
enable_lazy_load_no_trans: true
hibernate:
ddl-auto: update
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
fint:
metamodell: https://beta.felleskomponent.no/fint/metamodell/klasse
database:
username: postgres
password: password
url: jdbc:postgresql://localhost:5436/fint-personvern-kodeverk-adapter
adapter:
id: https://vigoiks.no/fintlabs-no/personvern/kodeverk-henrik-test
password: ${fint.adapter.password}
Expand All @@ -24,9 +28,9 @@ fint:

spring:
datasource:
url: jdbc:postgresql://localhost:5432/fint-personvern-kodeverk-adapter
url: jdbc:postgresql://localhost:5436/fint-personvern-kodeverk-adapter
username: postgres
password: postgres
password: password
security:
oauth2:
client:
Expand Down

0 comments on commit 4b3d14b

Please sign in to comment.