#357 Code Review of Asynchronous Document Processing
Perform a code review:
@Service
@RequiredArgsConstructor
public class DocumentProcessService {
private final DocumentRepo repo;
@Async
@Transactional
void revokeDocument(List<Document> docs) {
List<Integer> id_list = docs.stream().map(Document::getId).collect(Collectors.toList());
List<Document> list = repo.findAllById(id_list);
Optional<Document> doc = Optional.empty();
for (int i = 0; i < list.size(); i++) {
Integer statusId = list.get(i).getStatusId();
if (statusId == 4) {
doc = Optional.of(list.get(i));
break;
}
}
if (doc.isPresent()) return;
System.out.println("Processing document id: " + doc.get().getId());
int processed = process(doc.get());
if (processed == 1) {
// Save the document if it was processed
repo.save(doc.get());
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public int process(Document doc) {
Integer result = 0;
doc.getAssistants().forEach(a -> a.setFullName("dismissed"));
// some logic:
// if document is processed returns 1, else 0
return result;
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor