Skip to content

Commit

Permalink
Merge branch 'release/2024.01.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattboll committed Jan 17, 2024
2 parents 0c28759 + a5c3b1c commit 8eb37bf
Show file tree
Hide file tree
Showing 41 changed files with 135 additions and 1,452 deletions.
2 changes: 1 addition & 1 deletion dossierfacile-api-owner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<name>dossierfacile-api-owner</name>
<description>Owner api for DossierFacile</description>
<properties>
<java.version>19</java.version>
<java.version>21</java.version>
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
<lombok.version>1.18.30</lombok.version>
<keycloak.version>21.1.2</keycloak.version>
Expand Down
2 changes: 1 addition & 1 deletion dossierfacile-api-tenant/.java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0
21.0
2 changes: 1 addition & 1 deletion dossierfacile-api-tenant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Front api for dossier facile</description>

<properties>
<java.version>19</java.version>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
Expand Down
2 changes: 1 addition & 1 deletion dossierfacile-api-watermark/.java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0
21.0
2 changes: 1 addition & 1 deletion dossierfacile-api-watermark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</description>

<properties>
<java.version>19</java.version>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
Expand Down
2 changes: 1 addition & 1 deletion dossierfacile-bo/.java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0
21.0
2 changes: 1 addition & 1 deletion dossierfacile-bo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<hibernate-validator.version>6.0.20.Final</hibernate-validator.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>19</java.version>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<jackson.version>2.11.0</jackson.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.security.Principal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -49,7 +48,6 @@
@Controller
@RequiredArgsConstructor
public class BOController {

private static final int BUTTONS_TO_SHOW = 5;
private static final String EMAIL = "email";
private static final String PAGER = "pager";
Expand Down Expand Up @@ -101,18 +99,6 @@ public String loginPage(Model model) {
return "login";
}

@GetMapping("/callback/manually/{userApiId}")
public String callBackManuallyToUserApi(@PathVariable("userApiId") Long userApiId, @RequestParam("since") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime since) {
tenantService.sendCallBacksManuallyToUserApi(userApiId, since);
return REDIRECT_BO;
}

@GetMapping("/computeStatusOfAllTenants")
public String computeStatusOfAllTenants() {
tenantService.computeStatusOfAllTenants();
return REDIRECT_BO;
}

@GetMapping("/bo/documentFailedList")
public String documentFailedList(Model model, @RequestParam("pageSize") Optional<Integer> pageSize, @RequestParam("page") Optional<Integer> page) {
EmailDTO emailDTO = new EmailDTO();
Expand Down Expand Up @@ -276,26 +262,6 @@ public String regeneratePdfDocument(RedirectAttributes redirectAttributes, @Mode
return REDIRECT_BO;
}

@PostMapping(value = "/bo/regenerateStatusOfTenants")
public String regenerateStatusOfTenants(@RequestParam("email") String email) {
tenantService.updateStatusOfSomeTenants(email);
return REDIRECT_BO;
}

@GetMapping("/bo/computeTenantsStatus")
public String computeTenantStatus(Model model) {
EmailDTO emailDTO = new EmailDTO();
model.addAttribute("tenantList", emailDTO);
model.addAttribute(EMAIL, emailDTO);
return "bo/compute-status";
}

@GetMapping("/update/documents/creationDate")
public String updateDocumentsWithNullCreationDate() {
tenantService.updateDocumentsWithNullCreationDateTime();
return REDIRECT_BO;
}

@AllArgsConstructor
@Getter
static class ClientRegistrationLight {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,67 +1,42 @@
package fr.gouv.bo.controller;

import fr.dossierfacile.common.entity.StorageFile;
import fr.dossierfacile.common.repository.StorageFileRepository;
import fr.dossierfacile.common.service.interfaces.FileStorageService;
import fr.gouv.bo.dto.EmailDTO;
import fr.gouv.bo.service.ToolsService;
import fr.gouv.bo.service.TenantService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;


@Slf4j
@Controller
@RequiredArgsConstructor
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class BOToolsController {

private final FileStorageService fileStorageService;
private final StorageFileRepository storageFileRepository;

private final ToolsService toolsService;
private final TenantService tenantService;

@GetMapping("/bo/tools")
public String outils(Model model) {
model.addAttribute("email", new EmailDTO());
model.addAttribute("files", toolsService.getFiles());
return "bo/tools";
}

@PostMapping("/bo/tools/lamanufacture")
public String lamanufacture(Model model, @RequestParam("count") int count) {
/**
* Emails list split by ","
*/
@PostMapping(value = "/bo/tools/regenerateStatusOfTenants")
public String regenerateStatusOfTenants(@RequestParam("tenantList") String tenantList, Model model) {
try {
toolsService.generateLastTreatedDossiers(count);
tenantService.updateStatusOfSomeTenants(tenantList);
} catch (Exception e) {
log.error("not working");
}

return "redirect:/bo/tools";
}

@GetMapping(value = "/bo/tools/lamanufacture/files/{fileId}")
public void getLaManufactureFiles(HttpServletResponse response, @PathVariable("fileId") Long fileId) {
// Get zip from storage Id
StorageFile file = storageFileRepository.findById(fileId).get();

try (InputStream in = fileStorageService.download(file)) {
response.setContentType(file.getContentType());
IOUtils.copy(in, response.getOutputStream());
} catch (final IOException e) {
log.error("Error", e);
response.setStatus(404);
log.error("Error regenerating status for tenants", e);
model.addAttribute("errorMessage", "Quelque chose c'est mal passé: " + e.getMessage());
}
model.addAttribute("email", new EmailDTO());
return "bo/tools";
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

public interface DocumentRepository extends JpaRepository<Document, Long> {

@Query(value = "SELECT d.* FROM document d WHERE d.creation_date is null ORDER BY d.id DESC", nativeQuery = true)
Page<Document> findDocumentsByCreationDateTimeIsNull(Pageable pageable);

@Query(value = """
SELECT d.id
FROM Document d
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.bo.service;

import fr.dossierfacile.common.entity.User;
import fr.dossierfacile.common.entity.UserApi;
import org.keycloak.representations.idm.UserRepresentation;

import java.util.List;
Expand All @@ -11,4 +12,6 @@ public interface KeycloakService {
void deleteKeycloakSingleUser(User tenant);

void deleteKeycloakUsers(List<User> tenants);

void createKeycloakClient(UserApi userApi);
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,63 +410,6 @@ public void declineTenant(Principal principal, Long tenantId) {
changeTenantStatusToDeclined(tenant, operator, null, ProcessedDocuments.NONE);
}

public void sendCallBacksManuallyToUserApi(Long userApiId, LocalDateTime since) {
synchronized (this) {
UserApi userApi = userApiRepository.findOneById(userApiId).orElseThrow(NotFoundException::new);

//Finding the IDs of tenants pending to send info for partner with ID 2.
List<Long> ids = tenantRepository.listIdTenantsAccountCompletedPendingToSendCallBack(userApiId, since);
int numberOfTotalCalls = ids.size();
log.info(numberOfTotalCalls + " tenants pending to send the validation information to the partner.");
int indexCall = 1;
for (Long id : ids) {
Tenant tenant = tenantRepository.findOneById(id);
WebhookDTO webhookDTO = partnerCallBackService.getWebhookDTO(tenant, userApi, PartnerCallBackType.VERIFIED_ACCOUNT);
partnerCallBackService.sendCallBack(tenant, webhookDTO);

if (indexCall < numberOfTotalCalls) {
try {
indexCall++;
log.info("Waiting 50ms for the next call...");
this.wait(50); //It will wait 3 minutes to send the next callback
} catch (InterruptedException e) {
log.error("InterruptedException sendCallBacksManually ", e);
Thread.currentThread().interrupt();
}
}
}
}
}

@Transactional
public void computeStatusOfAllTenants() {
int numberOfUpdate = 1;
int lengthOfPage = 1000;
Pageable page = PageRequest.of(0, lengthOfPage, Sort.Direction.DESC, "id");
Page<Tenant> allTenants = tenantRepository.findAllTenants(page);

while (!allTenants.isEmpty()) {
page = page.next();

updatePage(numberOfUpdate++, allTenants);

allTenants = tenantRepository.findAllTenants(page);
}
log.info("Update for [" + allTenants.getTotalElements() + "] tenants finished");
}


private void updatePage(int numberOfUpdate, Page<Tenant> allTenants) {
List<Tenant> tenantsToChange = new ArrayList<>();
allTenants.forEach(tenant -> {
tenant.setStatus(tenant.computeStatus());
tenantsToChange.add(tenant);
});

tenantRepository.saveAll(tenantsToChange);
log.info("Update number [" + numberOfUpdate + "] for " + allTenants.getNumberOfElements() + " tenants finished");
}

private int checkValueOfCustomMessage(CustomMessage customMessage) {

List<MessageItem> messageItems = customMessage.getMessageItems();
Expand Down Expand Up @@ -731,38 +674,6 @@ public List<Document> getMissingDocuments(Guarantor guarantor, List<DocumentCate
return documentList;
}

@Transactional
public void updateDocumentsWithNullCreationDateTime() {
int numberOfUpdate = 1;
int lengthOfPage = 1000;
Pageable page = PageRequest.of(0, lengthOfPage, Sort.Direction.DESC, "id");
Page<Document> documents = documentRepository.findDocumentsByCreationDateTimeIsNull(page);
long totalElements = documents.getTotalElements();
log.info("[" + totalElements + "] documents to update with [creation_date=null]");
while (!documents.isEmpty()) {
page = page.next();

updatePageOfDocumentsWithNullCreationDateTime(documents);
log.info("Update number [" + numberOfUpdate++ + "] for " + documents.getNumberOfElements() + " documents finished");

documents = documentRepository.findDocumentsByCreationDateTimeIsNull(page);
}
log.info("[" + totalElements + "] documents updated with [creation_date=null] finished");
}

private void updatePageOfDocumentsWithNullCreationDateTime(Page<Document> documents) {
documents.forEach(document -> {
if (document.getCreationDateTime() == null) {
if (document.getTenant() != null) {
document.setCreationDateTime(document.getTenant().getLastUpdateDate());
} else if (document.getGuarantor() != null) {
document.setCreationDateTime(document.getGuarantor().getTenant().getLastUpdateDate());
}
documentRepository.save(document);
}
});
}

public long getCountOfTenantsWithFailedGeneratedPdfDocument() {
return tenantRepository.countAllTenantsWithoutPdfDocument();
}
Expand Down
Loading

0 comments on commit 8eb37bf

Please sign in to comment.