Merge branch 'master' into add-ValidationService
This commit is contained in:
@ -39,7 +39,7 @@ public class AddUserEvent extends Event {
|
||||
throw new UserAlreadyExistsException(this.getClass().toString());
|
||||
}
|
||||
|
||||
if (group.getMembers().size() == group.getUserMaximum()) {
|
||||
if (group.getMembers().size() >= group.getUserMaximum()) {
|
||||
throw new GroupFullException(this.getClass().toString());
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
//TODO Rename Queries + Formatting
|
||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@Query("select distinct group_id from event where user_id =:id")
|
||||
|
||||
@ -56,7 +56,7 @@ public class ControllerService {
|
||||
*/
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException {
|
||||
Visibility visibility1;
|
||||
UUID groupId = eventService.checkGroup();
|
||||
UUID groupId = UUID.randomUUID();
|
||||
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
|
||||
@ -91,8 +91,7 @@ public class ControllerService {
|
||||
visibility = visibility == null;
|
||||
lecture = lecture != null;
|
||||
Visibility visibility1;
|
||||
UUID groupId = eventService.checkGroup();
|
||||
|
||||
UUID groupId = UUID.randomUUID();
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
|
||||
@ -12,6 +12,7 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
//TODO: Evtl aufsplitten in EventRepoService und EventService?
|
||||
public class EventService {
|
||||
|
||||
private final JsonService jsonService;
|
||||
@ -28,8 +29,22 @@ public class EventService {
|
||||
* @param event Event, welches gespeichert wird
|
||||
*/
|
||||
public void saveEvent(Event event) {
|
||||
EventDTO eventDTO = getDTO(event);
|
||||
eventStore.save(eventDTO);
|
||||
eventStore.save(getDTO(event));
|
||||
}
|
||||
|
||||
public void saveAll(Event... events) {
|
||||
for (Event event : events) {
|
||||
eventStore.save(getDTO(event));
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void saveAll(List<Event>... events) {
|
||||
for (List<Event> eventlist : events) {
|
||||
for (Event event : eventlist) {
|
||||
eventStore.save(getDTO(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,6 +54,7 @@ public class EventService {
|
||||
* @param event Event, welches in DTO übersetzt wird
|
||||
* @return EventDTO Neues DTO
|
||||
*/
|
||||
//TODO Rename: getDTOFromEvent?
|
||||
public EventDTO getDTO(Event event) {
|
||||
String payload = "";
|
||||
try {
|
||||
@ -56,26 +72,9 @@ public class EventService {
|
||||
return event.getClass().getName().substring(lastDot + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die nächst höhere groupID zurück die belegt werden kann.
|
||||
* Gibt 1 zurück, falls keine Gruppe vorhanden ist.
|
||||
*
|
||||
* @return Long GruppenId
|
||||
*/
|
||||
public UUID checkGroup() {
|
||||
return UUID.randomUUID();
|
||||
|
||||
/*Long maxGroupID = eventStore.getMaxGroupID();
|
||||
|
||||
if (maxGroupID == null) {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
return maxGroupID + 1;*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Findet alle Events welche ab dem neuen Status hinzugekommen sind.
|
||||
* Sucht alle Events mit event_id > status
|
||||
*
|
||||
* @param status Die Id des zuletzt gespeicherten Events
|
||||
* @return Liste von neueren Events
|
||||
@ -93,6 +92,7 @@ public class EventService {
|
||||
* @param eventDTOS Liste von DTOs
|
||||
* @return Liste von Events
|
||||
*/
|
||||
//TODO Rename: getEventsFromDTO?
|
||||
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) {
|
||||
List<Event> events = new ArrayList<>();
|
||||
|
||||
@ -106,17 +106,6 @@ public class EventService {
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event).
|
||||
*
|
||||
* @param eventList Liste von Event Objekten
|
||||
*/
|
||||
public void saveEventList(List<Event> eventList) {
|
||||
for (Event event : eventList) {
|
||||
saveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public Long getMaxEvent_id() {
|
||||
return eventStore.getHighesEvent_ID();
|
||||
}
|
||||
@ -126,6 +115,7 @@ public class EventService {
|
||||
return translateEventDTOs(eventDTOList);
|
||||
}
|
||||
|
||||
//TODO: Nur AddUserEvents betrachten
|
||||
public List<UUID> findGroupIdsByUser(String userId) {
|
||||
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||
.map(UUID::fromString)
|
||||
|
||||
@ -35,6 +35,7 @@ public class GroupService {
|
||||
* @param groupIds Liste an IDs
|
||||
* @return Liste an Events
|
||||
*/
|
||||
//TODO Das vielleicht in den EventRepoService?
|
||||
public List<Event> getGroupEvents(List<UUID> groupIds) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
for (UUID groupId : groupIds) {
|
||||
@ -75,6 +76,7 @@ public class GroupService {
|
||||
* @return Liste von projizierten Gruppen
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
@ -91,21 +93,16 @@ public class GroupService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
||||
*
|
||||
* @return
|
||||
* @throws EventException
|
||||
*/
|
||||
|
||||
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(createEvents);
|
||||
|
||||
return visibleGroups.parallelStream()
|
||||
.filter(group -> group.getType() != null)
|
||||
.filter(group -> group.getType() == GroupType.LECTURE)
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
@ -120,6 +117,7 @@ public class GroupService {
|
||||
* @return Liste von projizierten Gruppen
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//Todo Rename
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
if (search.isEmpty()) {
|
||||
return getAllGroupWithVisibilityPublic(account.getName());
|
||||
@ -127,9 +125,8 @@ public class GroupService {
|
||||
|
||||
return getAllGroupWithVisibilityPublic(account.getName())
|
||||
.parallelStream()
|
||||
.filter(group ->
|
||||
group.getTitle().toLowerCase().contains(search.toLowerCase()) ||
|
||||
group.getDescription().toLowerCase().contains(search.toLowerCase()))
|
||||
.filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase())
|
||||
|| group.getDescription().toLowerCase().contains(search.toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user