-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathActiveUserDeleteCommand.java
More file actions
53 lines (43 loc) · 1.72 KB
/
ActiveUserDeleteCommand.java
File metadata and controls
53 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package edu.uark.registerapp.commands.activeUsers;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import edu.uark.registerapp.commands.VoidCommandInterface;
import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException;
import edu.uark.registerapp.models.entities.ActiveUserEntity;
import edu.uark.registerapp.models.repositories.ActiveUserRepository;
@Service
public class ActiveUserDeleteCommand implements VoidCommandInterface {
@Transactional
@Override
public void execute() {
final Optional<ActiveUserEntity> activeUserEntity =
this.activeUserRepository.findBySessionKey(this.sessionKey);
validateEmployeeRequestObject(activeUserEntity);
//removes active user
if (activeUserEntity.isPresent()) {
this.activeUserRepository.delete(activeUserEntity.get());
}
}
private void validateEmployeeRequestObject(Optional<ActiveUserEntity> activeUserEntity){
if (StringUtils.isBlank(activeUserEntity.get().getName())) {
throw new UnprocessableEntityException("Name");
}
String [] name = activeUserEntity.get().getName().split(" ", 2);
if (StringUtils.isBlank(name[0])) {throw new UnprocessableEntityException("First Name");}
if (StringUtils.isBlank(name[1])) {throw new UnprocessableEntityException("Last Name");}
}
// Properties
private String sessionKey;
public String getSessionKey() {
return this.sessionKey;
}
public ActiveUserDeleteCommand setSessionKey(final String sessionKey) {
this.sessionKey = sessionKey;
return this;
}
@Autowired
private ActiveUserRepository activeUserRepository;
}