Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
947c64ca
Commit
947c64ca
authored
8 years ago
by
juanf
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-3092 : Export functionality, ongoing work
SVN: 36601
parent
c13a4b54
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
openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/exports-api/exports-api.py
+20
-13
20 additions, 13 deletions
...n-lims/1/dss/reporting-plugins/exports-api/exports-api.py
with
20 additions
and
13 deletions
openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/exports-api/exports-api.py
+
20
−
13
View file @
947c64ca
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
from
collections
import
deque
from
collections
import
deque
import
time
import
time
import
jarray
#Java Core
#Java Core
from
java.io
import
ByteArrayInputStream
from
java.io
import
ByteArrayInputStream
...
@@ -129,8 +130,8 @@ def exportAll(tr, params):
...
@@ -129,8 +130,8 @@ def exportAll(tr, params):
params
.
put
(
"
entities
"
,
entitiesToExport
);
params
.
put
(
"
entities
"
,
entitiesToExport
);
return
export
(
tr
,
params
);
return
export
(
tr
,
params
);
def
getFileName
(
rootDir
,
spaceCode
,
projCode
,
expCode
,
sampCode
,
dataCode
):
def
getFileName
(
spaceCode
,
projCode
,
expCode
,
sampCode
,
dataCode
):
fileName
=
rootDir
;
fileName
=
""
;
if
spaceCode
is
not
None
:
if
spaceCode
is
not
None
:
fileName
+=
"
/
"
+
spaceCode
;
fileName
+=
"
/
"
+
spaceCode
;
if
projCode
is
not
None
:
if
projCode
is
not
None
:
...
@@ -143,13 +144,12 @@ def getFileName(rootDir, spaceCode, projCode, expCode, sampCode, dataCode):
...
@@ -143,13 +144,12 @@ def getFileName(rootDir, spaceCode, projCode, expCode, sampCode, dataCode):
fileName
+=
"
/
"
+
dataCode
;
fileName
+=
"
/
"
+
dataCode
;
return
fileName
;
return
fileName
;
def
addToZipFile
(
fileName
,
zos
):
def
addToZipFile
(
path
,
file
,
zos
):
file
=
File
(
fileName
);
fis
=
FileInputStream
(
file
);
fis
=
FileInputStream
(
file
);
zipEntry
=
ZipEntry
(
fileName
);
zipEntry
=
ZipEntry
(
path
);
zos
.
putNextEntry
(
zipEntry
);
zos
.
putNextEntry
(
zipEntry
);
bytes
=
byte
[
1024
]
;
bytes
=
jarray
.
zeros
(
1024
,
"
b
"
)
;
length
=
fis
.
read
(
bytes
);
length
=
fis
.
read
(
bytes
);
while
length
>=
0
:
while
length
>=
0
:
zos
.
write
(
bytes
,
0
,
length
);
zos
.
write
(
bytes
,
0
,
length
);
...
@@ -170,6 +170,10 @@ def export(tr, params):
...
@@ -170,6 +170,10 @@ def export(tr, params):
rootDirFile
.
mkdir
();
rootDirFile
.
mkdir
();
rootDir
=
rootDirFile
.
getCanonicalPath
();
rootDir
=
rootDirFile
.
getCanonicalPath
();
#Create Zip File
fos
=
FileOutputStream
(
rootDir
+
"
.zip
"
);
zos
=
ZipOutputStream
(
fos
);
for
entity
in
params
.
get
(
"
entities
"
):
for
entity
in
params
.
get
(
"
entities
"
):
type
=
entity
[
"
type
"
];
type
=
entity
[
"
type
"
];
permId
=
entity
[
"
permId
"
];
permId
=
entity
[
"
permId
"
];
...
@@ -187,7 +191,7 @@ def export(tr, params):
...
@@ -187,7 +191,7 @@ def export(tr, params):
fetchOps
.
withRegistrator
();
fetchOps
.
withRegistrator
();
fetchOps
.
withModifier
();
fetchOps
.
withModifier
();
entityObj
=
v3
.
searchProjects
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityObj
=
v3
.
searchProjects
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityFilePath
=
getFileName
(
rootDir
,
entityObj
.
getSpace
().
getCode
(),
entityObj
.
getCode
(),
None
,
None
,
None
);
entityFilePath
=
getFileName
(
entityObj
.
getSpace
().
getCode
(),
entityObj
.
getCode
(),
None
,
None
,
None
);
if
type
==
"
EXPERIMENT
"
:
if
type
==
"
EXPERIMENT
"
:
criteria
=
ExperimentSearchCriteria
();
criteria
=
ExperimentSearchCriteria
();
criteria
.
withPermId
().
thatEquals
(
permId
);
criteria
.
withPermId
().
thatEquals
(
permId
);
...
@@ -199,7 +203,7 @@ def export(tr, params):
...
@@ -199,7 +203,7 @@ def export(tr, params):
fetchOps
.
withProperties
();
fetchOps
.
withProperties
();
fetchOps
.
withTags
();
fetchOps
.
withTags
();
entityObj
=
v3
.
searchExperiments
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityObj
=
v3
.
searchExperiments
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityFilePath
=
getFileName
(
rootDir
,
entityObj
.
getProject
().
getSpace
().
getCode
(),
entityObj
.
getProject
().
getCode
(),
entityObj
.
getCode
(),
None
,
None
);
entityFilePath
=
getFileName
(
entityObj
.
getProject
().
getSpace
().
getCode
(),
entityObj
.
getProject
().
getCode
(),
entityObj
.
getCode
(),
None
,
None
);
if
type
==
"
SAMPLE
"
:
if
type
==
"
SAMPLE
"
:
criteria
=
SampleSearchCriteria
();
criteria
=
SampleSearchCriteria
();
criteria
.
withPermId
().
thatEquals
(
permId
);
criteria
.
withPermId
().
thatEquals
(
permId
);
...
@@ -213,7 +217,7 @@ def export(tr, params):
...
@@ -213,7 +217,7 @@ def export(tr, params):
fetchOps
.
withParents
();
fetchOps
.
withParents
();
fetchOps
.
withChildren
();
fetchOps
.
withChildren
();
entityObj
=
v3
.
searchSamples
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityObj
=
v3
.
searchSamples
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityFilePath
=
getFileName
(
rootDir
,
entityObj
.
getExperiment
().
getProject
().
getSpace
().
getCode
(),
entityObj
.
getExperiment
().
getProject
().
getCode
(),
entityObj
.
getExperiment
().
getCode
(),
entityObj
.
getCode
(),
None
);
entityFilePath
=
getFileName
(
entityObj
.
getExperiment
().
getProject
().
getSpace
().
getCode
(),
entityObj
.
getExperiment
().
getProject
().
getCode
(),
entityObj
.
getExperiment
().
getCode
(),
entityObj
.
getCode
(),
None
);
if
type
==
"
DATASET
"
:
if
type
==
"
DATASET
"
:
criteria
=
DataSetSearchCriteria
();
criteria
=
DataSetSearchCriteria
();
criteria
.
withPermId
().
thatEquals
(
permId
);
criteria
.
withPermId
().
thatEquals
(
permId
);
...
@@ -227,13 +231,16 @@ def export(tr, params):
...
@@ -227,13 +231,16 @@ def export(tr, params):
fetchOps
.
withParents
();
fetchOps
.
withParents
();
fetchOps
.
withChildren
();
fetchOps
.
withChildren
();
entityObj
=
v3
.
searchDataSets
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityObj
=
v3
.
searchDataSets
(
sessionToken
,
criteria
,
fetchOps
).
getObjects
().
get
(
0
);
entityFilePath
=
getFileName
(
rootDir
,
entityObj
.
getSample
().
getExperiment
().
getProject
().
getSpace
().
getCode
(),
entityObj
.
getSample
().
getExperiment
().
getProject
().
getCode
(),
entityObj
.
getSample
().
getExperiment
().
getCode
(),
entityObj
.
getSample
().
getCode
(),
entityObj
.
getCode
());
entityFilePath
=
getFileName
(
entityObj
.
getSample
().
getExperiment
().
getProject
().
getSpace
().
getCode
(),
entityObj
.
getSample
().
getExperiment
().
getProject
().
getCode
(),
entityObj
.
getSample
().
getExperiment
().
getCode
(),
entityObj
.
getSample
().
getCode
(),
entityObj
.
getCode
());
if
entityObj
is
not
None
and
entityFilePath
is
not
None
:
if
entityObj
is
not
None
and
entityFilePath
is
not
None
:
entityJson
=
String
(
objectMapper
.
writeValueAsString
(
entityObj
));
entityJson
=
String
(
objectMapper
.
writeValueAsString
(
entityObj
));
jsonEntityFile
=
File
(
entityFilePath
+
"
.json
"
);
jsonEntityFile
=
File
(
rootDir
+
entityFilePath
+
"
.json
"
);
jsonEntityFile
.
getParentFile
().
mkdirs
();
jsonEntityFile
.
getParentFile
().
mkdirs
();
IOUtils
.
write
(
entityJson
.
getBytes
(),
FileOutputStream
(
jsonEntityFile
));
IOUtils
.
write
(
entityJson
.
getBytes
(),
FileOutputStream
(
jsonEntityFile
));
addToZipFile
(
entityFilePath
+
"
.json
"
,
jsonEntityFile
,
zos
);
print
"
Folder found at:
"
+
rootDir
zos
.
close
();
fos
.
close
();
print
"
Zip file found at:
"
+
rootDir
+
"
.zip
"
return
True
return
True
\ No newline at end of file
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