Java 17 Upgrade
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / SoOperation.java
index 9020c0b..d840457 100644 (file)
@@ -2,8 +2,9 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020 Wipro Limited.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,14 +24,14 @@ package org.onap.policy.controlloop.actor.so;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 import org.onap.aai.domain.yang.CloudRegion;
 import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.aai.domain.yang.ModelVer;
@@ -89,7 +90,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
      * @param config configuration for this operation
      * @param propertyNames names of properties required by this operation
      */
-    public SoOperation(ControlLoopOperationParams params, HttpPollingConfig config, List<String> propertyNames) {
+    protected SoOperation(ControlLoopOperationParams params, HttpPollingConfig config, List<String> propertyNames) {
         super(params, config, SoResponse.class, propertyNames);
 
         this.modelCustomizationId = null;
@@ -109,7 +110,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
      * @param propertyNames names of properties required by this operation
      * @param targetEntityIds Target Entity information
      */
-    public SoOperation(ControlLoopOperationParams params, HttpPollingConfig config, List<String> propertyNames,
+    protected SoOperation(ControlLoopOperationParams params, HttpPollingConfig config, List<String> propertyNames,
                        Map<String, String> targetEntityIds) {
         super(params, config, SoResponse.class, propertyNames);
 
@@ -251,7 +252,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
     }
 
     protected SoModelInfo prepareSoModelInfo() {
-        SoModelInfo soModelInfo = new SoModelInfo();
+        var soModelInfo = new SoModelInfo();
         soModelInfo.setModelCustomizationId(modelCustomizationId);
         soModelInfo.setModelInvariantId(modelInvariantId);
         soModelInfo.setModelName(modelName);
@@ -267,7 +268,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
      * @return SO request information
      */
     protected SoRequestInfo constructRequestInfo() {
-        SoRequestInfo soRequestInfo = new SoRequestInfo();
+        var soRequestInfo = new SoRequestInfo();
         soRequestInfo.setSource("POLICY");
         soRequestInfo.setSuppressRollback(false);
         soRequestInfo.setRequestorId("policy");
@@ -323,12 +324,27 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
      * @return SO cloud configuration
      */
     protected SoCloudConfiguration constructCloudConfiguration(Tenant tenantItem, CloudRegion cloudRegionItem) {
-        SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration();
-        cloudConfiguration.setTenantId(tenantItem.getTenantId());
-        cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId());
+        var cloudConfiguration = new SoCloudConfiguration();
+        cloudConfiguration.setTenantId(getRequiredText("tenant ID", tenantItem.getTenantId()));
+        cloudConfiguration.setLcpCloudRegionId(getRequiredText("cloud region ID", cloudRegionItem.getCloudRegionId()));
         return cloudConfiguration;
     }
 
+    /**
+     * Verifies that a value is not {@code null}.
+     *
+     * @param name value name
+     * @param value value to check
+     * @return the value
+     */
+    protected String getRequiredText(String name, String value) {
+        if (value == null) {
+            throw new IllegalArgumentException("missing " + name);
+        }
+
+        return value;
+    }
+
     /**
      * Create simple HTTP headers for unauthenticated requests to SO.
      *
@@ -345,7 +361,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
      * IllegalArgumentException if the desired data item is not found.
      */
 
-    protected GenericVnf getVnfItem(SoModelInfo soModelInfo) {
+    protected GenericVnf getVnfItem() {
         return getRequiredProperty(OperationProperties.AAI_VNF, "generic VNF");
     }