Search in sources :

Example 1 with SysPeriodBinder

use of org.ehrbase.jooq.binding.SysPeriodBinder in project ehrbase by ehrbase.

the class FolderAccess method buildFolderAccessFromGenericRecord.

/**
 * Create a new {@link FolderAccess} from a {@link org.jooq.Record} DB record
 *
 * @param record_      record containing all the information to build one folder-subfolder
 *                     relationship.
 * @param domainAccess containing the DB connection information.
 * @return FolderAccess instance
 */
private static FolderAccess buildFolderAccessFromGenericRecord(final Record record_, final I_DomainAccess domainAccess) {
    Record13<UUID, UUID, UUID, Timestamp, Object, UUID, UUID, String, String, Boolean, JSONB, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>> record = (Record13<UUID, UUID, UUID, Timestamp, Object, UUID, UUID, String, String, Boolean, JSONB, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>>) record_;
    FolderAccess folderAccess = new FolderAccess(domainAccess);
    folderAccess.folderRecord = new FolderRecord();
    folderAccess.setFolderId(record.value1());
    folderAccess.setInContribution(record.value7());
    folderAccess.setFolderName(record.value8());
    folderAccess.setFolderNArchetypeNodeId(record.value9());
    folderAccess.setIsFolderActive(record.value10());
    // Due to generic type from JOIN The ItemStructure binding does not cover the details
    // and we have to parse it manually
    folderAccess.setFolderDetails(new OtherDetailsJsonbBinder().converter().from(record.value11()));
    folderAccess.setFolderSysTransaction(record.value12());
    folderAccess.setFolderSysPeriod(new SysPeriodBinder().converter().from(record.value13()));
    folderAccess.getItems().addAll(FolderAccess.retrieveItemsByFolderAndContributionId(record.value1(), record.value7(), domainAccess));
    return folderAccess;
}
Also used : JSONB(org.jooq.JSONB) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) Record13(org.jooq.Record13) OtherDetailsJsonbBinder(org.ehrbase.jooq.binding.OtherDetailsJsonbBinder) Timestamp(java.sql.Timestamp) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) AbstractMap(java.util.AbstractMap) OffsetDateTime(java.time.OffsetDateTime) UUID(java.util.UUID) SysPeriodBinder(org.ehrbase.jooq.binding.SysPeriodBinder)

Example 2 with SysPeriodBinder

use of org.ehrbase.jooq.binding.SysPeriodBinder in project ehrbase by ehrbase.

the class FolderAccess method retrieveItemsByFolderAndContributionId.

/**
 * Retrieves a list containing the items as ObjectRefs of the folder corresponding to the id
 * provided.
 *
 * @param folderId        of the FOLDER that the items correspond to.
 * @param in_contribution contribution that establishes the reference between a FOLDER and its
 *                        item.
 * @param domainAccess    connection DB data.
 * @return
 */
private static List<ObjectRef<?>> retrieveItemsByFolderAndContributionId(UUID folderId, UUID in_contribution, I_DomainAccess domainAccess) {
    Result<Record> retrievedRecords = domainAccess.getContext().with("folderItemsSelect").as(select(FOLDER_ITEMS.OBJECT_REF_ID.as("object_ref_id"), FOLDER_ITEMS.IN_CONTRIBUTION.as("item_in_contribution")).from(FOLDER_ITEMS).where(FOLDER_ITEMS.FOLDER_ID.eq(folderId))).select().from(OBJECT_REF, table(name("folderItemsSelect"))).where(field(name("object_ref_id"), FOLDER_ITEMS.OBJECT_REF_ID.getType()).eq(OBJECT_REF.ID).and(field(name("item_in_contribution"), FOLDER_ITEMS.IN_CONTRIBUTION.getType()).eq(OBJECT_REF.IN_CONTRIBUTION))).fetch();
    List<ObjectRef<?>> result = new ArrayList<>();
    for (Record recordRecord : retrievedRecords) {
        Record8<String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>, UUID, UUID> recordParam = (Record8<String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>, UUID, UUID>) recordRecord;
        ObjectRefRecord objectRef = new ObjectRefRecord();
        objectRef.setIdNamespace(recordParam.value1());
        objectRef.setType(recordParam.value2());
        objectRef.setId(recordParam.value3());
        objectRef.setInContribution(recordParam.value4());
        objectRef.setSysTransaction(recordParam.value5());
        objectRef.setSysPeriod(new SysPeriodBinder().converter().from(recordParam.value6()));
        objectRef.setId(recordParam.value7());
        result.add(parseObjectRefRecordIntoObjectRef(objectRef, domainAccess));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) AbstractMap(java.util.AbstractMap) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) OffsetDateTime(java.time.OffsetDateTime) Record8(org.jooq.Record8) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) FolderHistoryRecord(org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord) ContributionRecord(org.ehrbase.jooq.pg.tables.records.ContributionRecord) Record(org.jooq.Record) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) FolderHierarchyRecord(org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord) FolderItemsRecord(org.ehrbase.jooq.pg.tables.records.FolderItemsRecord) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID) SysPeriodBinder(org.ehrbase.jooq.binding.SysPeriodBinder)

