use of org.ehrbase.dao.access.util.TransactionTime in project ehrbase by ehrbase.
the class FolderAccess method internalUpdate.
private Boolean internalUpdate(final Timestamp transactionTime, boolean rootFolder, UUID parentFolder, UUID oldContribution, UUID newContribution, UUID systemId, UUID committerId, String description, ContributionChangeType contributionChangeType) {
boolean result;
// Set new Contribution for MODIFY
this.setInContribution(newContribution);
// create new folder audit with given values
auditDetailsAccess = new AuditDetailsAccess(this);
auditDetailsAccess.setSystemId(systemId);
auditDetailsAccess.setCommitter(committerId);
auditDetailsAccess.setDescription(description);
auditDetailsAccess.setChangeType(I_ConceptAccess.fetchContributionChangeType(this, contributionChangeType));
UUID auditId = this.auditDetailsAccess.commit();
if (rootFolder) {
// if it is the root folder preserve the original id, otherwise let the DB provide a new one for the overridden subfolders.
folderRecord.setInContribution(newContribution);
folderRecord.setSysTransaction(transactionTime);
getContext().attach(folderRecord);
result = folderRecord.update() > 0;
} else {
// Copy into new instance and attach to DB context.
var updatedFolderRecord = new FolderRecord();
updatedFolderRecord.setInContribution(newContribution);
updatedFolderRecord.setName(this.getFolderName());
updatedFolderRecord.setArchetypeNodeId(this.getFolderArchetypeNodeId());
updatedFolderRecord.setActive(this.isFolderActive());
updatedFolderRecord.setDetails(this.getFolderDetails());
updatedFolderRecord.setSysTransaction(transactionTime);
updatedFolderRecord.setSysPeriod(this.getFolderSysPeriod());
updatedFolderRecord.setHasAudit(auditId);
// attach to context DB
getContext().attach(updatedFolderRecord);
// Save new Folder entry to the database
result = updatedFolderRecord.insert() > 0;
// Finally overwrite original FolderRecord on this FolderAccess instance to have the
// new data available at service layer. Thus we do not need to re-fetch the updated folder
// tree from DB
this.folderRecord = updatedFolderRecord;
// Create FolderHierarchy entries this sub folder instance
var updatedFhR = new FolderHierarchyRecord();
updatedFhR.setParentFolder(parentFolder);
updatedFhR.setChildFolder(updatedFolderRecord.getId());
updatedFhR.setInContribution(newContribution);
updatedFhR.setSysTransaction(transactionTime);
updatedFhR.setSysPeriod(folderRecord.getSysPeriod());
getContext().attach(updatedFhR);
updatedFhR.store();
}
// Get new folder id for folder items and hierarchy
UUID updatedFolderId = this.folderRecord.getId();
// Update items -> Save new list of all items in this folder
this.saveFolderItems(updatedFolderId, oldContribution, newContribution, transactionTime, getContext());
boolean anySubfolderModified = // Map of sub folders with UUID
this.getSubfoldersList().values().stream().map(subfolder -> (// Update each entry and return if there has been at least one entry updated
((FolderAccess) subfolder).internalUpdate(transactionTime, false, updatedFolderId, oldContribution, newContribution, systemId, committerId, description, contributionChangeType))).reduce((b1, b2) -> b1 || b2).orElse(false);
return result || anySubfolderModified;
}
Aggregations