diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/AbstractCachingTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/AbstractCachingTranslator.java index 4107f82877c34fb8de0de2244b64f565f8a30a3e..b189e09de574febb421599b73c498740a1454f4f 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/AbstractCachingTranslator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/AbstractCachingTranslator.java @@ -60,7 +60,6 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten } } - @SuppressWarnings("unchecked") @Override protected Collection<O> doTranslate(Collection<I> inputs) { @@ -71,60 +70,10 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten { if (getTranslationCache().hasTranslatedObject(getClass().getName(), input.getId())) { - O output = (O) getTranslationCache().getTranslatedObject(getClass().getName(), input.getId()); - - 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); - } - } + handleAlreadyTranslatedInput(input, translated, updated); } else { - if (shouldTranslate(input)) - { - 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()); - } + handleNewInput(input, translated, updated); } } @@ -142,6 +91,69 @@ public abstract class AbstractCachingTranslator<I extends IIdHolder, O, F> exten 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 * performed for)