Search in sources :

Example 1 with ContributionChangeType

use of org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType in project ehrbase by ehrbase.

the class FolderAccess method update.

/**
 * {@inheritDoc}
 */
@Override
public boolean update(final LocalDateTime transactionTime, UUID contribution) {
    /*create new contribution*/
    UUID oldContribution = this.folderRecord.getInContribution();
    UUID newContribution;
    // Custom contribution is provided, so use given one
    this.getFolderRecord().setInContribution(contribution);
    newContribution = folderRecord.getInContribution();
    var newContributionAccess = I_ContributionAccess.retrieveInstance(this.getDataAccess(), newContribution);
    UUID systemId = newContributionAccess.getAuditsSystemId();
    UUID committerId = newContributionAccess.getAuditsCommitter();
    String description = newContributionAccess.getAuditsDescription();
    ContributionChangeType changeType = newContributionAccess.getAuditsChangeType();
    return this.internalUpdate(Timestamp.valueOf(transactionTime), true, null, oldContribution, newContribution, systemId, committerId, description, changeType);
}
Also used : ContributionChangeType(org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType) UUID(java.util.UUID)

Example 2 with ContributionChangeType

use of org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType 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;
}
Also used : FOLDER_HISTORY(org.ehrbase.jooq.pg.Tables.FOLDER_HISTORY) Date(java.util.Date) DSL.field(org.jooq.impl.DSL.field) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) Table(org.jooq.Table) Folder(com.nedap.archie.rm.directory.Folder) UIDBasedId(com.nedap.archie.rm.support.identification.UIDBasedId) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) OtherDetailsJsonbBinder(org.ehrbase.jooq.binding.OtherDetailsJsonbBinder) Map(java.util.Map) DSLContext(org.jooq.DSLContext) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) ContributionDataType(org.ehrbase.jooq.pg.enums.ContributionDataType) Record8(org.jooq.Record8) I_ContributionAccess(org.ehrbase.dao.access.interfaces.I_ContributionAccess) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) DSL.name(org.jooq.impl.DSL.name) Timestamp(java.sql.Timestamp) Set(java.util.Set) Field(org.jooq.Field) DSL.select(org.jooq.impl.DSL.select) UUID(java.util.UUID) I_DomainAccess(org.ehrbase.dao.access.interfaces.I_DomainAccess) CONTRIBUTION(org.ehrbase.jooq.pg.Tables.CONTRIBUTION) Instant(java.time.Instant) Result(org.jooq.Result) I_AuditDetailsAccess(org.ehrbase.dao.access.interfaces.I_AuditDetailsAccess) I_ConceptAccess(org.ehrbase.dao.access.interfaces.I_ConceptAccess) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) InternalServerException(org.ehrbase.api.exception.InternalServerException) TransactionTime(org.ehrbase.dao.access.util.TransactionTime) FolderUtils(org.ehrbase.dao.access.util.FolderUtils) FolderHistoryRecord(org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ContributionRecord(org.ehrbase.jooq.pg.tables.records.ContributionRecord) ContributionChangeType(org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType) ContributionDef(org.ehrbase.dao.access.util.ContributionDef) ItemStructure(com.nedap.archie.rm.datastructures.ItemStructure) Record(org.jooq.Record) FOLDER_ITEMS(org.ehrbase.jooq.pg.Tables.FOLDER_ITEMS) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) DateTime(org.joda.time.DateTime) Record13(org.jooq.Record13) FolderHierarchy(org.ehrbase.jooq.pg.tables.FolderHierarchy) FolderHierarchyRecord(org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord) OBJECT_REF(org.ehrbase.jooq.pg.Tables.OBJECT_REF) DataAccess(org.ehrbase.dao.access.support.DataAccess) SysPeriodBinder(org.ehrbase.jooq.binding.SysPeriodBinder) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) FOLDER_HIERARCHY(org.ehrbase.jooq.pg.Tables.FOLDER_HIERARCHY) JSONB(org.jooq.JSONB) FOLDER(org.ehrbase.jooq.pg.Tables.FOLDER) FolderItemsRecord(org.ehrbase.jooq.pg.tables.records.FolderItemsRecord) DSL.table(org.jooq.impl.DSL.table) I_AuditDetailsAccess(org.ehrbase.dao.access.interfaces.I_AuditDetailsAccess) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) FolderHierarchyRecord(org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord) UUID(java.util.UUID) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess)

Example 3 with ContributionChangeType

use of org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType in project ehrbase by ehrbase.

the class ContributionAccess method update.

@Override
public Boolean update(Timestamp transactionTime, UUID committerId, UUID systemId, String contributionType, String contributionState, String contributionChangeType, String description) {
    // set contribution  attributes
    ContributionDataType type = null;
    ContributionDef.ContributionState state = null;
    I_ConceptAccess.ContributionChangeType changeType = null;
    if (contributionType == null)
        type = ContributionDataType.valueOf(contributionType);
    if (contributionState != null)
        state = ContributionDef.ContributionState.valueOf(contributionState);
    if (contributionChangeType != null)
        changeType = I_ConceptAccess.ContributionChangeType.valueOf(contributionChangeType);
    // audit handling will be executed centralized in the following called method
    return update(transactionTime, committerId, systemId, type, state, changeType, description);
}
Also used : ContributionDef(org.ehrbase.dao.access.util.ContributionDef) ContributionDataType(org.ehrbase.jooq.pg.enums.ContributionDataType) ContributionChangeType(org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType)

Aggregations

ContributionChangeType (org.ehrbase.dao.access.interfaces.I_ConceptAccess.ContributionChangeType)3 UUID (java.util.UUID)2 ContributionDef (org.ehrbase.dao.access.util.ContributionDef)2 ContributionDataType (org.ehrbase.jooq.pg.enums.ContributionDataType)2 ItemStructure (com.nedap.archie.rm.datastructures.ItemStructure)1 Folder (com.nedap.archie.rm.directory.Folder)1 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)1 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)1 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)1 UIDBasedId (com.nedap.archie.rm.support.identification.UIDBasedId)1 Timestamp (java.sql.Timestamp)1 Instant (java.time.Instant)1 LocalDateTime (java.time.LocalDateTime)1 OffsetDateTime (java.time.OffsetDateTime)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1