* ============LICENSE_START=======================================================\r
* ONAP Policy API\r
* ================================================================================\r
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.\r
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
import java.util.Map;\r
import java.util.function.BiConsumer;\r
import javax.ws.rs.core.Response;\r
-\r
import org.apache.commons.lang3.tuple.Pair;\r
import org.onap.policy.api.main.parameters.ApiParameterGroup;\r
import org.onap.policy.common.parameters.ParameterService;\r
import org.onap.policy.models.provider.PolicyModelsProvider;\r
import org.onap.policy.models.provider.PolicyModelsProviderFactory;\r
import org.onap.policy.models.provider.PolicyModelsProviderParameters;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;\r
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
\r
/**\r
* Super class for providers that use a model provider.\r
modelsProvider.close();\r
}\r
\r
- /**\r
- * Checks if service template contains any policy.\r
- *\r
- * @param serviceTemplate the service template to check against\r
- *\r
- * @return boolean whether service template contains any policy\r
- */\r
- protected boolean hasPolicy(ToscaServiceTemplate serviceTemplate) {\r
-\r
- return hasData(serviceTemplate.getToscaTopologyTemplate().getPolicies());\r
- }\r
-\r
- /**\r
- * Checks if service template contains any policy type.\r
- *\r
- * @param serviceTemplate the service template to check against\r
- *\r
- * @return boolean whether service template contains any policy type\r
- */\r
- protected boolean hasPolicyType(ToscaServiceTemplate serviceTemplate) {\r
-\r
- return hasData(serviceTemplate.getPolicyTypes());\r
- }\r
-\r
- /**\r
- * Checks if the first element of a list contains data.\r
- *\r
- * @param list list to be examined\r
- * @return {@code true} if the list contains data, {@code false} otherwise\r
- */\r
- protected <T> boolean hasData(List<Map<String, T>> list) {\r
-\r
- return (list != null && !list.isEmpty() && !list.get(0).isEmpty());\r
- }\r
-\r
- /**\r
- * Validates that some text represents a number.\r
- *\r
- * @param text text to be validated\r
- * @param errorMsg error message included in the exception, if the text is not a valid\r
- * number\r
- * @throws PfModelException if the text is not a valid number\r
- */\r
- protected void validNumber(String text, String errorMsg) throws PfModelException {\r
- try {\r
- Integer.parseInt(text);\r
-\r
- } catch (NumberFormatException exc) {\r
- throw new PfModelException(Response.Status.BAD_REQUEST, errorMsg, exc);\r
- }\r
- }\r
-\r
- /**\r
- * Constructs returned message for policy delete rule violation.\r
- *\r
- * @param policyId the ID of policy\r
- * @param policyVersion the version of policy\r
- * @param pdpGroups the list of pdp groups\r
- *\r
- * @return the constructed message\r
- */\r
- protected String constructDeletePolicyViolationMessage(String policyId, String policyVersion,\r
- List<PdpGroup> pdpGroups) {\r
-\r
- List<String> pdpGroupNameVersionList = new ArrayList<>(pdpGroups.size());\r
- for (PdpGroup pdpGroup : pdpGroups) {\r
- pdpGroupNameVersionList.add(pdpGroup.getName() + ":" + pdpGroup.getVersion());\r
- }\r
- String deployedPdpGroups = String.join(",", pdpGroupNameVersionList);\r
- return "policy with ID " + policyId + ":" + policyVersion\r
- + " cannot be deleted as it is deployed in pdp groups " + deployedPdpGroups;\r
- }\r
-\r
- /**\r
- * Constructs returned message for policy type delete rule violation.\r
- *\r
- * @param policyTypeId the ID of policy type\r
- * @param policyTypeVersion the version of policy type\r
- * @param policies the list of policies that parameterizes specified policy type\r
- *\r
- * @return the constructed message\r
- */\r
- protected String constructDeletePolicyTypeViolationMessage(String policyTypeId, String policyTypeVersion,\r
- List<ToscaPolicy> policies) {\r
-\r
- List<String> policyNameVersionList = new ArrayList<>(policies.size());\r
- for (ToscaPolicy policy : policies) {\r
- policyNameVersionList.add(policy.getName() + ":" + policy.getVersion());\r
- }\r
- String parameterizedPolicies = String.join(",", policyNameVersionList);\r
- return "policy type with ID " + policyTypeId + ":" + policyTypeVersion\r
- + " cannot be deleted as it is parameterized by policies " + parameterizedPolicies;\r
- }\r
-\r
/**\r
* Collects all deployed versions of specified policy in all pdp groups.\r
*\r
}\r
\r
@FunctionalInterface\r
- protected interface BiFunctionWithEx<T,U,R> {\r
+ protected interface BiFunctionWithEx<T, U, R> {\r
public R apply(T value1, U value2) throws PfModelException;\r
}\r
\r
/**\r
- * Checks if the list of pdp groups is empty.\r
- * If so, throws exception saying specified policy deployment is not found in all existing pdp groups.\r
+ * Checks if the list of pdp groups is empty. If so, throws exception saying specified policy deployment is not\r
+ * found in all existing pdp groups.\r
*\r
* @param pdpGroups the list of pdp groups to check against\r
* @param policyType the concept key of policy type\r
*\r
* @throws PfModelException the PfModel parsing exception\r
*/\r
- private List<PdpGroup> getPolicyTypeFilteredPdpGroups(PfConceptKey policyType)\r
- throws PfModelException {\r
+ private List<PdpGroup> getPolicyTypeFilteredPdpGroups(PfConceptKey policyType) throws PfModelException {\r
\r
List<ToscaPolicyTypeIdentifier> policyTypes = new ArrayList<>();\r
policyTypes.add(new ToscaPolicyTypeIdentifier(policyType.getName(), policyType.getVersion()));\r
- PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder().policyTypeList(policyTypes)\r
- .groupState(PdpState.ACTIVE).pdpState(PdpState.ACTIVE).build();\r
+ PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder().policyTypeList(policyTypes).groupState(PdpState.ACTIVE)\r
+ .pdpState(PdpState.ACTIVE).build();\r
return modelsProvider.getFilteredPdpGroups(pdpGroupFilter);\r
}\r
\r
*/\r
private <T, R> Map<Pair<String, String>, T> constructDeployedPolicyMap(List<PdpGroup> pdpGroups, String policyId,\r
PfConceptKey policyType, BiFunctionWithEx<String, String, R> getter, BiConsumer<T, R> consumer, T data)\r
- throws PfModelException {\r
+ throws PfModelException {\r
\r
Map<Pair<String, String>, T> deployedPolicyMap = new HashMap<>();\r
for (PdpGroup pdpGroup : pdpGroups) {\r
* @return the trimmed version\r
*/\r
private String getTrimedVersionForLegacyType(String fullVersion, PfConceptKey policyType) {\r
- return (policyType.getName().contains("guard")\r
- || policyType.getName().contains("Operational")) ? fullVersion.split("\\.")[0] : fullVersion;\r
+ return (policyType.getName().contains("guard") || policyType.getName().contains("Operational"))\r
+ ? fullVersion.split("\\.")[0]\r
+ : fullVersion;\r
}\r
\r
/**\r
*/\r
private String constructDeploymentNotFoundMessage(PfConceptKey policyType, String policyId) {\r
\r
- return "could not find policy with ID " + policyId + " and type "\r
- + policyType.getName() + ":" + policyType.getVersion() + " deployed in any pdp group";\r
+ return "could not find policy with ID " + policyId + " and type " + policyType.getName() + ":"\r
+ + policyType.getVersion() + " deployed in any pdp group";\r
}\r
-}
\ No newline at end of file
+}\r