diff --git a/core-customize/hybris/bin/custom/sapcxtools/sapcommercetoolkit/src/tools/sapcx/commerce/toolkit/model/FailureLoggingModelService.java b/core-customize/hybris/bin/custom/sapcxtools/sapcommercetoolkit/src/tools/sapcx/commerce/toolkit/model/FailureLoggingModelService.java index 63e9464..9faa0b8 100644 --- a/core-customize/hybris/bin/custom/sapcxtools/sapcommercetoolkit/src/tools/sapcx/commerce/toolkit/model/FailureLoggingModelService.java +++ b/core-customize/hybris/bin/custom/sapcxtools/sapcommercetoolkit/src/tools/sapcx/commerce/toolkit/model/FailureLoggingModelService.java @@ -37,295 +37,295 @@ * implementation class is removed from the platform. */ public class FailureLoggingModelService extends DefaultModelService { - private static final Logger LOG = LoggerFactory.getLogger(FailureLoggingModelService.class); - private static final String EXCEPTION_MESSAGE = "Exception of type '%s' occurred during model service interaction: %s"; - private static final String SUPPRESSED_EXCEPTION_MESSAGE = "Suppressed exception (%d of %d): %s"; - - private void wrapWithLoggingCapabilities(final Runnable command) { - try { - command.run(); - } catch (IllegalArgumentException | SystemException | NullPointerException e) { - performLogging(e); - throw e; - } - } - - private T wrapWithLoggingCapabilities(final Supplier command) { - try { - return command.get(); - } catch (IllegalArgumentException | SystemException | NullPointerException e) { - performLogging(e); - throw e; - } - } - - private void performLogging(final T exception) { - if (LOG.isDebugEnabled()) { - LOG.debug(String.format(EXCEPTION_MESSAGE, exception.getClass().getSimpleName(), exception.getLocalizedMessage()), exception); - - final Throwable[] suppressed = exception.getSuppressed(); - if (suppressed != null) { - int total = suppressed.length; - for (int i = 0; i < total; i++) { - LOG.debug(String.format(SUPPRESSED_EXCEPTION_MESSAGE, i, total, suppressed[i].getLocalizedMessage()), suppressed[i]); - } - } - } - } - - @Override - public void attach(Object o) { - wrapWithLoggingCapabilities(() -> super.attach(o)); - } - - @Override - public void detach(Object o) { - wrapWithLoggingCapabilities(() -> super.detach(o)); - } - - @Override - public void detach(PK pk) { - wrapWithLoggingCapabilities(() -> super.detach(pk)); - } - - @Override - public void detachAll() { - wrapWithLoggingCapabilities(() -> super.detachAll()); - } - - @Override - public T clone(T t) { - return wrapWithLoggingCapabilities(() -> super.clone(t)); - } - - @Override - public T clone(Object o, Class aClass) { - return wrapWithLoggingCapabilities(() -> super.clone(o, aClass)); - } - - @Override - public T clone(T t, ModelCloningContext modelCloningContext) { - return wrapWithLoggingCapabilities(() -> super.clone(t, modelCloningContext)); - } - - @Override - public T clone(Object o, Class aClass, ModelCloningContext modelCloningContext) { - return wrapWithLoggingCapabilities(() -> super.clone(o, aClass, modelCloningContext)); - } - - @Override - public T create(Class aClass) { - return wrapWithLoggingCapabilities(() -> super.create(aClass)); - } - - @Override - public T create(String s) { - return wrapWithLoggingCapabilities(() -> super.create(s)); - } - - @Override - public T get(Object o) { - return wrapWithLoggingCapabilities(() -> super.get(o)); - } - - @Override - public T get(Object o, String s) { - return wrapWithLoggingCapabilities(() -> super.get(o, s)); - } - - @Override - public T get(PK pk) { - return wrapWithLoggingCapabilities(() -> super.get(pk)); - } - - @Override - public T getAll(Collection collection, T t) { - return wrapWithLoggingCapabilities(() -> super.getAll(collection, t)); - } - - @Override - public T getAll(Collection collection, T t, String s) { - return wrapWithLoggingCapabilities(() -> super.getAll(collection, t, s)); - } - - @Override - public void refresh(Object o) { - wrapWithLoggingCapabilities(() -> super.refresh(o)); - } - - @Override - public void save(Object o) throws ModelSavingException { - wrapWithLoggingCapabilities(() -> super.save(o)); - } - - @Override - public void saveAll(Collection collection) throws ModelSavingException { - wrapWithLoggingCapabilities(() -> super.saveAll(collection)); - } - - @Override - public void saveAll(Object... objects) throws ModelSavingException { - wrapWithLoggingCapabilities(() -> super.saveAll(objects)); - } - - @Override - public void saveAll() throws ModelSavingException { - wrapWithLoggingCapabilities(() -> super.saveAll()); - } - - @Override - public boolean isUniqueConstraintErrorAsRootCause(Exception e) { - return wrapWithLoggingCapabilities(() -> super.isUniqueConstraintErrorAsRootCause(e)); - } - - @Override - public void remove(Object o) throws ModelRemovalException { - wrapWithLoggingCapabilities(() -> super.remove(o)); - } - - @Override - public void removeAll(Collection collection) throws ModelRemovalException { - wrapWithLoggingCapabilities(() -> super.removeAll(collection)); - } - - @Override - public void removeAll(Object... objects) throws ModelRemovalException { - wrapWithLoggingCapabilities(() -> super.removeAll(objects)); - } - - @Override - public void remove(PK pk) throws ModelRemovalException { - wrapWithLoggingCapabilities(() -> super.remove(pk)); - } - - @Override - public T getSource(Object o) { - return wrapWithLoggingCapabilities(() -> super.getSource(o)); - } - - @Override - public T getAllSources(Collection collection, T t) { - return wrapWithLoggingCapabilities(() -> super.getAllSources(collection, t)); - } - - @Override - public String getModelType(Class aClass) { - return wrapWithLoggingCapabilities(() -> super.getModelType(aClass)); - } - - @Override - public Class getModelTypeClass(Class aClass) { - return wrapWithLoggingCapabilities(() -> super.getModelTypeClass(aClass)); - } - - @Override - public String getModelType(Object o) { - return wrapWithLoggingCapabilities(() -> super.getModelType(o)); - } - - @Override - public T toModelLayer(Object o) { - return wrapWithLoggingCapabilities(() -> super.toModelLayer(o)); - } - - @Override - public T toPersistenceLayer(Object o) { - return wrapWithLoggingCapabilities(() -> super.toPersistenceLayer(o)); - } - - @Override - public void initDefaults(Object o) throws ModelInitializationException { - wrapWithLoggingCapabilities(() -> super.initDefaults(o)); - } - - @Override - public T getAttributeValue(Object o, String s) { - return wrapWithLoggingCapabilities(() -> super.getAttributeValue(o, s)); - } - - @Override - public T getAttributeValue(Object o, String s, Locale locale) { - return wrapWithLoggingCapabilities(() -> super.getAttributeValue(o, s, locale)); - } - - @Override - public Map getAttributeValues(Object o, String s, Locale... locales) { - return wrapWithLoggingCapabilities(() -> super.getAttributeValues(o, s, locales)); - } - - @Override - public void setAttributeValue(Object o, String s, Object o1) { - wrapWithLoggingCapabilities(() -> super.setAttributeValue(o, s, o1)); - } - - @Override - public void setAttributeValue(Object o, String s, Map map) { - wrapWithLoggingCapabilities(() -> super.setAttributeValue(o, s, map)); - } - - @Override - public boolean isUpToDate(Object o) { - return wrapWithLoggingCapabilities(() -> super.isUpToDate(o)); - } - - @Override - public boolean isModified(Object o) { - return wrapWithLoggingCapabilities(() -> super.isModified(o)); - } - - @Override - public boolean isNew(Object o) { - return wrapWithLoggingCapabilities(() -> super.isNew(o)); - } - - @Override - public boolean isRemoved(Object o) { - return wrapWithLoggingCapabilities(() -> super.isRemoved(o)); - } - - @Override - public boolean isAttached(Object o) { - return wrapWithLoggingCapabilities(() -> super.isAttached(o)); - } - - @Override - public boolean isSourceAttached(Object o) { - return wrapWithLoggingCapabilities(() -> super.isSourceAttached(o)); - } - - @Override - public void enableTransactions() { - wrapWithLoggingCapabilities(() -> super.enableTransactions()); - } - - @Override - public void disableTransactions() { - wrapWithLoggingCapabilities(() -> super.disableTransactions()); - } - - @Override - public void clearTransactionsSettings() { - wrapWithLoggingCapabilities(() -> super.clearTransactionsSettings()); - } - - @Override - @Deprecated(since = "6.1.0", forRemoval = true) - public T getByExample(T t) { - return wrapWithLoggingCapabilities(() -> super.getByExample(t)); - } - - @Override - public void lock(PK pk) { - wrapWithLoggingCapabilities(() -> super.lock(pk)); - } - - @Override - public void lock(Object o) { - wrapWithLoggingCapabilities(() -> super.lock(o)); - } - - @Override - public T getWithLock(Object o) { - return wrapWithLoggingCapabilities(() -> super.getWithLock(o)); - } + private static final Logger LOG = LoggerFactory.getLogger(FailureLoggingModelService.class); + private static final String EXCEPTION_MESSAGE = "Exception of type '%s' occurred during model service interaction: %s"; + private static final String SUPPRESSED_EXCEPTION_MESSAGE = "Suppressed exception (%d of %d): %s"; + + private void wrapWithLoggingCapabilities(final Runnable command) { + try { + command.run(); + } catch (IllegalArgumentException | SystemException | NullPointerException e) { + performLogging(e); + throw e; + } + } + + private T wrapWithLoggingCapabilities(final Supplier command) { + try { + return command.get(); + } catch (IllegalArgumentException | SystemException | NullPointerException e) { + performLogging(e); + throw e; + } + } + + private void performLogging(final T exception) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format(EXCEPTION_MESSAGE, exception.getClass().getSimpleName(), exception.getLocalizedMessage()), exception); + + final Throwable[] suppressed = exception.getSuppressed(); + if (suppressed != null) { + int total = suppressed.length; + for (int i = 0; i < total; i++) { + LOG.debug(String.format(SUPPRESSED_EXCEPTION_MESSAGE, i, total, suppressed[i].getLocalizedMessage()), suppressed[i]); + } + } + } + } + + @Override + public void attach(Object o) { + wrapWithLoggingCapabilities(() -> super.attach(o)); + } + + @Override + public void detach(Object o) { + wrapWithLoggingCapabilities(() -> super.detach(o)); + } + + @Override + public void detach(PK pk) { + wrapWithLoggingCapabilities(() -> super.detach(pk)); + } + + @Override + public void detachAll() { + wrapWithLoggingCapabilities(() -> super.detachAll()); + } + + @Override + public T clone(T t) { + return wrapWithLoggingCapabilities(() -> super.clone(t)); + } + + @Override + public T clone(Object o, Class aClass) { + return wrapWithLoggingCapabilities(() -> super.clone(o, aClass)); + } + + @Override + public T clone(T t, ModelCloningContext modelCloningContext) { + return wrapWithLoggingCapabilities(() -> super.clone(t, modelCloningContext)); + } + + @Override + public T clone(Object o, Class aClass, ModelCloningContext modelCloningContext) { + return wrapWithLoggingCapabilities(() -> super.clone(o, aClass, modelCloningContext)); + } + + @Override + public T create(Class aClass) { + return wrapWithLoggingCapabilities(() -> super.create(aClass)); + } + + @Override + public T create(String s) { + return wrapWithLoggingCapabilities(() -> super.create(s)); + } + + @Override + public T get(Object o) { + return wrapWithLoggingCapabilities(() -> super.get(o)); + } + + @Override + public T get(Object o, String s) { + return wrapWithLoggingCapabilities(() -> super.get(o, s)); + } + + @Override + public T get(PK pk) { + return wrapWithLoggingCapabilities(() -> super.get(pk)); + } + + @Override + public T getAll(Collection collection, T t) { + return wrapWithLoggingCapabilities(() -> super.getAll(collection, t)); + } + + @Override + public T getAll(Collection collection, T t, String s) { + return wrapWithLoggingCapabilities(() -> super.getAll(collection, t, s)); + } + + @Override + public void refresh(Object o) { + wrapWithLoggingCapabilities(() -> super.refresh(o)); + } + + @Override + public void save(Object o) throws ModelSavingException { + wrapWithLoggingCapabilities(() -> super.save(o)); + } + + @Override + public void saveAll(Collection collection) throws ModelSavingException { + wrapWithLoggingCapabilities(() -> super.saveAll(collection)); + } + + @Override + public void saveAll(Object... objects) throws ModelSavingException { + wrapWithLoggingCapabilities(() -> super.saveAll(objects)); + } + + @Override + public void saveAll() throws ModelSavingException { + wrapWithLoggingCapabilities(() -> super.saveAll()); + } + + @Override + public boolean isUniqueConstraintErrorAsRootCause(Exception e) { + return wrapWithLoggingCapabilities(() -> super.isUniqueConstraintErrorAsRootCause(e)); + } + + @Override + public void remove(Object o) throws ModelRemovalException { + wrapWithLoggingCapabilities(() -> super.remove(o)); + } + + @Override + public void removeAll(Collection collection) throws ModelRemovalException { + wrapWithLoggingCapabilities(() -> super.removeAll(collection)); + } + + @Override + public void removeAll(Object... objects) throws ModelRemovalException { + wrapWithLoggingCapabilities(() -> super.removeAll(objects)); + } + + @Override + public void remove(PK pk) throws ModelRemovalException { + wrapWithLoggingCapabilities(() -> super.remove(pk)); + } + + @Override + public T getSource(Object o) { + return wrapWithLoggingCapabilities(() -> super.getSource(o)); + } + + @Override + public T getAllSources(Collection collection, T t) { + return wrapWithLoggingCapabilities(() -> super.getAllSources(collection, t)); + } + + @Override + public String getModelType(Class aClass) { + return wrapWithLoggingCapabilities(() -> super.getModelType(aClass)); + } + + @Override + public Class getModelTypeClass(Class aClass) { + return wrapWithLoggingCapabilities(() -> super.getModelTypeClass(aClass)); + } + + @Override + public String getModelType(Object o) { + return wrapWithLoggingCapabilities(() -> super.getModelType(o)); + } + + @Override + public T toModelLayer(Object o) { + return wrapWithLoggingCapabilities(() -> super.toModelLayer(o)); + } + + @Override + public T toPersistenceLayer(Object o) { + return wrapWithLoggingCapabilities(() -> super.toPersistenceLayer(o)); + } + + @Override + public void initDefaults(Object o) throws ModelInitializationException { + wrapWithLoggingCapabilities(() -> super.initDefaults(o)); + } + + @Override + public T getAttributeValue(Object o, String s) { + return wrapWithLoggingCapabilities(() -> super.getAttributeValue(o, s)); + } + + @Override + public T getAttributeValue(Object o, String s, Locale locale) { + return wrapWithLoggingCapabilities(() -> super.getAttributeValue(o, s, locale)); + } + + @Override + public Map getAttributeValues(Object o, String s, Locale... locales) { + return wrapWithLoggingCapabilities(() -> super.getAttributeValues(o, s, locales)); + } + + @Override + public void setAttributeValue(Object o, String s, Object o1) { + wrapWithLoggingCapabilities(() -> super.setAttributeValue(o, s, o1)); + } + + @Override + public void setAttributeValue(Object o, String s, Map map) { + wrapWithLoggingCapabilities(() -> super.setAttributeValue(o, s, map)); + } + + @Override + public boolean isUpToDate(Object o) { + return wrapWithLoggingCapabilities(() -> super.isUpToDate(o)); + } + + @Override + public boolean isModified(Object o) { + return wrapWithLoggingCapabilities(() -> super.isModified(o)); + } + + @Override + public boolean isNew(Object o) { + return wrapWithLoggingCapabilities(() -> super.isNew(o)); + } + + @Override + public boolean isRemoved(Object o) { + return wrapWithLoggingCapabilities(() -> super.isRemoved(o)); + } + + @Override + public boolean isAttached(Object o) { + return wrapWithLoggingCapabilities(() -> super.isAttached(o)); + } + + @Override + public boolean isSourceAttached(Object o) { + return wrapWithLoggingCapabilities(() -> super.isSourceAttached(o)); + } + + @Override + public void enableTransactions() { + wrapWithLoggingCapabilities(() -> super.enableTransactions()); + } + + @Override + public void disableTransactions() { + wrapWithLoggingCapabilities(() -> super.disableTransactions()); + } + + @Override + public void clearTransactionsSettings() { + wrapWithLoggingCapabilities(() -> super.clearTransactionsSettings()); + } + + @Override + @Deprecated(since = "6.1.0", forRemoval = true) + public T getByExample(T t) { + return wrapWithLoggingCapabilities(() -> super.getByExample(t)); + } + + @Override + public void lock(PK pk) { + wrapWithLoggingCapabilities(() -> super.lock(pk)); + } + + @Override + public void lock(Object o) { + wrapWithLoggingCapabilities(() -> super.lock(o)); + } + + @Override + public T getWithLock(Object o) { + return wrapWithLoggingCapabilities(() -> super.getWithLock(o)); + } }