Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit b02efbc

Browse files
author
barnabartha
committed
SORMAS-Foundation#3259 - validate campaign dashboard element fields are not null
1 parent 834a0e2 commit b02efbc

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/i18n/Validations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface Validations {
1515
String beforeDate = "beforeDate";
1616
String beforeDateSoft = "beforeDateSoft";
1717
String campaignDashboardChartPercentage = "campaignDashboardChartPercentage";
18+
String campaignDashboardChartValueNull = "campaignDashboardChartValueNull";
1819
String campaignFormDependingOnNotFound = "campaignFormDependingOnNotFound";
1920
String campaignFormDependingOnValuesMissing = "campaignFormDependingOnValuesMissing";
2021
String campaignFormElementDuplicateId = "campaignFormElementDuplicateId";

sormas-api/src/main/resources/validations.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ campaignFormElementDuplicateId = Field IDs need to be unique, but the campaign f
110110
errorsInForm = There are errors in the form you tried to save. Please check the fields highlighted in red and make sure to only enter valid values.
111111
campaignFormInvalidIdInListElements = The ID %s in the campaign form list definition is not associated to any element of the form.
112112
campaignDashboardChartPercentage = Value must be a number that is multiple of 5!
113+
campaignDashboardChartValueNull = Campaign dashboard elements cannot be null!
113114
sormasToSormasCaseExists=This case already exists
114115
sormasToSormasContactExists=This contact already exists
115116
sormasToSormasContactCaseNotExists=The linked case does not exist

sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/CampaignFacadeEjb.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
import de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto;
3434
import de.symeda.sormas.api.i18n.I18nProperties;
3535
import de.symeda.sormas.api.i18n.Strings;
36+
import de.symeda.sormas.api.i18n.Validations;
3637
import de.symeda.sormas.api.user.UserRight;
3738
import de.symeda.sormas.api.user.UserRole;
3839
import de.symeda.sormas.api.utils.SortProperty;
40+
import de.symeda.sormas.api.utils.ValidationRuntimeException;
3941
import de.symeda.sormas.backend.campaign.form.CampaignFormMetaService;
4042
import de.symeda.sormas.backend.common.AbstractAdoService;
4143
import de.symeda.sormas.backend.common.AbstractDomainObject;
@@ -167,6 +169,8 @@ public Campaign fromDto(@NotNull CampaignDto source) {
167169
}
168170
DtoHelper.validateDto(source, target);
169171

172+
validate(source);
173+
170174
target.setCreatingUser(userService.getByReferenceDto(source.getCreatingUser()));
171175
target.setDescription(source.getDescription());
172176
target.setEndDate(source.getEndDate());
@@ -184,6 +188,15 @@ public Campaign fromDto(@NotNull CampaignDto source) {
184188
return target;
185189
}
186190

191+
private void validate(CampaignDto campaignDto) {
192+
final List<CampaignDashboardElement> campaignDashboardElements = campaignDto.getCampaignDashboardElements();
193+
for (CampaignDashboardElement cde : campaignDashboardElements) {
194+
if (cde.getDiagramId() == null || cde.getTabId() == null || cde.getWidth() == null || cde.getHeight() == null || cde.getOrder() == null) {
195+
throw new ValidationRuntimeException(I18nProperties.getValidationError(Validations.campaignDashboardChartValueNull));
196+
}
197+
}
198+
}
199+
187200
public CampaignDto toDto(Campaign source) {
188201

189202
if (source == null) {

sormas-ui/src/main/java/de/symeda/sormas/ui/campaign/campaigns/CampaignDashboardElementsGridComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected Binder<CampaignDashboardElement> addColumnsBinder(List<CampaignDashboa
3737
.map(campaignDiagramDefinitionDto -> campaignDiagramDefinitionDto.getDiagramId())
3838
.distinct()
3939
.collect(Collectors.toList()));
40+
diagramIdCombo.setEmptySelectionAllowed(false);
4041
Binder.Binding<CampaignDashboardElement, String> diagramIdBind =
4142
binder.bind(diagramIdCombo, CampaignDashboardElement::getDiagramId, CampaignDashboardElement::setDiagramId);
4243
Grid.Column<CampaignDashboardElement, String> diagramIdColumn =
@@ -51,6 +52,7 @@ protected Binder<CampaignDashboardElement> addColumnsBinder(List<CampaignDashboa
5152
.distinct()
5253
.collect(Collectors.toList()));
5354

55+
tabIdCombo.setEmptySelectionAllowed(false);
5456
tabIdCombo.setTextInputAllowed(true);
5557
tabIdCombo.setNewItemProvider((ComboBox.NewItemProvider<String>) s -> Optional.of(s));
5658

0 commit comments

Comments
 (0)