initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.partey.api.controller.support.DebugLogger;
|
||||
import de.bstly.we.partey.api.security.ParteyApiAuthentication;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/api")
|
||||
public class DebugController extends DebugLogger {
|
||||
|
||||
@Autowired
|
||||
private ParteyApiAuthentication parteyApiAuthentication;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequestMapping("/**")
|
||||
public void debug(@RequestBody Optional<Object> payload, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
parteyApiAuthentication.authenticateRequest(request);
|
||||
|
||||
debugPrintRequest(request, payload);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
|
||||
import de.bstly.we.partey.api.controller.model.MapDetailsData;
|
||||
import de.bstly.we.partey.api.controller.support.DebugLogger;
|
||||
import de.bstly.we.partey.api.security.ParteyApiAuthentication;
|
||||
import de.bstly.we.partey.businesslogic.ParteyMapManager;
|
||||
import de.bstly.we.partey.businesslogic.model.Room;
|
||||
import de.bstly.we.partey.model.GameRoomPolicyTypes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/api/map")
|
||||
public class MapController extends DebugLogger {
|
||||
|
||||
@Autowired
|
||||
private ParteyApiAuthentication parteyApiAuthentication;
|
||||
@Autowired
|
||||
private ParteyMapManager parteyMapManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param playUri
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping
|
||||
public MapDetailsData getMapData(@RequestParam("playUri") String playUri, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
parteyApiAuthentication.authenticateRequest(request);
|
||||
|
||||
debugPrintRequest(request);
|
||||
|
||||
MapDetailsData mapData = new MapDetailsData();
|
||||
mapData.setTags(Lists.newArrayList());
|
||||
mapData.setPolicy_type(GameRoomPolicyTypes.UNKNOWN);
|
||||
|
||||
Room room = parteyMapManager.parseRoom(playUri, request);
|
||||
mapData.setMapUrl(room.getMapUrl());
|
||||
|
||||
if (room.getTags() != null) {
|
||||
mapData.setTags(room.getTags());
|
||||
}
|
||||
|
||||
if (room.getPolicyType() != null) {
|
||||
mapData.setPolicy_type(room.getPolicyType());
|
||||
}
|
||||
|
||||
debugPrintResponse(request, Optional.of(mapData));
|
||||
|
||||
return mapData;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.partey.api.controller.model.UserReport;
|
||||
import de.bstly.we.partey.api.controller.support.DebugLogger;
|
||||
import de.bstly.we.partey.api.security.ParteyApiAuthentication;
|
||||
import de.bstly.we.partey.businesslogic.ParteyUserReportManager;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/api/report")
|
||||
public class ReportController extends DebugLogger {
|
||||
|
||||
@Autowired
|
||||
private ParteyApiAuthentication parteyApiAuthentication;
|
||||
@Autowired
|
||||
private ParteyUserReportManager parteyUserReportManager;
|
||||
|
||||
@PostMapping("")
|
||||
public void report(@RequestBody UserReport userReport, HttpServletRequest request) {
|
||||
parteyApiAuthentication.authenticateRequest(request);
|
||||
debugPrintRequest(request);
|
||||
|
||||
parteyUserReportManager.create(Long.valueOf(userReport.getReporterUserUuid()),
|
||||
Long.valueOf(userReport.getReportedUserUuid()), userReport.getReportedUserComment(),
|
||||
userReport.getReportWorldSlug());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
|
||||
import de.bstly.we.businesslogic.PermissionManager;
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.model.User;
|
||||
import de.bstly.we.partey.api.controller.model.MemberData;
|
||||
import de.bstly.we.partey.api.controller.support.DebugLogger;
|
||||
import de.bstly.we.partey.api.security.ParteyApiAuthentication;
|
||||
import de.bstly.we.partey.businesslogic.ParteyMapManager;
|
||||
import de.bstly.we.partey.businesslogic.ParteyPermissions;
|
||||
import de.bstly.we.partey.businesslogic.ParteyUserTagManager;
|
||||
import de.bstly.we.partey.businesslogic.model.Room;
|
||||
import de.bstly.we.partey.model.ParteyUserTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/api/room")
|
||||
public class RoomController extends DebugLogger {
|
||||
|
||||
@Autowired
|
||||
private ParteyApiAuthentication parteyApiAuthentication;
|
||||
@Autowired
|
||||
private PermissionManager permissionManager;
|
||||
@Autowired
|
||||
private ParteyMapManager parteyMapManager;
|
||||
@Autowired
|
||||
private ParteyUserTagManager parteyUserTagManager;
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
|
||||
@Value("${we.bstly.partey.visitCardUrlFormat:}")
|
||||
private String visitCardUrlFormat;
|
||||
|
||||
private List<String> worldMapCache = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userIdentifier
|
||||
* @param roomId
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/access")
|
||||
public MemberData access(@RequestParam("userIdentifier") String userIdentifier,
|
||||
@RequestParam("roomId") String roomId, HttpServletRequest request) {
|
||||
parteyApiAuthentication.authenticateRequest(request);
|
||||
|
||||
debugPrintRequest(request);
|
||||
|
||||
Room room = parteyMapManager.parseRoom(roomId, request);
|
||||
|
||||
if (!worldMapCache.contains(room.getUrl())) {
|
||||
worldMapCache.add(room.getUrl());
|
||||
}
|
||||
|
||||
MemberData memberData = new MemberData();
|
||||
memberData.setUserUuid(userIdentifier);
|
||||
memberData.setAnonymous(true);
|
||||
memberData.setTags(Lists.newArrayList());
|
||||
try {
|
||||
Long userId = Long.parseLong(userIdentifier);
|
||||
|
||||
if (StringUtils.hasText(visitCardUrlFormat)) {
|
||||
User user = userManager.get(userId);
|
||||
memberData.setVisitCardUrl(String.format(visitCardUrlFormat, user.getUsername()));
|
||||
}
|
||||
|
||||
if (permissionManager.isFullUser(userId)
|
||||
&& permissionManager.hasPermission(userId, ParteyPermissions.PARTEY)) {
|
||||
memberData.setAnonymous(false);
|
||||
|
||||
for (ParteyUserTag parteyUserTag : parteyUserTagManager.getForTarget(userId)) {
|
||||
memberData.getTags().add(parteyUserTag.getTag());
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
debugPrintResponse(request, Optional.of(memberData));
|
||||
|
||||
return memberData;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param roomUrl
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/sameWorld")
|
||||
public List<String> sameWorld(@RequestParam("roomUrl") String roomUrl,
|
||||
HttpServletRequest request) {
|
||||
parteyApiAuthentication.authenticateRequest(request);
|
||||
|
||||
debugPrintRequest(request);
|
||||
|
||||
Room room = parteyMapManager.parseRoom(roomUrl, request);
|
||||
|
||||
if (!worldMapCache.contains(room.getUrl())) {
|
||||
worldMapCache.add(room.getUrl());
|
||||
}
|
||||
|
||||
return worldMapCache;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller.model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public class CharacterTexture {
|
||||
|
||||
private int id;
|
||||
private int level;
|
||||
private String url;
|
||||
private String rights;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the level
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level the level to set
|
||||
*/
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rights
|
||||
*/
|
||||
public String getRights() {
|
||||
return rights;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rights the rights to set
|
||||
*/
|
||||
public void setRights(String rights) {
|
||||
this.rights = rights;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.bstly.we.partey.model.GameRoomPolicyTypes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public class MapDetailsData {
|
||||
|
||||
private String mapUrl;
|
||||
private GameRoomPolicyTypes policy_type = GameRoomPolicyTypes.ANONYMOUS_POLICY;
|
||||
private List<String> tags = Lists.newArrayList();
|
||||
private List<CharacterTexture> textures = Lists.newArrayList();
|
||||
private boolean authenticationMandatory;
|
||||
private String iframeAuthentication;
|
||||
|
||||
/**
|
||||
* @return the mapUrl
|
||||
*/
|
||||
public String getMapUrl() {
|
||||
return mapUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapUrl the mapUrl to set
|
||||
*/
|
||||
public void setMapUrl(String mapUrl) {
|
||||
this.mapUrl = mapUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the policy_type
|
||||
*/
|
||||
public GameRoomPolicyTypes getPolicy_type() {
|
||||
return policy_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policy_type the policy_type to set
|
||||
*/
|
||||
public void setPolicy_type(GameRoomPolicyTypes policy_type) {
|
||||
this.policy_type = policy_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tags
|
||||
*/
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tags the tags to set
|
||||
*/
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the textures
|
||||
*/
|
||||
public List<CharacterTexture> getTextures() {
|
||||
return textures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param textures the textures to set
|
||||
*/
|
||||
public void setTextures(List<CharacterTexture> textures) {
|
||||
this.textures = textures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the authenticationMandatory
|
||||
*/
|
||||
public boolean isAuthenticationMandatory() {
|
||||
return authenticationMandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationMandatory the authenticationMandatory to set
|
||||
*/
|
||||
public void setAuthenticationMandatory(boolean authenticationMandatory) {
|
||||
this.authenticationMandatory = authenticationMandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the iframeAuthentication
|
||||
*/
|
||||
public String getIframeAuthentication() {
|
||||
return iframeAuthentication;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param iframeAuthentication the iframeAuthentication to set
|
||||
*/
|
||||
public void setIframeAuthentication(String iframeAuthentication) {
|
||||
this.iframeAuthentication = iframeAuthentication;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public class MemberData {
|
||||
|
||||
private String userUuid;
|
||||
private List<String> tags = Lists.newArrayList();
|
||||
private String visitCardUrl;
|
||||
private List<CharacterTexture> textures = Lists.newArrayList();
|
||||
private List<Object> messages = Lists.newArrayList();
|
||||
private boolean anonymous;
|
||||
|
||||
/**
|
||||
* @return the userUuid
|
||||
*/
|
||||
public String getUserUuid() {
|
||||
return userUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userUuid the userUuid to set
|
||||
*/
|
||||
public void setUserUuid(String userUuid) {
|
||||
this.userUuid = userUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tags
|
||||
*/
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tags the tags to set
|
||||
*/
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the visitCardUrl
|
||||
*/
|
||||
public String getVisitCardUrl() {
|
||||
return visitCardUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visitCardUrl the visitCardUrl to set
|
||||
*/
|
||||
public void setVisitCardUrl(String visitCardUrl) {
|
||||
this.visitCardUrl = visitCardUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the textures
|
||||
*/
|
||||
public List<CharacterTexture> getTextures() {
|
||||
return textures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param textures the textures to set
|
||||
*/
|
||||
public void setTextures(List<CharacterTexture> textures) {
|
||||
this.textures = textures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the messages
|
||||
*/
|
||||
public List<Object> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param messages the messages to set
|
||||
*/
|
||||
public void setMessages(List<Object> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the anonymous
|
||||
*/
|
||||
public boolean isAnonymous() {
|
||||
return anonymous;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param anonymous the anonymous to set
|
||||
*/
|
||||
public void setAnonymous(boolean anonymous) {
|
||||
this.anonymous = anonymous;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller.model;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public class UserReport {
|
||||
|
||||
private String reportedUserUuid;
|
||||
private String reportedUserComment;
|
||||
private String reporterUserUuid;
|
||||
private String reportWorldSlug;
|
||||
|
||||
/**
|
||||
* @return the reportedUserUuid
|
||||
*/
|
||||
public String getReportedUserUuid() {
|
||||
return reportedUserUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reportedUserUuid the reportedUserUuid to set
|
||||
*/
|
||||
public void setReportedUserUuid(String reportedUserUuid) {
|
||||
this.reportedUserUuid = reportedUserUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reportedUserComment
|
||||
*/
|
||||
public String getReportedUserComment() {
|
||||
return reportedUserComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reportedUserComment the reportedUserComment to set
|
||||
*/
|
||||
public void setReportedUserComment(String reportedUserComment) {
|
||||
this.reportedUserComment = reportedUserComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reporterUserUuid
|
||||
*/
|
||||
public String getReporterUserUuid() {
|
||||
return reporterUserUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reporterUserUuid the reporterUserUuid to set
|
||||
*/
|
||||
public void setReporterUserUuid(String reporterUserUuid) {
|
||||
this.reporterUserUuid = reporterUserUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reportWorldSlug
|
||||
*/
|
||||
public String getReportWorldSlug() {
|
||||
return reportWorldSlug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reportWorldSlug the reportWorldSlug to set
|
||||
*/
|
||||
public void setReportWorldSlug(String reportWorldSlug) {
|
||||
this.reportWorldSlug = reportWorldSlug;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.controller.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public class DebugLogger {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected Gson gson = new Gson();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
public void debugPrintRequest(HttpServletRequest request) {
|
||||
debugPrintRequest(request, Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @param payload
|
||||
*/
|
||||
public void debugPrintRequest(HttpServletRequest request, Optional<Object> payload) {
|
||||
logger.debug(
|
||||
"Request: " + request.getMethod().toUpperCase() + " " + request.getRequestURI());
|
||||
|
||||
logger.debug("Headers:");
|
||||
|
||||
for (Iterator<String> it = request.getHeaderNames().asIterator(); it.hasNext();) {
|
||||
String headerName = it.next();
|
||||
logger.debug("\t" + headerName + ": " + request.getHeader(headerName));
|
||||
}
|
||||
|
||||
if (!request.getParameterMap().isEmpty()) {
|
||||
logger.debug("Parameters:");
|
||||
for (Iterator<String> it = request.getParameterNames().asIterator(); it.hasNext();) {
|
||||
String parameterName = it.next();
|
||||
logger.debug("\t" + parameterName + ": " + request.getParameter(parameterName));
|
||||
}
|
||||
}
|
||||
|
||||
if (payload.isPresent()) {
|
||||
logger.debug("Body:");
|
||||
logger.debug(gson.toJson(payload.get()));
|
||||
}
|
||||
|
||||
logger.debug("");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param response
|
||||
* @param payload
|
||||
*/
|
||||
public void debugPrintResponse(HttpServletRequest response, Optional<Object> payload) {
|
||||
if (payload.isPresent()) {
|
||||
logger.debug("Response: " + response.getRequestURI());
|
||||
logger.debug("Body:");
|
||||
logger.debug(gson.toJson(payload.get()));
|
||||
logger.debug("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.api.security;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import de.bstly.we.businesslogic.PermissionManager;
|
||||
import de.bstly.we.businesslogic.Permissions;
|
||||
import de.bstly.we.controller.support.EntityResponseStatusException;
|
||||
import de.bstly.we.security.model.LocalUserDetails;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ParteyApiAuthentication {
|
||||
|
||||
@Value("${we.bstly.partey.apiToken:}")
|
||||
private String apiToken;
|
||||
|
||||
@Autowired
|
||||
private PermissionManager permissionManager;
|
||||
|
||||
public void authenticateRequest(HttpServletRequest request) {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.isAuthenticated()
|
||||
&& auth.getPrincipal() instanceof LocalUserDetails) {
|
||||
LocalUserDetails details = (LocalUserDetails) auth.getPrincipal();
|
||||
if (!permissionManager.hasPermission(details.getUserId(), Permissions.ROLE_ADMIN)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
} else {
|
||||
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
|
||||
if (!StringUtils.hasText(token) || !token.equals(apiToken)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
|
||||
import de.bstly.we.partey.businesslogic.model.Room;
|
||||
import de.bstly.we.partey.model.GameRoomPolicyTypes;
|
||||
import de.bstly.we.partey.model.ParteyMap;
|
||||
import de.bstly.we.partey.repository.ParteyMapRepository;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ParteyMapManager {
|
||||
|
||||
@Autowired
|
||||
private ParteyMapRepository parteyMapRepository;
|
||||
|
||||
@Value("${we.bstly.partey.mapUrl:http://localhost/}")
|
||||
private String internalMapUri;
|
||||
|
||||
private Pattern internalMapUriPattern = Pattern.compile("\\/@\\/(.+)");
|
||||
private Pattern externalMapUriPattern = Pattern.compile("\\/_\\/(.+)");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public ParteyMap get(String id) {
|
||||
return parteyMapRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page
|
||||
* @param size
|
||||
* @param sortBy
|
||||
* @param descending
|
||||
* @return
|
||||
*/
|
||||
public Page<ParteyMap> get(int page, int size, String sortBy, boolean descending) {
|
||||
PageRequest pageRequest = PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||
|
||||
return parteyMapRepository.findAll(pageRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public ParteyMap save(ParteyMap parteyMap) {
|
||||
return parteyMapRepository.save(parteyMap);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void delete(String id) {
|
||||
parteyMapRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public Room parseRoom(String url, HttpServletRequest request) {
|
||||
Room room = new Room();
|
||||
room.setPolicyType(GameRoomPolicyTypes.UNKNOWN);
|
||||
room.setTags(Lists.newArrayList());
|
||||
room.setUrl(url);
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new ResponseStatusException(HttpStatus.CONFLICT, "invalid playUri");
|
||||
}
|
||||
|
||||
Matcher internalMatcher = internalMapUriPattern.matcher(uri.getPath());
|
||||
Matcher externalMatcher = externalMapUriPattern.matcher(uri.getPath());
|
||||
|
||||
if (internalMatcher.matches()) {
|
||||
room.setPolicyType(GameRoomPolicyTypes.MEMBERS_ONLY_POLICY);
|
||||
room.setMapId(internalMatcher.group(1));
|
||||
room.setMapUrl(internalMapUri + room.getMapId());
|
||||
} else if (externalMatcher.matches()) {
|
||||
room.setMapId(externalMatcher.group(1));
|
||||
if (StringUtils.hasText(uri.getScheme())) {
|
||||
room.setMapUrl(uri.getScheme() + "://" + room.getMapId());
|
||||
} else {
|
||||
room.setMapUrl(request.getScheme() + "://" + room.getMapId());
|
||||
}
|
||||
} else {
|
||||
throw new ResponseStatusException(HttpStatus.CONFLICT, "invalid playUri");
|
||||
}
|
||||
|
||||
ParteyMap parteyMap = get(room.getMapId());
|
||||
if (parteyMap != null) {
|
||||
if (parteyMap.getPolicyType() != null) {
|
||||
room.setPolicyType(parteyMap.getPolicyType());
|
||||
}
|
||||
if (parteyMap.getTags() != null) {
|
||||
room.setTags(parteyMap.getTags());
|
||||
}
|
||||
}
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public interface ParteyPermissions {
|
||||
|
||||
public static final String PARTEY = "partey";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public interface ParteyQuotas {
|
||||
|
||||
public static final String PARTEY_TIMESLOT = "partey_timeslot";
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import de.bstly.we.partey.model.ParteyUserReport;
|
||||
import de.bstly.we.partey.model.QParteyUserReport;
|
||||
import de.bstly.we.partey.repository.ParteyUserReportRepository;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ParteyUserReportManager {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserReportRepository parteyUserReportRepository;
|
||||
@Autowired
|
||||
private ParteyUserReportModeratorManager parteyUserReportModeratorManager;
|
||||
private QParteyUserReport qParteyUserReport = QParteyUserReport.parteyUserReport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param reporter
|
||||
* @param user
|
||||
* @param comment
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public ParteyUserReport create(Long reporter, Long user, String comment, String world) {
|
||||
ParteyUserReport parteyUserReport = new ParteyUserReport();
|
||||
|
||||
parteyUserReport.setReporter(reporter);
|
||||
parteyUserReport.setUser(user);
|
||||
parteyUserReport.setComment(comment);
|
||||
parteyUserReport.setWorld(world);
|
||||
parteyUserReport.setCreated(Instant.now());
|
||||
|
||||
parteyUserReport = parteyUserReportRepository.save(parteyUserReport);
|
||||
|
||||
parteyUserReportModeratorManager.sendMail(parteyUserReport);
|
||||
|
||||
return parteyUserReport;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page
|
||||
* @param size
|
||||
* @param sortBy
|
||||
* @param descending
|
||||
* @return
|
||||
*/
|
||||
public Page<ParteyUserReport> get(int page, int size, String sortBy, boolean descending) {
|
||||
PageRequest pageRequest = PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||
|
||||
return parteyUserReportRepository.findAll(pageRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserReport
|
||||
* @return
|
||||
*/
|
||||
public ParteyUserReport save(ParteyUserReport parteyUserReport) {
|
||||
return parteyUserReportRepository.save(parteyUserReport);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
parteyUserReportRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void deleteAll() {
|
||||
parteyUserReportRepository.deleteAll();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param before
|
||||
*/
|
||||
public void deleteAllBefore(Instant before) {
|
||||
parteyUserReportRepository.deleteAll(
|
||||
parteyUserReportRepository.findAll(qParteyUserReport.created.before(before)));
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.email.businesslogic.EmailManager;
|
||||
import de.bstly.we.i18n.businesslogic.I18nManager;
|
||||
import de.bstly.we.model.User;
|
||||
import de.bstly.we.partey.model.ParteyUserReport;
|
||||
import de.bstly.we.partey.model.ParteyUserReportModerator;
|
||||
import de.bstly.we.partey.model.QParteyUserReportModerator;
|
||||
import de.bstly.we.partey.repository.ParteyUserReportModeratorRepository;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ParteyUserReportModeratorManager {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserReportModeratorRepository parteyUserReportModeratorRepository;
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
@Autowired
|
||||
private EmailManager emailManager;
|
||||
@Autowired
|
||||
private I18nManager i18nManager;
|
||||
private QParteyUserReportModerator qParteyUserReportModerator = QParteyUserReportModerator.parteyUserReportModerator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page
|
||||
* @param size
|
||||
* @param sortBy
|
||||
* @param descending
|
||||
* @return
|
||||
*/
|
||||
public Page<ParteyUserReportModerator> get(int page, int size, String sortBy,
|
||||
boolean descending) {
|
||||
PageRequest pageRequest = PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||
|
||||
return parteyUserReportModeratorRepository.findAll(pageRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserReport
|
||||
*/
|
||||
public void sendMail(ParteyUserReport parteyUserReport) {
|
||||
String subject = "User in partey reported";
|
||||
String textTemplate = "User '%s' reported '%s' on map '%s' at %s with following comment:\n\n'%s'";
|
||||
|
||||
JsonObject label = i18nManager.getLabel("en");
|
||||
if (label != null) {
|
||||
if (label.has("partey.report.email.text")) {
|
||||
textTemplate = label.get("partey.report.email.text").getAsString();
|
||||
}
|
||||
if (label.has("partey.report.email.subject")) {
|
||||
subject = label.get("partey.report.email.subject").getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
User reporter = userManager.get(parteyUserReport.getReporter());
|
||||
User user = userManager.get(parteyUserReport.getUser());
|
||||
|
||||
String text = String.format(textTemplate, reporter.getUsername(), user.getUsername(),
|
||||
parteyUserReport.getWorld(), parteyUserReport.getCreated(),
|
||||
parteyUserReport.getComment());
|
||||
|
||||
List<String> bcc = Lists.newArrayList();
|
||||
for (ParteyUserReportModerator parteyUserReportModerator : parteyUserReportModeratorRepository
|
||||
.findAll(qParteyUserReportModerator.disabled.isFalse())) {
|
||||
bcc.add(parteyUserReportModerator.getEmail());
|
||||
}
|
||||
|
||||
emailManager.sendBcc(bcc.toArray(new String[] {}), "no-reply@prty.bstly.de", subject, text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserReportModerator
|
||||
* @return
|
||||
*/
|
||||
public ParteyUserReportModerator save(ParteyUserReportModerator parteyUserReportModerator) {
|
||||
return parteyUserReportModeratorRepository.save(parteyUserReportModerator);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
parteyUserReportModeratorRepository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.bstly.we.partey.model.ParteyUserTag;
|
||||
import de.bstly.we.partey.model.QParteyUserTag;
|
||||
import de.bstly.we.partey.repository.ParteyUserTagRepository;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ParteyUserTagManager {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserTagRepository parteyUserTagRepository;
|
||||
private QParteyUserTag qParteyUserTag = QParteyUserTag.parteyUserTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page
|
||||
* @param size
|
||||
* @param sortBy
|
||||
* @param descending
|
||||
* @return
|
||||
*/
|
||||
public Page<ParteyUserTag> get(int page, int size, String sortBy, boolean descending) {
|
||||
PageRequest pageRequest = PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||
|
||||
return parteyUserTagRepository.findAll(pageRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
*/
|
||||
public List<ParteyUserTag> getForTarget(long target) {
|
||||
return Lists
|
||||
.newArrayList(parteyUserTagRepository.findAll(qParteyUserTag.target.eq(target)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserTag
|
||||
* @return
|
||||
*/
|
||||
public ParteyUserTag save(ParteyUserTag parteyUserTag) {
|
||||
return parteyUserTagRepository.save(parteyUserTag);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
parteyUserTagRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param before
|
||||
*/
|
||||
public void deleteAllForTarget(Long target) {
|
||||
parteyUserTagRepository
|
||||
.deleteAll(parteyUserTagRepository.findAll(qParteyUserTag.target.eq(target)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.businesslogic.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.bstly.we.partey.model.GameRoomPolicyTypes;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public class Room {
|
||||
|
||||
private String url;
|
||||
private String mapId;
|
||||
private String mapUrl;
|
||||
private GameRoomPolicyTypes policyType;
|
||||
private List<String> tags = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mapId
|
||||
*/
|
||||
public String getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapId the mapId to set
|
||||
*/
|
||||
public void setMapId(String mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mapUrl
|
||||
*/
|
||||
public String getMapUrl() {
|
||||
return mapUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapUrl the mapUrl to set
|
||||
*/
|
||||
public void setMapUrl(String mapUrl) {
|
||||
this.mapUrl = mapUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the policyType
|
||||
*/
|
||||
public GameRoomPolicyTypes getPolicyType() {
|
||||
return policyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policyType the policyType to set
|
||||
*/
|
||||
public void setPolicyType(GameRoomPolicyTypes policyType) {
|
||||
this.policyType = policyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tags
|
||||
*/
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tags the tags to set
|
||||
*/
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.controller;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.partey.businesslogic.ParteyMapManager;
|
||||
import de.bstly.we.partey.model.GameRoomPolicyTypes;
|
||||
import de.bstly.we.partey.model.ParteyMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/maps")
|
||||
public class MapManagementController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ParteyMapManager parteyMapManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pageParameter
|
||||
* @param sizeParameter
|
||||
* @param sortParameter
|
||||
* @param descParameter
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping
|
||||
public Page<ParteyMap> getParteyMaps(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
|
||||
Page<ParteyMap> page = parteyMapManager.get(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false));
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyMap
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public ParteyMap createOrUpdateParteyMap(@RequestBody ParteyMap parteyMap) {
|
||||
if (parteyMap.getPolicyType() == null) {
|
||||
parteyMap.setPolicyType(GameRoomPolicyTypes.MEMBERS_ONLY_POLICY);
|
||||
}
|
||||
|
||||
if (parteyMap.getTags() == null) {
|
||||
parteyMap.setTags(Lists.newArrayList());
|
||||
}
|
||||
|
||||
return parteyMapManager.save(parteyMap);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteParteyMap(@PathVariable("id") String id) {
|
||||
parteyMapManager.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.controller;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.partey.businesslogic.ParteyUserReportManager;
|
||||
import de.bstly.we.partey.model.ParteyUserReport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/reports")
|
||||
public class UserReportManagementController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserReportManager parteyUserReportManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pageParameter
|
||||
* @param sizeParameter
|
||||
* @param sortParameter
|
||||
* @param descParameter
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping
|
||||
public Page<ParteyUserReport> getParteyUserReports(
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
|
||||
Page<ParteyUserReport> page = parteyUserReportManager.get(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false));
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserReport
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public ParteyUserReport createOrUpdateParteyUserReport(
|
||||
@RequestBody ParteyUserReport parteyUserReport) {
|
||||
return parteyUserReportManager.save(parteyUserReport);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteParteyUserReport(@PathVariable("id") Long id) {
|
||||
parteyUserReportManager.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param beforeParameter
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping()
|
||||
public void deleteAllParteyUserReport(
|
||||
@RequestParam("before") Optional<Instant> beforeParameter) {
|
||||
if (beforeParameter.isPresent()) {
|
||||
parteyUserReportManager.deleteAllBefore(beforeParameter.get());
|
||||
} else {
|
||||
parteyUserReportManager.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.controller;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.partey.businesslogic.ParteyUserReportModeratorManager;
|
||||
import de.bstly.we.partey.model.ParteyUserReportModerator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/reports/moderators")
|
||||
public class UserReportModeratorManagementController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserReportModeratorManager parteyUserReportModeratorManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pageParameter
|
||||
* @param sizeParameter
|
||||
* @param sortParameter
|
||||
* @param descParameter
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping
|
||||
public Page<ParteyUserReportModerator> getParteyUserReportModerators(
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
|
||||
Page<ParteyUserReportModerator> page = parteyUserReportModeratorManager.get(
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserReport
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public ParteyUserReportModerator createOrUpdateParteyUserReportModerator(
|
||||
@RequestBody ParteyUserReportModerator parteyUserReportModerator) {
|
||||
return parteyUserReportModeratorManager.save(parteyUserReportModerator);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteParteyUserReportModerator(@PathVariable("id") Long id) {
|
||||
parteyUserReportModeratorManager.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.partey.businesslogic.ParteyUserTagManager;
|
||||
import de.bstly.we.partey.model.ParteyUserTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/tags")
|
||||
public class UserTagController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserTagManager parteyUserTagManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping
|
||||
public List<ParteyUserTag> getParteyUserTagsForTarget() {
|
||||
return parteyUserTagManager.getForTarget(getCurrentUserId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.controller.support.EntityResponseStatusException;
|
||||
import de.bstly.we.model.User;
|
||||
import de.bstly.we.partey.businesslogic.ParteyUserTagManager;
|
||||
import de.bstly.we.partey.model.ParteyUserTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/tags/manage")
|
||||
public class UserTagManagementController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ParteyUserTagManager parteyUserTagManager;
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pageParameter
|
||||
* @param sizeParameter
|
||||
* @param sortParameter
|
||||
* @param descParameter
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping
|
||||
public Page<ParteyUserTag> getParteyUserTags(
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
|
||||
Page<ParteyUserTag> page = parteyUserTagManager.get(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping("{username}")
|
||||
public List<ParteyUserTag> getParteyUserTagsForTarget(
|
||||
@PathVariable("username") String username) {
|
||||
User user = userManager.getByUsername(username);
|
||||
|
||||
if (user == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return parteyUserTagManager.getForTarget(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parteyUserReport
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public ParteyUserTag createOrUpdateParteyUserTag(@RequestBody ParteyUserTag parteyUserTag) {
|
||||
return parteyUserTagManager.save(parteyUserTag);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteParteyUserTag(@PathVariable("id") Long id) {
|
||||
parteyUserTagManager.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
public enum GameRoomPolicyTypes {
|
||||
UNKNOWN, ANONYMOUS_POLICY, MEMBERS_ONLY_POLICY, USE_TAGS_POLICY
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "partey_maps")
|
||||
public class ParteyMap {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private GameRoomPolicyTypes policyType = GameRoomPolicyTypes.MEMBERS_ONLY_POLICY;
|
||||
@ElementCollection
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
@CollectionTable(name = "partey_maps_tags")
|
||||
private List<String> tags = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the policyType
|
||||
*/
|
||||
public GameRoomPolicyTypes getPolicyType() {
|
||||
return policyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policyType the policyType to set
|
||||
*/
|
||||
public void setPolicyType(GameRoomPolicyTypes policyType) {
|
||||
this.policyType = policyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tags
|
||||
*/
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tags the tags to set
|
||||
*/
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.model;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class ParteyUserReport {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
private Long reporter;
|
||||
private Long user;
|
||||
@Lob
|
||||
private String comment;
|
||||
private String world;
|
||||
private Instant created;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reporter
|
||||
*/
|
||||
public Long getReporter() {
|
||||
return reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reporter the reporter to set
|
||||
*/
|
||||
public void setReporter(Long reporter) {
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user
|
||||
*/
|
||||
public Long getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param user the user to set
|
||||
*/
|
||||
public void setUser(Long user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment
|
||||
*/
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param comment the comment to set
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the world
|
||||
*/
|
||||
public String getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world the world to set
|
||||
*/
|
||||
public void setWorld(String world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the created
|
||||
*/
|
||||
public Instant getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param created the created to set
|
||||
*/
|
||||
public void setCreated(Instant created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class ParteyUserReportModerator {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
private String email;
|
||||
@Column(columnDefinition = "boolean default false")
|
||||
private boolean disabled;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the email
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param email the email to set
|
||||
*/
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the disabled
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param disabled the disabled to set
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class ParteyUserTag {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
private Long target;
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the target
|
||||
*/
|
||||
public Long getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param target the target to set
|
||||
*/
|
||||
public void setTarget(Long target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tag
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tag the tag to set
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.bstly.we.partey.model.ParteyMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public interface ParteyMapRepository
|
||||
extends JpaRepository<ParteyMap, String>, QuerydslPredicateExecutor<ParteyMap> {
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.bstly.we.partey.model.ParteyUserReportModerator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public interface ParteyUserReportModeratorRepository
|
||||
extends JpaRepository<ParteyUserReportModerator, Long>,
|
||||
QuerydslPredicateExecutor<ParteyUserReportModerator> {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.bstly.we.partey.model.ParteyUserReport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public interface ParteyUserReportRepository
|
||||
extends JpaRepository<ParteyUserReport, Long>, QuerydslPredicateExecutor<ParteyUserReport> {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.bstly.we.partey.model.ParteyUserTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public interface ParteyUserTagRepository
|
||||
extends JpaRepository<ParteyUserTag, Long>, QuerydslPredicateExecutor<ParteyUserTag> {
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.businesslogic;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
|
||||
import de.bstly.we.businesslogic.UserDataProvider;
|
||||
import de.bstly.we.model.UserData;
|
||||
import de.bstly.we.model.Visibility;
|
||||
import de.bstly.we.partey.timeslot.model.QTimeslot;
|
||||
import de.bstly.we.partey.timeslot.model.Timeslot;
|
||||
import de.bstly.we.partey.timeslot.model.TimeslotType;
|
||||
import de.bstly.we.partey.timeslot.repository.TimeslotRepository;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class TimeslotManager implements UserDataProvider {
|
||||
|
||||
public static final String TIMESLOT_MINUTES = "timeslot.minutes";
|
||||
public static final long TIMESLOT_MINUTES_DEFAULT = 480; // 8h
|
||||
public static final String TIMESLOT_TOLERANCE = "timeslot.tolerance";
|
||||
public static final long TIMESLOT_TOLERANCE_DEFAULT = 5;
|
||||
|
||||
@Autowired
|
||||
private TimeslotRepository timeslotRepository;
|
||||
private QTimeslot qTimeslot = QTimeslot.timeslot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Timeslot get(Long id) {
|
||||
return timeslotRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owner
|
||||
* @return
|
||||
*/
|
||||
public List<Timeslot> getAllByOwner(Long owner) {
|
||||
return Lists.newArrayList(timeslotRepository.findAll(qTimeslot.owner.eq(owner)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owner
|
||||
* @param after
|
||||
* @param type
|
||||
* @param visibility
|
||||
* @param search
|
||||
* @param page
|
||||
* @param size
|
||||
* @param sortBy
|
||||
* @param descending
|
||||
* @return
|
||||
*/
|
||||
public Page<Timeslot> get(Long owner, boolean invertOwner, Instant after, TimeslotType type,
|
||||
Visibility visibility, String search, int page, int size, String sortBy,
|
||||
boolean descending) {
|
||||
|
||||
PageRequest pageRequest = PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||
|
||||
BooleanBuilder query = new BooleanBuilder();
|
||||
|
||||
if (owner != null) {
|
||||
if (invertOwner) {
|
||||
query.and(qTimeslot.owner.ne(owner));
|
||||
} else {
|
||||
query.and(qTimeslot.owner.eq(owner));
|
||||
}
|
||||
}
|
||||
|
||||
if (after != null) {
|
||||
query.and(qTimeslot.starts.after(after).or(qTimeslot.ends.after(after)));
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
query.and(qTimeslot.type.eq(type));
|
||||
}
|
||||
|
||||
if (visibility != null) {
|
||||
query.and(qTimeslot.visibility.eq(visibility));
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(search)) {
|
||||
query.and(qTimeslot.title.containsIgnoreCase(search)
|
||||
.or(qTimeslot.description.containsIgnoreCase(search)));
|
||||
}
|
||||
|
||||
if (query.hasValue()) {
|
||||
return timeslotRepository.findAll(query.getValue(), pageRequest);
|
||||
}
|
||||
|
||||
return timeslotRepository.findAll(pageRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owner
|
||||
* @return
|
||||
*/
|
||||
public long quota(Long owner) {
|
||||
return timeslotRepository.count(qTimeslot.owner.eq(owner).and(
|
||||
qTimeslot.starts.after(Instant.now()).or(qTimeslot.ends.after(Instant.now()))));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @return
|
||||
*/
|
||||
public Timeslot save(Timeslot timeslot) {
|
||||
Assert.isTrue(timeslot.getStarts().isBefore(timeslot.getEnds()),
|
||||
"starts must be before ends.");
|
||||
return timeslotRepository.save(timeslot);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
timeslotRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see de.bstly.we.businesslogic.UserDataProvider#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return "partey-timeslots";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see de.bstly.we.businesslogic.UserDataProvider#getUserData(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
public List<UserData> getUserData(Long userId) {
|
||||
List<UserData> result = Lists.newArrayList();
|
||||
for (Timeslot timeslot : getAllByOwner(userId)) {
|
||||
result.add(timeslot);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see de.bstly.we.businesslogic.UserDataProvider#purgeUserData(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
public void purgeUserData(Long userId) {
|
||||
for (Timeslot timeslot : getAllByOwner(userId)) {
|
||||
timeslotRepository.delete(timeslot);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Scheduled(cron = "0 */5 * * * *")
|
||||
protected void clearEndedTimeslots() {
|
||||
timeslotRepository.deleteAll(timeslotRepository
|
||||
.findAll(qTimeslot.clearAfter.isTrue().and(qTimeslot.ends.before(Instant.now()))));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.controller;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.businesslogic.PermissionManager;
|
||||
import de.bstly.we.businesslogic.QuotaManager;
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.controller.support.EntityResponseStatusException;
|
||||
import de.bstly.we.controller.support.RequestBodyErrors;
|
||||
import de.bstly.we.model.Quota;
|
||||
import de.bstly.we.model.Visibility;
|
||||
import de.bstly.we.partey.businesslogic.ParteyPermissions;
|
||||
import de.bstly.we.partey.businesslogic.ParteyQuotas;
|
||||
import de.bstly.we.partey.timeslot.businesslogic.TimeslotManager;
|
||||
import de.bstly.we.partey.timeslot.controller.validation.TimeslotValidator;
|
||||
import de.bstly.we.partey.timeslot.model.Timeslot;
|
||||
import de.bstly.we.partey.timeslot.model.TimeslotType;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/timeslots")
|
||||
public class TimeslotController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TimeslotManager timeslotManager;
|
||||
@Autowired
|
||||
private TimeslotValidator timeslotValidator;
|
||||
@Autowired
|
||||
private PermissionManager permissionManager;
|
||||
@Autowired
|
||||
private QuotaManager quotaManager;
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pageParameter
|
||||
* @param sizeParameter
|
||||
* @param sortParameter
|
||||
* @param descParameter
|
||||
* @param ownerParameter
|
||||
* @param afterParameter
|
||||
* @param typeParameter
|
||||
* @param visibilityParameter
|
||||
* @param searchParameter
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping
|
||||
public Page<Timeslot> getTimeslots(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("owner") Optional<String> ownerParameter,
|
||||
@RequestParam("after") Optional<Instant> afterParameter,
|
||||
@RequestParam("type") Optional<TimeslotType> typeParameter,
|
||||
@RequestParam("visibility") Optional<Visibility> visibilityParameter,
|
||||
@RequestParam("search") Optional<String> searchParameter) {
|
||||
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
Long ownerId = getCurrentUserId();
|
||||
|
||||
if (ownerParameter.isPresent() && "all".equals(ownerParameter.get())) {
|
||||
ownerId = null;
|
||||
}
|
||||
|
||||
Page<Timeslot> page = timeslotManager.get(ownerId,
|
||||
ownerParameter.isPresent() && "others".equals(ownerParameter.get()),
|
||||
afterParameter.orElse(null), typeParameter.orElse(null),
|
||||
visibilityParameter.orElse(null), searchParameter.orElse(null),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
|
||||
for (Timeslot timeslot : page.getContent()) {
|
||||
if (!getCurrentUserId().equals(timeslot.getOwner())) {
|
||||
switch (timeslot.getVisibility()) {
|
||||
case PRIVATE:
|
||||
timeslot.setUsername(null);
|
||||
timeslot.setTitle(null);
|
||||
timeslot.setDescription(null);
|
||||
break;
|
||||
default:
|
||||
timeslot.setUsername(userManager.get(timeslot.getOwner()).getUsername());
|
||||
break;
|
||||
|
||||
}
|
||||
timeslot.setSecret(null);
|
||||
timeslot.setStream(null);
|
||||
timeslot.setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/quota")
|
||||
public long quota() {
|
||||
Quota timeslotQuota = quotaManager.get(getCurrentUserId(), ParteyQuotas.PARTEY_TIMESLOT);
|
||||
return timeslotQuota == null ? 0
|
||||
: timeslotQuota.getValue() - timeslotManager.quota(getCurrentUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@PostMapping
|
||||
public Timeslot createTimeslot(@RequestBody Timeslot timeslot) {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
Quota timeslotQuota = quotaManager.get(getCurrentUserId(), ParteyQuotas.PARTEY_TIMESLOT);
|
||||
if (timeslotQuota == null
|
||||
|| timeslotQuota.getValue() < timeslotManager.quota(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
timeslot.setId(null);
|
||||
timeslot.setOwner(getCurrentUserId());
|
||||
Errors errors = new RequestBodyErrors(timeslot);
|
||||
timeslotValidator.validate(timeslot, errors);
|
||||
if (errors.hasErrors()) {
|
||||
throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
if (timeslot.getVisibility() == null) {
|
||||
timeslot.setVisibility(Visibility.PROTECTED);
|
||||
}
|
||||
|
||||
return timeslotManager.save(timeslot);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@PatchMapping
|
||||
public Timeslot updateTimeslot(@RequestBody Timeslot timeslot) {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
if (timeslot.getId() == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
Timeslot existing = timeslotManager.get(timeslot.getId());
|
||||
if (existing == null || !getCurrentUserId().equals(existing.getOwner())
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
timeslot.setOwner(getCurrentUserId());
|
||||
Errors errors = new RequestBodyErrors(timeslot);
|
||||
timeslotValidator.validate(timeslot, errors);
|
||||
if (errors.hasErrors()) {
|
||||
throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
if (timeslot.getStarts().isAfter(Instant.now())
|
||||
|| timeslot.getEnds().isAfter(Instant.now())) {
|
||||
Quota timeslotQuota = quotaManager.get(getCurrentUserId(),
|
||||
ParteyQuotas.PARTEY_TIMESLOT);
|
||||
if (timeslotQuota == null
|
||||
|| timeslotQuota.getValue() < timeslotManager.quota(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
if (timeslot.getVisibility() == null) {
|
||||
timeslot.setVisibility(Visibility.PROTECTED);
|
||||
}
|
||||
|
||||
return timeslotManager.save(timeslot);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteTimeslot(@PathVariable("id") Long id) {
|
||||
Timeslot existing = timeslotManager.get(id);
|
||||
if (existing == null || !getCurrentUserId().equals(existing.getOwner())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
timeslotManager.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.controller;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.controller.BaseController;
|
||||
import de.bstly.we.controller.support.EntityResponseStatusException;
|
||||
import de.bstly.we.controller.support.RequestBodyErrors;
|
||||
import de.bstly.we.model.Visibility;
|
||||
import de.bstly.we.partey.timeslot.businesslogic.TimeslotManager;
|
||||
import de.bstly.we.partey.timeslot.controller.validation.TimeslotValidator;
|
||||
import de.bstly.we.partey.timeslot.model.Timeslot;
|
||||
import de.bstly.we.partey.timeslot.model.TimeslotType;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/partey/timeslots/manage")
|
||||
public class TimeslotManagementController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TimeslotManager timeslotManager;
|
||||
@Autowired
|
||||
private TimeslotValidator timeslotValidator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pageParameter
|
||||
* @param sizeParameter
|
||||
* @param sortParameter
|
||||
* @param descParameter
|
||||
* @param afterParameter
|
||||
* @param typeParameter
|
||||
* @param visibilityParameter
|
||||
* @param searchParameter
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping
|
||||
public Page<Timeslot> getTimeslots(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("owner") Optional<Long> ownerParameter,
|
||||
@RequestParam("owner-invert") Optional<Boolean> invertOwnerParameter,
|
||||
@RequestParam("after") Optional<Instant> afterParameter,
|
||||
@RequestParam("type") Optional<TimeslotType> typeParameter,
|
||||
@RequestParam("visibility") Optional<Visibility> visibilityParameter,
|
||||
@RequestParam("search") Optional<String> searchParameter) {
|
||||
|
||||
Page<Timeslot> page = timeslotManager.get(ownerParameter.orElse(null),
|
||||
invertOwnerParameter.isPresent() && invertOwnerParameter.get(),
|
||||
afterParameter.orElse(null), typeParameter.orElse(null),
|
||||
visibilityParameter.orElse(null), searchParameter.orElse(null),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public Timeslot createOrUpdateTimeslot(@RequestBody Timeslot timeslot) {
|
||||
Errors errors = new RequestBodyErrors(timeslot);
|
||||
timeslotValidator.validate(timeslot, errors);
|
||||
if (errors.hasErrors()) {
|
||||
throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
if (timeslot.getVisibility() == null) {
|
||||
timeslot.setVisibility(Visibility.PROTECTED);
|
||||
}
|
||||
|
||||
return timeslotManager.save(timeslot);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteTimeslot(@PathVariable("id") Long id) {
|
||||
timeslotManager.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.controller.validation;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
|
||||
import de.bstly.we.businesslogic.SystemPropertyManager;
|
||||
import de.bstly.we.partey.timeslot.businesslogic.TimeslotManager;
|
||||
import de.bstly.we.partey.timeslot.model.QTimeslot;
|
||||
import de.bstly.we.partey.timeslot.model.Timeslot;
|
||||
import de.bstly.we.partey.timeslot.repository.TimeslotRepository;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class TimeslotValidator implements Validator {
|
||||
|
||||
public final static int STREAM_SECRET_LENGTH = 64;
|
||||
|
||||
@Autowired
|
||||
private TimeslotRepository timeslotRepository;
|
||||
@Autowired
|
||||
private SystemPropertyManager systemPropertyManager;
|
||||
private QTimeslot qTimeslot = QTimeslot.timeslot;
|
||||
|
||||
/*
|
||||
* @see org.springframework.validation.Validator#supports(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return clazz.isAssignableFrom(Timeslot.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.validation.Validator#validate(java.lang.Object,
|
||||
* org.springframework.validation.Errors)
|
||||
*/
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
Timeslot timeslot = (Timeslot) target;
|
||||
|
||||
validateType(timeslot, errors);
|
||||
validateTime(timeslot, errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeslot
|
||||
* @param errors
|
||||
*/
|
||||
public void validateTime(Timeslot timeslot, Errors errors) {
|
||||
if (timeslot.getStarts() == null) {
|
||||
errors.rejectValue("starts", "REQUIRED");
|
||||
}
|
||||
|
||||
if (timeslot.getEnds() == null) {
|
||||
errors.rejectValue("ends", "REQUIRED");
|
||||
}
|
||||
|
||||
if (timeslot.getStarts() != null && timeslot.getEnds() != null) {
|
||||
if (timeslot.getStarts().isAfter(timeslot.getStarts())) {
|
||||
errors.rejectValue("starts", "NOT_VALID");
|
||||
errors.rejectValue("ends", "NOT_VALID");
|
||||
} else {
|
||||
BooleanBuilder timeQuery = new BooleanBuilder();
|
||||
|
||||
// same type
|
||||
timeQuery.and(qTimeslot.type.eq(timeslot.getType()));
|
||||
|
||||
// ends after start
|
||||
timeQuery
|
||||
.and(qTimeslot.ends.after(timeslot.getStarts().minus(
|
||||
systemPropertyManager.getLong(TimeslotManager.TIMESLOT_TOLERANCE,
|
||||
TimeslotManager.TIMESLOT_TOLERANCE_DEFAULT),
|
||||
ChronoUnit.MINUTES)));
|
||||
|
||||
// starts before end
|
||||
timeQuery
|
||||
.and(qTimeslot.starts.before(timeslot.getEnds().plus(
|
||||
systemPropertyManager.getLong(TimeslotManager.TIMESLOT_TOLERANCE,
|
||||
TimeslotManager.TIMESLOT_TOLERANCE_DEFAULT),
|
||||
ChronoUnit.MINUTES)));
|
||||
|
||||
if (timeslot.getId() != null && timeslotRepository.existsById(timeslot.getId())) {
|
||||
timeQuery.and(qTimeslot.id.ne(timeslot.getId()));
|
||||
}
|
||||
|
||||
if (timeslotRepository.exists(timeQuery.getValue())) {
|
||||
errors.rejectValue("starts", "ALREADY_EXISTS");
|
||||
errors.rejectValue("ends", "ALREADY_EXISTS");
|
||||
} else if (((timeslot.getEnds().getEpochSecond()
|
||||
- timeslot.getStarts().getEpochSecond()) / 60) > systemPropertyManager
|
||||
.getLong(TimeslotManager.TIMESLOT_MINUTES,
|
||||
TimeslotManager.TIMESLOT_MINUTES_DEFAULT)) {
|
||||
errors.rejectValue("ends", "TOO_LONG",
|
||||
String.valueOf(
|
||||
systemPropertyManager.getLong(TimeslotManager.TIMESLOT_MINUTES,
|
||||
TimeslotManager.TIMESLOT_MINUTES_DEFAULT)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeslot
|
||||
* @param errors
|
||||
*/
|
||||
public void validateType(Timeslot timeslot, Errors errors) {
|
||||
if (timeslot.getId() != null && timeslotRepository.existsById(timeslot.getId())) {
|
||||
Timeslot existing = timeslotRepository.findById(timeslot.getId()).get();
|
||||
timeslot.setType(existing.getType());
|
||||
}
|
||||
|
||||
switch (timeslot.getType()) {
|
||||
case AUDIO:
|
||||
validateTypeAudio(timeslot, errors);
|
||||
break;
|
||||
case VIDEO:
|
||||
validateTypeVideo(timeslot, errors);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @param errors
|
||||
*/
|
||||
public void validateTypeAudio(Timeslot timeslot, Errors errors) {
|
||||
timeslot.setStream(null);
|
||||
if (timeslot.getId() != null && timeslotRepository.existsById(timeslot.getId())) {
|
||||
Timeslot existing = timeslotRepository.findById(timeslot.getId()).get();
|
||||
timeslot.setSecret(existing.getSecret());
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(timeslot.getSecret())) {
|
||||
timeslot.setSecret(RandomStringUtils.random(STREAM_SECRET_LENGTH, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeslot
|
||||
* @param errors
|
||||
*/
|
||||
public void validateTypeVideo(Timeslot timeslot, Errors errors) {
|
||||
timeslot.setSecret(null);
|
||||
if (!StringUtils.hasText(timeslot.getStream())) {
|
||||
errors.rejectValue("stream", "REQUIRED");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import de.bstly.we.model.UserData;
|
||||
import de.bstly.we.model.Visibility;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "timeslots")
|
||||
public class Timeslot implements UserData {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
@Column(name = "owner", nullable = false)
|
||||
private Long owner;
|
||||
@Column(name = "type", nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private TimeslotType type;
|
||||
@Column(name = "starts", nullable = false)
|
||||
private Instant starts;
|
||||
@Column(name = "ends", nullable = false)
|
||||
private Instant ends;
|
||||
@Column(name = "visibility", nullable = false)
|
||||
private Visibility visibility;
|
||||
@Column(name = "title", nullable = true)
|
||||
private String title;
|
||||
@Column(name = "description", nullable = true)
|
||||
@Lob
|
||||
private String description;
|
||||
@Column(name = "stream", nullable = true)
|
||||
private String stream;
|
||||
@Column(name = "secret", nullable = true)
|
||||
private String secret;
|
||||
@Column(name = "clear_after", columnDefinition = "boolean default false")
|
||||
private boolean clearAfter;
|
||||
@Transient
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
public Long getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param owner the owner to set
|
||||
*/
|
||||
public void setOwner(Long owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public TimeslotType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(TimeslotType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the starts
|
||||
*/
|
||||
public Instant getStarts() {
|
||||
return starts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param starts the starts to set
|
||||
*/
|
||||
public void setStarts(Instant starts) {
|
||||
this.starts = starts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ends
|
||||
*/
|
||||
public Instant getEnds() {
|
||||
return ends;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ends the ends to set
|
||||
*/
|
||||
public void setEnds(Instant ends) {
|
||||
this.ends = ends;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the visibility
|
||||
*/
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visibility the visibility to set
|
||||
*/
|
||||
public void setVisibility(Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param title the title to set
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the stream
|
||||
*/
|
||||
public String getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stream the stream to set
|
||||
*/
|
||||
public void setStream(String stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the secret
|
||||
*/
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param secret the secret to set
|
||||
*/
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clearAfter
|
||||
*/
|
||||
public boolean isClearAfter() {
|
||||
return clearAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clearAfter the clearAfter to set
|
||||
*/
|
||||
public void setClearAfter(boolean clearAfter) {
|
||||
this.clearAfter = clearAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the username
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username the username to set
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.model;
|
||||
|
||||
/**
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
public enum TimeslotType {
|
||||
VIDEO, AUDIO
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.partey.timeslot.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.bstly.we.partey.timeslot.model.Timeslot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author _bastler@bstly.de
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public interface TimeslotRepository
|
||||
extends JpaRepository<Timeslot, Long>, QuerydslPredicateExecutor<Timeslot> {
|
||||
}
|
||||
Reference in New Issue
Block a user