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

Commit 7e958af

Browse files
authored
Merge pull request SORMAS-Foundation#3269 from hzi-braunschweig/bigfix-3259-CampaignDashboardEditNullValidation
SORMAS-Foundation#3259 - validate campaign dashboard element fields are not null
2 parents 2b83f91 + e434703 commit 7e958af

4 files changed

Lines changed: 19 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
import de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto;
3535
import de.symeda.sormas.api.i18n.I18nProperties;
3636
import de.symeda.sormas.api.i18n.Strings;
37+
import de.symeda.sormas.api.i18n.Validations;
3738
import de.symeda.sormas.api.user.UserRight;
3839
import de.symeda.sormas.api.user.UserRole;
3940
import de.symeda.sormas.api.utils.SortProperty;
41+
import de.symeda.sormas.api.utils.ValidationRuntimeException;
4042
import de.symeda.sormas.backend.campaign.form.CampaignFormMetaFacadeEjb;
4143
import de.symeda.sormas.backend.campaign.form.CampaignFormMetaService;
4244
import de.symeda.sormas.backend.common.AbstractAdoService;
@@ -173,6 +175,8 @@ public Campaign fromDto(@NotNull CampaignDto source) {
173175
}
174176
DtoHelper.validateDto(source, target);
175177

178+
validate(source);
179+
176180
target.setCreatingUser(userService.getByReferenceDto(source.getCreatingUser()));
177181
target.setDescription(source.getDescription());
178182
target.setEndDate(source.getEndDate());
@@ -190,6 +194,17 @@ public Campaign fromDto(@NotNull CampaignDto source) {
190194
return target;
191195
}
192196

197+
private void validate(CampaignDto campaignDto) {
198+
final List<CampaignDashboardElement> campaignDashboardElements = campaignDto.getCampaignDashboardElements();
199+
if (campaignDashboardElements != null) {
200+
for (CampaignDashboardElement cde : campaignDashboardElements) {
201+
if (cde.getDiagramId() == null || cde.getTabId() == null || cde.getWidth() == null || cde.getHeight() == null || cde.getOrder() == null) {
202+
throw new ValidationRuntimeException(I18nProperties.getValidationError(Validations.campaignDashboardChartValueNull));
203+
}
204+
}
205+
}
206+
}
207+
193208
public CampaignDto toDto(Campaign source) {
194209

195210
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)