Skip to content

Commit

Permalink
added check to see of submission has attachments (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelswart authored Mar 5, 2024
1 parent 031d475 commit 46db7a1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public class LambdaSubmissionDefinition {

private Integer schemeVersion;

private boolean hasAttachments;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package gov.cabinetoffice.gap.adminbackend.entities;

import gov.cabinetoffice.gap.adminbackend.dtos.submission.GrantApplicant;
import gov.cabinetoffice.gap.adminbackend.enums.GrantAttachmentStatus;
import lombok.*;

import javax.persistence.*;
import java.time.Instant;
import java.util.UUID;

@Entity
@Table(name = "grant_attachment")
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GrantAttachment {

@Id
@GeneratedValue
@Column(name = "grant_attachment_id")
private UUID id;

@ManyToOne
@JoinColumn(name = "submission_id", referencedColumnName = "id")
private Submission submission;

@Column(name = "question_id", nullable = false)
private String questionId;

@Column(name = "version", nullable = false)
@Builder.Default
private Integer version = 1;

@Column(name = "created", nullable = false)
@Builder.Default
private Instant created = Instant.now();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "created_by", referencedColumnName = "id")
private GrantApplicant createdBy;

@Column(name = "last_updated", nullable = false)
private Instant lastUpdated;

@Column(name = "status", nullable = false)
@Enumerated(EnumType.STRING)
private GrantAttachmentStatus status;

@Column(name = "filename", nullable = false)
private String filename;

@Column(name = "location", nullable = false, columnDefinition = "TEXT")
private String location;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gov.cabinetoffice.gap.adminbackend.enums;

public enum GrantAttachmentStatus {
AWAITING_SCAN,
QUARANTINED,
AVAILABLE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gov.cabinetoffice.gap.adminbackend.repositories;

import gov.cabinetoffice.gap.adminbackend.entities.GrantAttachment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface GrantAttachmentRepository extends JpaRepository<GrantAttachment, UUID> {
boolean existsBySubmissionId(UUID id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import gov.cabinetoffice.gap.adminbackend.exceptions.SpotlightExportException;
import gov.cabinetoffice.gap.adminbackend.mappers.SubmissionMapper;
import gov.cabinetoffice.gap.adminbackend.models.AdminSession;
import gov.cabinetoffice.gap.adminbackend.repositories.GrantAttachmentRepository;
import gov.cabinetoffice.gap.adminbackend.repositories.GrantExportBatchRepository;
import gov.cabinetoffice.gap.adminbackend.repositories.GrantExportRepository;
import gov.cabinetoffice.gap.adminbackend.repositories.SubmissionRepository;
Expand Down Expand Up @@ -66,6 +67,8 @@ public class SubmissionsService {

private final GrantExportBatchRepository grantExportBatchRepository;

private final GrantAttachmentRepository grantAttachmentRepository;

@Value("${cloud.aws.sqs.submissions-export-queue}")
private String submissionsExportQueue;

Expand Down Expand Up @@ -238,10 +241,13 @@ public LambdaSubmissionDefinition getSubmissionInfo(final UUID submissionId, fin
.orElseThrow(NotFoundException::new);
final String userId = submission.getApplicant().getUserId();
final String email = getEmailFromUserId(userId, authHeader);
final boolean hasAttachments = grantAttachmentRepository.existsBySubmissionId(submissionId);


final LambdaSubmissionDefinition lambdaSubmissionDefinition = submissionMapper
.submissionToLambdaSubmissionDefinition(submission);
lambdaSubmissionDefinition.setEmail(email);
lambdaSubmissionDefinition.setHasAttachments(hasAttachments);
return lambdaSubmissionDefinition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import gov.cabinetoffice.gap.adminbackend.exceptions.SpotlightExportException;
import gov.cabinetoffice.gap.adminbackend.mappers.SubmissionMapper;
import gov.cabinetoffice.gap.adminbackend.mappers.SubmissionMapperImpl;
import gov.cabinetoffice.gap.adminbackend.repositories.GrantAttachmentRepository;
import gov.cabinetoffice.gap.adminbackend.repositories.GrantExportBatchRepository;
import gov.cabinetoffice.gap.adminbackend.repositories.GrantExportRepository;
import gov.cabinetoffice.gap.adminbackend.repositories.SubmissionRepository;
Expand Down Expand Up @@ -61,6 +62,9 @@ class SubmissionsServiceTest {
@Mock
private SubmissionRepository submissionRepository;

@Mock
private GrantAttachmentRepository grantAttachmentRepository;

@Mock
private AmazonSQS amazonSQS;

Expand Down

0 comments on commit 46db7a1

Please sign in to comment.