use of org.ehrbase.dao.access.interfaces.I_FolderAccess in project ehrbase by ehrbase.
the class FolderAccessTest method shouldDeleteExistingFolder.
@Test
@Ignore
public void shouldDeleteExistingFolder() {
I_FolderAccess fa1 = new FolderAccess(testDomainAccess);
fa1.setFolderId(UUID.fromString("00550555-ec91-4025-838d-09ddb4e999cb"));
int affectedRows = fa1.delete(LocalDateTime.now(), UUID.randomUUID());
// assertEquals(5, affectedRows); commented since metadata indicating that affected rows are 5 could not be mocked. Now checked relyingon the Moch Data Provider that intercepts the SQL code generated.
}
use of org.ehrbase.dao.access.interfaces.I_FolderAccess in project ehrbase by ehrbase.
the class FolderAccessTest method shouldUpdateExistingFolder.
@Test
@Ignore
public void shouldUpdateExistingFolder() throws Exception {
// 1-retrieve a DAO for an existing folder in the DB
FolderAccess fa1 = new FolderAccess(testDomainAccess);
FolderAccess fa2 = (FolderAccess) FolderAccess.retrieveInstanceForExistingFolder(fa1, UUID.fromString("00550555-ec91-4025-838d-09ddb4e999cb"));
assertEquals("folder_archetype.v1", fa2.getFolderRecord().getArchetypeNodeId());
assertEquals("folder_archetype_name_1", fa2.getFolderRecord().getName());
// 2-perform update and persist changes with the previously retrieved DAO
fa2.setFolderName("modifiedName");
fa2.setFolderNArchetypeNodeId("modifiedArchetypeNodeId");
fa2.setIsFolderActive(false);
ItemStructure is = new ItemStructure() {
@Override
public List getItems() {
Item item = new Item() {
@Override
public DvText getName() {
return new DvText("modifiedValue");
}
};
List<Item> items = new ArrayList<>();
items.add(item);
return items;
}
};
// fa2.setFolderDetails(DSL.field(DSL.val("{\"s\": \"modifiedValue\"}") + "::jsonb"));
fa2.setFolderDetails(is);
fa2.setFolderSysTransaction(new Timestamp(DateTime.now().getMillis()));
fa2.setFolderSysPeriod(new AbstractMap.SimpleEntry<>(OffsetDateTime.parse("2019-07-26 11:28:11.631959+02"), null));
// perform updates in a second level subfolder
I_FolderAccess fa3 = fa2.getSubfoldersList().get(UUID.fromString("99550555-ec91-4025-838d-09ddb4e999cb"));
fa3.setFolderName("new name of folder 2");
// perform update second level subfolder
I_FolderAccess fa4 = fa3.getSubfoldersList().get(UUID.fromString("33550555-ec91-4025-838d-09ddb4e999cb"));
fa4.setFolderNArchetypeNodeId("new archetype node id");
// perform update in a third level subforlder
I_FolderAccess fa5 = fa4.getSubfoldersList().get(UUID.fromString("8701233c-c8fd-47ba-91b5-ef9ff23c259b"));
fa5.setIsFolderActive(false);
// the mock data provider checks the UPDATE SQL code generated and returns 1 simulating the update of one row in the FOLDER table.
// this way the correct sql generation is checked indirectly.
boolean updated = false;
updated = fa2.update(LocalDateTime.now(), UUID.randomUUID());
// assertEquals(true, updated);// could not manage to mock the result "Affected row(s) : 1" from updates" for the UPDATEE statement. The mock data provider returns 0 irrespectively of weather the record is modified in the DB or not. As a consequence this always is false in the mocked version.
}
use of org.ehrbase.dao.access.interfaces.I_FolderAccess in project ehrbase by ehrbase.
the class FolderAccessTest method canBuildBasicFolderAccessForInsert.
@Test
public void canBuildBasicFolderAccessForInsert() throws IOException {
UUID ehrId = UUID.randomUUID();
Folder folder = generateFolderFromTestFile(FolderTestDataCanonicalJson.FLAT_FOLDER_INSERT);
I_ContributionAccess contributionAccess = I_ContributionAccess.getInstance(testDomainAccess, ehrId);
I_FolderAccess folderAccess = FolderAccess.buildNewFolderAccessHierarchy(testDomainAccess, folder, Timestamp.from(Instant.now()), ehrId, contributionAccess);
assertThat(folderAccess).isNotNull();
assertThat(folderAccess.getSubfoldersList().size()).isEqualTo(0);
assertThat(folderAccess.getFolderName()).isEqualTo("Flat root");
assertThat(folderAccess.isFolderActive()).isTrue();
}
use of org.ehrbase.dao.access.interfaces.I_FolderAccess in project ehrbase by ehrbase.
the class FolderAccessTest method canBuildNestedFolderAccessForInsert.
@Test
public void canBuildNestedFolderAccessForInsert() throws IOException {
UUID ehrId = UUID.randomUUID();
Folder folder = generateFolderFromTestFile(FolderTestDataCanonicalJson.NESTED_FOLDER);
I_ContributionAccess contributionAccess = I_ContributionAccess.getInstance(testDomainAccess, ehrId);
I_FolderAccess folderAccess = FolderAccess.buildNewFolderAccessHierarchy(testDomainAccess, folder, Timestamp.from(Instant.now()), ehrId, contributionAccess);
assertThat(folderAccess).isNotNull();
assertThat(folderAccess.getSubfoldersList().size()).isEqualTo(2);
assertThat(folderAccess.getFolderName()).isEqualTo("hospital episodes");
}
use of org.ehrbase.dao.access.interfaces.I_FolderAccess in project ehrbase by ehrbase.
the class FolderHistoryAccessTest method shouldRetrieveFolderByTimestampAfterLatestVersion.
@Test
public void shouldRetrieveFolderByTimestampAfterLatestVersion() {
/**
* This test assumes status in the file testFolderVersionsDB.sql
*/
FolderHistoryAccess fa1 = new FolderHistoryAccess(testDomainAccess);
fa1.setFolderId(UUID.fromString("129dc79c-e0bc-4946-bfa6-28ce609bbd2c"));
// GET MOST RECENT VERSION IN TIME
I_FolderAccess returned = fa1.retrieveInstanceForExistingFolder(fa1, UUID.fromString("7f069129-7312-447b-bd71-567305a9a871"), Timestamp.valueOf("2021-12-17 15:10:33.54"));
String middleNodeNamespace = returned.getSubfoldersList().get(UUID.fromString("129dc79c-e0bc-4946-bfa6-28ce609bbd2c")).getItems().get(0).getNamespace();
assertEquals(middleNodeNamespace, "middle leave UPDATED");
// GET VERSION THAT CORRESPONDS TO A TIMESTAMP BETWEEN THE FIRST SUBMISSION AMD THE SECOND UPDATE SO HISTORY VERSIONS ARE RETRIEVED
I_FolderAccess returnedHistoricalVersion = fa1.retrieveInstanceForExistingFolder(fa1, UUID.fromString("7f069129-7312-447b-bd71-567305a9a871"), Timestamp.valueOf("2019-12-07 15:10:33.54"));
String leaveNodeLatestNamespaceHistorical = returnedHistoricalVersion.getSubfoldersList().get(UUID.fromString("129dc79c-e0bc-4946-bfa6-28ce609bbd2c")).getSubfoldersList().get(UUID.fromString("eda6951b-5506-4726-89dc-7032872997ce")).getItems().get(0).getNamespace();
assertEquals(leaveNodeLatestNamespaceHistorical, "namespace leave");
}
Aggregations