Skip to content

Commit

Permalink
Merge pull request #7049 from deutschebank/db-contrib/waltz-7048-inli…
Browse files Browse the repository at this point in the history
…ne-select-field

inline select field
  • Loading branch information
davidwatkins73 authored Apr 9, 2024
2 parents e7a02aa + 5a578d8 commit a5ea461
Show file tree
Hide file tree
Showing 12 changed files with 614 additions and 454 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

256 changes: 1 addition & 255 deletions waltz-data/src/main/java/org/finos/waltz/data/JooqUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,11 @@
import org.finos.waltz.model.EndOfLifeStatus;
import org.finos.waltz.model.EntityKind;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.ImmutableCommonTableFields;
import org.finos.waltz.model.ImmutableEntityReference;
import org.finos.waltz.model.tally.ImmutableOrderedTally;
import org.finos.waltz.model.tally.ImmutableTally;
import org.finos.waltz.model.tally.OrderedTally;
import org.finos.waltz.model.tally.Tally;
import org.finos.waltz.schema.Tables;
import org.finos.waltz.schema.tables.Actor;
import org.finos.waltz.schema.tables.Application;
import org.finos.waltz.schema.tables.ApplicationGroup;
import org.finos.waltz.schema.tables.AssessmentDefinition;
import org.finos.waltz.schema.tables.ChangeInitiative;
import org.finos.waltz.schema.tables.ComplexityKind;
import org.finos.waltz.schema.tables.CostKind;
import org.finos.waltz.schema.tables.DataType;
import org.finos.waltz.schema.tables.EntityStatisticDefinition;
import org.finos.waltz.schema.tables.FlowClassification;
import org.finos.waltz.schema.tables.FlowClassificationRule;
import org.finos.waltz.schema.tables.InvolvementKind;
import org.finos.waltz.schema.tables.Measurable;
import org.finos.waltz.schema.tables.MeasurableCategory;
import org.finos.waltz.schema.tables.MeasurableRating;
import org.finos.waltz.schema.tables.OrganisationalUnit;
import org.finos.waltz.schema.tables.PhysicalFlow;
import org.finos.waltz.schema.tables.SurveyQuestion;
import org.finos.waltz.schema.tables.SurveyTemplate;
import org.finos.waltz.schema.tables.records.ChangeLogRecord;
import org.jooq.Batch;
import org.jooq.CommonTableExpression;
Expand Down Expand Up @@ -424,246 +403,13 @@ public static int summarizeResults(int[] rcs) {
}



public static CommonTableFields<?> determineCommonTableFields(EntityKind kind) {
return determineCommonTableFields(kind, null);
}


