[Biolevante] fix creazione dataSheet: Cast string variabili e gestiti errori download minio
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package it.integry.ems.document.data_sheet.controller;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.activity.controller.ActivityController;
|
||||
import it.integry.ems.document.data_sheet.service.DataSheetServices;
|
||||
import it.integry.ems.response.StatusResponse;
|
||||
import it.integry.ems.service.dto.AttachmentDTO;
|
||||
import it.integry.ems.status.ServiceChecker;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -13,8 +11,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Scope(value = "request")
|
||||
@@ -27,19 +23,11 @@ public class DataSheetController {
|
||||
@Autowired
|
||||
private DataSheetServices dataSheetServices;
|
||||
|
||||
@RequestMapping(value = "status", method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
List<StatusResponse> status(HttpServletRequest request) {
|
||||
Method[] methods = ActivityController.class.getDeclaredMethods();
|
||||
return serviceChecker.getServiceStatus(methods, ActivityController.class);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "compileWordFile", method = RequestMethod.GET)
|
||||
public ResponseEntity<byte[]> compileWordFile (HttpServletRequest request,
|
||||
@GetMapping(value = "compileWordFile")
|
||||
public ResponseEntity<byte[]> compileWordFile(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String config,
|
||||
@RequestParam String codMart) {
|
||||
@RequestParam String codMart) throws Exception {
|
||||
|
||||
try{
|
||||
AttachmentDTO attachmentDTO = dataSheetServices.compileWordFile(codMart);
|
||||
|
||||
if (attachmentDTO != null) {
|
||||
@@ -49,10 +37,5 @@ public class DataSheetController {
|
||||
.header("Content-Disposition", "attachment; filename=\"" + attachmentDTO.getFileName() + "\"")
|
||||
.body(attachmentDTO.getFileContent());
|
||||
}
|
||||
} catch (Exception e){
|
||||
return ResponseEntity.status(420).body(e.toString().getBytes());
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DataSheetServices {
|
||||
Connection conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
|
||||
StbFilesAttached filesAttached = getDocument(codMart);
|
||||
byte[] bytes = minIOService.downloadObject(filesAttached.getRefUuid(), conn);
|
||||
byte[] bytes = downloadFile(filesAttached);
|
||||
XWPFDocument document = UtilityDocx.readDocxFile(bytes, filesAttached.getFileName());
|
||||
|
||||
HashMap<String, String> variableValues = getVariableValues(codMart, UtilityDocx.findAllVariables(document));
|
||||
@@ -119,7 +119,7 @@ public class DataSheetServices {
|
||||
|
||||
allVariables.forEach(variable -> {
|
||||
if (mtb_aart.containsKey(variable)) {
|
||||
resultMap.put(variable, (String) mtb_aart.get(variable));
|
||||
resultMap.put(variable, String.valueOf(mtb_aart.get(variable)));
|
||||
}
|
||||
|
||||
Optional<HashMap<String, Object>> optionalMap = hashMaps.stream()
|
||||
@@ -158,7 +158,7 @@ public class DataSheetServices {
|
||||
for (StbFilesAttached stbFilesAttached : stbFilesAttacheds) {
|
||||
String key = String.format("%02d", counter);
|
||||
|
||||
byte[] fileData = minIOService.downloadObject(stbFilesAttached.getRefUuid(), conn);
|
||||
byte[] fileData = downloadFile(stbFilesAttached);
|
||||
Map<String, Object> innerMap = new HashMap<>();
|
||||
innerMap.put("fileName", stbFilesAttached.getFileName());
|
||||
innerMap.put("byte", fileData);
|
||||
@@ -182,4 +182,12 @@ public class DataSheetServices {
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private byte[] downloadFile(StbFilesAttached stbFilesAttached) throws Exception {
|
||||
try {
|
||||
return minIOService.downloadObject(stbFilesAttached.getRefUuid(), multiDBTransactionManager.getPrimaryConnection());
|
||||
} catch (Exception e){
|
||||
throw new Exception("Errore nel download del file: " + stbFilesAttached.getFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user