use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class FolderAccess method retrieveFolderVersionIdsInContribution.
/**
* Retrieve a set of all folders from a given contribution.
*
* @param domainAccess Domain access object
* @param contribution Given contribution ID to check for
* @param nodeName Nodename (e.g. "[...]::NODENAME::[...]") from the service layer, which is
* not accessible in the access layer
* @return Set of version ID of matching folders
*/
public static Set<ObjectVersionId> retrieveFolderVersionIdsInContribution(I_DomainAccess domainAccess, UUID contribution, String nodeName) {
// Set, because of unique values
Set<UUID> folders = new HashSet<>();
// add all folders having a link to given contribution
domainAccess.getContext().select(FOLDER.ID).from(FOLDER).where(FOLDER.IN_CONTRIBUTION.eq(contribution)).fetch().forEach(rec -> folders.add(rec.value1()));
// and older versions or deleted ones, too
domainAccess.getContext().select(FOLDER_HISTORY.ID).from(FOLDER_HISTORY).where(FOLDER_HISTORY.IN_CONTRIBUTION.eq(contribution)).fetch().forEach(rec -> folders.add(rec.value1()));
// get whole "version map" of each matching folder and do fine-grain check for matching contribution
// precondition: each UUID in `folders` set is unique, so for each the "version map" is only created once below
// (meta: can't do that as jooq query, because the specific version number isn't stored in DB)
Set<ObjectVersionId> result = new HashSet<>();
for (UUID folderId : folders) {
Map<Record, Integer> map = getVersionMapOfFolder(domainAccess, folderId);
// fine-grained contribution ID check
for (Map.Entry<Record, Integer> entry : map.entrySet()) {
// record can be of type FolderRecord or FolderHistoryRecord
if (entry.getKey().getClass().equals(FolderRecord.class)) {
FolderRecord rec = (FolderRecord) entry.getKey();
if (rec.getInContribution().equals(contribution)) // set version ID
{
result.add(new ObjectVersionId(rec.getId().toString() + "::" + nodeName + "::" + entry.getValue()));
}
} else if (entry.getKey().getClass().equals(FolderHistoryRecord.class)) {
FolderHistoryRecord rec = (FolderHistoryRecord) entry.getKey();
if (rec.getInContribution().equals(contribution)) // set version ID
{
result.add(new ObjectVersionId(rec.getId().toString() + "::" + nodeName + "::" + entry.getValue()));
}
}
}
}
return result;
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class StatusAccess method retrieveInstanceByContribution.
public static Map<ObjectVersionId, I_StatusAccess> retrieveInstanceByContribution(I_DomainAccess domainAccess, UUID contributionId, String node) {
// Set, because of unique values
Set<UUID> statuses = new HashSet<>();
// add all compositions having a link to given contribution
domainAccess.getContext().select(STATUS.ID).from(STATUS).where(STATUS.IN_CONTRIBUTION.eq(contributionId)).fetch().forEach(rec -> statuses.add(rec.value1()));
// and older versions or deleted ones, too
domainAccess.getContext().select(STATUS_HISTORY.ID).from(STATUS_HISTORY).where(STATUS_HISTORY.IN_CONTRIBUTION.eq(contributionId)).fetch().forEach(rec -> statuses.add(rec.value1()));
// get whole "version map" of each matching status and do fine-grain check for matching contribution
// precondition: each UUID in `statuses` set is unique, so for each the "version map" is only created once below
// (meta: can't do that as jooq query, because the specific version number isn't stored in DB)
Map<ObjectVersionId, I_StatusAccess> resultMap = new HashMap<>();
for (UUID statusId : statuses) {
Map<Integer, I_StatusAccess> map = getVersionMapOfStatus(domainAccess, statusId);
// fine-grained contribution ID check
map.forEach((k, v) -> {
if (v.getContributionId().equals(contributionId)) {
resultMap.put(new ObjectVersionId(statusId.toString(), node, k.toString()), v);
}
});
}
return resultMap;
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId 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());
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class OpenehrDirectoryController method checkDirectoryVersionConflicts.
private void checkDirectoryVersionConflicts(ObjectVersionId requestedFolderId, UUID ehrId) {
UUID directoryUuid = ehrService.getDirectoryId(ehrId);
int latestVersion = folderService.getLastVersionNumber(new ObjectVersionId(directoryUuid.toString()));
// TODO: Change column 'directory' in EHR to String with ObjectVersionId
String directoryId = String.format("%s::%s::%d", directoryUuid, ehrService.getServerConfig().getNodename(), latestVersion);
if (requestedFolderId != null && !requestedFolderId.toString().equals(directoryId)) {
throw new PreconditionFailedException("If-Match version_uid does not match latest version.", directoryId, encodePath(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId.toString() + "/directory/" + directoryId));
}
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class ContributionServiceImp method getVersionedUidFromVersion.
/**
* Create versionUid UUID from retrieved precedingVersionUid from payload (and do sanity checks before continuing), or throw errors if ID is not present nor valid.
* Note: The precedingVersionUid parameter technically is optional for contributions but necessary when invoking other change types than creation.
* @param version RM object of Version type
* @return versionedUid
* @throws IllegalArgumentException Given {@link Version} has no or no valid precedingVersionUid
*/
private UUID getVersionedUidFromVersion(Version version) {
ObjectVersionId precedingVersionUid = version.getPrecedingVersionUid();
if (precedingVersionUid == null) {
throw new IllegalArgumentException("Input invalid. Composition can't be modified without pointer to precedingVersionUid in Version container.");
}
if (precedingVersionUid.toString().split("::").length != 3) {
throw new IllegalArgumentException("Input invalid. Given precedingVersionUid is not a versionUid.");
}
String versionedUid = precedingVersionUid.toString().split("::")[0];
return UUID.fromString(versionedUid);
}
Aggregations