public static CommonTableFields<?> determineCommonTableFields(EntityKind kind, String alias) {
switch (kind) {
case ACTOR:
Actor actor = alias == null ? Tables.ACTOR : Tables.ACTOR.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.ACTOR)
.table(actor)
.idField(actor.ID)
.parentIdField(null)
.nameField(actor.NAME)
.descriptionField(actor.DESCRIPTION)
.externalIdField(actor.EXTERNAL_ID)
.build();
case APPLICATION:
Application app = alias == null ? Tables.APPLICATION : Tables.APPLICATION.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.APPLICATION)
.table(app)
.idField(app.ID)
.parentIdField(null)
.nameField(app.NAME)
.descriptionField(app.DESCRIPTION)
.externalIdField(app.ASSET_CODE)
.build();
case APP_GROUP:
ApplicationGroup ag = alias == null ? Tables.APPLICATION_GROUP : Tables.APPLICATION_GROUP.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.APP_GROUP)
.table(ag)
.idField(ag.ID)
.parentIdField(null)
.nameField(ag.NAME)
.descriptionField(ag.DESCRIPTION)
.externalIdField(ag.EXTERNAL_ID)
.build();
case ASSESSMENT_DEFINITION:
AssessmentDefinition ad = alias == null ? Tables.ASSESSMENT_DEFINITION : Tables.ASSESSMENT_DEFINITION.as("alias");
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.ASSESSMENT_DEFINITION)
.table(ad)
.idField(ad.ID)
.parentIdField(null)
.nameField(ad.NAME)
.descriptionField(ad.DESCRIPTION)
.externalIdField(ad.EXTERNAL_ID)
.build();
case CHANGE_INITIATIVE:
ChangeInitiative ci = alias == null ? Tables.CHANGE_INITIATIVE : Tables.CHANGE_INITIATIVE.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.CHANGE_INITIATIVE)
.table(ci)
.idField(ci.ID)
.parentIdField(ci.PARENT_ID)
.nameField(ci.NAME)
.descriptionField(ci.DESCRIPTION)
.externalIdField(ci.EXTERNAL_ID)
.build();
case COMPLEXITY_KIND:
ComplexityKind cxk = alias == null ? Tables.COMPLEXITY_KIND : Tables.COMPLEXITY_KIND.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.COMPLEXITY_KIND)
.table(cxk)
.idField(cxk.ID)
.parentIdField(null)
.nameField(cxk.NAME)
.descriptionField(cxk.DESCRIPTION)
.externalIdField(cxk.EXTERNAL_ID)
.build();
case COST_KIND:
CostKind ck = alias == null ? Tables.COST_KIND : Tables.COST_KIND.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.COST_KIND)
.table(ck)
.idField(ck.ID)
.parentIdField(null)
.nameField(ck.NAME)
.descriptionField(ck.DESCRIPTION)
.externalIdField(ck.EXTERNAL_ID)
.build();
case DATA_TYPE:
DataType dt = alias == null ? Tables.DATA_TYPE : Tables.DATA_TYPE.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.DATA_TYPE)
.table(dt)
.idField(dt.ID)
.parentIdField(dt.PARENT_ID)
.nameField(dt.NAME)
.descriptionField(dt.DESCRIPTION)
.externalIdField(dt.CODE)
.build();
case ENTITY_STATISTIC:
EntityStatisticDefinition esd = alias == null ? Tables.ENTITY_STATISTIC_DEFINITION : Tables.ENTITY_STATISTIC_DEFINITION.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.ENTITY_STATISTIC)
.table(esd)
.idField(esd.ID)
.parentIdField(esd.PARENT_ID)
.nameField(esd.NAME)
.descriptionField(esd.DESCRIPTION)
.externalIdField(esd.EXTERNAL_ID)
.build();
case FLOW_CLASSIFICATION_RULE:
FlowClassificationRule fcr = alias == null ? Tables.FLOW_CLASSIFICATION_RULE : Tables.FLOW_CLASSIFICATION_RULE.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.FLOW_CLASSIFICATION_RULE)
.table(fcr)
.idField(fcr.ID)
.parentIdField(null)
.nameField(null)
.descriptionField(null)
.externalIdField(null)
.build();
case FLOW_CLASSIFICATION:
FlowClassification fc = alias == null ? Tables.FLOW_CLASSIFICATION : Tables.FLOW_CLASSIFICATION.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.FLOW_CLASSIFICATION)
.table(fc)
.idField(fc.ID)
.parentIdField(null)
.nameField(fc.NAME)
.descriptionField(fc.DESCRIPTION)
.externalIdField(fc.CODE)
.build();
case INVOLVEMENT_KIND:
InvolvementKind ik = alias == null ? Tables.INVOLVEMENT_KIND : Tables.INVOLVEMENT_KIND.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.INVOLVEMENT_KIND)
.table(ik)
.idField(ik.ID)
.parentIdField(null)
.nameField(ik.NAME)
.descriptionField(ik.DESCRIPTION)
.externalIdField(ik.EXTERNAL_ID)
.build();
case MEASURABLE:
Measurable m = alias == null ? Tables.MEASURABLE : Tables.MEASURABLE.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.MEASURABLE)
.table(m)
.idField(m.ID)
.parentIdField(m.PARENT_ID)
.nameField(m.NAME)
.descriptionField(m.DESCRIPTION)
.externalIdField(m.EXTERNAL_ID)
.build();
case MEASURABLE_CATEGORY:
MeasurableCategory mc = alias == null ? Tables.MEASURABLE_CATEGORY : Tables.MEASURABLE_CATEGORY.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.MEASURABLE_CATEGORY)
.table(mc)
.idField(mc.ID)
.parentIdField(null)
.nameField(mc.NAME)
.descriptionField(mc.DESCRIPTION)
.externalIdField(mc.EXTERNAL_ID)
.build();
case MEASURABLE_RATING:
MeasurableRating mr = alias == null ? Tables.MEASURABLE_RATING : Tables.MEASURABLE_RATING.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.MEASURABLE_RATING)
.table(mr)
.idField(mr.ID)
.parentIdField(null)
.nameField(null)
.descriptionField(mr.DESCRIPTION)
.externalIdField(null)
.build();
case ORG_UNIT:
OrganisationalUnit ou = alias == null ? Tables.ORGANISATIONAL_UNIT : Tables.ORGANISATIONAL_UNIT.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.ORG_UNIT)
.table(ou)
.idField(ou.ID)
.parentIdField(ou.PARENT_ID)
.nameField(ou.NAME)
.descriptionField(ou.DESCRIPTION)
.externalIdField(ou.EXTERNAL_ID)
.build();
case SURVEY_QUESTION:
SurveyQuestion sq = alias == null ? Tables.SURVEY_QUESTION : Tables.SURVEY_QUESTION.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.SURVEY_QUESTION)
.table(sq)
.idField(sq.ID)
.parentIdField(null)
.nameField(sq.QUESTION_TEXT)
.descriptionField(sq.HELP_TEXT)
.externalIdField(sq.EXTERNAL_ID)
.build();
case SURVEY_TEMPLATE:
SurveyTemplate st = alias == null ? Tables.SURVEY_TEMPLATE : Tables.SURVEY_TEMPLATE.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.SURVEY_TEMPLATE)
.table(st)
.idField(st.ID)
.parentIdField(null)
.nameField(st.NAME)
.descriptionField(st.DESCRIPTION)
.externalIdField(st.EXTERNAL_ID)
.build();
case PHYSICAL_FLOW:
PhysicalFlow pf = alias == null ? Tables.PHYSICAL_FLOW : Tables.PHYSICAL_FLOW.as(alias);
return ImmutableCommonTableFields
.builder()
.entityKind(EntityKind.PHYSICAL_FLOW)
.table(pf)
.idField(pf.ID)
.parentIdField(null)
.nameField(pf.NAME)
.descriptionField(pf.DESCRIPTION)
.externalIdField(pf.EXTERNAL_ID)
.build();
default:
throw new UnsupportedOperationException("Cannot determine table fields for entity kind:" + kind);
}
return CommonTableFieldsRegistry.determineCommonTableFields(kind, alias);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.CollectionUtilities.isEmpty;
import static org.finos.waltz.common.DateTimeUtilities.toLocalDateTime;
import static org.finos.waltz.common.ListUtilities.newArrayList;
import static org.finos.waltz.common.MapUtilities.groupBy;
import static org.finos.waltz.common.SetUtilities.*;
import static org.finos.waltz.common.SetUtilities.asSet;
import static org.finos.waltz.common.SetUtilities.intersection;
import static org.finos.waltz.common.SetUtilities.map;
import static org.finos.waltz.common.SetUtilities.maybeAdd;
import static org.finos.waltz.common.SetUtilities.union;
import static org.finos.waltz.common.StringUtilities.mkSafe;
import static org.finos.waltz.common.StringUtilities.notEmpty;
import static org.finos.waltz.common.StringUtilities.sanitizeCharacters;
Expand All @@ -98,18 +101,15 @@ public class AssessmentRatingDao {

private static final Field<String> ENTITY_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
ar.ENTITY_ID,
ar.ENTITY_KIND,
newArrayList(EntityKind.values())).as("entity_name");
ar.ENTITY_KIND).as("entity_name");

