Support 7.2.1 VES in TCAGEN2
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-tca-web / src / main / java / org / onap / dcae / analytics / tca / web / domain / TcaPolicyWrapper.java
index fcfc3fe..1873c3c 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * ================================================================================
+ * ===========LICENSE_START=====================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2022 Wipro Limited Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,9 +24,11 @@ import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion
 
 import java.time.ZonedDateTime;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.List;
 
 import org.onap.dcae.analytics.model.common.ConfigSource;
 import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException;
+import org.onap.dcae.analytics.tca.core.exception.TcaProcessingException;
 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
 import org.onap.dcae.analytics.tca.model.policy.TcaPolicyModel;
 import org.onap.dcae.analytics.tca.web.TcaAppProperties;
@@ -57,7 +60,7 @@ public class TcaPolicyWrapper implements TcaPolicyModel {
         this.policyVersion = getPolicyVersion(new AtomicInteger(0));
     }
 
-    public TcaPolicy getTcaPolicy() {
+    public List<TcaPolicy> getTcaPolicy() {
         String tcaPolicyString = tcaAppProperties.getTca().getPolicy();
         boolean isConfigBindingServiceProfileActive = tcaAppProperties.isConfigBindingServiceProfileActive();
         if (isConfigBindingServiceProfileActive) {
@@ -75,15 +78,22 @@ public class TcaPolicyWrapper implements TcaPolicyModel {
                     tcaPolicy, configSource.name(), policyVersion);
         }
 
-        return convertTcaPolicy(tcaPolicyString);
+        List<TcaPolicy> tcaPolicyList = convertTcaPolicy(tcaPolicyString);
+        if( tcaPolicyList.size() > 2)
+        {
+           throw new TcaProcessingException(" TCA Policy size exceeding limit of 2");
+        }
+        else
+           return tcaPolicyList;
+
     }
 
-    public void setTcaPolicy(TcaPolicy tcaPolicy, ConfigSource configSource) {
+    public void setTcaPolicy(List<TcaPolicy> tcaPolicy, ConfigSource configSource) {
         this.tcaPolicy = tcaPolicy.toString();
         this.configSource = configSource;
     }
 
-    public TcaPolicy convertTcaPolicy(String tcaPolicyString) {
+    public List<TcaPolicy> convertTcaPolicy(String tcaPolicyString) {
         return TCA_POLICY_JSON_FUNCTION.apply(tcaPolicyString).orElseThrow(
                 () -> new AnalyticsParsingException("Unable to parse Tca Policy String: " + tcaPolicyString,
                         new IllegalArgumentException()));