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
48d0926c
Commit
48d0926c
authored
10 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-943: Long method AbstractCachingTranslator.doTranslate() refactored.
SVN: 32601
parent
7639ad6e
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/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/AbstractCachingTranslator.java
+65
-53
65 additions, 53 deletions
...c/server/api/v3/translator/AbstractCachingTranslator.java
with
65 additions
and
53 deletions
openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/AbstractCachingTranslator.java
+
65
−
53
View file @
48d0926c
...
@@ -60,7 +60,6 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten
...
@@ -60,7 +60,6 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten
}
}
}
}
@SuppressWarnings
(
"unchecked"
)
@Override
@Override
protected
Collection
<
O
>
doTranslate
(
Collection
<
I
>
inputs
)
protected
Collection
<
O
>
doTranslate
(
Collection
<
I
>
inputs
)
{
{
...
@@ -71,60 +70,10 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten
...
@@ -71,60 +70,10 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten
{
{
if
(
getTranslationCache
().
hasTranslatedObject
(
getClass
().
getName
(),
input
.
getId
()))
if
(
getTranslationCache
().
hasTranslatedObject
(
getClass
().
getName
(),
input
.
getId
()))
{
{
O
output
=
(
O
)
getTranslationCache
().
getTranslatedObject
(
getClass
().
getName
(),
input
.
getId
());
handleAlreadyTranslatedInput
(
input
,
translated
,
updated
);
if
(
output
==
null
)
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Found that object was already rejected from translation: "
+
input
.
getId
());
}
}
else
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Found in cache: "
+
output
.
getClass
()
+
" with id: "
+
input
.
getId
());
}
if
(
getTranslationCache
().
isFetchedWithOptions
(
output
,
getFetchOptions
()))
{
translated
.
add
(
output
);
}
else
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Updating from cache: "
+
output
.
getClass
()
+
" with id: "
+
input
.
getId
());
}
getTranslationCache
().
setFetchedWithOptions
(
output
,
getFetchOptions
());
updated
.
put
(
input
,
output
);
translated
.
add
(
output
);
}
}
}
else
}
else
{
{
if
(
shouldTranslate
(
input
))
handleNewInput
(
input
,
translated
,
updated
);
{
O
output
=
createObject
(
input
);
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Created: "
+
output
.
getClass
()
+
" with id: "
+
input
.
getId
());
}
getTranslationCache
().
putTranslatedObject
(
getClass
().
getName
(),
input
.
getId
(),
output
);
getTranslationCache
().
setFetchedWithOptions
(
output
,
getFetchOptions
());
updated
.
put
(
input
,
output
);
translated
.
add
(
output
);
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Updating created: "
+
output
.
getClass
()
+
" with id: "
+
input
.
getId
());
}
}
else
{
operationLog
.
debug
(
"Should not translate object: "
+
input
.
getClass
()
+
" with id: "
+
input
.
getId
());
}
}
}
}
}
...
@@ -142,6 +91,69 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten
...
@@ -142,6 +91,69 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten
return
translated
;
return
translated
;
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
handleAlreadyTranslatedInput
(
I
input
,
List
<
O
>
translated
,
Map
<
I
,
O
>
updated
)
{
Long
id
=
input
.
getId
();
O
output
=
(
O
)
getTranslationCache
().
getTranslatedObject
(
getClass
().
getName
(),
id
);
if
(
output
==
null
)
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Found that object was already rejected from translation: "
+
id
);
}
}
else
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Found in cache: "
+
output
.
getClass
()
+
" with id: "
+
id
);
}
if
(
getTranslationCache
().
isFetchedWithOptions
(
output
,
getFetchOptions
()))
{
translated
.
add
(
output
);
}
else
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Updating from cache: "
+
output
.
getClass
()
+
" with id: "
+
id
);
}
getTranslationCache
().
setFetchedWithOptions
(
output
,
getFetchOptions
());
updated
.
put
(
input
,
output
);
translated
.
add
(
output
);
}
}
}
private
void
handleNewInput
(
I
input
,
List
<
O
>
translated
,
Map
<
I
,
O
>
updated
)
{
Long
id
=
input
.
getId
();
if
(
shouldTranslate
(
input
))
{
O
output
=
createObject
(
input
);
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Created: "
+
output
.
getClass
()
+
" with id: "
+
id
);
}
getTranslationCache
().
putTranslatedObject
(
getClass
().
getName
(),
id
,
output
);
getTranslationCache
().
setFetchedWithOptions
(
output
,
getFetchOptions
());
updated
.
put
(
input
,
output
);
translated
.
add
(
output
);
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Updating created: "
+
output
.
getClass
()
+
" with id: "
+
id
);
}
}
else
{
operationLog
.
debug
(
"Should not translate object: "
+
input
.
getClass
()
+
" with id: "
+
id
);
}
}
/**
/**
* Override this method if you want to conditionally skip translation (e.g. when the input object is not visible for a user the translation is
* Override this method if you want to conditionally skip translation (e.g. when the input object is not visible for a user the translation is
* performed for)
* performed for)
...
...
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