Commit e9bfa3c4 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'new-endpoints-for-repository-controller'

* new-endpoints-for-repository-controller:
  Change to UTF-8
  Added new endpoints to the RepositoryController
parents 4dadf72e 825b05c5
......@@ -19,6 +19,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -37,6 +38,8 @@ import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.service.impl.FilesMetadataInfo;
import org.genesys2.server.service.impl.FilesMetadataUpdate;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -83,6 +86,12 @@ public class RepositoryController {
@Autowired
private ImageGalleryService imagegalleryService;
@Autowired
private FilesMetadataInfo filesMetadataInfo;
@Autowired
private FilesMetadataUpdate filesMetadataUpdate;
/**
* Gets the file.
*
......@@ -145,6 +154,47 @@ public class RepositoryController {
return repositoryService.addFile(repositoryPath, file.getOriginalFilename(), file.getContentType(), file.getBytes(), metadata);
}
/**
* Upload folder metadata file.
*
* @param file the file
* @param request the request
* @return repository files by specified folder path
* @throws IOException Signals that an I/O exception has occurred.
* @throws InvalidRepositoryPathException the invalid repository path exception
*/
@PostMapping(value = "/upload/folder-metadata/**")
public Page<RepositoryFile> uploadFolderMetadata(@RequestPart(name = "file", required = true) final MultipartFile file,
final HttpServletRequest request) throws IOException, InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/upload/folder-metadata").length());
filesMetadataUpdate.updateFromCsv(file.getInputStream(), '\t', '"', '\\');
return repositoryService.listFiles(Paths.get(folderPath), Pagination.toPageRequest(50, RepositoryFile.DEFAULT_SORT));
}
/**
* Download file metadata of specified folder.
*
* @param request the request
* @param response the response
* @throws ResourceNotFoundException the no such repository folder
* @throws IOException Signals that an I/O exception has occurred.
* @throws InvalidRepositoryPathException the invalid repository path exception
*/
@GetMapping(value = "/download/folder-metadata/**")
public void downloadFolderMetadata(final HttpServletRequest request, final HttpServletResponse response) throws ResourceNotFoundException, IOException, InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/download/folder-metadata").length());
final RepositoryFolder folder = repositoryService.getFolder(Paths.get(folderPath));
if (folder == null) {
throw new ResourceNotFoundException("No folder with path=" + folderPath);
}
response.setContentType("text/csv;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + folder.getName() + "_files_metadata.csv ");
Stream<RepositoryFile> files = repositoryService.streamFiles(Paths.get(folder.getPath()), RepositoryFile.DEFAULT_SORT);
filesMetadataInfo.downloadMetadata(files, response, '\t', '"', '\\', "\n", "UTF-8");
}
/**
* Download file.
*
......
......@@ -736,11 +736,11 @@ public class WiewsController extends BaseController {
instituteService.getInstituteForEdit(wiewsCode);
final Path wiewsPath = Paths.get("/wiews/", wiewsCode);
response.setContentType("text/csv;charset=UTF-16LE");
response.setContentType("text/csv;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + wiewsCode + "_files_metadata.csv ");
Stream<RepositoryFile> files = repositoryService.streamFiles(wiewsPath, RepositoryFile.DEFAULT_SORT);
filesMetadataInfo.downloadMetadata(files, response, '\t', '"', '\\', "\n", "UTF-16LE");
filesMetadataInfo.downloadMetadata(files, response, '\t', '"', '\\', "\n", "UTF-8");
}
@PostMapping(value = "/{wiewsCode}/files/metadata/upload")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment