From e0d0fdb5484d2c02669358160a11d6751ada4f3a Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 25 Feb 2020 09:05:02 -0800 Subject: Fix Bug due to user management changes Fix the bugs, build is broken due to changes done previously Issue-ID: CLAMP-651 Change-Id: I57523bc2c3bfbf5ca5a3acf5c59823df06fd4cd9 Signed-off-by: sebdet --- .../onap/clamp/clds/ClampInUserAuditorAware.java | 10 +-- .../clamp/clds/client/PolicyEngineServices.java | 36 ++------- .../clamp/loop/template/PolicyModelsService.java | 15 ++++ .../policy/downloader/PolicyEngineController.java | 5 -- src/main/resources/META-INF/resources/swagger.html | 90 +++++++++++----------- .../resources/clds/camel/routes/loop-flows.xml | 2 +- .../onap/clamp/loop/LoopRepositoriesItCase.java | 4 +- .../onap/clamp/loop/PolicyModelServiceItCase.java | 9 ++- 8 files changed, 78 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java b/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java index d18e7ebf3..9351db23c 100644 --- a/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java +++ b/src/main/java/org/onap/clamp/clds/ClampInUserAuditorAware.java @@ -24,10 +24,9 @@ package org.onap.clamp.clds; import java.util.Optional; - +import org.onap.clamp.authorization.AuthorizationController; import org.springframework.data.domain.AuditorAware; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; @Component @@ -35,12 +34,7 @@ public class ClampInUserAuditorAware implements AuditorAware { @Override public Optional getCurrentAuditor() { - if (SecurityContextHolder.getContext().getAuthentication() != null - && SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) { - return Optional.of(((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()) - .getUsername()); - } - return Optional.of(""); + return Optional.of(AuthorizationController.getPrincipalName(SecurityContextHolder.getContext())); } } diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java index 2302cc891..02e2dd0b6 100644 --- a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java +++ b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java @@ -25,24 +25,19 @@ package org.onap.clamp.clds.client; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; - import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.builder.ExchangeBuilder; import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService; import org.onap.clamp.loop.template.PolicyModel; -import org.onap.clamp.loop.template.PolicyModelId; -import org.onap.clamp.loop.template.PolicyModelsRepository; +import org.onap.clamp.loop.template.PolicyModelsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; import org.yaml.snakeyaml.Yaml; @@ -58,7 +53,7 @@ import org.yaml.snakeyaml.Yaml; public class PolicyEngineServices { private final CamelContext camelContext; - private final PolicyModelsRepository policyModelsRepository; + private final PolicyModelsService policyModelsSService; private static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.class); private static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); @@ -74,18 +69,18 @@ public class PolicyEngineServices { * * @param camelContext Camel context bean * @param clampProperties ClampProperties bean - * @param policyModelsRepository policyModel repository bean + * @param policyModelsSService policyModel repository bean */ @Autowired public PolicyEngineServices(CamelContext camelContext, ClampProperties clampProperties, - PolicyModelsRepository policyModelsRepository) { + PolicyModelsService policyModelsSService) { this.camelContext = camelContext; - this.policyModelsRepository = policyModelsRepository; + this.policyModelsSService = policyModelsSService; if (clampProperties.getStringValue(POLICY_RETRY_LIMIT) != null) { - retryLimit = Integer.valueOf(clampProperties.getStringValue(POLICY_RETRY_LIMIT)); + retryLimit = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_LIMIT)); } if (clampProperties.getStringValue(POLICY_RETRY_INTERVAL) != null) { - retryInterval = Integer.valueOf(clampProperties.getStringValue(POLICY_RETRY_INTERVAL)); + retryInterval = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_INTERVAL)); } } @@ -110,19 +105,6 @@ public class PolicyEngineServices { return createPolicyModelFromPolicyEngine(microService.getModelType(), microService.getModelVersion()); } - /** - * Thie method creates an PolicyModel in Db if it does not exist. - * - * @param policyModel The policyModel to save - */ - @Transactional(propagation = Propagation.REQUIRES_NEW) - public void createPolicyInDbIfNeeded(PolicyModel policyModel) { - if (!policyModelsRepository - .existsById(new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) { - policyModelsRepository.save(policyModel); - } - } - /** * This method synchronize the clamp database and the policy engine. * So it creates the required PolicyModel. @@ -140,7 +122,7 @@ public class PolicyEngineServices { policyTypesList.parallelStream().forEach(policyType -> { Map.Entry policyTypeEntry = (Map.Entry) new ArrayList(policyType.entrySet()).get(0); - createPolicyInDbIfNeeded( + policyModelsSService.createPolicyInDbIfNeeded( createPolicyModelFromPolicyEngine(policyTypeEntry.getKey(), ((String) ((LinkedHashMap) policyTypeEntry.getValue()).get("version")))); }); @@ -151,7 +133,6 @@ public class PolicyEngineServices { * policy engine. * * @return A yaml containing all policy Types and all data types - * @throws InterruptedException In case of issue when sleeping during the retry */ public String downloadAllPolicies() { return callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-policy-models"); @@ -163,7 +144,6 @@ public class PolicyEngineServices { * @param policyType The policy type (id) * @param policyVersion The policy version * @return A string with the whole policy tosca model - * @throws InterruptedException In case of issue when sleeping during the retry */ public String downloadOnePolicy(String policyType, String policyVersion) { return callCamelRoute(ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType) diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java index ad9ce7078..eb83c6608 100644 --- a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java +++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java @@ -32,6 +32,8 @@ import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor; import org.onap.clamp.util.SemanticVersioning; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; @Service public class PolicyModelsService { @@ -122,4 +124,17 @@ public class PolicyModelsService { return policyModelsRepository.findById(new PolicyModelId(type, version)).orElse(new PolicyModel()) .getPolicyModelTosca(); } + + /** + * This method creates an PolicyModel in Db if it does not exist. + * + * @param policyModel The policyModel to save + */ + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void createPolicyInDbIfNeeded(PolicyModel policyModel) { + if (!policyModelsRepository + .existsById(new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) { + policyModelsRepository.save(policyModel); + } + } } diff --git a/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java b/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java index 50be035b2..bd20eccb6 100644 --- a/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java +++ b/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java @@ -27,10 +27,6 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.time.Instant; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map.Entry; import org.onap.clamp.clds.client.PolicyEngineServices; import org.onap.clamp.loop.template.PolicyModelsRepository; @@ -38,7 +34,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; -import org.yaml.snakeyaml.Yaml; /** * This class implements a periodic job that is done in the background to diff --git a/src/main/resources/META-INF/resources/swagger.html b/src/main/resources/META-INF/resources/swagger.html index 74322f36b..16938529b 100644 --- a/src/main/resources/META-INF/resources/swagger.html +++ b/src/main/resources/META-INF/resources/swagger.html @@ -444,25 +444,25 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 2. Paths