Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ public ResponseEntity<Void> declineTenantFile(
return ok().build();
}

@PreAuthorize("hasRole('SUPPORT')")
@PostMapping("/{id}/reprocess")
public ResponseEntity<Void> reprocessTenantFile(
@PathVariable("id") Long tenantId,
@AuthenticationPrincipal UserPrincipal principal
) {
tenantService.reprocessTenant(principal, tenantId);
return ok().build();
}

@PostMapping("/{id}/customMessage")
public String customEmail(
@PathVariable("id") Long tenantId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public void addDeleteDocumentLog(Long tenantId, Long operatorId, Document docume
tenantLogCommonService.saveTenantLog(log);
}

public void addReprocessTenantLog(Long tenantId, Long operatorId, int documentCount) {
TenantLog log = TenantLog.builder()
.logType(LogType.ACCOUNT_REPROCESSED)
.tenantId(tenantId)
.operatorId(operatorId)
.creationDateTime(LocalDateTime.now())
.logDetails(writeAsObjectNode(Map.of("documentCount", documentCount)))
.build();
tenantLogCommonService.saveTenantLog(log);
}

public void addUpdateAmountLog(Long tenantId, Long operatorId, Document document, Integer newSum) {
TenantLog log = TenantLog.builder()
.logType(LogType.ACCOUNT_EDITED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,42 @@ public void declineTenant(UserPrincipal principal, Long tenantId) {
changeTenantStatusToDeclined(tenant, operator, null, ProcessedDocuments.NONE);
}

@Transactional
public void reprocessTenant(UserPrincipal principal, Long tenantId) {
Tenant tenant = find(tenantId);
User operator = userService.findUserByEmail(principal.getEmail());

// reprocess declined documents for all guarantors of tenant
int reprocessed = reprocessDeclinedDocuments(tenant.getDocuments());
reprocessed += Optional.ofNullable(tenant.getGuarantors()).orElse(new ArrayList<>())
.stream()
.mapToInt(g -> reprocessDeclinedDocuments(g.getDocuments()))
Comment thread
alixdeschamps marked this conversation as resolved.
.sum();

if (reprocessed == 0) {
log.info("Reprocess requested but no DECLINED documents for tenant {} by op {}",
tenantId, operator.getId());
return;
}

tenant.setStatus(tenant.computeStatus());
tenantRepository.save(tenant);
tenantLogService.addReprocessTenantLog(tenant.getId(), operator.getId(), reprocessed);
}

private int reprocessDeclinedDocuments(List<Document> documents) {
int count = 0;
for (Document d : Optional.ofNullable(documents).orElse(new ArrayList<>())) {
if (d.getDocumentStatus() == DocumentStatus.DECLINED) {
d.setDocumentStatus(DocumentStatus.TO_PROCESS);
d.setDocumentDeniedReasons(null);
documentRepository.save(d);
count++;
}
}
return count;
}

private boolean isDenied(MessageItem messageItem) {
boolean messageItemCheck = messageItem.getItemDetailList().stream().anyMatch(ItemDetail::isCheck);
return messageItemCheck || isNotEmpty(messageItem.getCommentDoc());
Expand Down
Loading
Loading