From ea207d1aa6b6a87474c49b8aa64d047040ae3dcd Mon Sep 17 00:00:00 2001 From: woodjes Date: Fri, 13 Jan 2023 09:09:03 +0000 Subject: [PATCH] Working ddl for legal entity #CTCTOWALTZ-2626 #6368 --- .../data/legal_entity/LegalEntityDao.java | 53 +++++++++++++++++++ .../LegalRelationshipKindDao.java | 53 +++++++++++++++++++ .../resources/liquibase/db.changelog-1.47.xml | 2 + 3 files changed, 108 insertions(+) create mode 100644 waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalRelationshipKindDao.java diff --git a/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalEntityDao.java b/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalEntityDao.java index c699da3c5a..f8fc52e623 100644 --- a/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalEntityDao.java +++ b/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalEntityDao.java @@ -1,4 +1,57 @@ package org.finos.waltz.data.legal_entity; +import org.finos.waltz.common.DateTimeUtilities; +import org.finos.waltz.model.legal_entity.ImmutableLegalEntity; +import org.finos.waltz.model.legal_entity.LegalEntity; +import org.finos.waltz.model.logical_flow.LogicalFlow; +import org.finos.waltz.schema.tables.records.LegalEntityRecord; +import org.finos.waltz.schema.tables.records.LogicalFlowRecord; +import org.jooq.DSLContext; +import org.jooq.Record; +import org.jooq.RecordMapper; + +import java.sql.Timestamp; +import java.util.Set; + +import static org.finos.waltz.schema.Tables.LEGAL_ENTITY; + public class LegalEntityDao { + + private final DSLContext dsl; + + public LegalEntityDao(DSLContext dsl) { + this.dsl = dsl; + } + + private static final RecordMapper TO_DOMAIN_MAPPER = r -> { + LegalEntityRecord record = r.into(LEGAL_ENTITY); + + return ImmutableLegalEntity.builder() + .id(record.getId()) + .name(record.getName()) + .description(record.getDescription()) + .externalId(record.getExternalId()) + .entityLifecycleStatus(record.getEntityLifecycleStatus()) + .lastUpdatedAt(record.getLastUpdatedAt()) + .lastUpdatedBy(record.getLastUpdatedBy()) + .provenance(record.getProvenance()) + .build(); + }; + + public LegalEntity getById(long id) { + return dsl + .select(LEGAL_ENTITY.fields()) + .from(LEGAL_ENTITY) + .where(LEGAL_ENTITY.ID.eq(id)) + .fetchOne(TO_DOMAIN_MAPPER); + } + + + public Set findAll() { + return dsl + .select(LEGAL_ENTITY.fields()) + .from(LEGAL_ENTITY) + .fetchSet(TO_DOMAIN_MAPPER); + } + } diff --git a/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalRelationshipKindDao.java b/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalRelationshipKindDao.java new file mode 100644 index 0000000000..b0f45c8650 --- /dev/null +++ b/waltz-data/src/main/java/org/finos/waltz/data/legal_entity/LegalRelationshipKindDao.java @@ -0,0 +1,53 @@ +package org.finos.waltz.data.legal_entity; + +import org.finos.waltz.model.legal_entity.ImmutableLegalEntity; +import org.finos.waltz.model.legal_entity.LegalEntity; +import org.finos.waltz.schema.tables.records.LegalEntityRecord; +import org.jooq.DSLContext; +import org.jooq.Record; +import org.jooq.RecordMapper; + +import java.util.Set; + +import static org.finos.waltz.schema.Tables.LEGAL_ENTITY; + +public class LegalRelationshipKindDao { + + private final DSLContext dsl; + + public LegalRelationshipKindDao(DSLContext dsl) { + this.dsl = dsl; + } + + private static final RecordMapper TO_DOMAIN_MAPPER = r -> { + LegalEntityRecord record = r.into(LEGAL_ENTITY); + + return ImmutableLegalEntity.builder() + .id(record.getId()) + .name(record.getName()) + .description(record.getDescription()) + .externalId(record.getExternalId()) + .entityLifecycleStatus(record.getEntityLifecycleStatus()) + .lastUpdatedAt(record.getLastUpdatedAt()) + .lastUpdatedBy(record.getLastUpdatedBy()) + .provenance(record.getProvenance()) + .build(); + }; + + public LegalEntity getById(long id) { + return dsl + .select(LEGAL_ENTITY.fields()) + .from(LEGAL_ENTITY) + .where(LEGAL_ENTITY.ID.eq(id)) + .fetchOne(TO_DOMAIN_MAPPER); + } + + + public Set findAll() { + return dsl + .select(LEGAL_ENTITY.fields()) + .from(LEGAL_ENTITY) + .fetchSet(TO_DOMAIN_MAPPER); + } + +} diff --git a/waltz-schema/src/main/resources/liquibase/db.changelog-1.47.xml b/waltz-schema/src/main/resources/liquibase/db.changelog-1.47.xml index 46353aa39a..31cd1e736f 100644 --- a/waltz-schema/src/main/resources/liquibase/db.changelog-1.47.xml +++ b/waltz-schema/src/main/resources/liquibase/db.changelog-1.47.xml @@ -420,6 +420,8 @@ remarks="when this legal entity record was last updated"/> +