-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathTransactionUpdateCommand.java
More file actions
68 lines (56 loc) · 2.25 KB
/
TransactionUpdateCommand.java
File metadata and controls
68 lines (56 loc) · 2.25 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package edu.uark.registerapp.commands.transactions;
import java.util.Optional;
import java.util.UUID;
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.ResultCommandInterface;
import edu.uark.registerapp.commands.exceptions.NotFoundException;
import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException;
import edu.uark.registerapp.models.api.transaction;
import edu.uark.registerapp.models.entities.transactionEntity;
import edu.uark.registerapp.models.repositories.transactionRepository;
@Service
public class transactionUpdateCommand implements ResultCommandInterface<transaction> {
@Transactional
@Override
public transaction execute() {
this.validateProperties();
final Optional<transactionEntity> transactionEntity =
this.transactionRepository.findById(this.transactionId);
if (!transactionEntity.isPresent()) { // No record with the associated record ID exists in the database.
throw new NotFoundException("transaction");
}
// Synchronize any incoming changes for UPDATE to the database.
this.apitransaction = transactionEntity.get().synchronize(this.apitransaction);
// Write, via an UPDATE, any changes to the database.
this.transactionRepository.save(transactionEntity.get());
return this.apitransaction;
}
// Helper methods
private void validateProperties() {
if (StringUtils.isBlank(this.apitransaction.getLookupCode())) {
throw new UnprocessableEntityException("lookupcode");
}
}
// Properties
private UUID transactionId;
public UUID gettransactionId() {
return this.transactionId;
}
public transactionUpdateCommand settransactionId(final UUID transactionId) {
this.transactionId = transactionId;
return this;
}
private transaction apitransaction;
public transaction getApitransaction() {
return this.apitransaction;
}
public transactionUpdateCommand setApitransaction(final transaction apitransaction) {
this.apitransaction = apitransaction;
return this;
}
@Autowired
private transactionRepository transactionRepository;
}