Skip to content

Commit 50cdd08

Browse files
Merge pull request #6784 from deutschebank/db-contrib/waltz-6763-survey-section-rework
Db contrib/waltz 6763 survey section rework
2 parents 483ad51 + 69e0e23 commit 50cdd08

14 files changed

Lines changed: 528 additions & 37 deletions

File tree

waltz-data/src/main/java/org/finos/waltz/data/involvement/InvolvementDao.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ public List<Involvement> findAllByEmployeeId(String employeeId) {
177177

178178

179179
public List<Person> findPeopleByEntityReference(EntityReference ref) {
180-
return dsl.selectDistinct(PERSON.fields())
180+
return dsl
181+
.selectDistinct(PERSON.fields())
181182
.from(PERSON)
182183
.innerJoin(INVOLVEMENT)
183184
.on(INVOLVEMENT.ENTITY_ID.eq(ref.id()))

waltz-data/src/main/java/org/finos/waltz/data/survey/SurveyInstanceDao.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ public int deleteForSurveyRun(long surveyRunId) {
316316
public int updateStatus(long instanceId, SurveyInstanceStatus newStatus) {
317317
checkNotNull(newStatus, "newStatus cannot be null");
318318

319-
return dsl.update(si)
319+
return dsl
320+
.update(si)
320321
.set(si.STATUS, newStatus.name())
321322
.where(si.STATUS.notEqual(newStatus.name())
322-
.and(si.ID.eq(instanceId)))
323+
.and(si.ID.eq(instanceId))
324+
.and(si.ORIGINAL_INSTANCE_ID.isNull()))
323325
.execute();
324326
}
325327

@@ -366,34 +368,53 @@ public int updateOwningRoleForSurveyRun(long surveyRunId, String role) {
366368
}
367369

368370

369-
public int updateSubmitted(long instanceId, String userName) {
371+
public int markSubmitted(long instanceId, String userName) {
370372
checkNotNull(userName, "userName cannot be null");
371373

372-
return dsl.update(si)
374+
return dsl
375+
.update(si)
376+
.set(si.STATUS, SurveyInstanceStatus.COMPLETED.name())
373377
.set(si.SUBMITTED_AT, Timestamp.valueOf(nowUtc()))
374378
.set(si.SUBMITTED_BY, userName)
375-
.where(si.ID.eq(instanceId))
379+
.where(si.ID.eq(instanceId)
380+
.and(si.ORIGINAL_INSTANCE_ID.isNull())
381+
.and(si.STATUS.in(
382+
SurveyInstanceStatus.NOT_STARTED.name(),
383+
SurveyInstanceStatus.IN_PROGRESS.name())))
376384
.execute();
377385
}
378386

379387

380388
public int markApproved(long instanceId, String userName) {
381389
checkNotNull(userName, "userName cannot be null");
382390

383-
return dsl.update(si)
391+
return dsl
392+
.update(si)
384393
.set(si.APPROVED_AT, Timestamp.valueOf(nowUtc()))
385394
.set(si.APPROVED_BY, userName)
386395
.set(si.STATUS, SurveyInstanceStatus.APPROVED.name())
387-
.where(si.ID.eq(instanceId))
396+
.where(si.ID.eq(instanceId)
397+
.and(si.ORIGINAL_INSTANCE_ID.isNull())
398+
.and(si.STATUS.eq(SurveyInstanceStatus.COMPLETED.name())))
388399
.execute();
389400
}
390401

391402

392-
public void clearApproved(long instanceId) {
393-
dsl.update(si)
403+
public int reopenSurvey(long instanceId) {
404+
return dsl
405+
.update(si)
406+
.set(si.STATUS, SurveyInstanceStatus.IN_PROGRESS.name())
394407
.set(si.APPROVED_AT, (Timestamp) null)
395408
.set(si.APPROVED_BY, (String) null)
396-
.where(si.ID.eq(instanceId))
409+
.set(si.SUBMITTED_AT, (Timestamp) null)
410+
.set(si.SUBMITTED_BY, (String) null)
411+
.set(si.ISSUED_ON, toSqlDate(nowUtcTimestamp())) //update the issued on to the current date
412+
.where(si.ID.eq(instanceId)
413+
.and(si.ORIGINAL_INSTANCE_ID.isNull())
414+
.and(si.STATUS.in(
415+
SurveyInstanceStatus.APPROVED.name(),
416+
SurveyInstanceStatus.REJECTED.name(),
417+
SurveyInstanceStatus.WITHDRAWN.name())))
397418
.execute();
398419
}
399420

waltz-data/src/main/java/org/finos/waltz/data/survey/SurveyViewDao.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
import org.finos.waltz.model.survey.SurveyInstanceStatus;
3131
import org.finos.waltz.model.survey.SurveyIssuanceKind;
3232
import org.finos.waltz.model.survey.SurveyRunStatus;
33+
import org.finos.waltz.schema.tables.SurveyInstance;
3334
import org.finos.waltz.schema.tables.records.SurveyInstanceRecord;
3435
import org.finos.waltz.schema.tables.records.SurveyRunRecord;
36+
import org.jooq.AggregateFunction;
3537
import org.jooq.Condition;
3638
import org.jooq.DSLContext;
3739
import org.jooq.Field;
3840
import org.jooq.Record;
41+
import org.jooq.Record1;
42+
import org.jooq.Select;
3943
import org.jooq.SelectConditionStep;
44+
import org.jooq.impl.DSL;
4045
import org.springframework.beans.factory.annotation.Autowired;
4146
import org.springframework.stereotype.Repository;
4247

@@ -78,10 +83,13 @@ public class SurveyViewDao {
7883
.as("external_id");
7984

8085
private static final String ID_SEPARATOR = ";";
81-
8286
private static final Condition IS_ORIGINAL_INSTANCE_CONDITION = SURVEY_INSTANCE.ORIGINAL_INSTANCE_ID.isNull();
8387

84-
private static SurveyInstanceInfo mkSurveyInstanceInfo(Record r, Map<Long, List<Long>> surveyInvolvementGroupKindIds) {
88+
private static final SurveyInstance historicalVersion = SURVEY_INSTANCE.as("historicalVersion");
89+
90+
private static SurveyInstanceInfo mkSurveyInstanceInfo(Record r,
91+
Map<Long, List<Long>> surveyInvolvementGroupKindIds,
92+
Map<Long, Integer> historicalVersions) {
8593

8694
SurveyInstanceRecord instanceRecord = r.into(SURVEY_INSTANCE);
8795
ImmutableSurveyInstance surveyInstance = ImmutableSurveyInstance.builder()
@@ -140,6 +148,8 @@ private static SurveyInstanceInfo mkSurveyInstanceInfo(Record r, Map<Long, List<
140148
.status(SurveyRunStatus.valueOf(runRecord.getStatus()))
141149
.build();
142150

151+
Integer historicalVersionCount = historicalVersions.getOrDefault(surveyInstance.id().get(), 0);
152+
143153
return ImmutableSurveyInstanceInfo.builder()
144154
.surveyInstance(surveyInstance)
145155
.surveyRun(run)
@@ -149,6 +159,7 @@ private static SurveyInstanceInfo mkSurveyInstanceInfo(Record r, Map<Long, List<
149159
r.get(SURVEY_TEMPLATE.NAME),
150160
r.get(SURVEY_TEMPLATE.DESCRIPTION),
151161
r.get(SURVEY_TEMPLATE.EXTERNAL_ID)))
162+
.historicalVersionsCount(historicalVersionCount)
152163
.build();
153164
};
154165

@@ -166,6 +177,7 @@ public SurveyViewDao(DSLContext dsl) {
166177
public SurveyInstanceInfo getById(long instanceId) {
167178

168179
Map<Long, List<Long>> surveyInvolvementGroupKindIds = findSurveyInvolvementGroupKindIds();
180+
Map<Long, Integer> historicalVersions = getHistoricalVersionCounts(historicalVersion.ORIGINAL_INSTANCE_ID.eq(instanceId));
169181

170182
return dsl
171183
.select(SURVEY_INSTANCE.fields())
@@ -181,14 +193,16 @@ public SurveyInstanceInfo getById(long instanceId) {
181193
.innerJoin(SURVEY_RUN).on(SURVEY_INSTANCE.SURVEY_RUN_ID.eq(SURVEY_RUN.ID))
182194
.innerJoin(SURVEY_TEMPLATE).on(SURVEY_RUN.SURVEY_TEMPLATE_ID.eq(SURVEY_TEMPLATE.ID))
183195
.where(SURVEY_INSTANCE.ID.eq(instanceId))
184-
.fetchOne(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds));
196+
.fetchOne(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds, historicalVersions));
185197
}
186198

187199

188200
public Set<SurveyInstanceInfo> findForRecipient(long personId) {
189201

190202
Map<Long, List<Long>> surveyInvolvementGroupKindIds = findSurveyInvolvementGroupKindIds();
191203

204+
Map<Long, Integer> historicalVersions = getHistoricalVersionCounts(DSL.trueCondition());
205+
192206
return dsl
193207
.select(SURVEY_INSTANCE.fields())
194208
.select(SURVEY_RUN.fields())
@@ -208,7 +222,7 @@ public Set<SurveyInstanceInfo> findForRecipient(long personId) {
208222
.and(IS_ORIGINAL_INSTANCE_CONDITION)
209223
.and(SURVEY_INSTANCE.STATUS.ne(SurveyInstanceStatus.WITHDRAWN.name()))
210224
.and(SURVEY_TEMPLATE.STATUS.eq(ReleaseLifecycleStatus.ACTIVE.name()))
211-
.fetchSet(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds));
225+
.fetchSet(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds, historicalVersions));
212226
}
213227

214228

@@ -218,6 +232,7 @@ public Set<SurveyInstanceInfo> findForOwner(Long personId) {
218232
Condition isRunOwnerOrHasOwnerInvolvement = SURVEY_INSTANCE_OWNER.PERSON_ID.eq(personId).or(SURVEY_RUN.OWNER_ID.eq(personId));
219233

220234
Map<Long, List<Long>> surveyInvolvementGroupKindIds = findSurveyInvolvementGroupKindIds();
235+
Map<Long, Integer> historicalVersions = getHistoricalVersionCounts(DSL.trueCondition());
221236

222237
SelectConditionStep<Record> selectSurveysByOwningInvolvement = dsl
223238
.select(SURVEY_INSTANCE.fields())
@@ -259,7 +274,7 @@ public Set<SurveyInstanceInfo> findForOwner(Long personId) {
259274

260275
return selectSurveysByOwningInvolvement
261276
.union(selectSurveysByOwningRole)
262-
.fetchSet(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds));
277+
.fetchSet(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds, historicalVersions));
263278
}
264279

265280

@@ -281,4 +296,44 @@ private Map<Long, List<Long>> findSurveyInvolvementGroupKindIds() {
281296
r -> r.get(INVOLVEMENT_GROUP_ENTRY.INVOLVEMENT_GROUP_ID),
282297
r -> r.get(INVOLVEMENT_GROUP_ENTRY.INVOLVEMENT_KIND_ID));
283298
}
299+
300+
public Set<SurveyInstanceInfo> findBySurveyInstanceIdSelector(Select<Record1<Long>> selector) {
301+
Map<Long, List<Long>> surveyInvolvementGroupKindIds = findSurveyInvolvementGroupKindIds();
302+
303+
Map<Long, Integer> historicalVersions = getHistoricalVersionCounts(historicalVersion.ORIGINAL_INSTANCE_ID.in(selector));
304+
305+
SelectConditionStep<Record> qry = dsl
306+
.select(SURVEY_INSTANCE.fields())
307+
.select(SURVEY_RUN.fields())
308+
.select(SURVEY_TEMPLATE.NAME,
309+
SURVEY_TEMPLATE.ID,
310+
SURVEY_TEMPLATE.DESCRIPTION,
311+
SURVEY_TEMPLATE.EXTERNAL_ID)
312+
.select(ENTITY_NAME_FIELD)
313+
.select(QUALIFIER_NAME_FIELD)
314+
.select(EXTERNAL_ID_FIELD)
315+
.from(SURVEY_INSTANCE)
316+
.innerJoin(SURVEY_RUN).on(SURVEY_INSTANCE.SURVEY_RUN_ID.eq(SURVEY_RUN.ID))
317+
.innerJoin(SURVEY_TEMPLATE).on(SURVEY_RUN.SURVEY_TEMPLATE_ID.eq(SURVEY_TEMPLATE.ID))
318+
.where(SURVEY_INSTANCE.ID.in(selector)
319+
.and(IS_ORIGINAL_INSTANCE_CONDITION));
320+
321+
return qry
322+
.fetchSet(r -> mkSurveyInstanceInfo(r, surveyInvolvementGroupKindIds, historicalVersions));
323+
}
324+
325+
private Map<Long, Integer> getHistoricalVersionCounts(Condition condition) {
326+
327+
AggregateFunction<Integer> surveyCount = DSL.count();
328+
329+
return dsl
330+
.select(historicalVersion.ORIGINAL_INSTANCE_ID, surveyCount)
331+
.from(historicalVersion)
332+
.where(historicalVersion.ORIGINAL_INSTANCE_ID.isNotNull())
333+
.and(condition)
334+
.groupBy(historicalVersion.ORIGINAL_INSTANCE_ID)
335+
.fetchMap(
336+
r -> r.get(historicalVersion.ORIGINAL_INSTANCE_ID),
337+
r -> r.get(surveyCount));
338+
}
284339
}

waltz-model/src/main/java/org/finos/waltz/model/survey/SurveyInstanceInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ public abstract class SurveyInstanceInfo {
3232
public abstract SurveyInstance surveyInstance();
3333
public abstract SurveyRun surveyRun();
3434
public abstract EntityReference surveyTemplateRef();
35+
public abstract Integer historicalVersionsCount();
3536

3637
}

waltz-ng/client/survey/components/survey-section.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ <h4>
459459

460460
<!-- SURVEY INSTANCE LIST -->
461461
<div ng-if="$ctrl.visibility.mode == 'list'">
462-
<waltz-survey-instance-list parent-entity-ref="$ctrl.parentEntityRef">
463-
</waltz-survey-instance-list>
462+
<waltz-svelte-component component="$ctrl.SurveyInstanceList"
463+
primary-entity-ref="$ctrl.parentEntityRef">
464+
</waltz-svelte-component>
464465
</div>
465466

466467

waltz-ng/client/survey/components/survey-section.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {displayError} from "../../common/error-utils";
2424
import {isSurveyTargetKind} from "../survey-utils";
2525
import toasts from "../../svelte-stores/toast-store";
2626
import SystemRoles from "../../user/system-roles";
27+
import SurveyInstanceList from "./svelte/SurveyInstanceList.svelte";
2728

2829

2930
const initialState = {
@@ -43,7 +44,8 @@ const initialState = {
4344
recipientInvolvementKinds: [],
4445
ownerInvolvementKinds: []
4546
},
46-
templateQuery: ""
47+
templateQuery: "",
48+
SurveyInstanceList
4749
};
4850

4951

0 commit comments

Comments
 (0)