Example 3 with SysPeriodBinder

use of org.ehrbase.jooq.binding.SysPeriodBinder in project ehrbase by ehrbase.

the class FolderHistoryAccess method buildFolderAccessFromGenericRecord.

private static FolderHistoryAccess buildFolderAccessFromGenericRecord(final Record record_, final I_DomainAccess domainAccess) {
    Record15<UUID, UUID, UUID, Timestamp, Object, UUID, Timestamp, UUID, UUID, String, String, Boolean, JSONB, Timestamp, Object> record = (Record15<UUID, UUID, UUID, Timestamp, Object, UUID, Timestamp, UUID, UUID, String, String, Boolean, JSONB, Timestamp, Object>) record_;
    FolderHistoryAccess folderAccess = new FolderHistoryAccess(domainAccess);
    folderAccess.folderRecord = new FolderRecord();
    folderAccess.setFolderId(record.value1());
    folderAccess.setInContribution(record.value3());
    folderAccess.setFolderName(record.value10());
    folderAccess.setFolderNArchetypeNodeId(record.value11());
    folderAccess.setIsFolderActive(record.value12());
    // Due to generic type from JOIN The ItemStructure binding does not cover the details
    // and we have to parse it manually
    folderAccess.setFolderDetails(new OtherDetailsJsonbBinder().converter().from(record.value13()));
    folderAccess.setFolderSysTransaction(record.value14());
    folderAccess.setFolderSysPeriod(new SysPeriodBinder().converter().from(record.value15()));
    folderAccess.getItems().addAll(FolderHistoryAccess.retrieveItemsByFolderAndContributionId(record.value1(), record.value3(), domainAccess));
    return folderAccess;
}
Also used : Record15(org.jooq.Record15) JSONB(org.jooq.JSONB) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) OtherDetailsJsonbBinder(org.ehrbase.jooq.binding.OtherDetailsJsonbBinder) UUID(java.util.UUID) SysPeriodBinder(org.ehrbase.jooq.binding.SysPeriodBinder) Timestamp(java.sql.Timestamp)

Aggregations

Timestamp (java.sql.Timestamp)3 UUID (java.util.UUID)3 SysPeriodBinder (org.ehrbase.jooq.binding.SysPeriodBinder)3 FolderRecord (org.ehrbase.jooq.pg.tables.records.FolderRecord)3 OffsetDateTime (java.time.OffsetDateTime)2 AbstractMap (java.util.AbstractMap)2 OtherDetailsJsonbBinder (org.ehrbase.jooq.binding.OtherDetailsJsonbBinder)2 JSONB (org.jooq.JSONB)2 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)1 ArrayList (java.util.ArrayList)1 I_FolderAccess (org.ehrbase.dao.access.interfaces.I_FolderAccess)1 ContributionRecord (org.ehrbase.jooq.pg.tables.records.ContributionRecord)1 FolderHierarchyRecord (org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord)1 FolderHistoryRecord (org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord)1 FolderItemsRecord (org.ehrbase.jooq.pg.tables.records.FolderItemsRecord)1 ObjectRefRecord (org.ehrbase.jooq.pg.tables.records.ObjectRefRecord)1 Record (org.jooq.Record)1 Record13 (org.jooq.Record13)1 Record15 (org.jooq.Record15)1 Record8 (org.jooq.Record8)1