private static final Field<String> ENTITY_LIFECYCLE_FIELD = InlineSelectFieldFactory.mkEntityLifecycleField(
ar.ENTITY_ID,
ar.ENTITY_KIND,
newArrayList(EntityKind.values())).as("entity_lifecycle_status");
ar.ENTITY_KIND).as("entity_lifecycle_status");

private static final Field<String> ENTITY_EXTID_FIELD = InlineSelectFieldFactory.mkExternalIdField(
ar.ENTITY_ID,
ar.ENTITY_KIND,
newArrayList(EntityKind.values())).as("entity_external_id");
ar.ENTITY_KIND).as("entity_external_id");

private static final RecordMapper<? super Record, AssessmentRating> TO_DOMAIN_MAPPER = r -> {
AssessmentRatingRecord record = r.into(ar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import static org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp;
import static org.finos.waltz.common.DateTimeUtilities.toLocalDate;
import static org.finos.waltz.common.DateTimeUtilities.toSqlDate;
import static org.finos.waltz.common.ListUtilities.newArrayList;
import static org.finos.waltz.schema.tables.AttestationInstance.ATTESTATION_INSTANCE;
import static org.finos.waltz.schema.tables.AttestationInstanceRecipient.ATTESTATION_INSTANCE_RECIPIENT;
import static org.finos.waltz.schema.tables.AttestationRun.ATTESTATION_RUN;
Expand All @@ -71,14 +70,12 @@ public class AttestationRunDao {

private static final Field<String> ENTITY_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
ATTESTATION_RUN.SELECTOR_ENTITY_ID,
ATTESTATION_RUN.SELECTOR_ENTITY_KIND,
newArrayList(EntityKind.values()))
ATTESTATION_RUN.SELECTOR_ENTITY_KIND)
.as("entity_name");

private static final Field<String> ATTESTED_ENTITY_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
ATTESTATION_RUN.ATTESTED_ENTITY_ID,
ATTESTATION_RUN.ATTESTED_ENTITY_KIND,
newArrayList(EntityKind.values()))
ATTESTATION_RUN.ATTESTED_ENTITY_KIND)
.as("attested_entity_name");

