Skip to content

Commit

Permalink
Added a util classes to validate empty html based description
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainsabir52 committed Jan 27, 2025
1 parent fe4bd0d commit 1b9b0b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/de/imi/mopat/helper/controller/HtmlUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.imi.mopat.helper.controller;

import java.util.regex.Pattern;

public class HtmlUtils {
private static final Pattern HTML_TAG_PATTERN = Pattern.compile("<[^>]*>");

public static String removeHtmlTags(String input) {
if (input == null) {
return null;
}
return HTML_TAG_PATTERN.matcher(input).replaceAll("");
}
}
9 changes: 9 additions & 0 deletions src/main/java/de/imi/mopat/validator/BundleDTOValidator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.imi.mopat.validator;

import de.imi.mopat.dao.BundleDao;
import de.imi.mopat.helper.controller.HtmlUtils;
import de.imi.mopat.model.Bundle;
import de.imi.mopat.model.dto.BundleDTO;
import de.imi.mopat.model.dto.BundleQuestionnaireDTO;
Expand Down Expand Up @@ -55,6 +56,14 @@ public void validate(final Object o, final Errors errors) {
LocaleContextHolder.getLocale()));
}

String bundleDescription = HtmlUtils.removeHtmlTags(bundleDTO.getDescription());

if (bundleDescription.isEmpty()) {
errors.rejectValue("description", "errormessage",
messageSource.getMessage("bundle.description.notNull", new Object[]{},
LocaleContextHolder.getLocale()));
}

// Check if at least the first questionnaire is enabled in this bundle
if (bundleDTO.getBundleQuestionnaireDTOs() != null
&& !bundleDTO.getBundleQuestionnaireDTOs().isEmpty()) {
Expand Down

0 comments on commit 1b9b0b6

Please sign in to comment.