Skip to content

Commit

Permalink
Merge pull request #6654 from deutschebank/db-contrib/waltz-6629-dire…
Browse files Browse the repository at this point in the history
…ct-indirect-inv-section-rework

Db contrib/waltz 6629 direct indirect inv section rework
  • Loading branch information
davidwatkins73 committed Jun 24, 2023
2 parents 4de7c10 + 6670196 commit ca7516a
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class MeasurableIdSelectorFactory implements IdSelectorFactory {


/**
* @param measurableId the identifier of the measurable to start from
* @return a selector which gives all measurable ids that belong to the same category as the given measurable id
* @param measurableId the identifier of the measurable to start from
* @return a selector which gives all measurable ids that belong to the same category as the given measurable id
*/
public static SelectConditionStep<Record1<Long>> allMeasurablesIdsInSameCategory(Long measurableId) {
return DSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ public int removeForCategory(EntityReference ref, long categoryId) {
* which map to this measurable. This is used to provide functionality for features like: "apps that
* do this function, also do these functions..."
*
* @param measurableId starting measurable
* @param selector set of apps to consider
* @return boolean indicating if there are implicitly related measurables
* @param measurableId starting measurable
* @param selector set of apps to consider
* @return boolean indicating if there are implicitly related measurables
*/
public boolean hasImplicitlyRelatedMeasurables(long measurableId, Select<Record1<Long>> selector) {

Expand Down Expand Up @@ -778,15 +778,14 @@ private SelectHavingStep<Record4<Long, Long, String, Integer>> selectAllocsToBeU
DSL.cast(DSL.sum(ALLOCATION.ALLOCATION_PERCENTAGE), Integer.class).as("allocation_percentage"))
.from(ALLOCATION)
.innerJoin(valuesToBeSummed)
.on(ALLOCATION.ALLOCATION_SCHEME_ID.eq(valuesToBeSummed.field(ALLOCATION.ALLOCATION_SCHEME_ID))
.on(ALLOCATION.ALLOCATION_SCHEME_ID.eq(valuesToBeSummed.field(ALLOCATION.ALLOCATION_SCHEME_ID))
.and(ALLOCATION.ENTITY_KIND.eq(valuesToBeSummed.field(ALLOCATION.ENTITY_KIND))
.and(ALLOCATION.ENTITY_ID.eq(valuesToBeSummed.field(ALLOCATION.ENTITY_ID)))))
.where(ALLOCATION.MEASURABLE_ID.in(targetId, measurableId))
.groupBy(ALLOCATION.ALLOCATION_SCHEME_ID, ALLOCATION.ENTITY_ID, ALLOCATION.ENTITY_KIND);
}



public boolean saveRatingItem(EntityReference entityRef,
long measurableId,
String ratingCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ public class MeasurableRatingHelper {
* Updates the given measurable rating to be set as primary.
* All other ratings for the same entity/category will be set to non-primary.
*
* @param tx the dsl connection to use
* @param ref the entity ref
* @param measurableId the measurable id
* @param isPrimary the new value of the isPrimary flag
* @param tx the dsl connection to use
* @param ref the entity ref
* @param measurableId the measurable id
* @param isPrimary the new value of the isPrimary flag
*/
public static boolean saveRatingIsPrimary(DSLContext tx,
EntityReference ref,
long measurableId,
boolean isPrimary,
String username) {
EntityReference ref,
long measurableId,
boolean isPrimary,
String username) {
tx.update(MEASURABLE_RATING)
.set(MEASURABLE_RATING.IS_PRIMARY, false)
.where(MEASURABLE_RATING.ENTITY_ID.eq(ref.id())
.and(MEASURABLE_RATING.ENTITY_KIND.eq(ref.kind().name()))
.and(MEASURABLE_RATING.MEASURABLE_ID.in(allMeasurablesIdsInSameCategory(measurableId))))
.execute();
.set(MEASURABLE_RATING.IS_PRIMARY, false)
.where(MEASURABLE_RATING.ENTITY_ID.eq(ref.id())
.and(MEASURABLE_RATING.ENTITY_KIND.eq(ref.kind().name()))
.and(MEASURABLE_RATING.MEASURABLE_ID.in(allMeasurablesIdsInSameCategory(measurableId))))
.execute();

if (isPrimary) {
// only update if we are setting to true as false case dealt with above
tx.update(MEASURABLE_RATING)
.set(MEASURABLE_RATING.IS_PRIMARY, true)
.set(MEASURABLE_RATING.LAST_UPDATED_BY, username)
.set(MEASURABLE_RATING.LAST_UPDATED_AT, nowUtcTimestamp())
.where(mkPkCondition(ref, measurableId))
.execute();
.set(MEASURABLE_RATING.IS_PRIMARY, true)
.set(MEASURABLE_RATING.LAST_UPDATED_BY, username)
.set(MEASURABLE_RATING.LAST_UPDATED_AT, nowUtcTimestamp())
.where(mkPkCondition(ref, measurableId))
.execute();
}

return true;
Expand All @@ -53,12 +53,12 @@ public static boolean saveRatingDescription(DSLContext tx,
String description,
String username) {
return tx
.update(MEASURABLE_RATING)
.set(MEASURABLE_RATING.DESCRIPTION, description)
.set(MEASURABLE_RATING.LAST_UPDATED_BY, username)
.set(MEASURABLE_RATING.LAST_UPDATED_AT, nowUtcTimestamp())
.where(mkPkCondition(entityRef, measurableId))
.execute() == 1;
.update(MEASURABLE_RATING)
.set(MEASURABLE_RATING.DESCRIPTION, description)
.set(MEASURABLE_RATING.LAST_UPDATED_BY, username)
.set(MEASURABLE_RATING.LAST_UPDATED_AT, nowUtcTimestamp())
.where(mkPkCondition(entityRef, measurableId))
.execute() == 1;
}


Expand Down Expand Up @@ -109,19 +109,19 @@ public static boolean doesRatingExist(DSLContext tx,
EntityReference entityRef,
long measurableId) {
return tx
.fetchExists(DSL
.select(DSL.val(1))
.from(MEASURABLE_RATING)
.where(mkPkCondition(entityRef, measurableId)));
.fetchExists(DSL
.select(DSL.val(1))
.from(MEASURABLE_RATING)
.where(mkPkCondition(entityRef, measurableId)));

}


private static Condition mkPkCondition(EntityReference entityRef,
long measurableId) {
return MEASURABLE_RATING.MEASURABLE_ID.eq(measurableId)
.and(MEASURABLE_RATING.ENTITY_ID.eq(entityRef.id()))
.and(MEASURABLE_RATING.ENTITY_KIND.eq(entityRef.kind().name()));
.and(MEASURABLE_RATING.ENTITY_ID.eq(entityRef.id()))
.and(MEASURABLE_RATING.ENTITY_KIND.eq(entityRef.kind().name()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public List<RatingSchemeItem> findRatingSchemeItemsForAssessmentDefinition(Long
.fetch(TO_ITEM_MAPPER);
}

public RatingSchemeItem getRatingSchemeItemById(long id){
public RatingSchemeItem getRatingSchemeItemById(long id) {
checkNotNull(id, "id cannot be null");
return dsl
.selectFrom(RATING_SCHEME_ITEM)
Expand All @@ -160,8 +160,8 @@ public RatingSchemeItem getRatingSchemeItemById(long id){
* This method takes into account any constraining assessment associated to the category.
* If the rating is constrained the <code>isRestricted</code> flag on the returned RatingSchemeItem will be set.
*
* @param ref the entity being checked
* @param measurableCategoryId the category being checked
* @param ref the entity being checked
* @param measurableCategoryId the category being checked
* @return list of permissible rating items for the given entity and category
*/
public List<RatingSchemeItem> findRatingSchemeItemsForEntityAndCategory(EntityReference ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.immutables.value.Value;

@Value.Immutable
@JsonDeserialize(as= ImmutableUpdateRatingCodeCommand.class)
@JsonDeserialize(as = ImmutableUpdateRatingCodeCommand.class)
public abstract class UpdateRatingCodeCommand implements Command {

public abstract String newCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.finos.waltz.model.involvement_group;

import org.finos.waltz.model.command.Command;
import org.immutables.value.Value;

import java.util.Collections;
import java.util.Set;

@Value.Immutable
public abstract class InvolvementGroupCreateCommand {
public abstract class InvolvementGroupCreateCommand implements Command {

public abstract InvolvementGroup involvementGroup();

@Value.Default
public Set<Long> involvementKindIds() {
return Collections.emptySet();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ public abstract class MeasurableRating implements
ProvenanceProvider {

public abstract EntityReference entityReference();

public abstract long measurableId();

public abstract char rating();

@Value.Default
public boolean isReadOnly() { return false; }
public boolean isReadOnly() {
return false;
}

@Value.Default
public boolean isPrimary() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public abstract class SaveMeasurableRatingCommand extends MeasurableRatingCommand implements DescriptionProvider, ProvenanceProvider {

public abstract char rating();

public abstract Optional<Character> previousRating();

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
*/

import { initialiseData, invokeFunction } from "../../index";
import { FILTER_CHANGED_EVENT } from "../../constants";
import {initialiseData, invokeFunction} from "../../index";
import {FILTER_CHANGED_EVENT} from "../../constants";

const bindings = {
onFiltersChanged: "<",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Entity</th>
<th>Person</th>
<th>Involvement</th>
<th></th>
</tr>
Expand Down Expand Up @@ -99,6 +99,7 @@
<br />

<select ng-model="$ctrl.currentInvolvement.involvement"
required
ng-options="rel.value as rel.name for rel in $ctrl.allowedInvolvements | orderBy:'name'"
class="form-control">
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ const bindings = {
currentInvolvements: "<",
parentEntityRef: "<",
targetEntityKind: "<",

onAdd: "<",
onRemove: "<"
};


const initialState = {
allowedInvolvements: [],
currentInvolvement: {},
currentInvolvement: {
involvement: null,
entity: null
},
currentInvolvements: [],
parentEntityRef: null,
targetEntityKind: null,
targetEntityDisplayName: null,

onAdd: () => console.log("default onAdd handler for entity-involvement-editor"),
onRemove: () => console.log("default onRemove handler for entity-involvement-editor")
};
Expand Down Expand Up @@ -69,8 +70,10 @@ function controller() {
vm.onInvolvementAdd = () => {
const currentInvolvement = vm.currentInvolvement;
invokeFunction(vm.onAdd, currentInvolvement)
.catch(e => displayError(`Could not add person with involvement`, e));
vm.currentInvolvement = {};
vm.currentInvolvement = {
involvement: null,
entity: null
};
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@

<!-- Viewer -->
<div ng-if="$ctrl.visibility.editor === false">

<div class="help-block"
style="padding-bottom: 1em"
ng-if="$ctrl.hierarchyScope !== 'EXACT'">
People are related to this <span ng-bind="$ctrl.parentEntityRef.kind | toDisplayName: 'entity'"></span>
either directly or inherited from a parent.
Use the toggle to filter the view.
<div style="padding-top: 1em">
<waltz-toggle
state="$ctrl.showDirectOnly"
on-toggle="$ctrl.onToggleScope()"
label-on="Showing direct involvements only"
label-off="Showing all involvements (including inherited)">
</waltz-toggle>
</div>
</div>

<div ng-if="$ctrl.gridData.length > 0">
<waltz-grid-with-search column-defs="$ctrl.columnDefs"
entries="$ctrl.gridData"
Expand Down
43 changes: 32 additions & 11 deletions waltz-ng/client/involvement/components/involved-people-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ const initialState = {
currentInvolvements: [],
gridData: [],
columnDefs,
exportGrid: () => {},
exportGrid: () => {
},
showDirectOnly: true,
visibility: {
editor: false
}
};


function mkGridData(involvements = [], displayNameService, descriptionService) {
return _.chain(involvements)
return _
.chain(involvements)
.filter(inv => !_.isEmpty(inv.involvements))
.map(inv => {
const roles = _.map(inv.involvements, pInv => ({
provenance: pInv.provenance,
Expand Down Expand Up @@ -136,8 +140,19 @@ function controller($q, displayNameService, descriptionService, serviceBroker, i

const vm = initialiseData(this, initialState);

function refreshGridData() {
const involvements = vm.showDirectOnly
? vm.aggDirectInvolvements
: vm.aggInvolvements;

vm.gridData = mkGridData(involvements, displayNameService, descriptionService);
}

const refresh = () => {
const options = mkSelectionOptions(vm.parentEntityRef, determineUpwardsScopeForKind(vm.parentEntityRef.kind));

vm.hierarchyScope = determineUpwardsScopeForKind(vm.parentEntityRef.kind);
const options = mkSelectionOptions(vm.parentEntityRef, vm.hierarchyScope);

const kindPromise = serviceBroker
.loadAppData(CORE_API.InvolvementKindStore.findAll, [])
.then(r => r.data);
Expand All @@ -163,28 +178,29 @@ function controller($q, displayNameService, descriptionService, serviceBroker, i
return $q
.all([involvementPromise, peoplePromise, kindPromise, userRolesPromise])
.then(([involvements = [], people = [], involvementKinds = [], userRoles = []]) => {
const aggInvolvements = aggregatePeopleInvolvements(involvements, people);
vm.gridData = mkGridData(aggInvolvements, displayNameService, descriptionService);
vm.currentInvolvements = mkCurrentInvolvements(aggInvolvements);
vm.involvementKinds = involvementKinds;

const directInvolvements = _.filter(involvements, d => d.entityReference.id === vm.parentEntityRef.id);

vm.aggInvolvements = aggregatePeopleInvolvements(involvements, people);
vm.aggDirectInvolvements = aggregatePeopleInvolvements(directInvolvements, people);
vm.currentInvolvements = mkCurrentInvolvements(vm.aggDirectInvolvements);

vm.allowedInvolvements = _
.chain(involvementKinds)
.filter(ik => ik.userSelectable)
.filter(ik => ik.subjectKind === vm.parentEntityRef.kind)
.filter(ik => _.isEmpty(ik.permittedRole) || _.includes(userRoles, ik.permittedRole))
.map(ik => ({ value: ik.id, name: ik.name }))
.map(ik => ({value: ik.id, name: ik.name}))
.value();
});
})
.then(refreshGridData);
};


vm.$onChanges = (changes) => {
if (changes.parentEntityRef && vm.parentEntityRef) {
refresh();
}


};


Expand All @@ -205,6 +221,11 @@ function controller($q, displayNameService, descriptionService, serviceBroker, i
.removeInvolvement(vm.parentEntityRef, entityInvolvement)
.then(refresh);
};

vm.onToggleScope = () => {
vm.showDirectOnly = !vm.showDirectOnly;
refreshGridData();
}
}


Expand Down
Loading

0 comments on commit ca7516a

Please sign in to comment.