Handle logs in  ExternalArtifactEnricher

removed try catch from both classes ToscaEnricher and
ExternalArtifactEnricher methods and Handled exception in EnrichmentManagerImpl

Change-Id: I7562185272e2a62d71a1c66208b711c3e30fcb3d
Issue-ID: SDC-836
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-core/src/main/java/org/openecomp/sdc/enrichment/impl/EnrichmentManagerImpl.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-core/src/main/java/org/openecomp/sdc/enrichment/impl/EnrichmentManagerImpl.java
index 6610ec5..40bd396 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-core/src/main/java/org/openecomp/sdc/enrichment/impl/EnrichmentManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-core/src/main/java/org/openecomp/sdc/enrichment/impl/EnrichmentManagerImpl.java
@@ -22,6 +22,7 @@
 
 import org.openecomp.core.enrichment.api.EnrichmentManager;
 import org.openecomp.core.enrichment.types.EntityInfo;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
 import org.openecomp.sdc.enrichment.EnrichmentInfo;
 import org.openecomp.sdc.enrichment.factory.EnricherHandlerFactory;
@@ -31,6 +32,7 @@
 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
 import org.openecomp.sdc.versioning.dao.types.Version;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -48,12 +50,17 @@
     Map<String, List<ErrorMessage>> enrichErrors = new HashMap<>();
     List<Enricher> enricherList =
         EnricherHandlerFactory.getInstance().createInterface().getEnrichers();
-    for (Enricher enricher : enricherList) {
-      enricher.setData(data);
-      enricher.setModel(model);
-      enrichErrors.putAll(enricher.enrich());
+      for (Enricher enricher : enricherList) {
+        enricher.setData(data);
+        enricher.setModel(model);
+        try {
+          enrichErrors.putAll(enricher.enrich());
+        } catch (Exception exception) {
+          enrichErrors.put("Enrich", Arrays.asList(new ErrorMessage(ErrorLevel.ERROR, exception
+                  .getMessage())));
+          logger.error("Exception occurred during enrichment", exception);
+        }
     }
-
     return enrichErrors;
   }
 
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java
index 150e962..49ba614 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java
@@ -25,8 +25,6 @@
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
 import org.openecomp.sdc.enrichment.inter.Enricher;
 import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
 
 import java.lang.reflect.Constructor;
@@ -40,7 +38,6 @@
       + ".json";
   private static Collection<String> implementingClasses =
       getExternalArtifactEnrichedImplClassesList();
-  private static Logger logger = LoggerFactory.getLogger(ExternalArtifactEnricher.class);
 
   private static Collection<String> getExternalArtifactEnrichedImplClassesList() {
     @SuppressWarnings("unchecked")
@@ -51,18 +48,13 @@
   }
 
   @Override
-  public Map<String, List<ErrorMessage>> enrich() {
+  public Map<String, List<ErrorMessage>> enrich() throws Exception{
     Map<String, List<ErrorMessage>> errors = new HashMap<>();
 
-        try {
             for (String implementingClassName : implementingClasses) {
                 ExternalArtifactEnricherInterface externalArtifactEnricherInstance = getExternalArtifactEnricherInstance(implementingClassName);
-                externalArtifactEnricherInstance.enrich(this.data, (ToscaServiceModel) this.model);
+                errors.putAll(externalArtifactEnricherInstance.enrich(this.data, (ToscaServiceModel) this.model));
             }
-        } catch (Exception e) {
-          logger.debug("",e);
-          logger.error(e.getMessage());
-        }
     return errors;
   }
 
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/Enricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/Enricher.java
index ed606f8..8e66887 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/Enricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/Enricher.java
@@ -42,5 +42,5 @@
         this.model = model;
     }
 
-    public abstract Map<String, List<ErrorMessage>> enrich();
+    public abstract Map<String, List<ErrorMessage>> enrich() throws Exception;
 }