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

[HOCS-6478] Work in prog report skeleton #935

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
@@ -0,0 +1,63 @@
package uk.gov.digital.ho.hocs.casework.reports.domain.mapping;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
import uk.gov.digital.ho.hocs.casework.reports.domain.reports.WorkInProgressData;
import uk.gov.digital.ho.hocs.casework.reports.domain.reports.WorkInProgressRow;

import java.util.Optional;

@Service
@Slf4j
@Profile("reporting")
public class WorkInProgressDataMapper {

private final UserNameValueMapper userNameValueMapper;

private final TeamNameValueMapper teamNameValueMapper;

private final StageNameValueMapper stageNameValueMapper;

public WorkInProgressDataMapper(
UserNameValueMapper userNameValueMapper,
TeamNameValueMapper teamNameValueMapper,
StageNameValueMapper stageNameValueMapper
) {
this.userNameValueMapper = userNameValueMapper;
this.teamNameValueMapper = teamNameValueMapper;
this.stageNameValueMapper = stageNameValueMapper;
}

public WorkInProgressRow mapDataToRow(WorkInProgressData data) {
Optional<String> maybeUser = userNameValueMapper.map(data.getAssignedUserUUID());
Optional<String> maybeTeam = teamNameValueMapper.map(data.getAssignedTeamUUID());

return new WorkInProgressRow(
data.getCaseUUID(),
data.getCaseReference(),
data.getCompType(),
data.getDateCreated(),
data.getDateReceived(),
data.getCaseDeadline(),
data.getOwningCSU(),
data.getDirectorate(),
data.getBusinessAreaBasedOnDirectorate(),
data.getEnquiryReason(),
data.getPrimaryCorrespondentName(),
data.getCaseSummary(),
data.getSeverity(),
data.getAssignedUserUUID(),
data.getAssignedTeamUUID(),
data.getStageUUID(),
data.getStageType(),
data.getDueWeek(),
maybeUser.orElse(null),
maybeTeam.orElse(null),
stageNameValueMapper.map(data.getStageType()).orElse(data.getStageType()),
data.getAssignedUserUUID() != null,
maybeUser.or(() -> maybeTeam).orElse(null)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package uk.gov.digital.ho.hocs.casework.reports.domain.reports;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.UUID;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Entity
@Table(name = "report_work_in_progress")
public class WorkInProgressData implements Serializable {

@Id
@Column(name = "case_uuid")
private UUID caseUUID;

private String caseReference;

private String compType;

private LocalDate dateCreated;

private LocalDate dateReceived;

private LocalDate caseDeadline;

@Column(name = "owning_csu")
private String owningCSU;

private String directorate;

private String businessAreaBasedOnDirectorate;

private String enquiryReason;

private String primaryCorrespondentName;

private String caseSummary;

private String severity;

@Column(name = "assigned_user_uuid")
private UUID assignedUserUUID;

@Column(name = "assigned_team_uuid")
private UUID assignedTeamUUID;

@Column(name = "stage_uuid")
private UUID stageUUID;

private String stageType;

private String caseType;

private String dueWeek;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package uk.gov.digital.ho.hocs.casework.reports.domain.reports;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.UUID;

@AllArgsConstructor
@Getter
@EqualsAndHashCode
public class WorkInProgressRow implements ReportRow, Serializable {

@JsonProperty("case_uuid")
private UUID caseUUID;

@JsonProperty("case_reference")
private String caseReference;

@JsonProperty("comp_type")
private String compType;

@JsonProperty("date_created")
private LocalDate dateCreated;

@JsonProperty("date_received")
private LocalDate dateReceived;

@JsonProperty("case_deadline")
private LocalDate caseDeadline;

@JsonProperty("owning_csu")
private String owningCSU;

@JsonProperty("directorate")
private String directorate;

@JsonProperty("business_area_based_on_directorate")
private String businessAreaBasedOnDirectorate;

@JsonProperty("enquiry_reason")
private String enquiryReason;

@JsonProperty("primary_correspondent_name")
private String primaryCorrespondentName;

@JsonProperty("case_summary")
private String caseSummary;

@JsonProperty("severity")
private String severity;

@JsonProperty("assigned_user_uuid")
private UUID assignedUserUUID;

@JsonProperty("assigned_team_uuid")
private UUID assignedTeamUUID;

@JsonProperty("stage_uuid")
private UUID stageUUID;

@JsonProperty("stage_type")
private String stageType;

@JsonProperty("due_week")
private String dueWeek;

@JsonProperty("user_name")
private String userName;

@JsonProperty("team_name")
private String teamName;

@JsonProperty("stage_name")
private String stageName;

@JsonProperty("allocation_status")
private boolean allocationStatus;

@JsonProperty("allocated_to")
private String allocatedTo;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.digital.ho.hocs.casework.reports.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.query.Param;
import uk.gov.digital.ho.hocs.casework.reports.domain.CaseType;
import uk.gov.digital.ho.hocs.casework.reports.domain.reports.WorkInProgressData;

import javax.persistence.QueryHint;
import java.util.UUID;
import java.util.stream.Stream;

import static org.hibernate.annotations.QueryHints.READ_ONLY;
import static org.hibernate.jpa.QueryHints.HINT_CACHEABLE;
import static org.hibernate.jpa.QueryHints.HINT_FETCH_SIZE;

public interface WorkInProgressRepository extends JpaRepository<WorkInProgressData, UUID> {

@QueryHints(value = {
@QueryHint(name = HINT_FETCH_SIZE, value = "50000"),
@QueryHint(name = HINT_CACHEABLE, value = "false"),
@QueryHint(name = READ_ONLY, value = "true")
})
@Query(
value = "SELECT * FROM report_work_in_progress WHERE case_type = :#{#caseType?.name()}",
nativeQuery = true
)
Stream<WorkInProgressData> getReportData(@Param("caseType") CaseType caseType);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package uk.gov.digital.ho.hocs.casework.reports.reports;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import uk.gov.digital.ho.hocs.casework.reports.api.dto.ColumnType;
import uk.gov.digital.ho.hocs.casework.reports.api.dto.FilterType;
import uk.gov.digital.ho.hocs.casework.reports.api.dto.ReportColumnDto;
import uk.gov.digital.ho.hocs.casework.reports.domain.CaseType;
import uk.gov.digital.ho.hocs.casework.reports.domain.mapping.WorkInProgressDataMapper;
import uk.gov.digital.ho.hocs.casework.reports.domain.reports.WorkInProgressRow;
import uk.gov.digital.ho.hocs.casework.reports.domain.repository.WorkInProgressRepository;

import javax.persistence.EntityManager;
import java.util.List;
import java.util.stream.Stream;

@Component
@Profile("reporting")
public class WorkInProgressReport implements Report<WorkInProgressRow> {

private final WorkInProgressRepository workInProgressRepository;

private final EntityManager entityManager;

private final WorkInProgressDataMapper workInProgressDataMapper;

private final ObjectMapper objectMapper;

public WorkInProgressReport(
WorkInProgressRepository workInProgressRepository,
EntityManager entityManager,
WorkInProgressDataMapper workInProgressDataMapper,
ObjectMapper objectMapper
) {
this.workInProgressRepository = workInProgressRepository;
this.entityManager = entityManager;
this.workInProgressDataMapper = workInProgressDataMapper;
this.objectMapper = objectMapper;
}

@Override
public String getSlug() {
return "work-in-progress";
}

@Override
public String getDisplayName() {
return "Work in progress report";
}

@Override
public String getDescription() {
return "A report of in progress cases to allow allocation to appropriate case workers.";
}

@Override
public List<CaseType> getAvailableCaseTypes() {
return List.of(CaseType.COMP, CaseType.COMP2);
}

@Override
public List<ReportColumnDto> getColumnMetadata() {
return List.of(new ReportColumnDto("case_uuid", "Case UUID", ColumnType.STRING, false, true),
new ReportColumnDto("case_reference", "Reference", ColumnType.LINK, true, true).withAdditionalField(
"link_pattern", "/case/${case_uuid}/stage/${stage_uuid}"),
new ReportColumnDto("stage_uuid", "Stage UUID", ColumnType.STRING, false, false),
new ReportColumnDto("stage_name", "Stage", ColumnType.STRING, true, true).withFilter(FilterType.SELECT),
new ReportColumnDto("case_summary", "Case summary", ColumnType.STRING, true, true).withFilter(
FilterType.CONTAINS_TEXT),
new ReportColumnDto("allocation_status", "Allocation status", ColumnType.BOOLEAN, true, true)
.withAdditionalField("label_if_true", "Allocated")
.withAdditionalField("label_if_false", "Unallocated")
.withFilter(FilterType.BOOLEAN),
new ReportColumnDto("allocated_to", "Allocated to", ColumnType.STRING, true, true).withFilter(
FilterType.SELECT), new ReportColumnDto("case_deadline", "Deadline", ColumnType.DATE, true, true),
new ReportColumnDto("due_week", "Due week", ColumnType.STRING, false, false)
.withAdditionalField("filter_values", getDueDateFilterValues())
.withFilter(FilterType.SELECT),
new ReportColumnDto("severity", "Severity", ColumnType.STRING, true, true).withFilter(FilterType.SELECT),
new ReportColumnDto("comp_type", "Complaint type", ColumnType.STRING, false, true),
new ReportColumnDto("date_created", "Created", ColumnType.DATE, false, true),
new ReportColumnDto("date_received", "Received", ColumnType.DATE, false, true),
new ReportColumnDto("owning_csu", "Owning CSU", ColumnType.STRING, false, true),
new ReportColumnDto("directorate", "Directorate", ColumnType.STRING, false, true),
new ReportColumnDto("business_area_based_on_directorate", "Business area based on directorate",
ColumnType.STRING, false, true
), new ReportColumnDto("enquiry_reason", "Enquiry reason", ColumnType.STRING, false, true),
new ReportColumnDto("primary_correspondent_name", "Primary correspondent name", ColumnType.STRING, false,
true
), new ReportColumnDto("stage_type", "Stage Type", ColumnType.STRING, false, true),
new ReportColumnDto("assigned_user_uuid", "Assigned user UUID", ColumnType.STRING, false, true),
new ReportColumnDto("assigned_team_uuid", "Assigned team UUID", ColumnType.STRING, false, true),
new ReportColumnDto("user_name", "User", ColumnType.STRING, false, true),
new ReportColumnDto("team_name", "Team", ColumnType.STRING, false, true)
);
}

private String getDueDateFilterValues() {
try {
return objectMapper.writeValueAsString(
List.of("Due this week", "Due next week", "Due week 3", "Due week 4", "Due week 5",
"Outside service standard"
));
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to serialise hardcoded Map to JSON object", e);
}
}

@Override
public String getIdColumnKey() {
return "case_uuid";
}

@Override
public Stream<WorkInProgressRow> getRows(CaseType caseType) {
return workInProgressRepository
.getReportData(caseType)
.peek(entityManager::detach)
.map(workInProgressDataMapper::mapDataToRow);
}

}
Loading