Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xnat-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
dhcp
xnat-web
Commits
34ff1c4c
Commit
34ff1c4c
authored
9 years ago
by
Rick Herrick
Browse files
Options
Downloads
Patches
Plain Diff
Fixed broken templatized namer that never set the persistent _template field.
parent
3e612591
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/org/nrg/dcm/id/TemplatizedDicomFileNamer.java
+24
-40
24 additions, 40 deletions
src/main/java/org/nrg/dcm/id/TemplatizedDicomFileNamer.java
with
24 additions
and
40 deletions
src/main/java/org/nrg/dcm/id/TemplatizedDicomFileNamer.java
+
24
−
40
View file @
34ff1c4c
...
...
@@ -10,18 +10,9 @@
*/
package
org.nrg.dcm.id
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.apache.commons.lang.StringUtils
;
import
com.google.common.base.Functions
;
import
com.google.common.collect.Lists
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.velocity.Template
;
import
org.apache.velocity.VelocityContext
;
import
org.apache.velocity.runtime.RuntimeServices
;
...
...
@@ -33,8 +24,11 @@ import org.nrg.dcm.DicomFileNamer;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.google.common.base.Functions
;
import
com.google.common.collect.Lists
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
TemplatizedDicomFileNamer
implements
DicomFileNamer
{
...
...
@@ -42,8 +36,8 @@ public class TemplatizedDicomFileNamer implements DicomFileNamer {
private
static
final
String
SUFFIX
=
".dcm"
;
private
static
final
String
HASH_PREFIX
=
"Hash"
;
private
static
final
Logger
_log
=
LoggerFactory
.
getLogger
(
TemplatizedDicomFileNamer
.
class
);
p
ublic
static
final
String
HASH_DELIMITER
=
"With"
;
private
static
final
Logger
_log
=
LoggerFactory
.
getLogger
(
TemplatizedDicomFileNamer
.
class
);
p
rivate
static
final
String
HASH_DELIMITER
=
"With"
;
public
TemplatizedDicomFileNamer
(
final
String
naming
)
throws
Exception
{
if
(
_log
.
isDebugEnabled
())
{
...
...
@@ -61,31 +55,21 @@ public class TemplatizedDicomFileNamer implements DicomFileNamer {
* @param dicomObject The DICOM object for which the name should be calculated.
* @return The generated file name from the variable values extracted from the DICOM object.
*/
public
String
makeFileName
(
DicomObject
dicomObject
)
{
Map
<
String
,
String
>
values
=
new
HashMap
<>();
public
String
makeFileName
(
final
DicomObject
dicomObject
)
{
final
VelocityContext
context
=
new
VelocityContext
();
final
Map
<
String
,
String
>
values
=
new
HashMap
<>();
for
(
final
String
variable
:
_variables
)
{
if
(!
variable
.
startsWith
(
HASH_PREFIX
))
{
final
String
tagValue
=
dicomObject
.
getString
(
Tag
.
forName
(
variable
));
values
.
put
(
variable
,
tagValue
==
null
?
"no-value-for-"
+
variable
:
tagValue
);
final
String
value
=
StringUtils
.
isEmpty
(
tagValue
)
?
"no-value-for-"
+
variable
:
tagValue
;
context
.
put
(
variable
,
value
);
values
.
put
(
variable
,
value
);
}
}
return
makeFileName
(
values
);
}
/**
* Makes the file name from the given variables.
* @param values The various extracted variable values.
* @return The generated file name from the given variable values.
*/
public
String
makeFileName
(
Map
<
String
,
String
>
values
)
{
VelocityContext
context
=
new
VelocityContext
();
for
(
Map
.
Entry
<
String
,
String
>
value
:
values
.
entrySet
())
{
context
.
put
(
value
.
getKey
(),
value
.
getValue
());
}
for
(
final
Map
.
Entry
<
String
,
List
<
String
>>
hash
:
_hashes
.
entrySet
())
{
context
.
put
(
hash
.
getKey
(),
calculateHashString
(
hash
.
getValue
(),
values
));
}
StringWriter
writer
=
new
StringWriter
();
final
StringWriter
writer
=
new
StringWriter
();
try
{
getTemplate
().
merge
(
context
,
writer
);
}
catch
(
Exception
exception
)
{
...
...
@@ -132,10 +116,10 @@ public class TemplatizedDicomFileNamer implements DicomFileNamer {
runtimeServices
.
init
();
StringReader
reader
=
new
StringReader
(
_naming
);
SimpleNode
node
=
runtimeServices
.
parse
(
reader
,
"naming"
);
Template
template
=
new
Template
();
template
.
setRuntimeServices
(
runtimeServices
);
template
.
setData
(
node
);
template
.
initDocument
();
_
template
=
new
Template
();
_
template
.
setRuntimeServices
(
runtimeServices
);
_
template
.
setData
(
node
);
_
template
.
initDocument
();
}
}
return
_template
;
...
...
@@ -160,14 +144,14 @@ public class TemplatizedDicomFileNamer implements DicomFileNamer {
* @return All of the hashes in the template.
*/
private
Map
<
String
,
List
<
String
>>
initializeHashes
()
{
Map
<
String
,
List
<
String
>>
hashes
=
new
HashMap
<>();
Set
<
String
>
hashedVariables
=
new
HashSet
<>();
final
Map
<
String
,
List
<
String
>>
hashes
=
new
HashMap
<>();
final
Set
<
String
>
hashedVariables
=
new
HashSet
<>();
for
(
final
String
variable
:
_variables
)
{
if
(
variable
.
startsWith
(
HASH_PREFIX
))
{
if
(!
variable
.
contains
(
HASH_DELIMITER
))
{
throw
new
RuntimeException
(
"You can't specify a "
+
HASH_PREFIX
+
" without specifying at least two DICOM header values joined by the "
+
HASH_DELIMITER
+
" delimiter."
);
}
List
<
String
>
variables
=
Arrays
.
asList
(
variable
.
substring
(
4
).
split
(
HASH_DELIMITER
));
final
List
<
String
>
variables
=
Arrays
.
asList
(
variable
.
substring
(
4
).
split
(
HASH_DELIMITER
));
hashes
.
put
(
variable
,
variables
);
hashedVariables
.
addAll
(
variables
);
}
...
...
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