update permissionmappings

This commit is contained in:
_Bastler 2021-12-15 13:03:21 +01:00
parent bfc335703c
commit aa79839a00
5 changed files with 89 additions and 36 deletions

View File

@ -42,7 +42,7 @@ public class PermissionManager implements UserDataProvider {
* Gets the.
*
* @param target the target
* @param name the name
* @param name the name
* @return the list
*/
public List<Permission> get(Long target, String name) {
@ -126,7 +126,7 @@ public class PermissionManager implements UserDataProvider {
* Checks for permission.
*
* @param target the target
* @param name the name
* @param name the name
* @return true, if successful
*/
public boolean hasPermission(Long target, String name) {
@ -143,10 +143,10 @@ public class PermissionManager implements UserDataProvider {
/**
* Creates the.
*
* @param target the target
* @param name the name
* @param addon the addon
* @param starts the starts
* @param target the target
* @param name the name
* @param addon the addon
* @param starts the starts
* @param expires the expires
* @return the permission
*/
@ -188,7 +188,7 @@ public class PermissionManager implements UserDataProvider {
/**
* Clone.
*
* @param name the name
* @param name the name
* @param clone the clone
* @return the list
*/
@ -212,7 +212,7 @@ public class PermissionManager implements UserDataProvider {
* Delete.
*
* @param target the target
* @param name the name
* @param name the name
*/
public void delete(Long target, String name) {
Assert.isTrue(
@ -249,10 +249,10 @@ public class PermissionManager implements UserDataProvider {
/**
* Apply item.
*
* @param target the target
* @param item the item
* @param target the target
* @param item the item
* @param answers the answers
* @param starts the starts
* @param starts the starts
* @param expires the expires
*/
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
@ -265,10 +265,10 @@ public class PermissionManager implements UserDataProvider {
/**
* Gets the for item.
*
* @param target the target
* @param item the item
* @param target the target
* @param item the item
* @param answers the answers
* @param starts the starts
* @param starts the starts
* @param expires the expires
* @return the for item
*/
@ -280,6 +280,14 @@ public class PermissionManager implements UserDataProvider {
Instant permissionStarts = starts;
Instant permissionsExpires = expires;
if (permissionMapping.getStarts() != null) {
permissionStarts = permissionMapping.getStarts();
}
if (permissionMapping.getExpires() != null) {
permissionsExpires = permissionMapping.getExpires();
}
if (permissionMapping.isLifetimeRound()) {
permissionStarts = InstantHelper.truncate(permissionStarts,
permissionMapping.getLifetimeUnit());

View File

@ -3,6 +3,7 @@
*/
package de.bstly.we.businesslogic;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Set;
@ -77,23 +78,26 @@ public class PermissionMappingManager {
/**
* Creates the.
*
* @param item the item
* @param names the names
* @param lifetime the lifetime
* @param lifetimeUnit the lifetime unit
* @param lifetimeRound the lifetime round
* @param addon the addon
* @param product the product
* @param startsQuestion the starts question
* @param item the item
* @param names the names
* @param lifetime the lifetime
* @param lifetimeUnit the lifetime unit
* @param lifetimeRound the lifetime round
* @param addon the addon
* @param product the product
* @param startsQuestion the starts question
* @param expiresQuestion the expires question
* @return the permission mapping
*/
public PermissionMapping create(Integer item, Set<String> names, Long lifetime,
ChronoUnit lifetimeUnit, boolean lifetimeRound, boolean addon, String product,
String startsQuestion, String expiresQuestion) {
Instant starts, Instant expires, String startsQuestion, String expiresQuestion) {
for (String name : names) {
Assert.isTrue(!exists(item, name), "PermissionMapping for item '" + item
+ "' with permission '" + name + "' already exists!");
Assert.isTrue(!exists(item, name), "PermissionMapping for item '"
+ item
+ "' with permission '"
+ name
+ "' already exists!");
}
PermissionMapping permissionMapping = new PermissionMapping();
permissionMapping.setItem(item);
@ -103,6 +107,8 @@ public class PermissionMappingManager {
permissionMapping.setLifetimeRound(lifetimeRound);
permissionMapping.setAddon(addon);
permissionMapping.setProduct(product);
permissionMapping.setStarts(starts);
permissionMapping.setExpires(expires);
permissionMapping.setStartsQuestion(startsQuestion);
permissionMapping.setExpiresQuestion(expiresQuestion);
return permissionMappingRepository.save(permissionMapping);
@ -124,8 +130,9 @@ public class PermissionMappingManager {
* @param id the id
*/
public void delete(Long id) {
Assert.isTrue(permissionMappingRepository.existsById(id),
"Permission Mapping '" + id + "' does not exists!");
Assert.isTrue(permissionMappingRepository.existsById(id), "Permission Mapping '"
+ id
+ "' does not exists!");
PermissionMapping permissionMapping = permissionMappingRepository.findById(id).get();
permissionMappingRepository.delete(permissionMapping);
}
@ -133,9 +140,9 @@ public class PermissionMappingManager {
/**
* Gets the.
*
* @param page the page
* @param size the size
* @param sortBy the sort by
* @param page the page
* @param size the size
* @param sortBy the sort by
* @param descending the descending
* @return the page
*/

View File

@ -52,7 +52,8 @@ public class PermissionMappingController extends BaseController {
public Page<PermissionMapping> getPermissionMappings(
@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter) {
return permissionMappingManager.get(pageParameter.orElse(0), sizeParameter.orElse(10), "item", true);
return permissionMappingManager.get(pageParameter.orElse(0), sizeParameter.orElse(10),
"item", true);
}
/**
@ -74,6 +75,7 @@ public class PermissionMappingController extends BaseController {
permissionMapping.getNames(), permissionMapping.getLifetime(),
permissionMapping.getLifetimeUnit(), permissionMapping.isLifetimeRound(),
permissionMapping.isAddon(), permissionMapping.getProduct(),
permissionMapping.getStarts(), permissionMapping.getExpires(),
permissionMapping.getStartsQuestion(), permissionMapping.getExpiresQuestion());
}
@ -99,6 +101,7 @@ public class PermissionMappingController extends BaseController {
permissionMapping.getNames(), permissionMapping.getLifetime(),
permissionMapping.getLifetimeUnit(), permissionMapping.isLifetimeRound(),
permissionMapping.isAddon(), permissionMapping.getProduct(),
permissionMapping.getStarts(), permissionMapping.getExpires(),
permissionMapping.getStartsQuestion(), permissionMapping.getExpiresQuestion()));
}
return result;

View File

@ -3,6 +3,7 @@
*/
package de.bstly.we.model;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Set;
@ -51,6 +52,10 @@ public class PermissionMapping {
private ChronoUnit lifetimeUnit = DEFAULT_LIFETIME_UNIT;
@Column(name = "lifetime_round", columnDefinition = "boolean default false")
private boolean lifetimeRound;
@Column(name = "starts")
private Instant starts;
@Column(name = "expires")
private Instant expires;
@Column(name = "starts_question")
private String startsQuestion;
@Column(name = "expires_question")
@ -200,6 +205,34 @@ public class PermissionMapping {
this.lifetimeRound = lifetimeRound;
}
/**
* @return the starts
*/
public Instant getStarts() {
return starts;
}
/**
* @param starts the starts to set
*/
public void setStarts(Instant starts) {
this.starts = starts;
}
/**
* @return the expires
*/
public Instant getExpires() {
return expires;
}
/**
* @param expires the expires to set
*/
public void setExpires(Instant expires) {
this.expires = expires;
}
/**
* Gets the starts question.
*
@ -241,9 +274,10 @@ public class PermissionMapping {
*/
@Converter
public static class ChronoUnitConverter implements AttributeConverter<ChronoUnit, String> {
/*
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object)
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.
* Object)
*/
@Override
public String convertToDatabaseColumn(ChronoUnit chronoUnit) {
@ -251,7 +285,8 @@ public class PermissionMapping {
}
/*
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object)
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.
* Object)
*/
@Override
public ChronoUnit convertToEntityAttribute(String value) {

View File

@ -12,8 +12,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<log4j2.version>2.15.0</log4j2.version>
<revision>1.4.5-SNAPSHOT</revision>
<log4j2.version>2.16.0</log4j2.version>
<revision>1.4.6-SNAPSHOT</revision>
</properties>
<parent>