Skip to content

Commit 3f0dd7f

Browse files
Merge pull request #206 from CodeForPhilly/customize-benefits-update
2 parents 77e63be + 155b1f6 commit 3f0dd7f

File tree

12 files changed

+97
-86
lines changed

12 files changed

+97
-86
lines changed

builder-api/src/main/java/org/acme/controller/DecisionResource.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,22 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
127127
List<OptionalBoolean> checkResultsList = new ArrayList<>();
128128
Map<String, Object> checkResults = new HashMap<>();
129129

130+
int checkNum = 0;
130131
for (CheckConfig checkConfig : benefit.getChecks()) {
131132
String dmnFilepath = storageService.getCheckDmnModelPath(checkConfig.getCheckId());
132-
OptionalBoolean result = dmnService.evaluateSimpleDmn(
133-
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
133+
OptionalBoolean result = dmnService.evaluateDmn(
134+
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
134135
);
135136
checkResultsList.add(result);
136-
checkResults.put(checkConfig.getCheckId(), Map.of("name", checkConfig.getCheckName(), "result", result));
137+
138+
String uniqueCheckKey = checkConfig.getCheckId() + checkNum;
139+
checkResults.put(uniqueCheckKey, Map.of("name", checkConfig.getCheckName(), "result", result));
140+
checkNum += 1;
137141
}
138142

139143
// Determine overall Benefit result
140144
Boolean allChecksTrue = checkResultsList.stream().allMatch(result -> result == OptionalBoolean.TRUE);
141145
Boolean anyChecksFalse = checkResultsList.stream().anyMatch(result -> result == OptionalBoolean.FALSE);
142-
Log.info("All True: " + allChecksTrue + " Any False: " + anyChecksFalse);
143146

144147
OptionalBoolean benefitResult;
145148
if (allChecksTrue) {
@@ -151,11 +154,11 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
151154
}
152155

153156
return new HashMap<String, Object>(
154-
Map.of(
155-
"name", benefit.getName(),
156-
"result", benefitResult,
157-
"check_results", checkResults
158-
)
157+
Map.of(
158+
"name", benefit.getName(),
159+
"result", benefitResult,
160+
"check_results", checkResults
161+
)
159162
);
160163
}
161164
}
@@ -188,10 +191,9 @@ public Response evaluateCheck(
188191

189192
try {
190193
String dmnFilepath = storageService.getCheckDmnModelPath(check.getId());
191-
String dmnModelName = check.getId();
192194

193-
OptionalBoolean result = dmnService.evaluateSimpleDmn(
194-
dmnFilepath, dmnModelName, request.inputData, request.checkConfig.getParameters()
195+
OptionalBoolean result = dmnService.evaluateDmn(
196+
dmnFilepath, request.checkConfig.getCheckName(), request.inputData, request.checkConfig.getParameters()
195197
);
196198
return Response.ok().entity(Map.of("result", result)).build();
197199
} catch (Exception e) {

builder-api/src/main/java/org/acme/controller/EligibilityCheckResource.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Response createPublicCheck(@Context SecurityIdentity identity,
7272
// TODO: Add validations for user provided data
7373
newCheck.setOwnerId(userId);
7474
newCheck.setPublic(true);
75-
newCheck.setVersion(1);
75+
newCheck.setVersion(0);
7676
try {
7777
String checkId = eligibilityCheckRepository.savePublicCheck(newCheck);
7878
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
@@ -152,7 +152,10 @@ public Response updateCheckDmn(@Context SecurityIdentity identity, SaveDmnReques
152152
// then all the working check objects owned by the user are returned
153153
@GET
154154
@Path("/custom-checks")
155-
public Response getCustomChecks(@Context SecurityIdentity identity, @QueryParam("working") Boolean working) {
155+
public Response getCustomChecks(
156+
@Context SecurityIdentity identity,
157+
@QueryParam("working") Boolean working
158+
) {
156159
String userId = AuthUtils.getUserId(identity);
157160
if (userId == null) {
158161
return Response.status(Response.Status.UNAUTHORIZED).build();
@@ -165,7 +168,7 @@ public Response getCustomChecks(@Context SecurityIdentity identity, @QueryParam(
165168
checks = eligibilityCheckRepository.getWorkingCustomChecks(userId);
166169
} else {
167170
Log.info("Fetching all published custom checks. User: " + userId);
168-
checks = eligibilityCheckRepository.getPublishedCustomChecks(userId);
171+
checks = eligibilityCheckRepository.getLatestVersionPublishedCustomChecks(userId);
169172
}
170173

171174
return Response.ok(checks, MediaType.APPLICATION_JSON).build();
@@ -214,7 +217,7 @@ public Response createCustomCheck(@Context SecurityIdentity identity,
214217
//TODO: Add validations for user provided data
215218
newCheck.setOwnerId(userId);
216219
newCheck.setPublic(false);
217-
newCheck.setVersion(1);
220+
newCheck.setVersion(0);
218221
try {
219222
eligibilityCheckRepository.saveNewWorkingCustomCheck(newCheck);
220223
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();

builder-api/src/main/java/org/acme/persistence/EligibilityCheckRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public interface EligibilityCheckRepository {
1818

1919
List<EligibilityCheck> getPublishedCheckVersions(EligibilityCheck workingCustomCheck);
2020

21+
List<EligibilityCheck> getLatestVersionPublishedCustomChecks(String userId);
22+
2123
List<EligibilityCheck> getPublishedCustomChecks(String userId);
2224

2325
Optional<EligibilityCheck> getWorkingCustomCheck(String userId, String checkId);

builder-api/src/main/java/org/acme/persistence/impl/EligibilityCheckRepositoryImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public List<EligibilityCheck> getPublishedCustomChecks(String userId){
8181
return checkMaps.stream().map(checkMap -> mapper.convertValue(checkMap, EligibilityCheck.class)).toList();
8282
}
8383

84+
public List<EligibilityCheck> getLatestVersionPublishedCustomChecks(String userId) {
85+
List<EligibilityCheck> publishedChecks = getPublishedCustomChecks(userId);
86+
Map<String, EligibilityCheck> latestVersionMap = publishedChecks.stream()
87+
.collect(java.util.stream.Collectors.toMap(
88+
check -> getPublishedPrefix(check),
89+
check -> check,
90+
(check1, check2) -> check1.getVersion() > check2.getVersion() ? check1 : check2
91+
));
92+
return new ArrayList<>(latestVersionMap.values());
93+
}
94+
8495
public List<EligibilityCheck> getPublishedCheckVersions(EligibilityCheck workingCustomCheck){
8596
Map<String, String> fieldValues = Map.of(
8697
"ownerId", workingCustomCheck.getOwnerId(),

builder-api/src/main/java/org/acme/service/DmnService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.Map;
55

66
public interface DmnService {
7-
public OptionalBoolean evaluateSimpleDmn(
7+
public OptionalBoolean evaluateDmn(
88
String dmnFilePath,
99
String dmnModelName,
1010
Map<String, Object> inputs,

builder-api/src/main/java/org/acme/service/KieDmnService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private byte[] compileDmnModel(String dmnXml, Map<String, String> dependenciesMa
8383
return kieModuleBytes;
8484
}
8585

86-
public OptionalBoolean evaluateSimpleDmn(
86+
public OptionalBoolean evaluateDmn(
8787
String dmnFilePath,
8888
String dmnModelName,
8989
Map<String, Object> inputs,

builder-frontend/src/api/check.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,8 @@ export const saveCheckDmn = async (checkId: string, dmnModel: string) => {
143143
export const fetchUserDefinedChecks = async (
144144
working: boolean
145145
): Promise<EligibilityCheck[]> => {
146-
let url: string;
147-
if (working) {
148-
url = apiUrl + "/custom-checks?working=true";
149-
} else {
150-
url = apiUrl + "/custom-checks?working=false";
151-
}
146+
const workingQueryParam = working ? "true" : "false";
147+
let url: string = apiUrl + `/custom-checks?working=${workingQueryParam}`;
152148

153149
try {
154150
const response = await authFetch(url, {

builder-frontend/src/components/project/manageBenefits/configureBenefit/ConfigureBenefit.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import BenefitResource from "./benefitResource";
88
import { fetchPublicChecks, fetchUserDefinedChecks } from "@/api/check";
99

1010
import type { EligibilityCheckListMode } from "./EligibilityCheckListView";
11-
import type { EligibilityCheck } from "@/types";
11+
import type { EligibilityCheck, ParameterValues } from "@/types";
1212

1313
const ConfigureBenefit = ({
1414
screenerId,
@@ -19,7 +19,7 @@ const ConfigureBenefit = ({
1919
benefitId: Accessor<string>;
2020
setBenefitId: (benefitId: string | null) => void;
2121
}) => {
22-
const { benefit, actions, initialLoadStatus } = BenefitResource(
22+
const { benefit, actions, actionInProgress, initialLoadStatus } = BenefitResource(
2323
screenerId,
2424
benefitId
2525
);
@@ -28,7 +28,7 @@ const ConfigureBenefit = ({
2828
createSignal<EligibilityCheckListMode>("public");
2929
const [publicChecks] = createResource<EligibilityCheck[]>(fetchPublicChecks);
3030
const [userDefinedChecks] = createResource<EligibilityCheck[]>(
31-
fetchUserDefinedChecks
31+
() => fetchUserDefinedChecks(false)
3232
);
3333

3434
const getSelectedCheck = (checkId: string) => {
@@ -39,9 +39,13 @@ const ConfigureBenefit = ({
3939
return allChecks.find((check) => check.id === checkId);
4040
};
4141

42+
const onRemoveEligibilityCheck = (checkIndexToRemove: number) => {
43+
actions.removeCheck(checkIndexToRemove);
44+
};
45+
4246
return (
4347
<>
44-
<Show when={initialLoadStatus.loading()}>
48+
<Show when={initialLoadStatus.loading() || actionInProgress()}>
4549
<Loading />
4650
</Show>
4751

@@ -69,13 +73,11 @@ const ConfigureBenefit = ({
6973
class="flex-3 border-2 border-gray-200 rounded-lg h-min"
7074
>
7175
<EligibilityCheckListView
72-
benefit={benefit}
7376
mode={checkListMode}
7477
setMode={setCheckListMode}
7578
publicChecks={publicChecks}
7679
userDefinedChecks={userDefinedChecks}
7780
addCheck={actions.addCheck}
78-
removeCheck={actions.removeCheck}
7981
/>
8082
</div>
8183
<div id="selected-eligibility-checks" class="flex-2">
@@ -98,9 +100,13 @@ const ConfigureBenefit = ({
98100
<SelectedEligibilityCheck
99101
check={getSelectedCheck(checkConfig.checkId)}
100102
checkConfig={() => checkConfig}
101-
checkIndex={checkIndex()}
103+
onRemove={() =>
104+
onRemoveEligibilityCheck(checkIndex())
105+
}
102106
updateCheckConfigParams={
103-
actions.updateCheckConfigParams
107+
(newCheckData: ParameterValues) => {
108+
actions.updateCheckConfigParams(checkIndex(), newCheckData);
109+
}
104110
}
105111
/>
106112
</Show>

builder-frontend/src/components/project/manageBenefits/configureBenefit/EligibilityCheckListView.tsx

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Accessor, For, Resource, Setter } from "solid-js";
22

3-
import type { Benefit, CheckConfig, EligibilityCheck } from "@/types";
3+
import { titleCase } from "@/utils/title_case";
4+
5+
import type { CheckConfig, EligibilityCheck } from "@/types";
6+
47

58
export type EligibilityCheckListMode = "user-defined" | "public";
69
interface CheckModeConfig {
@@ -33,17 +36,13 @@ const UserDefinedCheckConfig: CheckModeConfig = {
3336
- userDefinedChecks: resource containing the list of user-defined eligibility checks
3437
*/
3538
const EligibilityCheckListView = ({
36-
benefit,
3739
addCheck,
38-
removeCheck,
3940
mode,
4041
setMode,
4142
publicChecks,
4243
userDefinedChecks,
4344
}: {
44-
benefit: Accessor<Benefit>;
4545
addCheck: (newCheck: CheckConfig) => void;
46-
removeCheck: (indexToRemove: number) => void;
4746
mode: Accessor<EligibilityCheckListMode>;
4847
setMode: Setter<EligibilityCheckListMode>;
4948
publicChecks: Resource<EligibilityCheck[]>;
@@ -53,23 +52,14 @@ const EligibilityCheckListView = ({
5352
mode() === "public" ? PublicCheckConfig : UserDefinedCheckConfig;
5453
const activeChecks: Accessor<Resource<EligibilityCheck[]>> = () =>
5554
mode() === "public" ? publicChecks : userDefinedChecks;
56-
const onEligibilityCheckToggle = (check: EligibilityCheck) => {
57-
const isCheckSelected = benefit().checks.some(
58-
(selected) => selected.checkId === check.id
59-
);
60-
if (isCheckSelected) {
61-
const checkIndexToRemove = benefit().checks.findIndex(
62-
(selected) => selected.checkId === check.id
63-
);
64-
removeCheck(checkIndexToRemove);
65-
} else {
66-
const checkConfig: CheckConfig = {
67-
checkId: check.id,
68-
checkName: check.name,
69-
parameters: {},
70-
};
71-
addCheck(checkConfig);
72-
}
55+
56+
const onAddEligibilityCheck = (check: EligibilityCheck) => {
57+
const checkConfig: CheckConfig = {
58+
checkId: check.id,
59+
checkName: check.name,
60+
parameters: {},
61+
};
62+
addCheck(checkConfig);
7363
};
7464

7565
return (
@@ -102,9 +92,10 @@ const EligibilityCheckListView = ({
10292
<table class="table-auto w-full mt-4 border-collapse">
10393
<thead>
10494
<tr>
105-
<th class="eligibility-check-table-header">Select</th>
95+
<th class="eligibility-check-table-header">Add</th>
10696
<th class="eligibility-check-table-header">Check Name</th>
10797
<th class="eligibility-check-table-header">Description</th>
98+
<th class="eligibility-check-table-header">Version</th>
10899
</tr>
109100
</thead>
110101
<tbody>
@@ -126,8 +117,7 @@ const EligibilityCheckListView = ({
126117
{(check) => (
127118
<EligibilityCheckRow
128119
check={check}
129-
selectedCheckConfigs={benefit().checks}
130-
onToggle={() => onEligibilityCheckToggle(check)}
120+
onAdd={() => onAddEligibilityCheck(check)}
131121
/>
132122
)}
133123
</For>
@@ -139,30 +129,19 @@ const EligibilityCheckListView = ({
139129

140130
const EligibilityCheckRow = ({
141131
check,
142-
selectedCheckConfigs,
143-
onToggle,
132+
onAdd,
144133
}: {
145134
check: EligibilityCheck;
146-
selectedCheckConfigs: CheckConfig[];
147-
onToggle: (check: EligibilityCheck) => void;
135+
onAdd: (check: EligibilityCheck) => void;
148136
}) => {
149-
const isCheckSelected = () =>
150-
selectedCheckConfigs.some((selected) => selected.checkId === check.id);
151-
152137
return (
153138
<tr>
154139
<td class="eligibility-check-table-cell border-top">
155-
<input
156-
class="form-checkbox rounded-sm"
157-
type="checkbox"
158-
checked={isCheckSelected()}
159-
onChange={() => onToggle(check)}
160-
/>
161-
</td>
162-
<td class="eligibility-check-table-cell border-top">{check.name}</td>
163-
<td class="eligibility-check-table-cell border-top">
164-
{check.description}
140+
<div class="btn-default btn-blue" onClick={() => onAdd(check)}>Add</div>
165141
</td>
142+
<td class="eligibility-check-table-cell border-top">{titleCase(check.name)}</td>
143+
<td class="eligibility-check-table-cell border-top">{check.description}</td>
144+
<td class="eligibility-check-table-cell border-top">{check.version}</td>
166145
</tr>
167146
);
168147
};

builder-frontend/src/components/project/manageBenefits/configureBenefit/SelectedEligibilityCheck.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ interface ParameterWithConfiguredValue {
1717
}
1818

1919
const SelectedEligibilityCheck = (
20-
{ check, checkConfig, updateCheckConfigParams }:
20+
{ check, checkConfig, onRemove, updateCheckConfigParams }:
2121
{
2222
check: EligibilityCheck;
2323
checkConfig: Accessor<CheckConfig>;
24+
onRemove: () => void;
2425
updateCheckConfigParams: (newCheckData: ParameterValues) => void
2526
}
2627
) => {
@@ -44,11 +45,18 @@ const SelectedEligibilityCheck = (
4445
setConfiguringCheckModalOpen(true);
4546
}}
4647
class="
47-
mb-4 p-4 cursor-pointer select-none
48+
mb-4 p-4 cursor-pointer select-none relative
4849
border-2 border-gray-200 rounded-lg hover:bg-gray-200"
4950
>
51+
<div
52+
class="absolute px-2 top-2 right-2 hover:bg-gray-300 rounded-xl font-bold"
53+
onClick={(e) => { e.stopPropagation(); onRemove(); }}
54+
>
55+
X
56+
</div>
5057
<div class="text-xl font-bold mb-2">{titleCase(check.name)}</div>
5158
<div class="pl-2 [&:has(+div)]:mb-2">{check.description}</div>
59+
5260
{check.inputs.length > 0 && (
5361
<div class="[&:has(+div)]:mb-2">
5462
<div class="text-lg font-bold pl-2">Inputs</div>
@@ -91,6 +99,7 @@ const SelectedEligibilityCheck = (
9199
</div>
92100
)}
93101
</div>
102+
94103
{configuringCheckModalOpen() && (
95104
<ConfigureCheckModal
96105
check={check}

0 commit comments

Comments
 (0)