Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
String dmnFilepath = storageService.getCheckDmnModelPath(checkConfig.getCheckId());
EvaluationResult evaluationResult;
if (isLibraryCheck(checkConfig)){
EligibilityCheck check = libraryApi.getById(checkConfig.getCheckId());
String path = check.getPath();
evaluationResult = libraryApi.evaluateCheck(checkConfig, path, formData);

String evaluationUrl = checkConfig.getEvaluationUrl();
evaluationResult = libraryApi.evaluateCheck(checkConfig, evaluationUrl, formData);
} else {
Map<String, Object> customFormValues = (Map<String, Object>) formData.get("custom");
if (customFormValues == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ public Response createCustomCheck(@Context SecurityIdentity identity,
//TODO: Add validations for user provided data
newCheck.setOwnerId(userId);
newCheck.setPublic(false);
newCheck.setVersion(0);
if (newCheck.getVersion().isEmpty()){
newCheck.setVersion("1.0.0");
}
try {
eligibilityCheckRepository.saveNewWorkingCustomCheck(newCheck);
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
Expand Down Expand Up @@ -242,7 +244,7 @@ public Response publishCustomCheck(@Context SecurityIdentity identity, @PathPara
}

// Update workingCheck so that the incremented version number is saved
check.setVersion(check.getVersion() + 1);
check.setVersion(incrementMajorVersion(check.getVersion()));
try {
eligibilityCheckRepository.updateWorkingCustomCheck(check);
} catch (Exception e){
Expand Down Expand Up @@ -272,6 +274,24 @@ public Response publishCustomCheck(@Context SecurityIdentity identity, @PathPara
return Response.ok(check, MediaType.APPLICATION_JSON).build();
}

private String incrementMajorVersion(String version) {
int[] v = normalize(version);
v[0]++; // increment major
v[1] = 0; // reset minor
v[2] = 0; // reset patch
return v[0] + "." + v[1] + "." + v[2];
}

private int[] normalize(String version) {
String[] parts = version.split("\\.");
int[] nums = new int[]{0, 0, 0};

for (int i = 0; i < parts.length && i < 3; i++) {
nums[i] = Integer.parseInt(parts[i]);
}
return nums;
}

/* Endpoint for returning all Published Check Versions related to a given Working Eligibility Check */
@GET
@Path("/custom-checks/{checkId}/published-check-versions")
Expand All @@ -290,7 +310,7 @@ public Response getPublishedVersionsOfWorkingCheck(@Context SecurityIdentity ide
}

// Update workingCheck so that the incremented version number is saved
check.setVersion(check.getVersion() + 1);
check.setVersion(incrementMajorVersion(check.getVersion()));
try {
List<EligibilityCheck> publishedChecks = eligibilityCheckRepository.getPublishedCheckVersions(check);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package org.acme.model.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;

import java.util.List;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CheckConfig {
private String checkId;
private String checkName;
private String checkVersion;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: I'm wondering about module and whether that should be here too. We can already derive it from the checkId, but that's true of version as well, so maybe we don't even need version here as it's own param? We should try to decide if anything already in checkId is pulled from checkId, or if it's stored redundantly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add module, I'm worried that storing data in the id itself was a bad idea and would like to rely more on the actual attributes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 🫡

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth I think the composite property was a cool idea, but it may make sense to make an Index in the Firestore Database for that purpose instead.

private Map<String, Object> parameters;
// evaluation endpoint url for library checks
private String evaluationUrl;
private JsonNode inputDefinition;
private List<ParameterDefinition> parameterDefinitions;

public String getCheckId() {
return checkId;
Expand All @@ -33,4 +40,36 @@ public String getCheckName() {
public void setCheckName(String checkName) {
this.checkName = checkName;
}

public String getEvaluationUrl() {
return evaluationUrl;
}

public void setEvaluationUrl(String libraryCheckEvaluationUrl) {
this.evaluationUrl = libraryCheckEvaluationUrl;
}

public JsonNode getInputDefinition() {
return inputDefinition;
}

public void setInputDefinition(JsonNode inputDefinition) {
this.inputDefinition = inputDefinition;
}

public List<ParameterDefinition> getParameterDefinitions() {
return parameterDefinitions;
}

public void setParameterDefinitions(List<ParameterDefinition> parameterDefinitions) {
this.parameterDefinitions = parameterDefinitions;
}

public String getCheckVersion() {
return checkVersion;
}

public void setCheckVersion(String checkVersion) {
this.checkVersion = checkVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public class EligibilityCheck {
private String name;
private String module;
private String description;
private Integer version;
private String version;
private boolean isActive;
private String dmnModel;
private List<InputDefinition> inputs;
private JsonNode situation;
private List<ParameterDefinition> parameters;
private JsonNode inputDefinition;
private List<ParameterDefinition> parameterDefinitions;
private String ownerId;
@JsonProperty("isPublic")
private Boolean isPublic;
Expand Down Expand Up @@ -64,11 +63,11 @@ public void setDescription(String description) {
this.description = description;
}

public Integer getVersion() {
public String getVersion() {
return version;
}

public void setVersion(Integer version) {
public void setVersion(String version) {
this.version = version;
}

Expand All @@ -80,20 +79,12 @@ public void setActive(boolean active) {
isActive = active;
}

public List<InputDefinition> getInputs() {
return inputs;
public List<ParameterDefinition> getParameterDefinitions() {
return parameterDefinitions;
}

public void setInputs(List<InputDefinition> inputDefinitions) {
this.inputs = inputDefinitions;
}

public List<ParameterDefinition> getParameters() {
return parameters;
}

public void setParameters(List<ParameterDefinition> parameters) {
this.parameters = parameters;
public void setParameterDefinitions(List<ParameterDefinition> parameterDefinitions) {
this.parameterDefinitions = parameterDefinitions;
}

public String getOwnerId() {
Expand All @@ -112,12 +103,12 @@ public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}

public JsonNode getSituation() {
return situation;
public JsonNode getInputDefinition() {
return inputDefinition;
}

public void setSituation(JsonNode situation) {
this.situation = situation;
public void setInputDefinition(JsonNode inputDefinition) {
this.inputDefinition = inputDefinition;
}

public String getPath() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,33 @@ public List<EligibilityCheck> getLatestVersionPublishedCustomChecks(String userI
.collect(java.util.stream.Collectors.toMap(
check -> getPublishedPrefix(check),
check -> check,
(check1, check2) -> check1.getVersion() > check2.getVersion() ? check1 : check2
(check1, check2) -> compareVersions(check1.getVersion(), check2.getVersion()) > 0 ? check1 : check2
));
return new ArrayList<>(latestVersionMap.values());
}

private static int compareVersions(String v1, String v2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd really love a file for util functions related to version numbers, but that can be a future change.

int[] a = normalize(v1);
int[] b = normalize(v2);

for (int i = 0; i < 3; i++) {
if (a[i] != b[i]) {
return a[i] - b[i];
}
}
return 0;
}

private static int[] normalize(String version) {
String[] parts = version.split("\\.");
int[] nums = new int[] {0, 0, 0};

for (int i = 0; i < parts.length && i < 3; i++) {
nums[i] = Integer.parseInt(parts[i]);
}
return nums;
}

public List<EligibilityCheck> getPublishedCheckVersions(EligibilityCheck workingCustomCheck){
Map<String, String> fieldValues = Map.of(
"ownerId", workingCustomCheck.getOwnerId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class LibraryApiService {
@PostConstruct
void init() {
try {

// Get path of most recent library schema json document
Optional<Map<String, Object>> configOpt = FirestoreUtils.getFirestoreDocById("system", "config");
if (configOpt.isEmpty()){
Expand Down Expand Up @@ -71,7 +70,7 @@ public EligibilityCheck getById(String id) {
return matches.getFirst();
}

public EvaluationResult evaluateCheck(CheckConfig checkConfig, String path, Map<String, Object> inputs){
public EvaluationResult evaluateCheck(CheckConfig checkConfig, String evaluationUrl, Map<String, Object> inputs){
return EvaluationResult.TRUE;
}
}
Expand Down
14 changes: 11 additions & 3 deletions builder-frontend/src/api/benefit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { authFetch } from "@/api/auth";
import BenefitList from "@/components/project/manageBenefits/benefitList/BenefitList";

import { Benefit } from "@/types";

const apiUrl = import.meta.env.VITE_API_URL;

export const fetchScreenerBenefit = async (srceenerId: string, benefitId: string): Promise<Benefit> => {
export const fetchScreenerBenefit = async (
srceenerId: string,
benefitId: string
): Promise<Benefit> => {
const url = apiUrl + "/screener/" + srceenerId + "/benefit/" + benefitId;
try {
const response = await authFetch(url, {
Expand All @@ -25,7 +29,12 @@ export const fetchScreenerBenefit = async (srceenerId: string, benefitId: string
}
};

export const updateScreenerBenefit = async (screenerId: string, benefitData: Benefit): Promise<Benefit> => {
export const updateScreenerBenefit = async (
screenerId: string,
benefitData: Benefit
): Promise<Benefit> => {
console.log("in updateScreenerBenefit");
console.log(benefitData);
const url = apiUrl + "/screener/" + screenerId + "/benefit";
try {
const response = await authFetch(url, {
Expand All @@ -48,7 +57,6 @@ export const updateScreenerBenefit = async (screenerId: string, benefitData: Ben
}
};


export const fetchPublicBenefits = async (): Promise<Benefit[]> => {
const url = apiUrl + "/benefit";
try {
Expand Down
Loading