Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
File Repository
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
Operations
Operations
Incidents
Environments
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
File Repository
Commits
d3a2a787
Commit
d3a2a787
authored
Jan 31, 2020
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Metadata for .json files is stored in .json.json
parent
7cde148e
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
file-repository-core/src/main/java/org/genesys/filerepository/model/RepositoryFile.java
...java/org/genesys/filerepository/model/RepositoryFile.java
+5
-1
file-repository-core/src/test/java/org/genesys/filerepository/service/MetadataTest.java
...java/org/genesys/filerepository/service/MetadataTest.java
+34
-0
No files found.
file-repository-core/src/main/java/org/genesys/filerepository/model/RepositoryFile.java
View file @
d3a2a787
...
...
@@ -245,7 +245,11 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements Ac
return
null
;
}
return
new
StringBuffer
().
append
(
uuid
.
toString
()).
append
(
".json"
).
toString
();
StringBuffer
sb
=
new
StringBuffer
().
append
(
uuid
.
toString
());
if
(
StringUtils
.
equals
(
".json"
,
extension
))
{
sb
.
append
(
extension
);
}
return
sb
.
append
(
".json"
).
toString
();
}
/**
...
...
file-repository-core/src/test/java/org/genesys/filerepository/service/MetadataTest.java
View file @
d3a2a787
...
...
@@ -26,6 +26,7 @@ import java.nio.file.Paths;
import
org.genesys.filerepository.InvalidRepositoryFileDataException
;
import
org.genesys.filerepository.InvalidRepositoryPathException
;
import
org.genesys.filerepository.NoSuchRepositoryFileException
;
import
org.genesys.filerepository.model.RepositoryFile
;
import
org.genesys.filerepository.model.RepositoryImage
;
import
org.junit.After
;
import
org.junit.Test
;
...
...
@@ -109,4 +110,37 @@ public class MetadataTest extends RepositoryServiceTest {
metadata
=
bytesStorageService
.
get
(
repoImage1
.
storageFolder
().
resolve
(
repoImage1
.
getMetadataFilename
()));
assertThat
(
metadata
,
is
(
nullValue
()));
}
/**
* Test handling of metadata .json and assure it doesn't overwrite actual file contents.
*
* @throws InvalidRepositoryPathException the invalid repository path exception
* @throws InvalidRepositoryFileDataException the invalid repository file data
* exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws NoSuchRepositoryFileException the no such repository file exception
*/
@Test
public
void
createMetadataForJson
()
throws
InvalidRepositoryPathException
,
InvalidRepositoryFileDataException
,
IOException
,
NoSuchRepositoryFileException
{
final
String
json
=
"{}"
;
RepositoryFile
repoJson
=
repositoryService
.
addFile
(
initialPath
,
"file.json"
,
"application/json"
,
json
.
getBytes
(),
null
);
assertThat
(
repoJson
.
getUuid
(),
not
(
nullValue
()));
assertThat
(
repoJson
.
getMetadataFilename
(),
endsWith
(
".json.json"
));
byte
[]
contents
=
bytesStorageService
.
get
(
repoJson
.
storagePath
());
assertThat
(
contents
,
not
(
nullValue
()));
assertThat
(
"JSON contents is messed up"
,
new
String
(
contents
),
equalTo
(
json
));
byte
[]
metadata
=
bytesStorageService
.
get
(
repoJson
.
storageFolder
().
resolve
(
repoJson
.
getMetadataFilename
()));
assertThat
(
"Metadata .json not found"
,
metadata
,
not
(
nullValue
()));
metadata
=
bytesStorageService
.
get
(
repoJson
.
storageFolder
().
resolve
(
repoJson
.
getMetadataFilename
()));
RepositoryFile
meta
=
objectMapper
.
readValue
(
metadata
,
RepositoryFile
.
class
);
assertThat
(
"Metadata does not contain valid JSON metadata"
,
meta
.
getOriginalFilename
(),
is
(
repoJson
.
getOriginalFilename
()));
repositoryService
.
removeFile
(
repoJson
);
metadata
=
bytesStorageService
.
get
(
repoJson
.
storageFolder
().
resolve
(
repoJson
.
getMetadataFilename
()));
assertThat
(
metadata
,
is
(
nullValue
()));
}
}
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