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

Fix casing on organisasjons url from skole resource #5

Merged
merged 4 commits into from
Jan 16, 2025
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 @@ -57,7 +57,7 @@ public List<OrganisasjonselementResource> getAll() {
return organisasjonselementResourceCache.getAllDistinct();
}
public Optional<OrganisasjonselementResource> getOrganisasjonselementResource(String resourceId) {
return Optional.of( organisasjonselementResourceCache.get(resourceId));
return organisasjonselementResourceCache.getOptional(resourceId);
}

public List<ArbeidsforholdResource> getAllValidArbeidsforhold(
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/no/fintlabs/role/EduOrgUnitService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package no.fintlabs.role;

import lombok.extern.slf4j.Slf4j;
import no.fint.model.resource.administrasjon.organisasjon.OrganisasjonselementResource;
import no.fint.model.resource.utdanning.utdanningsprogram.SkoleResource;
import no.fintlabs.cache.FintCache;
import no.fintlabs.links.ResourceLinkUtil;
import no.fintlabs.organisasjonselement.OrganisasjonselementService;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class EduOrgUnitService {
private final FintCache<String, SkoleResource> skoleResourceFintCache;
Expand All @@ -22,15 +25,21 @@ public EduOrgUnitService(
}

public List<String> findAllEduOrgUnits() {
Optional<List<SkoleResource>> skoleResources = Optional.ofNullable(skoleResourceFintCache.getAll());
Optional<List<SkoleResource>> skoleResources = Optional.ofNullable(skoleResourceFintCache.getAllDistinct());

if (skoleResources.isEmpty()) {
return null;
}
List<String> schoolNames = skoleResources.get().stream()
.map(SkoleResource::getNavn)
.toList();
log.info("Found {} skole resources {}", skoleResources.get().size(), schoolNames);

return skoleResources
.map(resources -> resources.stream()
.map(SkoleResource::getOrganisasjon)
.map(list -> list.get(0).getHref())
.filter(list -> list != null && !list.isEmpty())
.map(list -> ResourceLinkUtil.idAttributeToLowerCase(list.get(0).getHref()) )
.map(organisasjonselementService::getOrganisasjonselementResource)
.filter(Optional::isPresent)
.map(Optional::get)
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/no/fintlabs/role/EduOrgUnitServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class EduOrgUnitServiceTest {
@Test
public void givenSkoleResourceCacheIsEmpty_findAllEduOrgUnits_should_return_null() {

given(skoleResourceFintCache.getAll()).willReturn(null);
given(skoleResourceFintCache.getAllDistinct()).willReturn(null);

List<String> result = eduOrgUnitService.findAllEduOrgUnits();

Expand All @@ -48,7 +48,8 @@ public void givenSkoleResourceCacheIsNonEmpty_findAllEduOrgUnits_should_return_e

Link link = new Link("https://example.com/organisasjonsid/2");
orgunitSchool.addSelf(link);
skoleResource.addOrganisasjon(link);
Link orgLink = new Link("https://example.com/organisasjonsId/2");
skoleResource.addOrganisasjon(orgLink);

Identifikator id2 = new Identifikator();
id2.setIdentifikatorverdi("2");
Expand All @@ -67,7 +68,7 @@ public void givenSkoleResourceCacheIsNonEmpty_findAllEduOrgUnits_should_return_e

given(organisasjonselementService.getOrganisasjonselementResource(link.getHref())).willReturn(Optional.of(orgunitSchool));
given(organisasjonselementService.getAllSubOrgUnits(orgunitSchool)).willReturn(List.of(orgunitSchool, orgunitSchoolSubUnit1, orgunitSchoolSubUnit2));
given(skoleResourceFintCache.getAll()).willReturn(List.of(skoleResource));
given(skoleResourceFintCache.getAllDistinct()).willReturn(List.of(skoleResource));

List<String> result = eduOrgUnitService.findAllEduOrgUnits();
List<String> expectedOrgUnitIds = List.of("2","3", "4");
Expand Down
Loading