1

initial groupcache

This commit is contained in:
Christoph
2020-04-15 02:04:06 +02:00
parent b2b636b4e8
commit 40adc558cb

View File

@ -0,0 +1,57 @@
package mops.gruppen2.infrastructure;
import lombok.RequiredArgsConstructor;
import mops.gruppen2.domain.model.group.Group;
import mops.gruppen2.domain.service.ProjectionService;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RequiredArgsConstructor
@Component
@Scope("singleton")
public class GroupCache {
private final ProjectionService projectionService;
private long version;
private boolean isValid;
private String principal;
private Map<UUID, Group> groups;
private List<UUID> userGroups;
private List<UUID> publics;
private List<UUID> privates;
private List<UUID> lectures;
@EventListener(ApplicationReadyEvent.class)
public void init() {
groups = projectionService.projectAllGroups();
Group current;
UUID currentId;
for (Map.Entry<UUID, Group> entry : groups.entrySet()) {
current = entry.getValue();
currentId = entry.getKey();
if (current.isMember(principal)) {
userGroups.add(currentId);
}
if (current.isPublic()) {
publics.add(currentId);
}
if (current.isPrivate()) {
privates.add(currentId);
}
if (current.isLecture()) {
lectures.add(currentId);
}
}
}
}