From 42c07321599ab57341a70e97208236967a350341 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 14 Nov 2022 15:23:44 +0100 Subject: [PATCH] fixed error logging --- .../servicelayer/dao/AdditionalAttributesDAO.java | 10 ++++++++-- .../dao/impl/AdditionalAttributesDAOImpl.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/AdditionalAttributesDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/AdditionalAttributesDAO.java index ed41f2e5..10c27cc4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/AdditionalAttributesDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/AdditionalAttributesDAO.java @@ -12,6 +12,9 @@ import java.util.Collection; import java.util.Map; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.util.Result; @@ -23,6 +26,8 @@ import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.AdditionalAttribut * in a separated data-base table. */ public interface AdditionalAttributesDAO { + Logger log = LoggerFactory.getLogger(AdditionalAttributesDAO.class); + /** Use this to get all additional attribute records for a specific entity. * * @param type the entity type @@ -85,8 +90,9 @@ public interface AdditionalAttributesDAO { return Result.tryCatch(() -> attributes.entrySet() .stream() - .map(attr -> saveAdditionalAttribute(type, entityId, attr.getKey(), attr.getValue())) - .flatMap(Result::onErrorLogAndSkip) + .map(attr -> saveAdditionalAttribute(type, entityId, attr.getKey(), attr.getValue()) + .onError(error -> log.warn("Failed to save additional attribute: ", error.getMessage()))) + .flatMap(Result::skipOnError) .collect(Collectors.toList())); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/AdditionalAttributesDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/AdditionalAttributesDAOImpl.java index d3643909..a26a55a8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/AdditionalAttributesDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/AdditionalAttributesDAOImpl.java @@ -95,7 +95,7 @@ public class AdditionalAttributesDAOImpl implements AdditionalAttributesDAO { if (value == null) { throw new IllegalArgumentException( - "value cannot be null. Use delete to delete an additional attribute"); + "value cannot be null. Use delete to delete an additional attribute: " + String.valueOf(name)); } if (log.isDebugEnabled()) {