Skip to content

Commit

Permalink
fix: reload structure after an update
Browse files Browse the repository at this point in the history
  • Loading branch information
Indah Juliani committed Oct 21, 2024
1 parent c12607d commit 9af2f13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private synchronized void reloadStructureById(final String id) {

if (this.cacheLoadingNeeded()) {
this.forceLoadStructureCache();
} else if (this.expiredIds.containsKey(id) && this.expiredIds.get(id).isBeforeNow()) {
} else if (this.expiredIds.containsKey(id) || this.expiredIds.get(id).isBeforeNow()) {
this.loadingInProgress = true;

log.debug("Refreshing cached structure with id [{}] ...", id);
Expand Down Expand Up @@ -457,6 +457,11 @@ public Map<String, String> getSiren(String code, String name, Map<String, Struct
public void updateStructure(DTOStructure dto, String customName, String siteWeb, String logo, String id) {

this.structureDao.saveStructure(dto, customName, siteWeb, logo, id);
this.invalidateStructureById(id);

if (this.expiredIds.containsKey(id)) {
this.reloadStructureById(id);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ private IImageUrlPath calculNewImageUrlPath(DTOStructure str, IImageUrlPath old)
if (old != null) {
log.info("old not null");
version = Integer.parseInt(old.getVersion());
} else {
log.info("old is null");
}
log.info("old is null");
url = logoStorageService.makeImageUrlPath(str.getId(), version + 1);
log.debug("pathuser: {}", url.getPathUser());
if (!mkdir(url.getPathUser())) {
Expand Down Expand Up @@ -248,7 +249,7 @@ public ResponseEntity<?> updateV2(
dtoStructure.setStructSiteWeb(structDto.getStructSiteWeb());
structureService.updateStructure(dtoStructure, dtoStructure.getStructCustomDisplayName(),
dtoStructure.getStructSiteWeb(), null, dtoStructure.getId());
structureService.invalidateStructureById(id); // refresh cache
// structureService.invalidateStructureById(id); // refresh cache
return new ResponseEntity<>(dtoStructure, HttpStatus.OK);
} else {
throw new HandledException("perte-connexion");
Expand All @@ -268,20 +269,20 @@ public ResponseEntity<?> updateV2(
@PostMapping("/logoupload/{id}")
public ResponseEntity<?> uploadFile(
@RequestHeader(name = "Authorization", required = true) String authorizationHeader,
@RequestPart(name = "file", required = false) MultipartFile file,
@RequestPart(name = "details") String detailsJson, @PathVariable("id") final String id) {
@RequestPart(name = "file", required = false) MultipartFile file, @PathVariable("id") final String id) {

try {
String userId = decodeJwt(authorizationHeader);
Person person = userInfoService.getPersonDetails(userId);

if (person != null) {
if (detailsJson != null) {
// Parse the detailsJson string back to DTO
DTOStructure dto = new Gson().fromJson(detailsJson, DTOStructure.class);
if (id != null) {
log.debug("idStruct: {}", id);
Structure structure = structureService.retrieveStructureById(id);
DTOStructure dtoUpd = structure2DTOStructure.toDTO(structure);

oldUrl = calculOldImageUrlPath(dto);
newUrl = calculNewImageUrlPath(dto, oldUrl);
oldUrl = calculOldImageUrlPath(dtoUpd);
newUrl = calculNewImageUrlPath(dtoUpd, oldUrl);
String pathName = newUrl.getPathName();
String getNewURL = newUrl.getUrl();
if (newUrl != null) {
Expand All @@ -294,11 +295,11 @@ public ResponseEntity<?> uploadFile(
HttpStatus.BAD_REQUEST);
}

dto.setStructLogo(getNewURL);
dtoUpd.setStructLogo(getNewURL);

oldUrl = newUrl;
structureService.updateStructure(dto, null, null, dto.getStructLogo(), id);
structureService.invalidateStructureById(id); // refresh cache
structureService.updateStructure(dtoUpd, null, null, dtoUpd.getStructLogo(), id);
// structureService.invalidateStructureById(id); // refresh cache
return new ResponseEntity<>(getNewURL, HttpStatus.OK);
}
return new ResponseEntity<>("Erreur : l'établissement n'est pas défini !", HttpStatus.BAD_REQUEST);
Expand Down

0 comments on commit 9af2f13

Please sign in to comment.