Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
318148e9
Commit
318148e9
authored
Jul 25, 2019
by
Piotr Gawron
Browse files
file ids are integers
parent
ac7c1d8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/files/FileController.java
View file @
318148e9
...
...
@@ -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
);
}
...
...
rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java
View file @
318148e9
...
...
@@ -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"
);
}
...
...
rest-api/src/test/java/lcsb/mapviewer/api/files/FileRestImplTest.java
View file @
318148e9
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment