1

Merge pull request #142 from hhu-propra2/refactor-ValidationService

Refactor validation service
This commit is contained in:
Talha Caliskan
2020-03-26 14:19:46 +01:00
committed by GitHub
5 changed files with 28 additions and 5 deletions

View File

@ -55,6 +55,7 @@ public class WebController {
* @param model tolles model
* @return index.html
*/
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("")
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
@ -326,6 +327,7 @@ public class WebController {
@RequestParam("group_id") String groupId,
KeycloakAuthenticationToken token) {
Account account = keyCloakService.createAccountFromPrincipal(token);
validationService.checkIfNewMaximumIsValid(maximum, groupId);
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
return "redirect:/gruppen2/details/members/" + groupId;
}

View File

@ -20,7 +20,7 @@ public class UpdateGroupDescriptionEvent extends Event {
public UpdateGroupDescriptionEvent(UUID groupId, String userId, String newGroupDescription) {
super(groupId, userId);
this.newGroupDescription = newGroupDescription;
this.newGroupDescription = newGroupDescription.trim();
}
@Override

View File

@ -20,7 +20,7 @@ public class UpdateGroupTitleEvent extends Event {
public UpdateGroupTitleEvent(UUID groupId, String userId, String newGroupTitle) {
super(groupId, userId);
this.newGroupTitle = newGroupTitle;
this.newGroupTitle = newGroupTitle.trim();
}
@Override

View File

@ -4,6 +4,6 @@ import org.springframework.http.HttpStatus;
public class WrongFileException extends EventException {
public WrongFileException(String info) {
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die entsprechende Datei ist keine valide CSV-Datei!", info);
super(HttpStatus.BAD_REQUEST, "Die entsprechende Datei ist keine valide CSV-Datei!", info);
}
}

View File

@ -130,16 +130,37 @@ public class ValidationService {
* @param userMaximum Das user Limit der Gruppe
*/
public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) {
if (description == null) {
if (description == null || description.trim().length() == 0) {
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
}
if (title == null) {
if (title == null || title.trim().length() == 0) {
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
}
if (userMaximum == null && maxInfiniteUsers == null) {
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
}
if (userMaximum != null) {
if (userMaximum < 1 || userMaximum > 10000L) {
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
}
}
}
public void checkIfNewMaximumIsValid(Long newUserMaximum, String groupId) {
Group group = userService.getGroupById(UUID.fromString(groupId));
if (newUserMaximum == null) {
throw new BadParameterException("Es wurde keine neue maximale Teilnehmeranzahl angegeben!");
}
if (newUserMaximum < 1 || newUserMaximum > 10000L) {
throw new BadParameterException("Die neue maximale Teilnehmeranzahl wurde nicht korrekt angegeben!");
}
if (group.getMembers().size() > newUserMaximum) {
throw new BadParameterException("Die neue maximale Teilnehmeranzahl ist kleiner als die aktuelle Teilnehmeranzahl!");
}
}
}