Fix UriBuilder import in OofUtils
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / OofHoming.groovy
index 623d5a6..6583ded 100644 (file)
@@ -32,17 +32,18 @@ import org.onap.so.bpmn.core.domain.ServiceDecomposition
 import org.onap.so.bpmn.core.domain.Subscriber
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.DefaultProperties
 import org.onap.so.client.HttpClient
 import org.onap.so.client.HttpClientFactory
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.db.catalog.beans.AuthenticationType
 import org.onap.so.db.catalog.beans.CloudIdentity
 import org.onap.so.db.catalog.beans.CloudSite
 import org.onap.so.db.catalog.beans.HomingInstance
 import org.onap.so.db.catalog.beans.ServerType
-import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.utils.TargetEntity
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
 
 import org.json.JSONArray
 import org.json.JSONObject
@@ -108,12 +109,12 @@ class OofHoming extends AbstractServiceTaskProcessor {
                 if (isBlank(subscriberInfo)) {
                     subscriber = new Subscriber("", "", "")
                 } else {
-                String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId")
-                String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName")
-                String subCommonSiteId = ""
-                if (jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")) {
-                    subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId")
-                }
+                    String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId")
+                    String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName")
+                    String subCommonSiteId = ""
+                    if (jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")) {
+                        subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId")
+                    }
                     subscriber = new Subscriber(subId, subName, subCommonSiteId)
                 }
 
@@ -163,21 +164,24 @@ class OofHoming extends AbstractServiceTaskProcessor {
                 logger.debug( "Posting to OOF Url: " + urlString)
 
 
-                               URL url = new URL(urlString);
-                HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.SNIRO)
+                URL url = new URL(urlString)
+                HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.OOF)
                 httpClient.addAdditionalHeader("Authorization", authHeader)
-                               Response httpResponse = httpClient.post(oofRequest)
+                Response httpResponse = httpClient.post(oofRequest)
 
-                               int responseCode = httpResponse.getStatus()
-                               logger.debug("OOF sync response code is: " + responseCode)
+                int responseCode = httpResponse.getStatus()
+                logger.debug("OOF sync response code is: " + responseCode)
 
+                if(responseCode != 202){
+                    exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
+                }
 
                 logger.debug( "*** Completed Homing Call OOF ***")
             }
         } catch (BpmnError b) {
             throw b
         } catch (Exception e) {
-                       logger.error(e);
+            logger.error(e);
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
                     "Internal Error - Occured in Homing callOof: " + e.getMessage())
         }
@@ -360,7 +364,7 @@ class OofHoming extends AbstractServiceTaskProcessor {
             throw b
         } catch (Exception e) {
             logger.debug( "ProcessHomingSolution Exception: " + e)
-                       logger.error(e);
+            logger.error(e);
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in Homing ProcessHomingSolution")
         }
     }