Skip to content

Commit

Permalink
Feature/foreldreansvar symmetrisk (#3572)
Browse files Browse the repository at this point in the history
* Add 'ansvarssubjekt' field to foreldreansvar in GraphQL query #deploy-person-service

This update introduces the 'ansvarssubjekt' field to the 'foreldreansvar' section of the GraphQL query. It ensures that additional responsibility data can be queried, enhancing the comprehensiveness of parental responsibility information available.

* Refactor ForeldreansvarService to improve relationship handling #deploy-test-pdl-forvalter

Added methods to delete parent-child relations when necessary and updated method signatures to include hovedperson's ID. Enhanced ForeldreansvarDTO with utility methods to filter non-applicable relations, ensuring correct deployment and more robust relation management.

* Refactor ForeldreansvarService to streamline logic
#deploy-test-pdl-forvalter

Simplified relationship handling by refining loops and conditions for parent-child associations. Added helper methods to manage related responsibilities and ensured consistent updates across all foreldreansvar scenarios.

* Refactor ForeldreansvarService to streamline logic
#deploy-test-pdl-forvalter

Simplified relationship handling by refining loops and conditions for parent-child associations. Added helper methods to manage related responsibilities and ensured consistent updates across all foreldreansvar scenarios.

* Update unit tests for ForeldreansvarService
#deploy-test-pdl-forvalter

Updated test cases to use specific identifiers for PersonDTO instances. Ensured validation logic accounts for the required relationship checks in various scenarios. Simplified identifier handling for more predictable test outcomes.

* Add 'Ansvarssubjekt' field to PdlForeldreansvar components

Introduced the 'Ansvarssubjekt' field to both PdlForeldreansvar and Foreldreansvar components. This change ensures that the 'ansvarssubjekt' property is displayed in the frontend for clarity. Tested and verified that the new field displays the correct data.

* Update relational deletion logic for existing persons #deploy-test-pdl-forvalter

Enhance deletion utility to remove specific relationships for existing persons by filtering out related entities. Added tests to ensure correct removal of 'forelderBarnRelasjon' and 'foreldreansvar' relationships for existing entities.

* Update relational deletion logic for existing persons #deploy-test-pdl-forvalter

Enhanced the deletion utility to correctly handle specific relationships for existing persons by removing the redundant filtering process. Revised logic ensures proper removal of 'forelderBarnRelasjon' and 'foreldreansvar' relationships.

* Refactor foreldreansvar handler functions
#deploy-test-pdl-forvalter

Simplified logic by merging `handle` and `handleBarn` methods in `ForeldreansvarService`. Updated relevant method calls and cleaned up redundant conditional checks. This reduces code duplication and increases maintainability.

* Refactor relationship handling in person services #deploy-test-pdl-forvalter

Simplified relationship handling by consolidating similar logic paths and removing redundant checks. Added `standalone` attribute to `PersonDTO` to streamline checks for isolated persons. This improves code maintainability and readability across the service classes.

* Update validation rules and UI labels
#deploy-test-frontend

Enhanced validation in familierelasjoner.tsx with conditions based on 'personFoerLeggTil' context and added a rule for 'typeAnsvarlig'. Updated labels in multiple files to provide clearer context, especially for 'Ansvarssubjekt (barnet)'. Adjusted UI logic to remove redundant checks in VisningRedigerbar.

* deploy
#deploy-test-frontend

* deploy  #deploy-test-pdl-forvalter

* Change visibility of validateBarn method
#deploy-test-pdl-forvalter

Changed the validateBarn method from public to private in ForeldreansvarService. This encapsulates the method, ensuring it can only be accessed within the class.

* Replace isNull with isBlank for ansvarlig

Updated ForeldreansvarService to use isBlank instead of isNull for checking the ansvarlig field. This change ensures that empty strings are properly handled alongside null values, preventing potential validation issues related to ansvarlig entries.
  • Loading branch information
krharum authored Aug 5, 2024
1 parent 154d794 commit a68106e
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ private Function<PredicateSpec, Buildable<Route>> createRoute(String segment, St
.filters(filter, addUserJwtHeaderFilter())
).uri(host);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const PdlForeldreansvarVisning = ({ data, idx }: VisningProps) => {
return (
<div className="person-visning_content" key={idx}>
<TitleValue title="Hvem har ansvaret" value={_.capitalize(data.ansvar)} />
<TitleValue title="Ansvarssubjekt (barnet)" value={data.ansvarssubjekt} />
<TitleValue title="Ansvarlig" value={data.ansvarlig} />
{data.ansvarligUtenIdentifikator && (
<div className="flexbox--full-width">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const ForeldreansvarForm = ({
/>
<FormDatepicker name={`${path}.gyldigFraOgMed`} label="Gyldig fra og med" />
<FormDatepicker name={`${path}.gyldigTilOgMed`} label="Gyldig til og med" />
{ansvar === 'ANDRE' && !opts?.personFoerLeggTil && (
{ansvar === 'ANDRE' && (
<FormSelect
name={`${path}.typeAnsvarlig`}
label="Type ansvarlig"
Expand All @@ -159,7 +159,7 @@ export const ForeldreansvarForm = ({
/>
)}

{(getTypeAnsvarlig() === TypeAnsvarlig.EKSISTERENDE || !kanHaForeldreansvar) && (
{getTypeAnsvarlig() === TypeAnsvarlig.EKSISTERENDE && (
<PdlEksisterendePerson
eksisterendePersonPath={`${path}.ansvarlig`}
label="Ansvarlig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ export const foreldreansvar = Yup.object({
ansvar: testForeldreansvar(requiredString),
gyldigFraOgMed: testDatoFom(Yup.mixed().nullable(), 'gyldigTilOgMed'),
gyldigTilOgMed: testDatoTom(Yup.mixed().nullable(), 'gyldigFraOgMed'),
typeAnsvarlig: Yup.string()
.test('type-Ansvarlig-paakrevd', 'Type Ansvarlig må velges', (value, testcontext) => {
return !!value || testcontext.parent?.ansvar !== 'ANDRE'
})
.nullable(),
ansvarlig: Yup.string()
.test('ansvarlig-andre-paakrevd', 'Ansvarlig person må velges', (value, testcontext) => {
return (
Expand All @@ -331,7 +336,10 @@ export const foreldreansvar = Yup.object({
ansvarssubjekt: Yup.string()
.test('ansvarssubjekt-er-paakrevd', 'Ansvarssubjekt er påkrevd', (value, testcontext) => {
return (
!!value || testcontext.parent?.ansvarlig || !testcontext.options?.context?.personFoerLeggTil
!!value ||
testcontext.parent?.ansvarlig ||
testcontext.parent?.typeAnsvarlig !== 'EKSISTERENDE' ||
!testcontext.options?.context?.personFoerLeggTil
)
})
.nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ForeldreansvarLes = ({ foreldreansvarData, redigertRelatertePersoner, rela
<div className="person-visning_content" key={idx}>
<>
<TitleValue title="Hvem har ansvaret" value={_.capitalize(foreldreansvarData.ansvar)} />
<TitleValue title="Ansvarssubjekt (barnet)" value={foreldreansvarData.ansvarssubjekt} />
<TitleValue
title="Gyldig fra og med"
value={formatDate(foreldreansvarData.gyldigFraOgMed)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,6 @@ export const VisningRedigerbar = ({
return submit()
}, [])

const handleSubmitRelatertPerson = useCallback((data: any, ident: string) => {
const submit = async () => {
setVisningModus(Modus.LoadingPdlf)
await PdlforvalterApi.setStandalone(ident).then((importResponse) => {
if (importResponse?.ok) {
sendData(data)
}
})
}
mountedRef.current = false
return submit()
}, [])

const handleDelete = useCallback(() => {
const slett = async () => {
setVisningModus(Modus.LoadingPdlf)
Expand All @@ -228,11 +215,7 @@ export const VisningRedigerbar = ({
const handleDeleteRelatertPerson = useCallback(() => {
const slett = async () => {
setVisningModus(Modus.LoadingPdlf)
await PdlforvalterApi.setStandalone(relatertPersonInfo?.ident)?.then((importResponse) => {
if (importResponse?.ok) {
sendSlett()
}
})
sendSlett()
}
mountedRef.current = false
return slett()
Expand Down Expand Up @@ -417,13 +400,7 @@ export const VisningRedigerbar = ({
</>
)}
{visningModus === Modus.Skriv && (
<Form
onSubmit={(data) =>
relatertPersonInfo?.ident
? handleSubmitRelatertPerson(data?.data, relatertPersonInfo.ident)
: handleSubmit(data?.data)
}
>
<Form onSubmit={(data) => handleSubmit(data?.data)}>
<>
<FieldArrayEdit>
<div className="flexbox--flex-wrap visning-redigerbar-form">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,4 @@ export default {
const endpoint = `${getPdlUrl()}/personer/${ident}/${attributt}/${id}`
return Request.delete(endpoint)
},
setStandalone(ident: string, standalone = true) {
if (!ident) {
return
}
const endpoint = `${getPdlUrl()}/identiteter/${ident}/standalone/${standalone}`
return Request.putWithoutResponse(endpoint)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public static void main(String[] args) {

SpringApplication.run(PdlForvalterApplicationStarter.class, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public Mono<List<IdentDTO>> releaseIdents(Set<String> identer, Bruker bruker) {

return tokenExchange.exchange(serverProperties)
.flatMap(token -> new IdentpoolPostCommand(webClient, RELEASE_IDENTS_URL, REKVIRERT_AV + bruker, identer,
token.getTokenValue()).call());
token.getTokenValue()).call())
.doOnNext(resultat -> log.info("Slettet identer mot identpool: {}", String.join(",", identer)));
}

public Flux<IdentpoolLedigDTO> getErLedig(Set<String> identer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ public void deleteForeldreansvar(String ident, Integer id) {

dbPerson.getPerson().getForeldreansvar().stream()
.filter(type -> id.equals(type.getId()) &&
isNotBlank(type.getAnsvarlig()))
(isNotBlank(type.getAnsvarlig()) || isNotBlank(type.getAnsvarssubjekt())))
.forEach(type -> {
var slettePerson = getPerson(type.getAnsvarlig());
var slettePerson = getPerson(isNotBlank(type.getAnsvarlig()) ?
type.getAnsvarlig() : type.getAnsvarssubjekt());

DeleteRelasjonerUtility.deleteRelasjoner(slettePerson, FORELDREANSVAR_FORELDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static boolean isEndretRolle(ForelderBarnRelasjonDTO relasjon, ForelderB
public void updateForeldreansvar(String ident, Integer id, ForeldreansvarDTO oppdatertAnsvar) {

var person = getPerson(ident);
foreldreansvarService.validateBarn(oppdatertAnsvar, person.getPerson());
foreldreansvarService.validate(oppdatertAnsvar, person.getPerson());

var foreldreansvar = person.getPerson().getForeldreansvar().stream()
.filter(relasjon -> relasjon.getId().equals(id))
Expand Down Expand Up @@ -346,7 +346,7 @@ public void updateForeldreansvar(String ident, Integer id, ForeldreansvarDTO opp

if (id == 0 || foreldreansvar.isPresent()) {

foreldreansvarService.handleBarn(oppdatertAnsvar, person.getPerson());
foreldreansvarService.handle(oppdatertAnsvar, person.getPerson());
}

person.getPerson().getForeldreansvar().stream()
Expand Down
Loading

0 comments on commit a68106e

Please sign in to comment.