Move PAP database provider to spring boot default
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PolicyUndeployerImpl.java
index f281208..004d4ad 100644 (file)
@@ -2,7 +2,9 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Bell Canada. 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.
@@ -28,29 +30,23 @@ import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
 import org.onap.policy.pap.main.comm.PolicyUndeployer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
 
 /**
  * Implementation of policy undeployer.
  */
+@Component
 public class PolicyUndeployerImpl extends ProviderBase implements PolicyUndeployer {
     private static final Logger logger = LoggerFactory.getLogger(PolicyUndeployerImpl.class);
 
-
-    /**
-     * Constructs the object.
-     */
-    public PolicyUndeployerImpl() {
-        super();
-    }
-
     @Override
-    public void undeploy(String group, String subgroup, Collection<ToscaPolicyIdentifier> policies)
+    public void undeploy(String group, String subgroup, Collection<ToscaConceptIdentifier> policies)
                     throws PfModelException {
 
         process(new Info(group, subgroup, policies), this::undeployPolicies);
@@ -80,19 +76,19 @@ public class PolicyUndeployerImpl extends ProviderBase implements PolicyUndeploy
         PdpSubGroup subgroup = optsub.get();
 
         // remove the policies
-        boolean updated = false;
+        var updated = false;
         Set<String> pdps = subgroup.getPdpInstances().stream().map(Pdp::getInstanceId).collect(Collectors.toSet());
 
-        for (ToscaPolicyIdentifier ident : policyInfo.policies) {
+        for (ToscaConceptIdentifier ident : policyInfo.policies) {
             if (!subgroup.getPolicies().remove(ident)) {
                 continue;
             }
 
-            logger.info("remove policy {} {} from subgroup {} {} count={}", ident.getName(), ident.getVersion(),
-                            group.getName(), subgroup.getPdpType(), subgroup.getPolicies().size());
+            logger.info("remove policy {} from subgroup {} {} count={}", ident, group.getName(),
+                    subgroup.getPdpType(), subgroup.getPolicies().size());
 
             updated = true;
-            data.trackUndeploy(ident, pdps);
+            data.trackUndeploy(ident, pdps, policyInfo.group, policyInfo.subgroup);
         }
 
         // push the updates
@@ -103,16 +99,17 @@ public class PolicyUndeployerImpl extends ProviderBase implements PolicyUndeploy
     }
 
     @Override
-    protected Updater makeUpdater(SessionData data, ToscaPolicy policy, ToscaPolicyIdentifierOptVersion desiredPolicy) {
+    protected Updater makeUpdater(SessionData data, ToscaPolicy policy,
+            ToscaConceptIdentifierOptVersion desiredPolicy) {
         throw new UnsupportedOperationException("makeUpdater should not be invoked");
     }
 
     private static class Info {
         private String group;
         private String subgroup;
-        private Collection<ToscaPolicyIdentifier> policies;
+        private Collection<ToscaConceptIdentifier> policies;
 
-        public Info(String group, String subgroup, Collection<ToscaPolicyIdentifier> policies) {
+        public Info(String group, String subgroup, Collection<ToscaConceptIdentifier> policies) {
             this.group = group;
             this.subgroup = subgroup;
             this.policies = policies;