Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/idporten eier gruppe #3596

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,35 @@
import no.nav.dolly.domain.resultset.Tags;
import no.nav.dolly.domain.resultset.entity.testgruppe.RsTestgruppe;
import no.nav.dolly.mapper.MappingStrategy;
import no.nav.testnav.libs.servletsecurity.action.GetUserInfo;
import org.springframework.stereotype.Component;

import static java.util.Objects.nonNull;
import static no.nav.dolly.util.CurrentAuthentication.getUserId;
import static org.apache.commons.lang3.BooleanUtils.isTrue;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Component
@RequiredArgsConstructor
public class TestgruppeMappingStrategy implements MappingStrategy {

private final GetUserInfo getUserInfo;

@Override
public void register(MapperFactory factory) {
factory.classMap(Testgruppe.class, RsTestgruppe.class)
.customize(new CustomMapper<>() {
@Override
public void mapAtoB(Testgruppe testgruppe, RsTestgruppe rsTestgruppe, MappingContext context) {

var brukerId = nonNull(context.getProperty("brukerId")) ? context.getProperty("brukerId") : getUserId(getUserInfo);

rsTestgruppe.setAntallIdenter(testgruppe.getTestidenter().size());
rsTestgruppe.setAntallIBruk((int) testgruppe.getTestidenter().stream()
.filter(ident -> isTrue(ident.getIBruk()))
.count());
rsTestgruppe.setFavorittIGruppen(!testgruppe.getFavorisertAv().isEmpty());
rsTestgruppe.setErEierAvGruppe(nonNull(context.getProperty("brukerId")) && (context.getProperty("brukerId")).equals(getBrukerId(testgruppe.getOpprettetAv())));
rsTestgruppe.setErEierAvGruppe(brukerId.equals(getBrukerId(testgruppe.getOpprettetAv())));
rsTestgruppe.setErLaast(isTrue(rsTestgruppe.getErLaast()));
rsTestgruppe.setTags(testgruppe.getTags().stream()
.filter(tag -> Tags.DOLLY != tag)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.dolly.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MappingContext;
import no.nav.dolly.bestilling.pdldata.PdlDataConsumer;
Expand Down Expand Up @@ -33,6 +34,7 @@
import static no.nav.dolly.util.IdentTypeUtil.isTenorIdent;

@Service
@Slf4j
@RequiredArgsConstructor
public class NavigasjonService {

Expand Down Expand Up @@ -88,6 +90,7 @@ private boolean filterOnBrukertype(String ident, Bruker.Brukertype brukertype) {

private RsTestgruppe mapGruppe(Testgruppe testgruppe, String brukerId) {

log.info("BrukerId: {}", brukerId);
var context = new MappingContext.Factory().getContext();
context.setProperty("brukerId", brukerId);
return mapperFacade.map(testgruppe, RsTestgruppe.class, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import no.nav.dolly.domain.resultset.entity.testident.RsTestident;
import no.nav.dolly.elastic.BestillingElasticRepository;
import no.nav.dolly.mapper.utils.MapperTestUtils;
import no.nav.testnav.libs.servletsecurity.action.GetUserInfo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -37,7 +38,7 @@ class TestgruppeMappingStrategyTest {

@BeforeEach
public void setUpHappyPath() {
mapper = MapperTestUtils.createMapperFacadeForMappingStrategy(new TestgruppeMappingStrategy());
mapper = MapperTestUtils.createMapperFacadeForMappingStrategy(new TestgruppeMappingStrategy(new GetUserInfo("dummy")));
MockedJwtAuthenticationTokenUtils.setJwtAuthenticationToken();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import no.nav.dolly.domain.jpa.Testident;
import no.nav.dolly.domain.resultset.entity.testident.RsTestident;
import no.nav.dolly.mapper.utils.MapperTestUtils;
import no.nav.testnav.libs.servletsecurity.action.GetUserInfo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -21,7 +22,7 @@ class TestidentMappingTest {

@BeforeEach
public void setUpHappyPath() {
mapper = MapperTestUtils.createMapperFacadeForMappingStrategy(new TestgruppeMappingStrategy());
mapper = MapperTestUtils.createMapperFacadeForMappingStrategy(new TestgruppeMappingStrategy(new GetUserInfo("dummy")));
}

@Test
Expand Down