Skip to content

Commit

Permalink
Merge pull request #74 from AAFC-BICoE/34789_Allow_to_save_export_con…
Browse files Browse the repository at this point in the history
…figs

34789 Allow to save export configs
  • Loading branch information
johnphan96 authored Sep 11, 2024
2 parents b4ea171 + b6673c9 commit c0b829d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package ca.gc.aafc.dinauser.api.dto;

import ca.gc.aafc.dina.dto.RelatedEntity;
import ca.gc.aafc.dinauser.api.entity.ExportColumnSelection;
import ca.gc.aafc.dinauser.api.entity.UserPreference;
import io.crnk.core.resource.annotations.JsonApiField;
import io.crnk.core.resource.annotations.JsonApiId;
import io.crnk.core.resource.annotations.JsonApiResource;
import io.crnk.core.resource.annotations.PatchStrategy;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -38,6 +40,9 @@ public class UserPreferenceDto {
@JsonApiField(patchStrategy = PatchStrategy.SET)
private Map<String, Object> savedSearches;

@JsonApiField(patchStrategy = PatchStrategy.SET)
private List<ExportColumnSelection> savedExportColumnSelection = List.of();

private UUID userId;
private OffsetDateTime createdOn;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ca.gc.aafc.dinauser.api.entity;

import java.util.List;
import javax.validation.constraints.Size;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExportColumnSelection {

@NotEmpty
@Size(max = 150)
private String name;

@NotEmpty
@Size(max = 50)
private String component;

@NotNull
private List<String> columns;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ca.gc.aafc.dina.entity.DinaEntity;

import io.hypersistence.utils.hibernate.type.json.JsonBinaryType;
import java.util.List;
import javax.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -54,6 +56,11 @@ public class UserPreference implements DinaEntity {
@Column(name = "saved_searches", columnDefinition = "jsonb")
private Map<String, Object> savedSearches;

@Type(type = "jsonb")
@Column(name = "saved_export_column_selection", columnDefinition = "jsonb")
@Valid
private List<ExportColumnSelection> savedExportColumnSelection = List.of();

@Column(name = "created_on", insertable = false, updatable = false)
@Generated(value = GenerationTime.INSERT)
private OffsetDateTime createdOn;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<include file="db/changelog/db.changelog-init.xml"/>
<include file="db/changelog/migrations/1-Add_saved_searches_user_preference_table.xml"/>
<include file="db/changelog/migrations/2-Add_uuid_to_user_preference_table.xml"/>
<include file="db/changelog/migrations/3-Add_saved_export_column_selection_to_user_preference_table.xml"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no" ?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://local.xsd/dbchangelog-4.4.xsd"
context="schema-change">

<changeSet context="schema-change" id="2-Add_uuid_to_user_preference_table.xml" author="Brandon Andre">

<addColumn tableName="user_preference">
<column name="saved_export_column_selection" type="jsonb"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringBootTest(classes = DinaUserModuleApiLauncher.class)
@TestPropertySource(properties = "spring.config.additional-location=classpath:application-test.yml")
@ContextConfiguration(initializers = PostgresTestContainerInitializer.class)
Expand Down Expand Up @@ -64,11 +67,11 @@ void create_validResource_recordCreated() {
UUID savedId = persistUserPreferenceDto(expectedUserId);
UserPreferenceDto result = repo.findOne(savedId, querySpec);

Assertions.assertEquals(savedId, result.getUuid());
Assertions.assertEquals("value", result.getUiPreference().get("key"));
Assertions.assertEquals(TestResourceHelper.readContentAsJsonMap(TEST_RESOURCE_PATH +SAVED_SEARCH_RESOURCE), result.getSavedSearches());
Assertions.assertEquals(expectedUserId, result.getUserId());
Assertions.assertNotNull(result.getCreatedOn());
assertEquals(savedId, result.getUuid());
assertEquals("value", result.getUiPreference().get("key"));
assertEquals(TestResourceHelper.readContentAsJsonMap(TEST_RESOURCE_PATH +SAVED_SEARCH_RESOURCE), result.getSavedSearches());
assertEquals(expectedUserId, result.getUserId());
assertNotNull(result.getCreatedOn());

//cleanup
Assertions.assertDoesNotThrow(() -> repo.delete(savedId));
Expand Down Expand Up @@ -100,8 +103,8 @@ void find_byUserID_recordFound() {
List<UserPreferenceDto> resultList = repo.findAll(null, customQuery);

// Ensure that the record with the expectedUserId1 UUID was brought back.
Assertions.assertEquals(1, resultList.size());
Assertions.assertEquals(expectedUserId1, resultList.get(0).getUserId());
assertEquals(1, resultList.size());
assertEquals(expectedUserId1, resultList.get(0).getUserId());

//cleanup
Assertions.assertDoesNotThrow(() -> repo.delete(savedId1));
Expand All @@ -124,7 +127,7 @@ void update_validUpdate_recordUpdated() {

// Ensure the user preference has been updated.
UserPreferenceDto updatedResult = repo.findOne(savedId, querySpec);
Assertions.assertEquals(TestResourceHelper.readContentAsJsonMap(TEST_RESOURCE_PATH +UPDATED_SAVED_SEARCH_RESOURCE), updatedResult.getSavedSearches());
assertEquals(TestResourceHelper.readContentAsJsonMap(TEST_RESOURCE_PATH +UPDATED_SAVED_SEARCH_RESOURCE), updatedResult.getSavedSearches());

Assertions.assertDoesNotThrow(() -> repo.delete(savedId));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package ca.gc.aafc.dinauser.api.testsupport.fixtures;

import ca.gc.aafc.dinauser.api.dto.UserPreferenceDto;
import ca.gc.aafc.dinauser.api.entity.ExportColumnSelection;

import java.util.List;
import java.util.Map;
import java.util.UUID;

public class UserPreferenceFixture {

public static UserPreferenceDto.UserPreferenceDtoBuilder newUserPreferenceDto(UUID expectedUserId) {
public static UserPreferenceDto.UserPreferenceDtoBuilder newUserPreferenceDto(
UUID expectedUserId) {
return UserPreferenceDto.builder()
.uiPreference(Map.of("key", "value"))
.userId(expectedUserId);
.uiPreference(Map.of("key", "value"))
.savedExportColumnSelection(List.of(ExportColumnSelection.builder()
.name("my export columns").component("material-sample").columns(List.of("col1", "col2"))
.build()))
.userId(expectedUserId);
}

}

0 comments on commit c0b829d

Please sign in to comment.