Skip to content

Commit

Permalink
Merge pull request #100 from virtualidentityag/revert-99-develop
Browse files Browse the repository at this point in the history
Revert "PR counselling relations"
  • Loading branch information
tkuzynow authored Aug 17, 2023
2 parents 0a3c144 + 46edd13 commit 3fcff3f
Show file tree
Hide file tree
Showing 30 changed files with 97 additions and 272 deletions.
17 changes: 1 addition & 16 deletions api/agencyadminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,6 @@ components:
deleteDate:
type: string
example: "2020-09-02T15:53:23"
counsellingRelations:
type: array
items:
type: string
enum: [ RELATIVE_COUNSELLING, SELF_COUNSELLING, PARENTAL_COUNSELLING ]


PostcodeRangeDTO:
type: object
Expand Down Expand Up @@ -625,11 +619,7 @@ components:
type: integer
format: int64
example: 12
counsellingRelations:
type: array
items:
type: string
enum: [ RELATIVE_COUNSELLING, SELF_COUNSELLING, PARENTAL_COUNSELLING]


AgencyAdminFullResponseDTO:
type: object
Expand Down Expand Up @@ -692,11 +682,6 @@ components:
type: long
demographics:
$ref: '#/components/schemas/DemographicsDTO'
counsellingRelations:
type: array
items:
type: string
enum: [ RELATIVE_COUNSELLING, SELF_COUNSELLING, PARENTAL_COUNSELLING ]

DemographicsDTO:
type: object
Expand Down
7 changes: 0 additions & 7 deletions api/agencyservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ paths:
schema:
type: string
example: "FEMALE"
- name: counsellingRelation
in: query
required: false
description: Counselling relation from the registration form
schema:
type: string
example: "PARENTAL_COUNSELLING"
responses:
200:
description: OK - successfull operation
Expand Down
22 changes: 22 additions & 0 deletions services/consultingtypeservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ components:
isAnonymousConversationAllowed:
type: boolean
example: false
isSetEmailAllowed:
type: boolean
example: true
showAskerProfile:
type: boolean
example: true
Expand All @@ -201,6 +204,9 @@ components:
languageFormal:
type: boolean
example: true
lockedAgencies:
type: boolean
example: false
excludeNonMainConsultantsFromTeamSessions:
type: boolean
example: true
Expand All @@ -216,9 +222,15 @@ components:
sendFurtherStepsMessage:
type: boolean
example: true
sendSaveSessionDataMessage:
type: boolean
example: false
sessionDataInitializing:
allOf:
- $ref: '#/components/schemas/SessionDataInitializingDTO'
monitoring:
allOf:
- $ref: '#/components/schemas/MonitoringDTO'
initializeFeedbackChat:
type: boolean
example: true
Expand Down Expand Up @@ -371,6 +383,16 @@ components:
type: boolean
example: true

MonitoringDTO:
type: object
properties:
initializeMonitoring:
type: boolean
example: true
monitoringTemplateFile:
type: string
example: file.json

RolesDTO:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static de.caritas.cob.agencyservice.api.model.AgencyTypeRequestDTO.AgencyTypeEnum.TEAM_AGENCY;
import static java.util.Objects.nonNull;

