use of com.nedap.archie.rm.support.identification.UIDBasedId in project ehrbase by ehrbase.
the class FolderAccessTest method shouldInsertFolderWithSubfolders.
@Test
@Ignore
public void shouldInsertFolderWithSubfolders() throws Exception {
// the creation and commit returning valid ids implies that the FolderMockDataProvider.java has provided the corresponding result for each SQL generated when inserting
// create folder to insert
Folder folder = new Folder();
UIDBasedId uid = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
ObjectVersionId uidim = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
folder.setUid(uid);
DvText name = new DvText();
name.setValue("nameOfFolder1");
folder.setName(name);
folder.setArchetypeNodeId("archetype_1");
ItemStructure is = new ItemStructure() {
@Override
public List getItems() {
Item item = new Item() {
@Override
public DvText getName() {
return new DvText("fol1");
}
};
List<Item> items = new ArrayList<>();
items.add(item);
return items;
}
};
folder.setDetails(is);
// create subfolder
Folder folder2 = new Folder();
UIDBasedId uid2 = new ObjectVersionId("f0a2af65-fe89-45a4-9456-07c5e17b1634");
ObjectVersionId uidim2 = new ObjectVersionId("f0a2af65-fe89-45a4-9456-07c5e17b1634");
folder2.setUid(uid2);
DvText name2 = new DvText();
name2.setValue("nameOfFolder2");
folder2.setName(name2);
folder2.setArchetypeNodeId("archetype_2");
ItemStructure is2 = new ItemStructure() {
@Override
public List getItems() {
Item item = new Item() {
@Override
public DvText getName() {
return new DvText("fol2");
}
};
List<Item> items = new ArrayList<>();
items.add(item);
return items;
}
};
folder2.setDetails(is2);
// create subfolder (grandson)
Folder folder3 = new Folder();
UIDBasedId uid3 = new ObjectVersionId("f4a2af65-fe89-45a4-9456-07c5e17b1634");
ObjectVersionId uidim3 = new ObjectVersionId("f4a2af65-fe89-45a4-9456-07c5e17b1634");
folder3.setUid(uid3);
DvText name3 = new DvText();
name3.setValue("nameOfFolder3");
folder3.setName(name3);
folder3.setArchetypeNodeId("archetype_3");
ItemStructure is3 = new ItemStructure() {
@Override
public List getItems() {
Item item = new Item() {
@Override
public DvText getName() {
return super.getName();
}
};
List<Item> items = new ArrayList<>();
items.add(item);
return items;
}
};
folder3.setDetails(is3);
// add subfolders
folder.getFolders().add(folder2);
folder2.addFolder(folder3);
// insert folder
FolderAccess fa1 = new FolderAccess(testDomainAccess);
FolderAccess fa2 = (FolderAccess) FolderAccess.getNewFolderAccessInstance(fa1, folder, DateTime.now(), UUID.fromString("f6a2af65-fe89-45a4-9456-07c5e17b1634"));
assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", fa2.getFolderRecord().getId().toString());
assertEquals("archetype_1", fa2.getFolderRecord().getArchetypeNodeId());
assertEquals("nameOfFolder1", fa2.getFolderRecord().getName());
String expected = ("'{\n" + " \"_type\" : \"\",\n" + " \"items\" : [ {\n" + " \"name\" : {\n" + " \"_type\" : \"DV_TEXT\",\n" + " \"value\" : \"fol1\"\n" + " }\n" + " } ]\n" + "}'::jsonb").replaceAll("\\n|\\r\\n", // avoids problems amond different platforms due to different representations of line change.
System.getProperty("line.separator"));
// avoids problems amond different platforms due to different representations of line change.
;
StringWriter expectedStringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(expectedStringWriter);
// avoids problems amond different platforms due to different representations of line change.
printWriter.print(expected);
printWriter.close();
assertEquals(expectedStringWriter.toString(), fa2.getFolderRecord().getDetails().toString());
assertEquals("f0a2af65-fe89-45a4-9456-07c5e17b1634", ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getId().toString());
assertEquals("archetype_2", ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getArchetypeNodeId());
assertEquals("nameOfFolder2", ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getName());
String expected2 = ("'{\n" + " \"_type\" : \"\",\n" + " \"items\" : [ {\n" + " \"name\" : {\n" + " \"_type\" : \"DV_TEXT\",\n" + " \"value\" : \"fol2\"\n" + " }\n" + " } ]\n" + "}'::jsonb").replaceAll("\\n|\\r\\n", // avoids problems amond different platforms due to different representations of line change.
System.getProperty("line.separator"));
expectedStringWriter = new StringWriter();
// avoids problems amond different platforms due to different representations of line change.
printWriter = new PrintWriter(expectedStringWriter);
printWriter.print(expected2);
printWriter.close();
assertEquals(expectedStringWriter.toString(), ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getDetails().toString());
assertEquals("f4a2af65-fe89-45a4-9456-07c5e17b1634", ((FolderAccess) ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getSubfoldersList().get(UUID.fromString("f4a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getId().toString());
assertEquals("archetype_3", ((FolderAccess) ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getSubfoldersList().get(UUID.fromString("f4a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getArchetypeNodeId());
assertEquals("nameOfFolder3", ((FolderAccess) ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getSubfoldersList().get(UUID.fromString("f4a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getName());
String expected3 = ("'{\n" + " \"_type\" : \"\",\n" + " \"items\" : [ { } ]\n" + "}'::jsonb").replaceAll("\\n|\\r\\n", // avoids problems amond different platforms due to different representations of line change.
System.getProperty("line.separator"));
expectedStringWriter = new StringWriter();
printWriter = new PrintWriter(expectedStringWriter);
// avoids problems amond different platforms due to different representations of line change.
printWriter.print(expected3);
assertEquals(expectedStringWriter.toString(), ((FolderAccess) ((FolderAccess) fa2.getSubfoldersList().get(UUID.fromString("f0a2af65-fe89-45a4-9456-07c5e17b1634"))).getSubfoldersList().get(UUID.fromString("f4a2af65-fe89-45a4-9456-07c5e17b1634"))).getFolderRecord().getDetails().toString());
expectedStringWriter.flush();
printWriter.flush();
printWriter.close();
UUID storedFolderUid = fa2.commit(LocalDateTime.now(), UUID.randomUUID());
// commit should return the top level folderId
assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", storedFolderUid.toString());
}
use of com.nedap.archie.rm.support.identification.UIDBasedId in project ehrbase by ehrbase.
the class FolderAccess method buildPlainFolderAccess.
/**
* Builds the FolderAccess with the collection of subfolders empty.
*
* @param domainAccess providing the information about the DB connection.
* @param folder to define a corresponding {@link I_FolderAccess} for allowing its
* persistence.
* @param timestamp that will be set as transaction date when the {@link
* com.nedap.archie.rm.directory.Folder} is persisted
* @param ehrId of the {@link com.nedap.archie.rm.ehr.Ehr} that references this {@link
* com.nedap.archie.rm.directory.Folder}
* @return {@link I_FolderAccess} with the information to persist the provided {@link
* com.nedap.archie.rm.directory.Folder}
*/
public static I_FolderAccess buildPlainFolderAccess(final I_DomainAccess domainAccess, final Folder folder, final Timestamp timestamp, final UUID ehrId, final I_ContributionAccess contributionAccess) {
FolderAccess folderAccessInstance = new FolderAccess(domainAccess, ehrId, contributionAccess);
folderAccessInstance.setEhrId(ehrId);
// In case of creation we have no folderId since it will be created from DB
if (folder.getUid() != null) {
UIDBasedId uid = folder.getUid();
int i = uid.getValue().indexOf("::");
String uidString;
if (i < 0) {
uidString = uid.getValue();
} else {
uidString = uid.getValue().substring(0, i);
}
folderAccessInstance.setFolderId(UUID.fromString(uidString));
}
folderAccessInstance.setInContribution(folderAccessInstance.getContributionAccess().getId());
folderAccessInstance.setFolderName(folder.getName().getValue());
folderAccessInstance.setFolderNArchetypeNodeId(folder.getArchetypeNodeId());
folderAccessInstance.setIsFolderActive(true);
// TODO: Are these guards required?
if (folder.getDetails() != null) {
folderAccessInstance.setFolderDetails(folder.getDetails());
}
if (folder.getItems() != null && !folder.getItems().isEmpty()) {
folderAccessInstance.getItems().addAll(folder.getItems());
}
folderAccessInstance.setFolderSysTransaction(new Timestamp(DateTime.now().getMillis()));
return folderAccessInstance;
}
use of com.nedap.archie.rm.support.identification.UIDBasedId in project ehrbase by ehrbase.
the class FolderAccessTest method shouldInsertFolderWithNoSubfolders.
@Test
@Ignore
public void shouldInsertFolderWithNoSubfolders() throws Exception {
// the creation and commit returning valid ids implies that the FolderMockDataProvider.java has provided the corresponding result for each SQL generated when inserting
// create folder to insert
Folder folder = new Folder();
UIDBasedId uid = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
ObjectVersionId uidim = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
folder.setUid(uid);
DvText name = new DvText();
name.setValue("nameOfFolder");
folder.setName(name);
folder.setArchetypeNodeId("archetype_1");
ItemStructure is = new ItemStructure() {
@Override
public List getItems() {
Item item = new Item() {
@Override
public DvText getName() {
return new DvText("fol1");
}
};
List<Item> items = new ArrayList<>();
items.add(item);
return items;
}
};
folder.setDetails(is);
// insert folder
FolderAccess fa1 = new FolderAccess(testDomainAccess);
FolderAccess fa2 = (FolderAccess) FolderAccess.getNewFolderAccessInstance(fa1, folder, DateTime.now(), UUID.fromString("f6a2af65-fe89-45a4-9456-07c5e17b1634"));
assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", fa2.getFolderRecord().getId().toString());
assertEquals("archetype_1", fa2.getFolderRecord().getArchetypeNodeId());
assertEquals("nameOfFolder", fa2.getFolderRecord().getName());
String expected = ("'{\n" + " \"_type\" : \"\",\n" + " \"items\" : [ {\n" + " \"name\" : {\n" + " \"_type\" : \"DV_TEXT\",\n" + " \"value\" : \"fol1\"\n" + " }\n" + " } ]\n" + "}'::jsonb").replaceAll("\\n|\\r\\n", // avoids problems amond different platforms due to different representations of line change.
System.getProperty("line.separator"));
StringWriter expectedStringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(expectedStringWriter);
// avoids problems amond different platforms due to different representations of line change.
printWriter.print(expected);
printWriter.close();
assertEquals(expectedStringWriter.toString(), fa2.getFolderRecord().getDetails().toString());
// commit and check returned UID is the valid one
UUID storedFolderUid = fa2.commit(LocalDateTime.now(), UUID.randomUUID());
assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", storedFolderUid.toString());
}
Aggregations