From efa5e56fe699240ac900e8e87c599b36ca63be03 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Tue, 27 Aug 2024 12:45:31 +0000 Subject: [PATCH 1/3] DST-15503 Fixes for user export changes --- .../bconline/ndelius/model/ExportResult.java | 6 +- .../ndelius/model/entity/BoroughEntity.java | 40 ----------- .../entity/export/BoroughExportEntity.java | 27 +++----- .../entity/export/DistrictExportEntity.java | 41 +++++++++++ .../model/entity/export/LDUExportEntity.java | 39 ----------- .../model/entity/export/TeamExportEntity.java | 26 +------ .../ndelius/service/UserRoleService.java | 3 +- .../service/impl/UserRoleServiceImpl.java | 7 ++ .../ndelius/transformer/UserTransformer.java | 68 +++++++------------ 9 files changed, 88 insertions(+), 169 deletions(-) delete mode 100644 src/main/java/uk/co/bconline/ndelius/model/entity/BoroughEntity.java create mode 100644 src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java delete mode 100644 src/main/java/uk/co/bconline/ndelius/model/entity/export/LDUExportEntity.java diff --git a/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java b/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java index 4d29d6a6..f8bdecc3 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java +++ b/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java @@ -45,12 +45,12 @@ public final class ExportResult { private String teams; @CsvBindByName(column = "LAU") @CsvBindByPosition(position = 14) - private String lau; + private String localAdminUnit; @CsvBindByName(column = "PDU") @CsvBindByPosition(position = 15) - private String pdu; + private String probationDeliveryUnit; @CsvBindByPosition(position = 16) private String provider; @CsvBindByPosition(position = 17) - private String roleDescriptions; + private String roleNames; } diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/BoroughEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/BoroughEntity.java deleted file mode 100644 index c9e43f3c..00000000 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/BoroughEntity.java +++ /dev/null @@ -1,40 +0,0 @@ -package uk.co.bconline.ndelius.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import uk.co.bconline.ndelius.model.entity.export.ProbationAreaExportEntity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; -import java.io.Serializable; - -@Getter -@Entity -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "BOROUGH") -public class BoroughEntity implements Serializable -{ - @Id - @Column(name = "BOROUGH_ID") - @GeneratedValue(generator = "BOROUGH_ID_SEQ") - @SequenceGenerator(name = "BOROUGH_ID_SEQ", sequenceName = "BOROUGH_ID_SEQ", allocationSize = 1) - private Long id; - - @Column(name = "CODE") - private String code; - - @Column(name = "DESCRIPTION") - private String description; - - @ManyToOne - @JoinColumn(name = "PROBATION_AREA_ID") - private ProbationAreaExportEntity probationArea; -} diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java index bcb40777..41589cee 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java @@ -3,26 +3,17 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import org.hibernate.annotations.Type; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; +import uk.co.bconline.ndelius.model.entity.converter.YNConverter; + +import javax.persistence.*; import java.io.Serializable; -import java.time.LocalDate; @Getter @Entity @NoArgsConstructor @AllArgsConstructor @Table(name = "BOROUGH") -public class BoroughExportEntity implements Serializable -{ +public class BoroughExportEntity implements Serializable { @Id @Column(name = "BOROUGH_ID") @GeneratedValue(generator = "BOROUGH_ID_SEQ") @@ -35,11 +26,15 @@ public class BoroughExportEntity implements Serializable @Column(name = "DESCRIPTION") private String description; + @Column(name = "SELECTABLE") + @Convert(converter = YNConverter.class) + private boolean selectable; + @ManyToOne @JoinColumn(name = "PROBATION_AREA_ID") private ProbationAreaExportEntity probationArea; - @Column(name = "END_DATE") - @Type(type = "java.time.LocalDate") - private LocalDate endDate; + public String getExportDescription() { + return description + " (" + code + ") " + (isSelectable() ? " [Active]" : " [Inactive]"); + } } diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java new file mode 100644 index 00000000..d72f15d3 --- /dev/null +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java @@ -0,0 +1,41 @@ +package uk.co.bconline.ndelius.model.entity.export; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import uk.co.bconline.ndelius.model.entity.converter.YNConverter; + +import javax.persistence.*; +import java.io.Serializable; + +@Getter +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "DISTRICT") +public class DistrictExportEntity implements Serializable +{ + @Id + @Column(name = "DISTRICT_ID") + @GeneratedValue(generator = "DISTRICT_ID_SEQ") + @SequenceGenerator(name = "DISTRICT_ID_SEQ", sequenceName = "DISTRICT_ID_SEQ", allocationSize = 1) + private Long id; + + @Column(name = "CODE") + private String code; + + @Column(name = "DESCRIPTION") + private String description; + + @Column(name = "SELECTABLE") + @Convert(converter = YNConverter.class) + private boolean selectable; + + @ManyToOne + @JoinColumn(name = "BOROUGH_ID") + private BoroughExportEntity borough; + + public String getExportDescription() { + return description + " (" + code + ") " + (isSelectable() ? " [Active]" : " [Inactive]"); + } +} diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/LDUExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/LDUExportEntity.java deleted file mode 100644 index b38e8dcc..00000000 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/LDUExportEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -package uk.co.bconline.ndelius.model.entity.export; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.Type; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; -import java.io.Serializable; -import java.time.LocalDate; - -@Getter -@Entity -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "LOCAL_DELIVERY_UNIT") -public class LDUExportEntity implements Serializable -{ - @Id - @Column(name = "LOCAL_DELIVERY_UNIT_ID") - @GeneratedValue(generator = "LOCAL_DELIVERY_UNIT_ID_SEQ") - @SequenceGenerator(name = "LOCAL_DELIVERY_UNIT_ID_SEQ", sequenceName = "LOCAL_DELIVERY_UNIT_ID_SEQ", allocationSize = 1) - private Long id; - - @Column(name = "CODE") - private String code; - - @Column(name = "DESCRIPTION") - private String description; - - @Column(name = "END_DATE") - @Type(type = "java.time.LocalDate") - private LocalDate endDate; -} diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java index 7ed76b9a..759b7170 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java @@ -29,13 +29,9 @@ public class TeamExportEntity implements Serializable { @Column(name = "DESCRIPTION") private String description; - @ManyToOne - @JoinColumn(name = "LOCAL_DELIVERY_UNIT_ID") - private LDUExportEntity localDeliveryUnit; - @ManyToOne @JoinColumn(name = "DISTRICT_ID") - private BoroughExportEntity borough; + private DistrictExportEntity district; @Column(name = "END_DATE") @Type(type = "java.time.LocalDate") @@ -45,24 +41,4 @@ public String getExportDescription() { return description + " (" + code + ") " + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]"); } - - public String getLDUDescription() - { - if (localDeliveryUnit != null) - { - return localDeliveryUnit.getDescription() + " (" + localDeliveryUnit.getCode() + ") " + ((localDeliveryUnit.getEndDate() != null && localDeliveryUnit.getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]"); - } else { - return null; - } - } - - public String getBoroughDescription() - { - if (borough != null) - { - return borough.getDescription() + " (" + borough.getCode() + ") " + ((borough.getEndDate() != null && borough.getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]"); - } else { - return null; - } - } } diff --git a/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java b/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java index 99a3d0cf..683f7d79 100644 --- a/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java +++ b/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java @@ -1,6 +1,5 @@ package uk.co.bconline.ndelius.service; -import uk.co.bconline.ndelius.model.entry.RoleAssociationEntry; import uk.co.bconline.ndelius.model.entry.RoleEntry; import java.util.List; @@ -10,6 +9,8 @@ public interface UserRoleService { Set getRolesICanAssign(); Set getUserRoles(String username); + + Set getUserRoleNames(String username); List getAllUsersWithRole(String role); Set getClientRoles(String clientId); Set getUserInteractions(String username); diff --git a/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java b/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java index 88799176..f3d3ce58 100644 --- a/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java +++ b/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java @@ -90,6 +90,13 @@ public Set getUserRoles(String username) { return getAssignedRoles(username, usersBase); } + @Override + public Set getUserRoleNames(String username) { + return stream(getAssignedRoleAssociations(username, usersBase).spliterator(), false) + .map(RoleAssociationEntry::getName) + .collect(toSet()); + } + @Override public Set getClientRoles(String clientId) { return getAssignedRoles(clientId, clientsBase); diff --git a/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java b/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java index 804e61cd..0e23e3e7 100644 --- a/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java +++ b/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java @@ -11,62 +11,31 @@ import uk.co.bconline.ndelius.model.ExportResult; import uk.co.bconline.ndelius.model.ReferenceData; import uk.co.bconline.ndelius.model.User; -import uk.co.bconline.ndelius.model.entity.ChangeNoteEntity; -import uk.co.bconline.ndelius.model.entity.OrganisationEntity; -import uk.co.bconline.ndelius.model.entity.ProbationAreaEntity; -import uk.co.bconline.ndelius.model.entity.ProbationAreaUserEntity; -import uk.co.bconline.ndelius.model.entity.ProbationAreaUserId; -import uk.co.bconline.ndelius.model.entity.ReferenceDataEntity; -import uk.co.bconline.ndelius.model.entity.StaffEntity; -import uk.co.bconline.ndelius.model.entity.StaffTeamEntity; -import uk.co.bconline.ndelius.model.entity.StaffTeamId; -import uk.co.bconline.ndelius.model.entity.SubContractedProviderEntity; -import uk.co.bconline.ndelius.model.entity.TeamEntity; -import uk.co.bconline.ndelius.model.entity.UserEntity; -import uk.co.bconline.ndelius.model.entity.export.BoroughExportEntity; -import uk.co.bconline.ndelius.model.entity.export.ProbationAreaExportEntity; -import uk.co.bconline.ndelius.model.entity.export.ReferenceDataExportEntity; -import uk.co.bconline.ndelius.model.entity.export.StaffExportEntity; -import uk.co.bconline.ndelius.model.entity.export.TeamExportEntity; -import uk.co.bconline.ndelius.model.entity.export.UserExportEntity; +import uk.co.bconline.ndelius.model.entity.*; +import uk.co.bconline.ndelius.model.entity.export.*; import uk.co.bconline.ndelius.model.entry.ClientEntry; -import uk.co.bconline.ndelius.model.entry.RoleEntry; import uk.co.bconline.ndelius.model.entry.UserEntry; -import uk.co.bconline.ndelius.service.DatasetService; -import uk.co.bconline.ndelius.service.ReferenceDataService; -import uk.co.bconline.ndelius.service.RoleService; -import uk.co.bconline.ndelius.service.TeamService; -import uk.co.bconline.ndelius.service.UserEntityService; -import uk.co.bconline.ndelius.service.UserHistoryService; -import uk.co.bconline.ndelius.service.UserRoleService; +import uk.co.bconline.ndelius.service.*; import uk.co.bconline.ndelius.util.LdapUtils; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import static java.time.LocalDateTime.now; import static java.time.temporal.ChronoUnit.MILLIS; -import static java.util.Collections.emptySet; -import static java.util.Collections.singleton; -import static java.util.Collections.singletonList; +import static java.util.Collections.*; import static java.util.Optional.ofNullable; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; +import static java.util.stream.Collectors.*; import static org.springframework.util.StringUtils.isEmpty; import static uk.co.bconline.ndelius.util.LdapUtils.mapLdapStringToDate; import static uk.co.bconline.ndelius.util.LdapUtils.mapToLdapString; -import static uk.co.bconline.ndelius.util.NameUtils.combineNames; -import static uk.co.bconline.ndelius.util.NameUtils.firstForename; -import static uk.co.bconline.ndelius.util.NameUtils.subsequentForenames; +import static uk.co.bconline.ndelius.util.NameUtils.*; @Slf4j @Component @@ -182,7 +151,7 @@ public Optional map(UserEntry user) public ExportResult combine(UserExportEntity db, UserEntry ldap) { if (ldap == null) return null; DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - val userRoles = ofNullable(ldap.getUsername()).map(userRoleService::getUserRoles).orElse(emptySet()); + val userRoles = ofNullable(ldap.getUsername()).map(userRoleService::getUserRoleNames).orElse(emptySet()); return ExportResult.builder() .username(ofNullable(ldap.getUsername()).orElseGet(db::getUsername)) .forenames(ofNullable(ldap.getForenames()).orElseGet(() -> combineNames(db.getForename(), db.getForename2()))) @@ -200,14 +169,23 @@ public ExportResult combine(UserExportEntity db, UserEntry ldap) { .datasets(ofNullable(db.getDatasets()).map(l -> l.stream() .map(ProbationAreaExportEntity::getCode).distinct().sorted().collect(joining(","))).orElse(null)) .lastAccessedDate(db.getLastAccessedDate() != null ? db.getLastAccessedDate().format(format) : null) - .lau(ofNullable(db.getStaff()).map(StaffExportEntity::getTeams).map(l -> l.stream() - .map(TeamExportEntity::getLDUDescription).filter(Objects::nonNull).distinct().sorted().collect(joining(","))).orElse(null)) - .pdu(ofNullable(db.getStaff()).map(StaffExportEntity::getTeams).map(l -> l.stream() - .map(TeamExportEntity::getBoroughDescription).filter(Objects::nonNull).distinct().sorted().collect(joining(","))).orElse(null)) + .localAdminUnit(ofNullable(db.getStaff()).map(StaffExportEntity::getTeams).map(l -> l.stream() + .map(TeamExportEntity::getDistrict) + .map(DistrictExportEntity::getExportDescription) + .filter(Objects::nonNull) + .distinct().sorted().collect(joining(","))).orElse(null)) + .probationDeliveryUnit(ofNullable(db.getStaff()).map(StaffExportEntity::getTeams).map(l -> l.stream() + .map(TeamExportEntity::getDistrict) + .map(DistrictExportEntity::getBorough) + .map(BoroughExportEntity::getExportDescription) + .filter(Objects::nonNull).distinct().sorted().collect(joining(","))).orElse(null)) .provider(ofNullable(db.getStaff()).map(StaffExportEntity::getTeams).map(l -> l.stream() - .map(TeamExportEntity::getBorough).filter(Objects::nonNull).map(BoroughExportEntity::getProbationArea).map(ProbationAreaExportEntity::getExportDescription).distinct().sorted().collect(joining(","))).orElse(null)) - .roleDescriptions(ofNullable(userRoles).map(l -> l.stream() - .map(RoleEntry::getName).distinct().sorted().collect(joining(","))).orElse(null)) + .map(TeamExportEntity::getDistrict) + .map(DistrictExportEntity::getBorough) + .map(BoroughExportEntity::getProbationArea) + .map(ProbationAreaExportEntity::getExportDescription) + .filter(Objects::nonNull).distinct().sorted().collect(joining(","))).orElse(null)) + .roleNames(userRoles.stream().sorted().collect(joining(","))) .build(); } From 34af79574fdcc91609fe641b7f452a81fe5aee48 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Tue, 27 Aug 2024 12:52:19 +0000 Subject: [PATCH 2/3] Add workflow_dispatch trigger --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bcb4902a..a4e6bcd1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,7 @@ name: Build on: + workflow_dispatch: release: types: [published, edited] push: From 1fb5733fdd3e94f0ccd13ea3d45c91828653355a Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Tue, 27 Aug 2024 13:17:16 +0000 Subject: [PATCH 3/3] Fix tests --- .../ndelius/model/entity/LDUEntity.java | 33 ------------------- .../entity/export/BoroughExportEntity.java | 2 +- .../entity/export/DistrictExportEntity.java | 2 +- .../export/ProbationAreaExportEntity.java | 4 +-- .../model/entity/export/TeamExportEntity.java | 5 ++- .../ndelius/service/UserRoleService.java | 1 - .../service/impl/UserRoleServiceImpl.java | 2 +- src/main/resources/data.ldif | 2 +- src/main/resources/data.sql | 30 ++++++++++++----- .../controller/UserControllerExportTest.java | 7 ++-- 10 files changed, 32 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/uk/co/bconline/ndelius/model/entity/LDUEntity.java diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/LDUEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/LDUEntity.java deleted file mode 100644 index 847673ae..00000000 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/LDUEntity.java +++ /dev/null @@ -1,33 +0,0 @@ -package uk.co.bconline.ndelius.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; -import java.io.Serializable; - -@Getter -@Entity -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "LOCAL_DELIVERY_UNIT") -public class LDUEntity implements Serializable -{ - @Id - @Column(name = "LOCAL_DELIVERY_UNIT_ID") - @GeneratedValue(generator = "LOCAL_DELIVERY_UNIT_ID_SEQ") - @SequenceGenerator(name = "LOCAL_DELIVERY_UNIT_ID_SEQ", sequenceName = "LOCAL_DELIVERY_UNIT_ID_SEQ", allocationSize = 1) - private Long id; - - @Column(name = "CODE") - private String code; - - @Column(name = "DESCRIPTION") - private String description; -} diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java index 41589cee..c401bf93 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/BoroughExportEntity.java @@ -35,6 +35,6 @@ public class BoroughExportEntity implements Serializable { private ProbationAreaExportEntity probationArea; public String getExportDescription() { - return description + " (" + code + ") " + (isSelectable() ? " [Active]" : " [Inactive]"); + return description + " (" + code + ")" + (isSelectable() ? "" : " [Inactive]"); } } diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java index d72f15d3..06fe93a3 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/DistrictExportEntity.java @@ -36,6 +36,6 @@ public class DistrictExportEntity implements Serializable private BoroughExportEntity borough; public String getExportDescription() { - return description + " (" + code + ") " + (isSelectable() ? " [Active]" : " [Inactive]"); + return description + " (" + code + ")" + (isSelectable() ? "" : " [Inactive]"); } } diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/ProbationAreaExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/ProbationAreaExportEntity.java index 2a023c65..a339cd07 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/ProbationAreaExportEntity.java +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/ProbationAreaExportEntity.java @@ -3,7 +3,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import org.hibernate.annotations.Cache; import org.hibernate.annotations.Type; import javax.persistence.*; @@ -11,7 +10,6 @@ import java.time.LocalDate; import static java.time.LocalDate.now; -import static org.hibernate.annotations.CacheConcurrencyStrategy.READ_ONLY; @Entity @Getter @@ -37,6 +35,6 @@ public class ProbationAreaExportEntity implements Serializable { public String getExportDescription() { - return description + " (" + code + ") " + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]"); + return description + " (" + code + ")" + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : ""); } } diff --git a/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java b/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java index 759b7170..8843c828 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java +++ b/src/main/java/uk/co/bconline/ndelius/model/entity/export/TeamExportEntity.java @@ -37,8 +37,7 @@ public class TeamExportEntity implements Serializable { @Type(type = "java.time.LocalDate") private LocalDate endDate; - public String getExportDescription() - { - return description + " (" + code + ") " + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]"); + public String getExportDescription() { + return description + " (" + code + ")" + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : ""); } } diff --git a/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java b/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java index 683f7d79..90841d5c 100644 --- a/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java +++ b/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java @@ -9,7 +9,6 @@ public interface UserRoleService { Set getRolesICanAssign(); Set getUserRoles(String username); - Set getUserRoleNames(String username); List getAllUsersWithRole(String role); Set getClientRoles(String clientId); diff --git a/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java b/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java index f3d3ce58..93096050 100644 --- a/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java +++ b/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java @@ -93,7 +93,7 @@ public Set getUserRoles(String username) { @Override public Set getUserRoleNames(String username) { return stream(getAssignedRoleAssociations(username, usersBase).spliterator(), false) - .map(RoleAssociationEntry::getName) + .map(RoleAssociationEntry::getCn) .collect(toSet()); } diff --git a/src/main/resources/data.ldif b/src/main/resources/data.ldif index 25890c5e..a3244404 100644 --- a/src/main/resources/data.ldif +++ b/src/main/resources/data.ldif @@ -521,7 +521,7 @@ dn: cn=UABT0052,cn=test.user.private,ou=Users,dc=bcl,dc=local objectclass: top objectclass: alias objectclass: NDRoleAssociation -cn: UABT0051 +cn: UABT0052 aliasedObjectName: cn=UABT0052,cn=ndRoleCatalogue,ou=Users,dc=bcl,dc=local dn: cn=TestUser1,ou=Users,dc=bcl,dc=local diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index da766086..812d21ad 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -21,12 +21,19 @@ INSERT INTO PROBATION_AREA(PROBATION_AREA_ID, CODE, DESCRIPTION, ORGANISATION_ID INSERT INTO PROBATION_AREA(PROBATION_AREA_ID, CODE, DESCRIPTION, ORGANISATION_ID, ESTABLISHMENT, SELECTABLE) VALUES (PROBATION_AREA_ID_SEQ.NEXTVAL, 'NWI', 'Norwich (HMP & YOI)', ORGANISATION_ID_SEQ.CURRVAL, 'Y', 'Y'); INSERT INTO PROBATION_AREA(PROBATION_AREA_ID, CODE, DESCRIPTION, ORGANISATION_ID, ESTABLISHMENT, SELECTABLE) VALUES (PROBATION_AREA_ID_SEQ.NEXTVAL, 'PVI', 'Pentonville (HMP)', ORGANISATION_ID_SEQ.CURRVAL, 'Y', 'Y'); --- LDU/PDU -INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, PROBATION_AREA_ID) VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B1', 'Borough A', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE='N01')); -INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, PROBATION_AREA_ID) VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B2', 'Borough B', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE='N02')); -INSERT INTO LOCAL_DELIVERY_UNIT (LOCAL_DELIVERY_UNIT_ID, CODE, DESCRIPTION) VALUES (LOCAL_DELIVERY_UNIT_ID_SEQ.NEXTVAL, 'LDU1', 'Local Delivery Unit A'); -INSERT INTO LOCAL_DELIVERY_UNIT (LOCAL_DELIVERY_UNIT_ID, CODE, DESCRIPTION) VALUES (LOCAL_DELIVERY_UNIT_ID_SEQ.NEXTVAL, 'LDU2', 'Local Delivery Unit B'); +-- Probation Delivery Units +INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, SELECTABLE, PROBATION_AREA_ID) +VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B1', 'Borough A', 'N', + (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01')); +INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, SELECTABLE, PROBATION_AREA_ID) +VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B2', 'Borough B', 'Y', + (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02')); +-- Local Admin Units +INSERT INTO DISTRICT (DISTRICT_ID, CODE, DESCRIPTION, SELECTABLE, BOROUGH_ID) +VALUES (DISTRICT_ID_SEQ.NEXTVAL, 'LAU1', 'Local Admin Unit A', 'Y', (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B1')); +INSERT INTO DISTRICT (DISTRICT_ID, CODE, DESCRIPTION, SELECTABLE, BOROUGH_ID) +VALUES (DISTRICT_ID_SEQ.NEXTVAL, 'LAU2', 'Local Admin Unit B', 'Y', (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B2')); -- Sub-contracted Providers INSERT INTO SC_PROVIDER(SC_PROVIDER_ID, CODE, DESCRIPTION, ACTIVE_FLAG, PROVIDER_ID) VALUES (SC_PROVIDER_ID_SEQ.NEXTVAL, 'N01SC1', 'NPS London SC 1', 1, (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE='N01')); @@ -480,6 +487,7 @@ INSERT INTO USER_NOTE (USER_NOTE_ID, ROW_VERSION, USER_ID, LAST_UPDATED_USER_ID, VALUES (USER_NOTE_ID_SEQ.NEXTVAL, 0, (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'Joe.Bloggs'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'Mavis.Mehler'), CURRENT_TIMESTAMP-9.9, 'Added user management roles, to allow access to UMT.'); INSERT INTO USER_NOTE (USER_NOTE_ID, ROW_VERSION, USER_ID, LAST_UPDATED_USER_ID, LAST_UPDATED_DATETIME, NOTES) VALUES (USER_NOTE_ID_SEQ.NEXTVAL, 0, (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'Joe.Bloggs'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = '[Data Maintenance]'), CURRENT_TIMESTAMP-9.9, 'Added user management roles, to allow access to UMT.'); + -- Datasets INSERT INTO PROBATION_AREA_USER (PROBATION_AREA_ID, USER_ID) VALUES ((SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'test.user')); INSERT INTO PROBATION_AREA_USER (PROBATION_AREA_ID, USER_ID) VALUES ((SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'test.user')); @@ -490,9 +498,15 @@ INSERT INTO PROBATION_AREA_USER (PROBATION_AREA_ID, USER_ID) VALUES ((SELECT PRO -- Teams INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, END_DATE) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N01TST', 'Test team (Ended)', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), CURRENT_TIMESTAMP); -INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N01TST', 'Test team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B2')); -INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID, LOCAL_DELIVERY_UNIT_ID) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N02TST', 'Other team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'), (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B1'), (SELECT LOCAL_DELIVERY_UNIT_ID FROM LOCAL_DELIVERY_UNIT WHERE CODE = 'LDU1')); -INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, LOCAL_DELIVERY_UNIT_ID) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N03TST', 'Another', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N03'), (SELECT LOCAL_DELIVERY_UNIT_ID FROM LOCAL_DELIVERY_UNIT WHERE CODE = 'LDU1')); +INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID) +VALUES (TEAM_ID_SEQ.NEXTVAL, 'N01TST', 'Test team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), + (SELECT DISTRICT_ID FROM DISTRICT WHERE CODE = 'LAU2')); +INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID) +VALUES (TEAM_ID_SEQ.NEXTVAL, 'N02TST', 'Other team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'), + (SELECT DISTRICT_ID FROM DISTRICT WHERE CODE = 'LAU1')); +INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID) +VALUES (TEAM_ID_SEQ.NEXTVAL, 'N03TST', 'Another', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N03'), + (SELECT DISTRICT_ID FROM DISTRICT WHERE CODE = 'LAU1')); INSERT INTO STAFF_TEAM (STAFF_ID, TEAM_ID) VALUES ((SELECT STAFF_ID FROM STAFF WHERE OFFICER_CODE = 'N01A001'), (SELECT TEAM_ID FROM TEAM WHERE CODE = 'N01TST' AND END_DATE IS NULL)); INSERT INTO STAFF_TEAM (STAFF_ID, TEAM_ID) VALUES ((SELECT STAFF_ID FROM STAFF WHERE OFFICER_CODE = 'N01A002'), (SELECT TEAM_ID FROM TEAM WHERE CODE = 'N01TST' AND END_DATE IS NULL)); INSERT INTO STAFF_TEAM (STAFF_ID, TEAM_ID) VALUES ((SELECT STAFF_ID FROM STAFF WHERE OFFICER_CODE = 'N01A003'), (SELECT TEAM_ID FROM TEAM WHERE CODE = 'N01TST' AND END_DATE IS NULL)); diff --git a/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java b/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java index c4db986d..31df2632 100644 --- a/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java +++ b/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java @@ -14,7 +14,6 @@ import static java.time.LocalDate.now; import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; -import static java.time.temporal.ChronoUnit.DAYS; import static org.hamcrest.Matchers.*; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; @@ -188,14 +187,14 @@ public void fullExportIsRestrictedToNationalAdmins() throws Exception { @Test public void dataIsDisplayedCorrectlyForFullExport() throws Exception { - String expectedHeader = "\"Username\",\"Forenames\",\"Surname\",\"Email\",\"Telephone Number\",\"Start Date\",\"End Date\",\"Last Accessed Delius\",\"Home Area\",\"Datasets\",\"Sector\",\"Staff Code\",\"Staff Grade\",\"Team\",\"LAU\",\"PDU\",\"Provider\",\"Role Descriptions\""; - String expectedStartDate = now().minus(10, DAYS).format(ISO_LOCAL_DATE); + String expectedHeader = "\"Username\",\"Forenames\",\"Surname\",\"Email\",\"Telephone Number\",\"Start Date\",\"End Date\",\"Last Accessed Delius\",\"Home Area\",\"Datasets\",\"Sector\",\"Staff Code\",\"Staff Grade\",\"Team\",\"LAU\",\"PDU\",\"Provider\",\"Role Names\""; + String expectedStartDate = now().minusDays(10).format(ISO_LOCAL_DATE); String expectedLoginDate = now().format(ISO_LOCAL_DATE);// see data.sql String[] expectedUsers = { "\n\"Abdul.Austria\",\"Abdul\",\"Austria\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A168\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"", "\n\"Leia.Leaman\",\"Leia\",\"Leaman\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A086\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"", "\n\"Zina.Zenon\",\"Zina\",\"Zenon\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A131\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"", - "\n\"test.user\",\"Test\",\"User\",\"test.user@test.com\",\"0123 456 789\",\"2000-01-02\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"N01\",\"N01,N02,N03\",\"Public\",\"N01A001\",\"GRADE1\",\"Another (N03TST) [Active],Other team (N02TST) [Active],Test team (N01TST) [Active]\",\"Local Delivery Unit A (LDU1) [Active]\",\"Borough A (B1) [Active],Borough B (B2) [Active]\",\"NPS London (N01) [Active],NPS North East (N02) [Active]\",\"APBT001,APBT002,RDBT001,SPGADBT005,UABT0050,UMBT001\"", + "\n\"test.user\",\"Test\",\"User\",\"test.user@test.com\",\"0123 456 789\",\"2000-01-02\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"N01\",\"N01,N02,N03\",\"Public\",\"N01A001\",\"GRADE1\",\"Another (N03TST),Other team (N02TST),Test team (N01TST)\",\"Local Admin Unit A (LAU1),Local Admin Unit B (LAU2)\",\"Borough A (B1) [Inactive],Borough B (B2)\",\"NPS London (N01),NPS North East (N02)\",\"APBT001,APBT002,RDBT001,SPGADBT005,UABT0050,UMBT001,UMBT003\"", "\n\"test.user.private\",\"Test\",\"User (Private)\",\"test.user.private@test.com\",\"\",\"\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"C01\",\"C01,C02\",\"Public\",\"\",\"\",\"\",\"\",\"\",\"\",\"UABT0052,UMBT001\""}; MvcResult asyncResult = mvc.perform(get("/api/users/export/all")