import com.google.common.base.Joiner;
import de.caritas.cob.agencyservice.api.admin.service.agency.AgencyAdminFullResponseDTOBuilder;
import de.caritas.cob.agencyservice.api.admin.service.agency.AgencyTopicEnrichmentService;
import de.caritas.cob.agencyservice.api.admin.service.agency.DemographicsConverter;
Expand All @@ -22,10 +21,7 @@
import de.caritas.cob.agencyservice.api.service.AppointmentService;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -93,26 +89,13 @@ public Agency findAgencyById(Long agencyId) {
* @return an {@link AgencyAdminFullResponseDTO} instance
*/
public AgencyAdminFullResponseDTO createAgency(AgencyDTO agencyDTO) {
setDefaultCounsellingRelationsIfEmpty(agencyDTO);
var savedAgency = agencyRepository.save(fromAgencyDTO(agencyDTO));
enrichWithAgencyTopicsIfTopicFeatureEnabled(savedAgency);
this.appointmentService.syncAgencyDataToAppointmentService(savedAgency);
return new AgencyAdminFullResponseDTOBuilder(savedAgency)
.fromAgency();
}

private void setDefaultCounsellingRelationsIfEmpty(AgencyDTO agencyDTO) {
if (agencyDTO.getCounsellingRelations() == null || agencyDTO.getCounsellingRelations().isEmpty()) {
agencyDTO.setCounsellingRelations(getAllPossibleCounsellingRelations());
}
}

private List<AgencyDTO.CounsellingRelationsEnum> getAllPossibleCounsellingRelations() {
return Arrays.stream(AgencyDTO.CounsellingRelationsEnum.values())
.collect(Collectors.toList());

}

/**
* Converts a {@link AgencyDTO} to an {@link Agency}. The attribute "offline" is always set to
* true, because a newly created agency still has no assigned postcode ranges.
Expand All @@ -133,7 +116,6 @@ private Agency fromAgencyDTO(AgencyDTO agencyDTO) {
.consultingTypeId(agencyDTO.getConsultingType())
.url(agencyDTO.getUrl())
.isExternal(agencyDTO.getExternal())
.counsellingRelations(Joiner.on(",").join(agencyDTO.getCounsellingRelations()))
.createDate(LocalDateTime.now(ZoneOffset.UTC))
.updateDate(LocalDateTime.now(ZoneOffset.UTC));

Expand All @@ -148,26 +130,9 @@ private Agency fromAgencyDTO(AgencyDTO agencyDTO) {
agencyDTO.getTopicIds());
agencyToCreate.setAgencyTopics(agencyTopics);
}

convertCounsellingRelations(agencyDTO, agencyToCreate);
return agencyToCreate;
}

private void convertCounsellingRelations(AgencyDTO agencyDTO, Agency agencyToCreate) {
if (agencyDTO.getCounsellingRelations() != null && !agencyDTO.getCounsellingRelations().isEmpty()) {
agencyToCreate.setCounsellingRelations(joinToCommaSeparatedValues(agencyDTO.getCounsellingRelations()));
}
}

private void convertCounsellingRelations(UpdateAgencyDTO agencyDTO, Agency agencyToUpdate) {
if (agencyDTO.getCounsellingRelations() != null && !agencyDTO.getCounsellingRelations().isEmpty()) {
agencyToUpdate.setCounsellingRelations(joinToCommaSeparatedValues(agencyDTO.getCounsellingRelations()));
}
}

private <T> String joinToCommaSeparatedValues(List<T> counsellingRelationsEnums) {
return Joiner.on(",").skipNulls().join(counsellingRelationsEnums);
}

/**
* Updates an agency in the database.
Expand Down Expand Up @@ -200,7 +165,6 @@ private Agency mergeAgencies(Agency agency, UpdateAgencyDTO updateAgencyDTO) {
.isExternal(updateAgencyDTO.getExternal())
.createDate(agency.getCreateDate())
.updateDate(LocalDateTime.now(ZoneOffset.UTC))
.counsellingRelations(agency.getCounsellingRelations())
.deleteDate(agency.getDeleteDate());

if (nonNull(updateAgencyDTO.getConsultingType())) {
Expand All @@ -214,7 +178,6 @@ private Agency mergeAgencies(Agency agency, UpdateAgencyDTO updateAgencyDTO) {
}

var agencyToUpdate = agencyBuilder.build();
convertCounsellingRelations(updateAgencyDTO, agencyToUpdate);

if (featureTopicsEnabled) {
List<AgencyTopic> agencyTopics = agencyTopicMergeService.getMergedTopics(agencyToUpdate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.caritas.cob.agencyservice.api.admin.service.agency;

import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import de.caritas.cob.agencyservice.api.admin.hallink.AgencyLinksBuilder;
import de.caritas.cob.agencyservice.api.model.AgencyAdminFullResponseDTO;
Expand Down Expand Up @@ -49,7 +48,6 @@ private AgencyAdminResponseDTO createAgency() {
.external((this.agency.isExternal()))
.offline(this.agency.isOffline())
.topics(getTopics())
.counsellingRelations(splitToList(agency.getCounsellingRelations()))
.createDate(String.valueOf(this.agency.getCreateDate()))
.updateDate(String.valueOf(this.agency.getUpdateDate()))
.deleteDate(String.valueOf(this.agency.getDeleteDate()));
Expand All @@ -58,15 +56,6 @@ private AgencyAdminResponseDTO createAgency() {
return responseDTO;
}

private List<AgencyAdminResponseDTO.CounsellingRelationsEnum> splitToList(String counsellingRelationsAsCommaSeparatedString) {
if (counsellingRelationsAsCommaSeparatedString == null) {
return Lists.newArrayList();
} else {
return Splitter.on(",").trimResults()
.splitToList(counsellingRelationsAsCommaSeparatedString).stream().map(AgencyAdminResponseDTO.CounsellingRelationsEnum::valueOf).collect(Collectors.toList());
}
}

private DemographicsDTO getDemographics(Agency agency) {
return agency.hasAnyDemographicsAttributes() ? new DemographicsConverter().convertToDTO(agency)
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ public ResponseEntity<List<FullAgencyResponseDTO>> getAgencies(
@RequestParam String postcode, @RequestParam Integer consultingType,
@RequestParam(value = "topicId", required = false) Integer topicId,
@RequestParam(value = "age", required = false) Integer age,
@RequestParam(value = "gender", required = false) String gender,
@RequestParam(value = "counsellingRelation", required = false) String counsellingRelation
@RequestParam(value = "gender", required = false) String gender
) {

var agencies = agencyService.getAgencies(postcode, consultingType,
ofNullable(topicId), ofNullable(age), ofNullable(gender), ofNullable(counsellingRelation));
ofNullable(topicId), ofNullable(age), ofNullable(gender));

return !CollectionUtils.isEmpty(agencies)
? new ResponseEntity<>(agencies, HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ private Integer getPostCodeInteger() {
@Field
private Long tenantId;

@Column(name = "counselling_relations")
@Field
private String counsellingRelations;

@Transient
public boolean hasAnyDemographicsAttributes() {
return getAgeTo() != null || getAgeFrom() != null || getGenders() != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public interface AgencyRepository extends CrudRepository<Agency, Long> {
+ AND_WITH_BRACKET
+ " (:age IS NULL) OR (COALESCE(a.age_to, :age) >= :age)"
+ ") "
+ "AND ((:counselling_relation IS NULL) OR (a.counselling_relations LIKE CONCAT('%,',:counselling_relation,'%') OR a.counselling_relations LIKE CONCAT(:counselling_relation,'%'))) "
+ "AND ((:gender IS NULL) OR (a.genders LIKE CONCAT('%,',:gender,'%') OR a.genders LIKE CONCAT(:gender,'%'))) "
+ "AND a.delete_date IS NULL ";

Expand All @@ -42,7 +41,6 @@ public interface AgencyRepository extends CrudRepository<Agency, Long> {
+ AND_WITH_BRACKET
+ " (:age IS NULL) OR (COALESCE(a.age_to, :age) >= :age)"
+ ") "
+ "AND ((:counselling_relation IS NULL) OR (a.counselling_relations LIKE CONCAT('%,',:counselling_relation,'%') OR a.counselling_relations LIKE CONCAT(:counselling_relation,'%'))) "
+ "AND ((:gender IS NULL) OR (a.genders LIKE CONCAT('%,',:gender,'%') OR a.genders LIKE CONCAT(:gender,'%'))) "
+ "AND a.delete_date IS NULL ";

Expand All @@ -64,7 +62,6 @@ List<Agency> searchWithoutTopic(@Param(value = "postcode") String postCode,
@Param(value = "length") int length, @Param(value = "type") Integer consultingTypeId,
@Param(value = "age") Integer age,
@Param(value = "gender") String gender,
@Param(value = "counselling_relation") String counsellingRelation,
Long tenantId);


Expand All @@ -77,7 +74,6 @@ List<Agency> searchWithTopic(@Param(value = "postcode") String postCode,
@Param(value = "topicId") int topicId,
@Param(value = "age") Integer age,
@Param(value = "gender") String gender,
@Param(value = "counselling_relation") String counsellingRelation,
Long tenantId);

Optional<Agency> findByIdAndDeleteDateNull(Long agencyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ List<Agency> searchWithoutTopic(@Param(value = "postcode") String postCode,
@Param(value = "length") int length, @Param(value = "type") Integer consultingTypeId,
@Param(value = "age") Integer age,
@Param(value = "gender") String gender,
@Param(value = "counselling_relation") String counsellingRelation,
@Param(value = "tenantId") Long tenantId);

@Query(
Expand All @@ -47,7 +46,6 @@ List<Agency> searchWithTopic(@Param(value = "postcode") String postCode,
@Param(value = "topicId") int topicId,
@Param(value = "age") Integer age,
@Param(value = "gender") String gender,
@Param(value = "counselling_relation") String counsellingRelation,
Long tenantId);

@Query("select a from Agency as a where a.id = :agencyId ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ public class AgencySearch {
private Optional<Integer> topicId;
private Optional<Integer> age;
private Optional<String> gender;

private Optional<String> counsellingRelation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public List<AgencyResponseDTO> getAgencies(int consultingTypeId) {

public List<FullAgencyResponseDTO> getAgencies(String postCode, int consultingTypeId,
Optional<Integer> topicId) {
return getAgencies(postCode, consultingTypeId, topicId, Optional.empty(), Optional.empty(), Optional.empty());
return getAgencies(postCode, consultingTypeId, topicId, Optional.empty(), Optional.empty());
}

/**
Expand All @@ -112,7 +112,7 @@ public List<FullAgencyResponseDTO> getAgencies(String postCode, int consultingTy
*/
public List<FullAgencyResponseDTO> getAgencies(String postCode, int consultingTypeId,
Optional<Integer> topicId,
Optional<Integer> age, Optional<String> gender, Optional<String> counsellingRelation) {
Optional<Integer> age, Optional<String> gender) {

var consultingTypeSettings = retrieveConsultingTypeSettings(
consultingTypeId);
Expand All @@ -122,7 +122,7 @@ public List<FullAgencyResponseDTO> getAgencies(String postCode, int consultingTy
}

var agencies = findAgencies(postCode, getConsultingTypeIdForSearch(consultingTypeId), topicId,
age, gender, counsellingRelation);
age, gender);
Collections.shuffle(agencies);
var agencyResponseDTOs = agencies.stream()
.map(this::convertToFullAgencyResponseDTO)
Expand All @@ -141,15 +141,14 @@ private Optional<Integer> getConsultingTypeIdForSearch(int consultingTypeId) {

private List<Agency> findAgencies(String postCode, Optional<Integer> consultingTypeId,
Optional<Integer> optionalTopicId, Optional<Integer> age,
Optional<String> gender, Optional<String> counsellingRelation) {
Optional<String> gender) {

AgencySearch agencySearch = AgencySearch.builder()
.postCode(postCode)
.consultingTypeId(consultingTypeId)
.topicId(optionalTopicId)
.age(age)
.gender(gender)
.counsellingRelation(counsellingRelation)
.build();

if (demographicsFeatureEnabled) {
Expand All @@ -171,7 +170,6 @@ private List<Agency> findAgencies(AgencySearch agencySearch) {
agencySearch.getPostCode().length(), agencySearch.getConsultingTypeId().orElse(null),
agencySearch.getAge().orElse(null),
agencySearch.getGender().orElse(null),
agencySearch.getCounsellingRelation().orElse(null),
TenantContext.getCurrentTenant());
} catch (DataAccessException ex) {
throw new InternalServerErrorException(LogService::logDatabaseError,
Expand Down Expand Up @@ -234,7 +232,6 @@ private List<Agency> findAgenciesWithTopic(AgencySearch agencySearch) {
agencySearch.getConsultingTypeId().orElse(null),
agencySearch.getTopicId().orElseThrow(),
agencySearch.getAge().orElse(null), agencySearch.getGender().orElse(null),
agencySearch.getCounsellingRelation().orElse(null),
TenantContext.getCurrentTenant());

} catch (DataAccessException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {

public static final String[] WHITE_LIST =
new String[]{"/agencies/docs", "/agencies/docs/**", "/v2/api-docs", "/configuration/ui",
"/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/swagger-ui/**", "/webjars/**", "/actuator/health", "/actuator/health/**"};
"/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/swagger-ui/**", "/webjars/**", "/actuator/health"};

@SuppressWarnings("unused")
private final KeycloakClientRequestFactory keycloakClientRequestFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
<include file="db/changelog/changeset/0009_agency_topic/0009_changeSet.xml"/>
<include file="db/changelog/changeset/0010_agency_demographics/0010_changeSet.xml"/>
<include file="db/changelog/changeset/0011_agency_demographics_gender_column_change/0011_changeSet.xml"/>
<include file="db/changelog/changeset/0012_agency_counseling_relations/0012_changeSet.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
<include file="db/changelog/changeset/0009_agency_topic/0009_changeSet.xml"/>
<include file="db/changelog/changeset/0010_agency_demographics/0010_changeSet.xml"/>
<include file="db/changelog/changeset/0011_agency_demographics_gender_column_change/0011_changeSet.xml"/>
<include file="db/changelog/changeset/0012_agency_counseling_relations/0012_changeSet.xml"/>
</databaseChangeLog>
Loading

0 comments on commit 3fcff3f

Please sign in to comment.