add Exceptions
Co-Authored-By: andibuls <andibuls@users.noreply.github.com> Co-Authored-By: Lukas Ettel <lukasettel@users.noreply.github.com>
This commit is contained in:
@ -120,11 +120,8 @@ public class WebController {
|
|||||||
@RequestParam(value = "parent", required = false) String parent) throws EventException {
|
@RequestParam(value = "parent", required = false) String parent) throws EventException {
|
||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
visibility = visibility == null;
|
|
||||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
|
||||||
UUID parentUUID = controllerService.getUUID(parent);
|
UUID parentUUID = controllerService.getUUID(parent);
|
||||||
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
||||||
|
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
package mops.gruppen2.domain.exception;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
public class BadParameterException extends EventException {
|
||||||
|
|
||||||
|
public BadParameterException(String info) {
|
||||||
|
super(HttpStatus.INTERNAL_SERVER_ERROR, "Fehlerhafter Parameter angegeben!", info);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package mops.gruppen2.domain.exception;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
|
|
||||||
public class NoMaximumMemberException extends EventException {
|
|
||||||
|
|
||||||
public NoMaximumMemberException(String info) {
|
|
||||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Es wurde keine maximale Gruppenanzahl festgelegt", info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -15,7 +15,7 @@ import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
|||||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||||
import mops.gruppen2.domain.exception.EventException;
|
import mops.gruppen2.domain.exception.EventException;
|
||||||
import mops.gruppen2.domain.exception.NoMaximumMemberException;
|
import mops.gruppen2.domain.exception.BadParameterException;
|
||||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.domain.exception.WrongFileException;
|
import mops.gruppen2.domain.exception.WrongFileException;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
@ -54,20 +54,37 @@ public class ControllerService {
|
|||||||
* @param title Gruppentitel
|
* @param title Gruppentitel
|
||||||
* @param description Gruppenbeschreibung
|
* @param description Gruppenbeschreibung
|
||||||
*/
|
*/
|
||||||
public void createGroup(Account account, String title, String description, Boolean maxInfiniteUsers, Boolean visibility, Long userMaximum, UUID parent) throws EventException {
|
public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException {
|
||||||
Visibility visibility1;
|
Visibility visibility1;
|
||||||
UUID groupId = eventService.checkGroup();
|
UUID groupId = eventService.checkGroup();
|
||||||
|
|
||||||
|
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||||
|
|
||||||
|
|
||||||
|
if(maxInfiniteUsers) {
|
||||||
|
userMaximum = 100000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(description == null) {
|
||||||
|
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(title == null) {
|
||||||
|
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userMaximum == null) {
|
||||||
|
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
visibility = visibility == null;
|
||||||
|
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
visibility1 = Visibility.PUBLIC;
|
visibility1 = Visibility.PUBLIC;
|
||||||
} else {
|
} else {
|
||||||
visibility1 = Visibility.PRIVATE;
|
visibility1 = Visibility.PRIVATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(maxInfiniteUsers){
|
|
||||||
userMaximum = 100000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
|
||||||
eventService.saveEvent(createGroupEvent);
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
|
||||||
@ -83,8 +100,17 @@ public class ControllerService {
|
|||||||
if(maxInfiniteUsers) {
|
if(maxInfiniteUsers) {
|
||||||
userMaximum = 100000L;
|
userMaximum = 100000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(description == null) {
|
||||||
|
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(title == null) {
|
||||||
|
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
if (userMaximum == null) {
|
if (userMaximum == null) {
|
||||||
throw new NoMaximumMemberException(this.getClass().toString());
|
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||||
}
|
}
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user