Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-server
Commits
718121de
Commit
718121de
authored
5 years ago
by
Daniel
Browse files
Options
Downloads
Patches
Plain Diff
FIX: Handle files on file system without File entity.
For
#14
.
parent
e2161ece
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/caosdb/server/resource/FileSystemResource.java
+26
-5
26 additions, 5 deletions
src/main/java/caosdb/server/resource/FileSystemResource.java
with
26 additions
and
5 deletions
src/main/java/caosdb/server/resource/FileSystemResource.java
+
26
−
5
View file @
718121de
...
...
@@ -29,6 +29,7 @@ import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import
caosdb.server.database.misc.TransactionBenchmark
;
import
caosdb.server.entity.Entity
;
import
caosdb.server.entity.FileProperties
;
import
caosdb.server.entity.Message
;
import
caosdb.server.entity.RetrieveEntity
;
import
caosdb.server.entity.container.TransactionContainer
;
import
caosdb.server.permissions.EntityPermission
;
...
...
@@ -149,17 +150,32 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
return
null
;
}
/**
* Return an element for the given file on a file system.
*
* <p>If there is no File entity for this file, an element without `id` is returned, instead a
* corresponding message is added to the element.
*/
Element
getFileElement
(
final
String
directory
,
final
File
file
)
throws
Exception
{
final
Element
celem
=
new
Element
(
"file"
);
celem
.
setAttribute
(
"id"
,
getEntityID
((
directory
.
endsWith
(
"/"
)
?
directory
:
directory
+
"/"
)
+
file
.
getName
()));
final
String
entId
=
getEntityID
((
directory
.
endsWith
(
"/"
)
?
directory
:
directory
+
"/"
)
+
file
.
getName
());
if
(
entId
==
null
)
{
new
Message
(
"Orphaned file"
).
addToElement
(
celem
);
}
else
{
celem
.
setAttribute
(
"id"
,
entId
);
}
celem
.
setAttribute
(
"name"
,
file
.
getName
());
return
celem
;
}
protected
String
getEntityID
(
final
String
path
)
throws
Exception
{
return
getEntity
(
path
).
getId
().
toString
();
final
Entity
fileEnt
=
getEntity
(
path
);
if
(
fileEnt
==
null
)
{
return
null
;
}
return
fileEnt
.
getId
().
toString
();
}
private
Entity
getEntity
(
final
String
path
)
throws
Exception
{
...
...
@@ -170,7 +186,12 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
e
.
setFileProperties
(
fp
);
c
.
add
(
e
);
final
Transaction
<?>
t
=
new
RetrieveSparseEntityByPath
(
c
);
t
.
execute
();
try
{
t
.
execute
();
}
catch
(
NullPointerException
npe
)
{
// For example files in file system without corresponding File records.
return
null
;
}
final
long
t2
=
System
.
currentTimeMillis
();
getBenchmark
().
addMeasurement
(
this
.
getClass
().
getSimpleName
()
+
".getEntity"
,
t2
-
t1
);
return
e
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment