Update service functions maintain create auditing fields
This commit is contained in:
@@ -15,10 +15,8 @@ import jakarta.persistence.MappedSuperclass;
|
|||||||
import jakarta.persistence.PrePersist;
|
import jakarta.persistence.PrePersist;
|
||||||
import jakarta.persistence.PreUpdate;
|
import jakarta.persistence.PreUpdate;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Data
|
@Data
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AuditableEntity{
|
public abstract class AuditableEntity{
|
||||||
@@ -50,9 +48,6 @@ public abstract class AuditableEntity{
|
|||||||
|
|
||||||
|
|
||||||
private UUID getCurrentUserId(){
|
private UUID getCurrentUserId(){
|
||||||
log.debug("Getting current auditor");
|
|
||||||
|
|
||||||
|
|
||||||
UUID returnUUID;
|
UUID returnUUID;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@@ -61,7 +56,6 @@ public abstract class AuditableEntity{
|
|||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){
|
||||||
returnUUID = new UUID(0, 0);
|
returnUUID = new UUID(0, 0);
|
||||||
log.debug("No user logged in: {}", returnUUID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnUUID;
|
return returnUUID;
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ public class ClassGroupService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClassGroup updateClassGroup(ClassGroup classGroup, Iterable<ClassGroupGameClassXref> xrefs){
|
public ClassGroup updateClassGroup(ClassGroup classGroup, Iterable<ClassGroupGameClassXref> xrefs){
|
||||||
|
ClassGroup existingClassGroup = classGroupRepository.findById(classGroup.getClassGroupId()).orElseThrow();
|
||||||
|
classGroup.setCreatedBy(existingClassGroup.getCreatedBy());
|
||||||
|
classGroup.setCreatedDate(existingClassGroup.getCreatedDate());
|
||||||
|
|
||||||
classGroupRepository.save(classGroup);
|
classGroupRepository.save(classGroup);
|
||||||
final UUID classGroupId = classGroup.getClassGroupId();
|
final UUID classGroupId = classGroup.getClassGroupId();
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ public class GameCalendarEventService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GameCalendarEvent updateGameCalendarEvent(GameCalendarEvent gce){
|
public GameCalendarEvent updateGameCalendarEvent(GameCalendarEvent gce){
|
||||||
|
GameCalendarEvent existingGce = gceRepository.findById(gce.getCalendarEventId()).orElseThrow();
|
||||||
|
gce.setCreatedBy(existingGce.getCreatedBy());
|
||||||
|
gce.setCreatedDate(existingGce.getCreatedDate());
|
||||||
|
|
||||||
return gceRepository.save(gce);
|
return gceRepository.save(gce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,9 @@ public class GameClassService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GameClass updateGameClass(GameClass gameClass, MultipartFile file){
|
public GameClass updateGameClass(GameClass gameClass, MultipartFile file){
|
||||||
GameClass existingGameClass = gameClassRepository.findById(gameClass.getGameClassId()).orElse(null);
|
GameClass existingGameClass = gameClassRepository.findById(gameClass.getGameClassId()).orElseThrow();
|
||||||
|
gameClass.setCreatedBy(existingGameClass.getCreatedBy());
|
||||||
|
gameClass.setCreatedDate(existingGameClass.getCreatedDate());
|
||||||
|
|
||||||
//Delete the old file if one exists
|
//Delete the old file if one exists
|
||||||
if((existingGameClass != null) && (existingGameClass.getGameClassIcon() != null) && (gameClass.getGameClassIcon() == null)){
|
if((existingGameClass != null) && (existingGameClass.getGameClassIcon() != null) && (gameClass.getGameClassIcon() == null)){
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ public class GamePermissionService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GamePermission updateGamePermission(GamePermission gamePermission){
|
public GamePermission updateGamePermission(GamePermission gamePermission){
|
||||||
|
GamePermission existingGamePermission = gamePermissionRepository.findById(gamePermission.getGamePermissionId()).orElseThrow();
|
||||||
|
gamePermission.setCreatedBy(existingGamePermission.getCreatedBy());
|
||||||
|
gamePermission.setCreatedDate(existingGamePermission.getCreatedDate());
|
||||||
|
|
||||||
return gamePermissionRepository.save(gamePermission);
|
return gamePermissionRepository.save(gamePermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ public class GameService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Game updateGame(Game game, MultipartFile file){
|
public Game updateGame(Game game, MultipartFile file){
|
||||||
Game existingGame = gameRepository.findById(game.getGameId()).orElse(null);
|
Game existingGame = gameRepository.findById(game.getGameId()).orElseThrow();
|
||||||
|
game.setCreatedBy(existingGame.getCreatedBy());
|
||||||
|
game.setCreatedDate(existingGame.getCreatedDate());
|
||||||
|
|
||||||
//Delete the old file if one exists
|
//Delete the old file if one exists
|
||||||
if((existingGame != null) && (existingGame.getGameIcon() != null) && (game.getGameIcon() == null)){
|
if((existingGame != null) && (existingGame.getGameIcon() != null) && (game.getGameIcon() == null)){
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public class PersonCharacterService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PersonCharacter updatePersonCharacter(PersonCharacter personCharacter){
|
public PersonCharacter updatePersonCharacter(PersonCharacter personCharacter){
|
||||||
|
PersonCharacter existingPersonCharacter = personCharacterRepository.findById(personCharacter.getPersonCharacterId()).orElseThrow();
|
||||||
|
personCharacter.setCreatedBy(existingPersonCharacter.getCreatedBy());
|
||||||
|
personCharacter.setCreatedDate(existingPersonCharacter.getCreatedDate());
|
||||||
|
|
||||||
return personCharacterRepository.save(personCharacter);
|
return personCharacterRepository.save(personCharacter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ public class PersonService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Person updatePerson(Person person){
|
public Person updatePerson(Person person){
|
||||||
|
Person existingPerson = personRepository.findById(person.getPersonId()).orElseThrow();
|
||||||
|
person.setCreatedBy(existingPerson.getCreatedBy());
|
||||||
|
person.setCreatedDate(existingPerson.getCreatedDate());
|
||||||
|
|
||||||
return personRepository.save(person);
|
return personRepository.save(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public class RaidGroupCalendarEventService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RaidGroupCalendarEvent updateRaidGroupCalendarEvent(RaidGroupCalendarEvent rgce){
|
public RaidGroupCalendarEvent updateRaidGroupCalendarEvent(RaidGroupCalendarEvent rgce){
|
||||||
|
RaidGroupCalendarEvent existingRaidGroupCalendarEvent = rgceRepository.findById(rgce.getRaidGroupCalendarEventId()).orElseThrow();
|
||||||
|
rgce.setCreatedBy(existingRaidGroupCalendarEvent.getCreatedBy());
|
||||||
|
rgce.setCreatedDate(existingRaidGroupCalendarEvent.getCreatedDate());
|
||||||
|
|
||||||
return rgceRepository.save(rgce);
|
return rgceRepository.save(rgce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class RaidGroupPermissionService{
|
|||||||
|
|
||||||
|
|
||||||
//Write
|
//Write
|
||||||
|
public RaidGroupPermission createRaidGroupPermission(RaidGroupPermission raidGroupPermission){
|
||||||
|
return raidGroupPermissionRepository.save(raidGroupPermission);
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteByAccountId(UUID accountId){
|
public void deleteByAccountId(UUID accountId){
|
||||||
raidGroupPermissionRepository.deleteAllByAccountId(accountId);
|
raidGroupPermissionRepository.deleteAllByAccountId(accountId);
|
||||||
}
|
}
|
||||||
@@ -39,10 +43,6 @@ public class RaidGroupPermissionService{
|
|||||||
|
|
||||||
|
|
||||||
//Read
|
//Read
|
||||||
public RaidGroupPermission createRaidGroupPermission(RaidGroupPermission raidGroupPermission){
|
|
||||||
return raidGroupPermissionRepository.save(raidGroupPermission);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RaidGroupPermission> getByAccountId(UUID accountId){
|
public List<RaidGroupPermission> getByAccountId(UUID accountId){
|
||||||
return raidGroupPermissionRepository.findAllByAccountId(accountId);
|
return raidGroupPermissionRepository.findAllByAccountId(accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ public class RaidGroupRequestService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RaidGroupRequest updateRaidGroupRequest(RaidGroupRequest raidGroupRequest){
|
public RaidGroupRequest updateRaidGroupRequest(RaidGroupRequest raidGroupRequest){
|
||||||
|
RaidGroupRequest existingRaidGroupRequest = rgrRepository.findById(raidGroupRequest.getRaidGroupRequestId()).orElseThrow();
|
||||||
|
raidGroupRequest.setCreatedBy(existingRaidGroupRequest.getCreatedBy());
|
||||||
|
raidGroupRequest.setCreatedDate(existingRaidGroupRequest.getCreatedDate());
|
||||||
return rgrRepository.save(raidGroupRequest);
|
return rgrRepository.save(raidGroupRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ public class RaidGroupService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RaidGroup updateRaidGroup(RaidGroup raidGroup, MultipartFile file){
|
public RaidGroup updateRaidGroup(RaidGroup raidGroup, MultipartFile file){
|
||||||
RaidGroup existingRaidGroup = raidGroupRepository.findById(raidGroup.getRaidGroupId()).orElse(null);
|
RaidGroup existingRaidGroup = raidGroupRepository.findById(raidGroup.getRaidGroupId()).orElseThrow();
|
||||||
|
raidGroup.setCreatedBy(existingRaidGroup.getCreatedBy());
|
||||||
|
raidGroup.setCreatedDate(existingRaidGroup.getCreatedDate());
|
||||||
|
|
||||||
//Delete the old file if one exists
|
//Delete the old file if one exists
|
||||||
if((existingRaidGroup != null) && (existingRaidGroup.getRaidGroupIcon() != null) && (raidGroup.getRaidGroupIcon() == null)){
|
if((existingRaidGroup != null) && (existingRaidGroup.getRaidGroupIcon() != null) && (raidGroup.getRaidGroupIcon() == null)){
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ public class RaidInstanceService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RaidInstance updateRaidInstance(RaidInstance raidInstance){
|
public RaidInstance updateRaidInstance(RaidInstance raidInstance){
|
||||||
|
RaidInstance existingRaidInstance = raidInstanceRepository.findById(raidInstance.getRaidInstanceId()).orElseThrow();
|
||||||
|
raidInstance.setCreatedBy(existingRaidInstance.getCreatedBy());
|
||||||
|
raidInstance.setCreatedDate(existingRaidInstance.getCreatedDate());
|
||||||
|
|
||||||
return raidInstanceRepository.save(raidInstance);
|
return raidInstanceRepository.save(raidInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class RaidLayoutService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RaidLayout updateRaidLayout(RaidLayout raidLayout, Iterable<RaidLayoutClassGroupXref> xrefs){
|
public RaidLayout updateRaidLayout(RaidLayout raidLayout, Iterable<RaidLayoutClassGroupXref> xrefs){
|
||||||
|
RaidLayout existingRaidLayout = raidLayoutRepository.findById(raidLayout.getRaidLayoutId()).orElseThrow();
|
||||||
|
raidLayout.setCreatedBy(existingRaidLayout.getCreatedBy());
|
||||||
|
raidLayout.setCreatedDate(existingRaidLayout.getCreatedDate());
|
||||||
raidLayout = raidLayoutRepository.save(raidLayout);
|
raidLayout = raidLayoutRepository.save(raidLayout);
|
||||||
final UUID raidLayoutId = raidLayout.getRaidLayoutId();
|
final UUID raidLayoutId = raidLayout.getRaidLayoutId();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user