-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPC-3599] Opt-out Import Database Migrations (#1941)
## 🎫 Ticket https://jira.cms.gov/browse/DPC-3599 ## 🛠 Changes This PR does the following: 1. A database migration for `dpc_consent` db. It creates a table called `opt_out_file`, consisting of metadata for each opt out file we import, as well as a foreign key `opt_out_file_id` on the `consent` table. For every beneficiary who chooses to opt out, we'll be storing a record in the `consent` table. The Many-to-One relationship here allows us to tie each record to an opt out file and timestamp, for visibility/transparency. 2. Creates an `OptOutFileEntity` for the ORM, so that our Java code can interact with it. 3. Updates the `ConsentEntity` to reflect the Many-to-One relationship. ## ✅ Acceptance Validation - Successfully ran the migration on my local environment without any issues. - Successfully compiled `dpc-common` and `dpc-consent`. ## 🔒 Security Implications - [ ] This PR adds a new software dependency or dependencies. - [ ] This PR modifies or invalidates one or more of our security controls. - [ ] This PR stores or transmits data that was not stored or transmitted before. - [ ] This PR requires additional review of its security implications for other reasons. If any security implications apply, add Jason Ashbaugh (GitHub username: StewGoin) as a reviewer and do not merge this PR without his approval. --------- Co-authored-by: Ashley Weaver <[email protected]>
- Loading branch information
1 parent
0b41f41
commit 18cc862
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/OptOutFileEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package gov.cms.dpc.common.consent.entities; | ||
|
||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
import javax.persistence.*; | ||
import java.io.Serializable; | ||
import java.time.LocalDate; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Entity(name = "opt_out_file") | ||
public class OptOutFileEntity implements Serializable { | ||
public static final String IMPORT_STATUS_IN_PROGRESS = "In-Progress"; | ||
public static final String IMPORT_STATUS_COMPLETED = "Completed"; | ||
public static final String IMPORT_STATUS_FAILED = "Failed"; | ||
|
||
public OptOutFileEntity() {} | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "uuid") | ||
private UUID id; | ||
|
||
@Column(name = "name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "timestamp", nullable = false) | ||
private LocalDate timestamp; | ||
|
||
@Column(name = "import_status") | ||
private String importStatus; | ||
|
||
@Column(name = "created_at", columnDefinition = "TIMESTAMP WITH TIME ZONE") | ||
@CreationTimestamp | ||
private OffsetDateTime createdAt; | ||
|
||
@Column(name = "updated_at", columnDefinition = "TIMESTAMP WITH TIME ZONE") | ||
@UpdateTimestamp | ||
private OffsetDateTime updatedAt; | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { return name; } | ||
|
||
public void setName(String name) { this.name = name; } | ||
|
||
public LocalDate getTimestamp() { return timestamp; } | ||
|
||
public void setTimestamp(LocalDate timestamp) { this.timestamp = timestamp; } | ||
|
||
public String getImportStatus() { return importStatus; } | ||
|
||
public void setImportStatus(String importStatus) { this.importStatus = importStatus; } | ||
|
||
public OffsetDateTime getCreatedAt() { return createdAt; } | ||
|
||
public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; } | ||
|
||
public OffsetDateTime getUpdatedAt() { return updatedAt; } | ||
|
||
public void setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; } | ||
|
||
public static OptOutFileEntity defaultOptOutEntity(Optional<UUID> id, Optional<String> name) { | ||
OptOutFileEntity optOut = new OptOutFileEntity(); | ||
|
||
optOut.setId(UUID.randomUUID()); | ||
id.ifPresent(optOut::setId); | ||
|
||
optOut.setName("TestOptOutFile"); | ||
name.ifPresent(optOut::setName); | ||
|
||
optOut.setImportStatus(IMPORT_STATUS_COMPLETED); | ||
|
||
optOut.setTimestamp(LocalDate.now(ZoneId.of("UTC"))); | ||
optOut.setCreatedAt(OffsetDateTime.now(ZoneId.of("UTC"))); | ||
optOut.setUpdatedAt(OffsetDateTime.now(ZoneId.of("UTC"))); | ||
|
||
return optOut; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters