notify catalog on items action 73/46373/1
authorayalaben <Ayala.Benzvi@Amdocs.Com>
Mon, 7 May 2018 11:01:00 +0000 (14:01 +0300)
committerayalaben <ayala.benzvi@amdocs.com>
Mon, 7 May 2018 11:01:58 +0000 (14:01 +0300)
Change-Id: I11aa241c0c74c1a426dc1eee30ec7adb09abdca4
Issue-ID: SDC-1257
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/CatalogNotifier.java

index 48a4f9c..f19de3d 100644 (file)
@@ -60,6 +60,7 @@ public class CatalogNotifier {
     private static String notifyCatalogUrl;
 
     private static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
+    private static boolean executeNotificationFlag = true;
 
 
     static {
@@ -72,38 +73,42 @@ public class CatalogNotifier {
 
         try {
             configurationMap = readFromFile(configurationYamlFile, reader);
+            Object protocol = configurationMap.get(PROTOCOL_KEY);
+            Object host = configurationMap.get(HOST_KEY);
+            Object port = configurationMap.get(PORT_KEY);
 
-        } catch (IOException e) {
-            throw new RuntimeException("Could not read configuration file configuration.yaml");
-        }
-
-        Object protocol = configurationMap.get(PROTOCOL_KEY);
-        Object host = configurationMap.get(HOST_KEY);
-        Object port = configurationMap.get(PORT_KEY);
+            if (protocol == null || host == null || port == null) {
+                LOGGER.error("Could not read configuration file configuration.yaml");
+                executeNotificationFlag = false;
+            }
 
-        if (protocol == null || host == null || port == null) {
-            throw new RuntimeException("Could not read configuration file configuration.yaml");
-        }
+            if (configurationMap.get(URL_KEY) != null) {
+                String urlFormat = String.valueOf(configurationMap.get(URL_KEY));
+                notifyCatalogUrl =
+                        String.format(urlFormat, String.valueOf(protocol), String.valueOf(host), String.valueOf(port));
 
-        if (configurationMap.get(URL_KEY) != null) {
-            String urlFormat = String.valueOf(configurationMap.get(URL_KEY));
-            notifyCatalogUrl =
-                    String.format(urlFormat, String.valueOf(protocol), String.valueOf(host), String.valueOf(port));
+            } else {
+                notifyCatalogUrl = String.format(URL_DEFAULT_FORMAT, String.valueOf(protocol), String.valueOf(host),
+                        String.valueOf(port));
+            }
 
-        } else {
-            notifyCatalogUrl = String.format(URL_DEFAULT_FORMAT, String.valueOf(protocol), String.valueOf(host),
-                    String.valueOf(port));
+        } catch (Exception e) {
+           LOGGER.error("Could not read configuration file configuration.yaml");
+           executeNotificationFlag = false;
         }
     }
 
 
     public void execute(Collection<String> itemIds, ItemAction action, int numOfRetries) {
 
-        String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
+        if (executeNotificationFlag) {
 
-        Callable callable = createCallable(JsonUtil.object2Json(itemIds), action, numOfRetries, userId);
+            String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
 
-        executor.submit(callable);
+            Callable callable = createCallable(JsonUtil.object2Json(itemIds), action, numOfRetries, userId);
+
+            executor.submit(callable);
+        }
 
     }