Commit 318148e9 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

file ids are integers

parent ac7c1d8a
......@@ -36,7 +36,7 @@ public class FileController extends BaseController {
@PostAuthorize("hasAuthority('IS_ADMIN') or returnObject['owner'] == authentication.name")
@GetMapping(value = "/{id}")
public Map<String, Object> getFile(@PathVariable(value = "id") String id) throws ObjectNotFoundException {
public Map<String, Object> getFile(@PathVariable(value = "id") Integer id) throws ObjectNotFoundException {
return fileRest.getFile(id);
}
......
......@@ -15,6 +15,7 @@ import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao;
import lcsb.mapviewer.services.interfaces.IFileService;
@Transactional
@Service
......@@ -22,9 +23,12 @@ public class FileRestImpl extends BaseRestImpl {
private UploadedFileEntryDao uploadedFileEntryDao;
private IFileService fileService;
@Autowired
public FileRestImpl(UploadedFileEntryDao uploadedFileEntryDao) {
public FileRestImpl(UploadedFileEntryDao uploadedFileEntryDao, IFileService fileService) {
this.uploadedFileEntryDao = uploadedFileEntryDao;
this.fileService = fileService;
}
public Map<String, Object> createFile(String filename, String length, User user) {
......@@ -35,15 +39,14 @@ public class FileRestImpl extends BaseRestImpl {
entry.setOwner(user);
uploadedFileEntryDao.add(entry);
try {
return getFile(entry.getId() + "");
return getFile(entry.getId());
} catch (ObjectNotFoundException e) {
throw new InvalidStateException(e);
}
}
public Map<String, Object> getFile(String id) throws ObjectNotFoundException {
int fileId = Integer.valueOf(id);
UploadedFileEntry fileEntry = uploadedFileEntryDao.getById(fileId);
public Map<String, Object> getFile(Integer id) throws ObjectNotFoundException {
UploadedFileEntry fileEntry = fileService.getById(id);
if (fileEntry == null) {
throw new ObjectNotFoundException("Object not found");
}
......
......@@ -46,14 +46,14 @@ public class FileRestImplTest extends RestTestFunctions {
byte[] dataChunkMerged = ArrayUtils.addAll(dataChunk, dataChunk2);
Map<String, Object> result = fileRestImpl.createFile("test.txt", "100", user);
int id = (Integer) result.get("id");
fileRestImpl.uploadContent(id + "", dataChunk);
fileRestImpl.uploadContent(id, dataChunk);
UploadedFileEntry file = uploadedFileEntryDao.getById(id);
assertEquals(100, file.getLength());
assertEquals(2, file.getFileContent().length);
assertArrayEquals(dataChunk, file.getFileContent());
fileRestImpl.uploadContent(id + "", dataChunk2);
fileRestImpl.uploadContent(id, dataChunk2);
assertEquals(100, file.getLength());
assertEquals(4, file.getFileContent().length);
......@@ -70,7 +70,7 @@ public class FileRestImplTest extends RestTestFunctions {
int id = (Integer) result.get("id");
try {
fileRestImpl.uploadContent(id + "", dataChunk);
fileRestImpl.uploadContent(id, dataChunk);
} finally {
uploadedFileEntryDao.getById(id);
UploadedFileEntry file = uploadedFileEntryDao.getById(id);
......
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