updated code
This commit is contained in:
@@ -43,7 +43,9 @@ public class DocumentDao {
|
||||
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long callId, DocumentTypeEnum fileType) {
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
CallEntity callEntity=callRepository.findById(callId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
CallEntity callEntity = callRepository.findById(callId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
for (MultipartFile file : files) {
|
||||
try {
|
||||
uploadFileOnAmazonS3 result = uploadFileOnAmazonS3(file);
|
||||
@@ -56,12 +58,11 @@ public class DocumentDao {
|
||||
documentEntity.setIsDeleted(false);
|
||||
documentEntities.add(documentEntity);
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
documentRepository.saveAll(documentEntities);
|
||||
return documentEntities.stream()
|
||||
.map(callDao::convertToDocumentResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
return documentEntities.stream().map(callDao::convertToDocumentResponseBean).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private uploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file) throws IOException {
|
||||
@@ -79,22 +80,25 @@ public class DocumentDao {
|
||||
|
||||
public void deleteFile(Long documentId) {
|
||||
DocumentEntity documentEntity = getDocumentEntity(documentId);
|
||||
String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||
deleteFileOnAmazonS3(fileName);
|
||||
documentRepository.delete(documentEntity);
|
||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||
// deleteFileOnAmazonS3(fileName);
|
||||
documentEntity.setIsDeleted(true);
|
||||
documentRepository.save(documentEntity);
|
||||
}
|
||||
|
||||
private DocumentEntity deleteFileOnAmazonS3(String fileName) {
|
||||
try {
|
||||
amazonS3Service.delete(fileName);
|
||||
}catch (Exception e){}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DocumentEntity getDocumentEntity(Long documentId) {
|
||||
Optional<DocumentEntity> documentEntity = documentRepository.findById(documentId);
|
||||
if (documentEntity.isEmpty()) {
|
||||
throw new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
throw new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
return documentEntity.orElse(null);
|
||||
}
|
||||
@@ -106,7 +110,8 @@ public class DocumentDao {
|
||||
uploadFileOnAmazonS3 result = null;
|
||||
try {
|
||||
result = uploadFileOnAmazonS3(file);
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
if (result != null) {
|
||||
documentEntity.setFilePath(result.filepath);
|
||||
documentEntity.setFileName(result.fileName);
|
||||
@@ -115,10 +120,12 @@ public class DocumentDao {
|
||||
}
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
}
|
||||
|
||||
public DocumentResponseBean getDocument(Long documentId) {
|
||||
Optional<DocumentEntity> documentEntity = documentRepository.findById(documentId);
|
||||
if (documentEntity.isEmpty()) {
|
||||
new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
return callDao.convertToDocumentResponseBean(documentEntity.orElse(null));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
public interface LookUpDataApi {
|
||||
|
||||
@Operation(summary = "API to create LookUp Data",
|
||||
@Operation(summary = "Api to create LookUp Data",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -31,7 +31,7 @@ public interface LookUpDataApi {
|
||||
@PostMapping(value = "", consumes = "application/json", produces = "application/json")
|
||||
ResponseEntity<Response<LookUpDataResponseBean>> createLookUpData(HttpServletRequest request, @Valid @RequestBody LookUpDataRequest lookUpDataReq);
|
||||
|
||||
@Operation(summary = "API to get LookUp Data by id",
|
||||
@Operation(summary = "Api to get LookUp Data by id",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -43,7 +43,7 @@ public interface LookUpDataApi {
|
||||
@GetMapping(value = "/{id}", produces = "application/json")
|
||||
ResponseEntity<Response<LookUpDataResponseBean>> getLookUpDataById(HttpServletRequest request, @PathVariable Long id);
|
||||
|
||||
@Operation(summary = "API to update LookUp Data",
|
||||
@Operation(summary = "Api to update LookUp Data",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -55,7 +55,7 @@ public interface LookUpDataApi {
|
||||
@PutMapping(value = "/{id}", consumes = "application/json", produces = "application/json")
|
||||
ResponseEntity<Response<LookUpDataResponseBean>> updateLookUpData(HttpServletRequest request, @PathVariable Long id, @Valid @RequestBody LookUpDataRequest lookUpDataReq);
|
||||
|
||||
@Operation(summary = "API to delete LookUp Data",
|
||||
@Operation(summary = "Api to delete LookUp Data",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "204", description = "No Content"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -67,7 +67,7 @@ public interface LookUpDataApi {
|
||||
@DeleteMapping(value = "/{id}")
|
||||
ResponseEntity<Response<Void>> deleteLookUpData(HttpServletRequest request, @PathVariable Long id);
|
||||
|
||||
@Operation(summary = "API to get LookUp Data by type",
|
||||
@Operation(summary = "Api to get LookUp Data by type",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
|
||||
Reference in New Issue
Block a user