Skip to content

Commit

Permalink
fix: agency topic conversion. Get rid of topic cache to avoid multite…
Browse files Browse the repository at this point in the history
…nancy caching issues
  • Loading branch information
tkuzynow committed Mar 21, 2024
1 parent 670cdc4 commit d3ca840
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ private List<TopicDTO> getTopics() {
}

private List<TopicDTO> getTopics(List<AgencyTopic> agencyTopics) {
return agencyTopics.stream().map(AgencyTopic::getTopicData).toList();
return agencyTopics.stream().map(agencyTopic -> createTopicDTO(agencyTopic)).toList();
}

private TopicDTO createTopicDTO(AgencyTopic agencyTopic) {
return new TopicDTO().id(agencyTopic.getTopicId())
.name(agencyTopic.getTopicData().getName())
.description(agencyTopic.getTopicData().getDescription())
.status(agencyTopic.getTopicData().getStatus())
.internalIdentifier(agencyTopic.getTopicData().getInternalIdentifier());

}

private AgencyLinks createAgencyLinks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class TopicService {
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;
private final @NonNull TenantHeaderSupplier tenantHeaderSupplier;

@Cacheable(cacheNames = CacheManagerConfig.TOPICS_CACHE)
public List<TopicDTO> getAllTopics() {
TopicControllerApi controllerApi = topicServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.collect.Lists;
import de.caritas.cob.agencyservice.api.model.AgencyAdminFullResponseDTO;
import de.caritas.cob.agencyservice.api.model.AgencyAdminResponseDTO;
import de.caritas.cob.agencyservice.api.model.AgencyDTO;
import de.caritas.cob.agencyservice.api.model.AgencyLinks;
import de.caritas.cob.agencyservice.api.model.DataProtectionContactDTO;
import de.caritas.cob.agencyservice.api.model.HalLink.MethodEnum;
import de.caritas.cob.agencyservice.api.model.TopicDTO;
import de.caritas.cob.agencyservice.api.repository.agency.Agency;
import de.caritas.cob.agencyservice.api.repository.agency.DataProtectionResponsibleEntity;
import de.caritas.cob.agencyservice.api.repository.agency.Gender;
import de.caritas.cob.agencyservice.api.repository.agencytopic.AgencyTopic;
import de.caritas.cob.agencyservice.api.util.JsonConverter;
import org.assertj.core.groups.Tuple;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -33,6 +37,7 @@ public void init() {
this.agency.setDataProtectionAgencyResponsibleContactData(JsonConverter.convertToJson(new DataProtectionContactDTO()));
this.agency.setDataProtectionOfficerContactData(JsonConverter.convertToJson(new DataProtectionContactDTO()));
this.agency.setDataProtectionAlternativeContactData(JsonConverter.convertToJson(new DataProtectionContactDTO()));
this.agency.setAgencyTopics(Lists.newArrayList(AgencyTopic.builder().topicId(1L).topicData(new TopicDTO().id(1L).name("topic name")).build()));
this.agency.setTenantId(TENANT_ID);
this.agencyAdminFullResponseDTOBuilder = new AgencyAdminFullResponseDTOBuilder(agency);
this.agency.setCounsellingRelations(AgencyDTO.CounsellingRelationsEnum.PARENTAL_COUNSELLING.getValue() + "," + AgencyDTO.CounsellingRelationsEnum.RELATIVE_COUNSELLING.getValue());
Expand Down Expand Up @@ -62,6 +67,8 @@ private void assertBaseDTOAttributesAreMapped(AgencyAdminFullResponseDTO result)
assertEquals(String.valueOf(agency.getCreateDate()), result.getEmbedded().getCreateDate());
assertEquals(String.valueOf(agency.getUpdateDate()), result.getEmbedded().getUpdateDate());
assertEquals(String.valueOf(agency.getDeleteDate()), result.getEmbedded().getDeleteDate());
assertThat(result.getEmbedded().getTopics()).extracting("id", "name").containsExactly(
Tuple.tuple(1L, "topic name"));
}

@Test
Expand Down

0 comments on commit d3ca840

Please sign in to comment.