Commit a22bbce1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

we should properly handle nulls

parent 9f2292ea
......@@ -42,7 +42,7 @@ public class FileController extends BaseController {
@PreAuthorize("@fileService.getOwnerByFileId(#id)?.login == authentication.name")
@PostMapping(value = "/{id}:uploadContent")
public Map<String, Object> uploadContent(@PathVariable(value = "id") String id, @RequestBody byte[] data)
public Map<String, Object> uploadContent(@PathVariable(value = "id") Integer id, @RequestBody byte[] data)
throws ObjectNotFoundException {
return fileRest.uploadContent(id, data);
}
......
......@@ -60,7 +60,7 @@ public class FileRestImpl extends BaseRestImpl {
return result;
}
public Map<String, Object> uploadContent(String id, byte[] data) throws ObjectNotFoundException {
public Map<String, Object> uploadContent(Integer id, byte[] data) throws ObjectNotFoundException {
int fileId = Integer.valueOf(id);
UploadedFileEntry fileEntry = uploadedFileEntryDao.getById(fileId);
if (fileEntry == null) {
......
......@@ -21,20 +21,22 @@ public class FileService implements IFileService {
}
@Override
public UploadedFileEntry getById(int id) {
public UploadedFileEntry getById(Integer id) {
return uploadedFileEntryDao.getById(id);
}
@Override
public User getOwnerByFileId(int id) {
UploadedFileEntry entry = uploadedFileEntryDao.getById(id);
if (entry != null && entry.getOwner() != null) {
//it's lazy initialized
entry.getOwner().getLogin();
return uploadedFileEntryDao.getById(id).getOwner();
} else {
return null;
public User getOwnerByFileId(Integer id) {
if (id != null) {
UploadedFileEntry entry = uploadedFileEntryDao.getById(id);
if (entry != null && entry.getOwner() != null) {
// it's lazy initialized
entry.getOwner().getLogin();
return uploadedFileEntryDao.getById(id).getOwner();
}
}
return null;
}
}
......@@ -5,8 +5,8 @@ import lcsb.mapviewer.model.user.User;
public interface IFileService {
UploadedFileEntry getById(int id);
UploadedFileEntry getById(Integer id);
User getOwnerByFileId(int id);
User getOwnerByFileId(Integer 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