Skip to content
Extraits de code Groupes Projets
Valider f9113fbd rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'MP-240' into 'develop'

MP-240 / create subfolder + import file to any folder or subfolder

Closes MP-240

See merge request !54
parents 86506577 d68931b6
Branches MP-240
1 requête de fusion!54MP-240 / create subfolder + import file to any folder or subfolder
## [1.0.4]
## Added
- Adding feature of : getting fines within a certain tender analysis folder
## Changed
- updating the docs service (features of defining a new analysis folder) and adapting the controller.
- MP-339: Updated `getUserRoles(Long userId)` to return the role assignment date from database
## [1.0.3]
-MP-350 : Apply filtering and pagination on the backend side rather than the frontend.
......
......@@ -23,7 +23,7 @@ public class DocsController {
@PostMapping(SET_APPEL_TO_ANALYSE)
ResponseEntity<?>
setAppelToAnalyse(@PathVariable String id)
throws S3FunctionalException, FunctionalException {
throws S3FunctionalException {
service.setAppelToAnalyse(id);
return ResponseEntity.ok().build();
}
......@@ -33,7 +33,7 @@ public class DocsController {
@RequestParam String appelOffre,
@PathVariable("email") String email)
throws S3FunctionalException, FunctionalException {
String fileUrl = service.uploadAnalyseFileToTender(appelOffre,
String fileUrl = service.uploadAnalyseFileToFolder(appelOffre,
file,
email);
return ResponseEntity.ok(fileUrl);
......@@ -45,4 +45,15 @@ public class DocsController {
return ResponseEntity.ok().
body(service.getAllFilesInBucket());
}
@GetMapping(GET_FILES_WITHIN_TENDER_FOLDER)
ResponseEntity<List<S3ObjectSummary>>
getFilesWithinFolder(
@PathVariable String id
) throws S3FunctionalException {
return ResponseEntity.ok().
body(
service.getAllFilesInTenderFolder(id)
);
}
}
......@@ -60,4 +60,5 @@ public class ApiPaths {
public static final String SET_APPEL_TO_ANALYSE = "/set-to-analyse/{id}";
public static final String UPLOAD_FILE = "/upload/{email}";
public static final String GET_BUCKET_FILES_MD = "/files-metadata";
public static final String GET_FILES_WITHIN_TENDER_FOLDER = "/files-metadata/{id}";
}
......@@ -8,11 +8,10 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public interface DocsService {
String uploadAnalyseFileToTender
(String appelOffre, MultipartFile fileMult,String email)
String setAppelToAnalyse(String id) throws S3FunctionalException;
String uploadAnalyseFileToFolder
(String parentFolder,MultipartFile fileMult,String email)
throws S3FunctionalException,FunctionalException;
void setAppelToAnalyse
(String id)
throws S3FunctionalException , FunctionalException;
List<S3ObjectSummary> getAllFilesInBucket() throws S3FunctionalException;
List<S3ObjectSummary> getAllFilesInTenderFolder(String id) throws S3FunctionalException;
}
......@@ -17,6 +17,7 @@ import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor
......@@ -30,7 +31,7 @@ public class DocsServiceImpl implements DocsService {
private final AmazonS3 amazonS3;
final String bucketName = "mobimarche-rec";
public void setAppelToAnalyse
public String setAppelToAnalyse
(String id)
throws S3FunctionalException {
......@@ -49,9 +50,10 @@ public class DocsServiceImpl implements DocsService {
emptyFile,
bucketName
);
Folder local = Folder.builder().folderName("analyse/appelsOffres/"+id).
Folder local = Folder.builder().folderName("analyse/appelsOffres/" + id).
build();
folderRepository.save(local);
return "analyse/appelsOffres/" + id;
}
@Override
......@@ -60,31 +62,47 @@ public class DocsServiceImpl implements DocsService {
}
@Override
public String uploadAnalyseFileToTender
(String appelOffre,MultipartFile fileMult,String email)
throws S3FunctionalException,FunctionalException {
String fileName = "analyse-" +
appelOffre + "-" +
public List<S3ObjectSummary> getAllFilesInTenderFolder(String id)
throws S3FunctionalException {
List<S3ObjectSummary> all = s3FileService.
listFilesWithMetadataByBucketName(bucketName);
List<S3ObjectSummary> spec = new ArrayList<>();
String witness = "analyse/appelsOffres/" + id;
all.forEach(tender -> {
if (tender.getKey().contains(witness)) {
spec.add(tender);
}
});
return spec;
}
@Override
public String uploadAnalyseFileToFolder
(String parentFolder, MultipartFile fileMult, String email)
throws S3FunctionalException, FunctionalException {
String originalFileName = getBareFileName(fileMult.getOriginalFilename());
if (originalFileName.contains(".") ||
originalFileName.contains("/") ||
originalFileName.contains("\\") ||
originalFileName.contains(("*")) ||
originalFileName.contains("|") ||
originalFileName.contains("@") ||
originalFileName.contains("-") ||
originalFileName.contains(",")) {
throw new FunctionalException
("File name mustn't contain special characters like : . , @ * \\ | / - ");
}
String fileName = originalFileName +
"@"+
System.currentTimeMillis() +
getExtension(fileMult.getOriginalFilename());
s3FileService.uploadElementToBucket
("file","analyse/appelsOffres/"+appelOffre,fileName,
fileMult,bucketName);
String url = amazonS3.getUrl
(bucketName,fileMult.getOriginalFilename()).toString();
("file", parentFolder, fileName,
fileMult, bucketName);
User connectedUser = userRepository.findByEmail(email).
orElseThrow(()-> new FunctionalException
orElseThrow(() -> new FunctionalException
("User with email " + email + " not found "));
Folder parentLocal = folderRepository.findByFolderName
("analyse/appelsOffres/"+appelOffre).
orElseThrow(()-> new FunctionalException("Folder not found "+appelOffre));
File createdFile = File.builder().
user(connectedUser).
url(url).
parentFolder(parentLocal).
build();
fileRepository.save(createdFile);
return url;
return parentFolder + "/" + fileName;
}
private String getExtension(String fileName) {
......@@ -92,4 +110,10 @@ public class DocsServiceImpl implements DocsService {
int dotIndex = fileName.lastIndexOf('.');
return (dotIndex == -1) ? "" : fileName.substring(dotIndex);
}
private String getBareFileName(String fileName) {
if (fileName == null) return "";
int dotIndex = fileName.lastIndexOf('.');
return (dotIndex == -1) ? "" : fileName.substring(0, dotIndex);
}
}
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter