Skip to content

Commit

Permalink
avniproject/avni-webapp#1203 | Code changes to perform safe set and g…
Browse files Browse the repository at this point in the history
…et for ReportCard.standardReportCardInput key-values
  • Loading branch information
himeshr committed Jun 12, 2024
1 parent 7c3b824 commit 8ab2c57
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.avni.server.web.request.SubjectTypeContract;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Entity
Expand Down Expand Up @@ -115,26 +116,37 @@ public void setIconFileS3Key(String iconFileS3Key) {
}

public List<String> getStandardReportCardInputSubjectTypes() {
return standardReportCardInput.getList("subjectTypes");
return safeGetterForStandardReportCardInput("subjectTypes");
}

public void setStandardReportCardInputSubjectTypes(List<String> subjectTypes) {
standardReportCardInput.with("subjectTypes", subjectTypes);
safeSetterForStandardReportCardInput("subjectTypes", subjectTypes);
}

public List<String> getStandardReportCardInputPrograms() {
return standardReportCardInput.getList("programs");
return safeGetterForStandardReportCardInput("programs");
}

public void setStandardReportCardInputPrograms(List<String> programs) {
standardReportCardInput.with("programs", programs);
safeSetterForStandardReportCardInput("programs", programs);
}

public List<String> getStandardReportCardInputEncounterTypes() {
return standardReportCardInput.getList("encounterTypes");
return safeGetterForStandardReportCardInput("encounterTypes");
}

public void setStandardReportCardInputEncounterTypes(List<String> encounterTypes) {
standardReportCardInput.with("encounterTypes", encounterTypes);
safeSetterForStandardReportCardInput("encounterTypes", encounterTypes);
}

private List safeGetterForStandardReportCardInput(String key) {
return standardReportCardInput == null ? new ArrayList() : standardReportCardInput.getList(key);
}

private void safeSetterForStandardReportCardInput(String key, List<String> value) {
if(standardReportCardInput == null) {
standardReportCardInput = new JsonObject(new HashMap<>());
}
standardReportCardInput.with(key, value);
}
}

0 comments on commit 8ab2c57

Please sign in to comment.