private static final Field<BigDecimal> COMPLETE_SUM = DSL.sum(DSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.DateTimeUtilities.toLocalDateTime;
import static org.finos.waltz.common.ListUtilities.newArrayList;
import static org.finos.waltz.schema.Tables.CHANGE_SET;
import static org.finos.waltz.schema.Tables.INVOLVEMENT;

Expand All @@ -54,8 +53,7 @@ public class ChangeSetDao {

private static final Field<String> ENTITY_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
CHANGE_SET.PARENT_ENTITY_ID,
CHANGE_SET.PARENT_ENTITY_KIND,
newArrayList(EntityKind.values()))
CHANGE_SET.PARENT_ENTITY_KIND)
.as("entity_name");

public static final RecordMapper<Record, ChangeSet> TO_DOMAIN_MAPPER = r -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
import java.util.function.Function;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.ListUtilities.newArrayList;
import static org.finos.waltz.schema.Tables.CHANGE_INITIATIVE;
import static org.finos.waltz.schema.Tables.END_USER_APPLICATION;
import static org.finos.waltz.schema.tables.Involvement.INVOLVEMENT;
Expand All @@ -69,8 +72,7 @@ public class InvolvementDao {
private static final Field<String> ENTITY_NAME_FIELD = InlineSelectFieldFactory
.mkNameField(
INVOLVEMENT.ENTITY_ID,
INVOLVEMENT.ENTITY_KIND,
newArrayList(EntityKind.values()))
INVOLVEMENT.ENTITY_KIND)
.as("entity_name");

private final RecordMapper<Record, Involvement> TO_MODEL_MAPPER = r -> {
Expand Down
Loading

0 comments on commit a5ea461

Please sign in to comment.