diff options
author | xg353y <xg353y@intl.att.com> | 2019-03-18 16:03:10 +0100 |
---|---|---|
committer | xg353y <xg353y@intl.att.com> | 2019-03-18 16:26:09 +0100 |
commit | 08a2202eb2d9c99927c8758df1575b01e266cf58 (patch) | |
tree | 34eba6db1fb96ca56baaaef83b6d5fb29d7b06e2 /src/main/java/org/onap | |
parent | 157e2de9766fdf9adc939dca43df4ccf0b16188d (diff) |
Fix check style issues
Fix the issues raised by the check style
Issue-ID: CLAMP-328
Change-Id: I07f80274968e032d060a7d881f4851568616a832
Signed-off-by: xg353y <xg353y@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
25 files changed, 237 insertions, 85 deletions
diff --git a/src/main/java/org/onap/clamp/authorization/AuthorizationController.java b/src/main/java/org/onap/clamp/authorization/AuthorizationController.java index 206102758..568af4800 100644 --- a/src/main/java/org/onap/clamp/authorization/AuthorizationController.java +++ b/src/main/java/org/onap/clamp/authorization/AuthorizationController.java @@ -58,30 +58,34 @@ public class AuthorizationController { private ClampProperties refProp; private SecurityContext securityContext = SecurityContextHolder.getContext(); - private final static String permPrefix = "security.permission.type."; - private final static String permInstance = "security.permission.instance"; + private static final String permPrefix = "security.permission.type."; + private static final String permInstance = "security.permission.instance"; public AuthorizationController() { } + /** - * Insert event using process variables. + * Insert authorize the api based on the permission * * @param camelExchange * The Camel Exchange object containing the properties - * @param actionState - * The action state that is used instead of the one in exchange property + * @param typeVar + * The type of the permissions + * @param instanceVar + * The instance of the permissions. e.g. dev + * @param action + * The action of the permissions. e.g. read */ - public void authorize (Exchange camelExchange, String typeVar, String instanceVar, String action) { String type = refProp.getStringValue(permPrefix + typeVar); String instance = refProp.getStringValue(permInstance); - + if (null == type || type.isEmpty()) { //authorization is turned off, since the permission is not defined return; } if (null != instanceVar && !instanceVar.isEmpty()) { - instance = instanceVar; + instance = instanceVar; } String principalName = PrincipalUtils.getPrincipalName(); SecureServicePermission perm = SecureServicePermission.create(type, instance, action); @@ -105,18 +109,22 @@ public class AuthorizationController { // check if the user has the permission key or the permission key with a // combination of all instance and/or all action. if (hasRole(inPermission.getKey())) { - auditLogger.info("{} authorized because user has permission with * for instance: {}", principalName, inPermission.getKey()); + auditLogger.info("{} authorized because user has permission with * for instance: {}", + principalName, inPermission.getKey()); authorized = true; // the rest of these don't seem to be required - isUserInRole method // appears to take * as a wildcard } else if (hasRole(inPermission.getKeyAllInstance())) { - auditLogger.info("{} authorized because user has permission with * for instance: {}", principalName, inPermission.getKey()); + auditLogger.info("{} authorized because user has permission with * for instance: {}", + principalName, inPermission.getKey()); authorized = true; } else if (hasRole(inPermission.getKeyAllInstanceAction())) { - auditLogger.info("{} authorized because user has permission with * for instance and * for action: {}", principalName, inPermission.getKey()); + auditLogger.info("{} authorized because user has permission with * for instance and * for action: {}", + principalName, inPermission.getKey()); authorized = true; } else if (hasRole(inPermission.getKeyAllAction())) { - auditLogger.info("{} authorized because user has permission with * for action: {}", principalName, inPermission.getKey()); + auditLogger.info("{} authorized because user has permission with * for action: {}", + principalName, inPermission.getKey()); authorized = true; } else { throw new NotAuthorizedException(""); @@ -124,9 +132,15 @@ public class AuthorizationController { return authorized; } + /** + * Verify whether the user has the permission + * + * @param inPermission + * The permissions to verify + */ public boolean isUserPermittedNoException(SecureServicePermission inPermission) { try { - return isUserPermitted (inPermission); + return isUserPermitted(inPermission); } catch (NotAuthorizedException e) { return false; } @@ -138,8 +152,9 @@ public class AuthorizationController { return false; } for (GrantedAuthority auth : authentication.getAuthorities()) { - if (role.equals(auth.getAuthority())) + if (role.equals(auth.getAuthority())) { return true; + } } return false; } diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java index 7e78504ff..025dbabda 100644 --- a/src/main/java/org/onap/clamp/clds/Application.java +++ b/src/main/java/org/onap/clamp/clds/Application.java @@ -101,7 +101,7 @@ public class Application extends SpringBootServletInitializer { * This method is used to declare the camel servlet. * * @return A servlet bean - * @throws IOException + * @throws IOException IO Exception */ @Bean public ServletRegistrationBean camelServletRegistrationBean() throws IOException { diff --git a/src/main/java/org/onap/clamp/clds/ClampServlet.java b/src/main/java/org/onap/clamp/clds/ClampServlet.java index 008a9c743..e8fd83e2e 100644 --- a/src/main/java/org/onap/clamp/clds/ClampServlet.java +++ b/src/main/java/org/onap/clamp/clds/ClampServlet.java @@ -50,7 +50,7 @@ import org.springframework.web.context.support.WebApplicationContextUtils; public class ClampServlet extends CamelHttpTransportServlet { /** - * + * The serial version ID. */ private static final long serialVersionUID = -4198841134910211542L; @@ -109,8 +109,8 @@ public class ClampServlet extends CamelHttpTransportServlet { @Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - Principal p = request.getUserPrincipal(); - if (loadDynamicAuthenticationClass().isInstance(p)) { + Principal principal = request.getUserPrincipal(); + if (loadDynamicAuthenticationClass().isInstance(principal)) { // When AAF is enabled, there is a need to provision the permissions to Spring // system List<GrantedAuthority> grantedAuths = new ArrayList<>(); @@ -120,7 +120,7 @@ public class ClampServlet extends CamelHttpTransportServlet { grantedAuths.add(new SimpleGrantedAuthority(permString)); } } - Authentication auth = new UsernamePasswordAuthenticationToken(new User(p.getName(), "", grantedAuths), "", + Authentication auth = new UsernamePasswordAuthenticationToken(new User(principal.getName(), "", grantedAuths), "", grantedAuths); SecurityContextHolder.getContext().setAuthentication(auth); } diff --git a/src/main/java/org/onap/clamp/clds/TomcatEmbeddedServletContainerFactoryRedirection.java b/src/main/java/org/onap/clamp/clds/TomcatEmbeddedServletContainerFactoryRedirection.java index 1d9150ee8..a0109a688 100644 --- a/src/main/java/org/onap/clamp/clds/TomcatEmbeddedServletContainerFactoryRedirection.java +++ b/src/main/java/org/onap/clamp/clds/TomcatEmbeddedServletContainerFactoryRedirection.java @@ -32,10 +32,8 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor * This class is a factory that redirects by default all HTTP to HTTPS * connector. It is used by the Application.java class and defined in a Spring * Bean. - * * In order to do this, the method postProcessContext has been overridden to * provide another behavior. - * */ public class TomcatEmbeddedServletContainerFactoryRedirection extends TomcatServletWebServerFactory { diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java index 68454525d..63caf5a93 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java @@ -63,6 +63,13 @@ public class DcaeDispatcherServices { this.dcaeHttpConnectionManager = dcaeHttpConnectionManager;
}
+ /**
+ * Get the Operation Status from a specified URL with retry.
+ * @param operationStatusUrl
+ * The URL of the DCAE
+ * @return The status
+ * @throws InterruptedException Exception during the retry
+ */
public String getOperationStatusWithRetry(String operationStatusUrl) throws InterruptedException {
String operationStatus = "";
for (int i = 0; i < Integer.valueOf(refProp.getStringValue("dcae.dispatcher.retry.limit")); i++) {
@@ -81,7 +88,6 @@ public class DcaeDispatcherServices { /**
* Get the Operation Status from a specified URL.
- *
* @param statusUrl
* The URL provided by a previous DCAE Query
* @return The status
@@ -112,7 +118,6 @@ public class DcaeDispatcherServices { /**
* Returns status URL for createNewDeployment operation.
- *
* @param deploymentId
* The deployment ID
* @param serviceTypeId
@@ -150,7 +155,6 @@ public class DcaeDispatcherServices { /***
* Returns status URL for deleteExistingDeployment operation.
- *
* @param deploymentId
* The deployment ID
* @param serviceTypeId
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java b/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java index 8781fc344..30afddcd0 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java @@ -42,9 +42,7 @@ import org.onap.clamp.clds.util.LoggingUtils; import org.springframework.stereotype.Component; /** - * * This class manages the HTTP and HTTPS connections to DCAE. - * */ @Component public class DcaeHttpConnectionManager { diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java index e5ef3c67b..ffd19d82e 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -64,6 +64,9 @@ public class DcaeInventoryServices { private final CldsDao cldsDao;
private final DcaeHttpConnectionManager dcaeHttpConnectionManager;
+ /**
+ * Constructor.
+ */
@Autowired
public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao,
DcaeHttpConnectionManager dcaeHttpConnectionManager) {
@@ -179,7 +182,6 @@ public class DcaeInventoryServices { */
public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
throws IOException, ParseException, InterruptedException {
- Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");
String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="
+ artifactName;
@@ -187,6 +189,7 @@ public class DcaeInventoryServices { logger.info("Dcae Inventory Service full url - " + fullUrl);
DcaeInventoryResponse response = queryDcaeInventory(fullUrl);
LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());
+ Date startTime = new Date();
LoggingUtils.setTimeContext(startTime, new Date());
return response;
}
diff --git a/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java index fb91d9c57..a758716b8 100644 --- a/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java @@ -76,7 +76,8 @@ public class GuardPolicyDelegate { Policy policy = prop.getType(Policy.class); if (policy.isFound()) { for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { - for(PolicyItem policyItem:GuardPolicyAttributesConstructor.getAllPolicyGuardsFromPolicyChain(policyChain)) { + for (PolicyItem policyItem:GuardPolicyAttributesConstructor + .getAllPolicyGuardsFromPolicyChain(policyChain)) { prop.setCurrentModelElementId(policy.getId()); prop.setPolicyUniqueId(policyChain.getPolicyId()); prop.setGuardUniqueId(policyItem.getId()); diff --git a/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java index 36eb147de..941f519e5 100644 --- a/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java @@ -70,7 +70,8 @@ public class GuardPolicyDeleteDelegate { String eventAction = (String) camelExchange.getProperty("eventAction"); if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) { for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { - for(PolicyItem policyItem:GuardPolicyAttributesConstructor.getAllPolicyGuardsFromPolicyChain(policyChain)) { + for (PolicyItem policyItem:GuardPolicyAttributesConstructor + .getAllPolicyGuardsFromPolicyChain(policyChain)) { prop.setCurrentModelElementId(policy.getId()); prop.setPolicyUniqueId(policyChain.getPolicyId()); prop.setGuardUniqueId(policyItem.getId()); diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java index 39377d4a2..307c8e511 100644 --- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java @@ -79,8 +79,8 @@ public class OperationalPolicyDelegate { Policy policy = prop.getType(Policy.class); if (policy.isFound()) { for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { - Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes(refProp, - prop, prop.getType(Policy.class).getId(), policyChain); + Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor + .formatAttributes(refProp,prop, prop.getType(Policy.class).getId(), policyChain); responseMessage = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId()); } if (responseMessage != null) { diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java index f15d33df2..bc82cb3da 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java @@ -61,6 +61,11 @@ public class GuardPolicyAttributesConstructor { return createAttributesMap(matchingAttributes); } + /** + * Get all the Guard policies from the policy chain. + * @param policyChain The policy chain + * @return The list of guard policies + */ public static List<PolicyItem> getAllPolicyGuardsFromPolicyChain(PolicyChain policyChain) { List<PolicyItem> listItem = new ArrayList<>(); for (PolicyItem policyItem : policyChain.getPolicyItems()) { diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java index c28f700b2..af23626da 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java @@ -59,6 +59,16 @@ public class OperationalPolicyAttributesConstructor { private OperationalPolicyAttributesConstructor() { } + /** + * Format the attributes. + * @param refProp The Clamp properties + * @param modelProperties The model properties + * @param modelElementId The model element ID + * @param policyChain The policy chain + * @return The attributes map + * @throws BuilderException Exception while building up the attributes map + * @throws UnsupportedEncodingException Unsupported encoding exception + */ public static Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp, ModelProperties modelProperties, String modelElementId, PolicyChain policyChain) @@ -75,7 +85,8 @@ public class OperationalPolicyAttributesConstructor { return createAttributesMap(matchingAttributes, ruleAttributes); } - private static Map<String, String> prepareRuleAttributes(ClampProperties clampProperties, ModelProperties modelProperties, + private static Map<String, String> prepareRuleAttributes(ClampProperties clampProperties, + ModelProperties modelProperties, String modelElementId, PolicyChain policyChain, String globalService) throws BuilderException, UnsupportedEncodingException { logger.info("Preparing rule attributes..."); @@ -112,7 +123,8 @@ public class OperationalPolicyAttributesConstructor { return attributes; } - private static ImmutableMap<String, String> createRuleAttributesFromPolicy(ClampProperties refProp, ModelProperties modelProperties, + private static ImmutableMap<String, String> createRuleAttributesFromPolicy(ClampProperties refProp, + ModelProperties modelProperties, String modelElementId, PolicyChain policyChain, String globalService, String operationTopic) throws BuilderException, UnsupportedEncodingException { @@ -127,7 +139,8 @@ public class OperationalPolicyAttributesConstructor { } } - private static ImmutableMap<String, String> createRuleAttributesFromPolicyItem(PolicyItem policyItem, String recipeTopic) { + private static ImmutableMap<String, String> createRuleAttributesFromPolicyItem(PolicyItem policyItem, + String recipeTopic) { logger.info("recipeTopic=" + recipeTopic); return ImmutableMap.<String, String>builder() .put(RECIPE_TOPIC, recipeTopic) diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java index b9ed0c095..f2536b1f0 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java @@ -21,6 +21,7 @@ * =================================================================== * */ + package org.onap.clamp.clds.client.req.policy; import com.att.eelf.configuration.EELFLogger; @@ -61,12 +62,12 @@ public class OperationalPolicyYamlFormatter { /** * Format Operational OpenLoop Policy yaml. * - * @param prop - * @param modelElementId - * @param policyChain - * @return - * @throws BuilderException - * @throws UnsupportedEncodingException + * @param prop The model properties + * @param modelElementId The model element ID + * @param policyChain The policy chain + * @return The operational openloop policy in yaml format + * @throws BuilderException The builder exception + * @throws UnsupportedEncodingException The unsupported encoding exception */ public static String formatOpenLoopYaml(ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { @@ -87,6 +88,15 @@ public class OperationalPolicyYamlFormatter { return URLEncoder.encode(results.getSpecification(), "UTF-8"); } + /** + * Format Operational Policy yaml. + * @param prop The model properties + * @param modelElementId The model element ID + * @param policyChain The policy chain + * @return The operational policy properties in yaml format + * @throws BuilderException The builder exception + * @throws UnsupportedEncodingException The unsupported encoding exception + */ public static String formatYaml(ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { // get property objects diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java index c7051157d..965c90f89 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java @@ -519,7 +519,7 @@ public class PolicyClient { } /** - * Method to return correct policy name with prefix + * Method to return correct policy name with prefix. * * @param prop * The ModelProperties @@ -527,7 +527,7 @@ public class PolicyClient { * Policy Prefix * @param policyNameWithPrefix * Policy Name With Prefix - * @return + * @return The policy name with the prefix */ protected String selectRightPolicyNameWithPrefix(ModelProperties prop, String policyPrefix, String policyNameWithPrefix) { @@ -561,8 +561,8 @@ public class PolicyClient { deletePolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group")); deletePolicyParameters.setPolicyType(policyType); // send delete request - StringBuilder responseMessage = new StringBuilder(sendDeletePolicy(deletePolicyParameters, prop)); logger.info("Deleting policy from PAP..."); + StringBuilder responseMessage = new StringBuilder(sendDeletePolicy(deletePolicyParameters, prop)); deletePolicyParameters.setPolicyComponent("PAP"); deletePolicyParameters.setDeleteCondition(DeletePolicyCondition.ALL); // send delete request @@ -605,7 +605,7 @@ public class PolicyClient { } /** - * Create a temp Tosca model file and perform import model to Policy Engine + * Create a temp Tosca model file and perform import model to Policy Engine. * * @param cldsToscaModel * Policy model details @@ -636,6 +636,7 @@ public class PolicyClient { } /** + * Import the model. * @param importParameters * The ImportParameters * @return The response message from policy @@ -671,6 +672,7 @@ public class PolicyClient { } /** + * Build file path for tosca file. * @param clampToscaPath * Temp directory path for writing tosca files * @param toscaModelName diff --git a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java index 65052888d..fed2c65b7 100644 --- a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java @@ -216,7 +216,7 @@ public class CsarInstallerImpl implements CsarInstaller { /** * ll get the latest version of the artifact (version can be specified to DCAE - * call) + * call). * * @return The DcaeInventoryResponse object containing the dcae values */ diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index 473364ae4..64e0108e3 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -57,7 +57,7 @@ import org.onap.clamp.policy.operational.OperationalPolicy; public class Loop implements Serializable { /** - * + * The serial version id. */ private static final long serialVersionUID = -286522707701388642L; @@ -105,7 +105,8 @@ public class Loop implements Serializable { @Expose @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id")) + @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), + inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id")) private Set<MicroServicePolicy> microServicePolicies = new HashSet<>(); @Expose @@ -115,6 +116,9 @@ public class Loop implements Serializable { public Loop() { } + /** + * Constructor. + */ public Loop(String name, String blueprint, String svgRepresentation) { this.name = name; this.svgRepresentation = svgRepresentation; @@ -234,6 +238,14 @@ public class Loop implements Serializable { this.modelPropertiesJson = modelPropertiesJson; } + /** + * Generate the loop name. + * @param serviceName The service name + * @param serviceVersion The service version + * @param resourceName The resource name + * @param blueprintFileName The blueprint file name + * @return The generated loop name + */ public static String generateLoopName(String serviceName, String serviceVersion, String resourceName, String blueprintFilename) { StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion) @@ -251,18 +263,23 @@ public class Loop implements Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Loop other = (Loop) obj; if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } return true; } diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java index 8b64e9d70..a02fa9333 100644 --- a/src/main/java/org/onap/clamp/loop/LoopController.java +++ b/src/main/java/org/onap/clamp/loop/LoopController.java @@ -42,9 +42,9 @@ public class LoopController { private final LoopService loopService; private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() { - }.getType(); + }.getType(); private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() { - }.getType(); + }.getType(); @Autowired public LoopController(LoopService loopService) { @@ -59,26 +59,55 @@ public class LoopController { return loopService.getLoop(loopName); } + /** + * Update the Operational Policy properties. + * @param loopName The loop name + * @param operationalPoliciesJson The new Operational Policy properties + * @return The updated loop + */ public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) { List<OperationalPolicy> operationalPolicies = JsonUtils.GSON .fromJson(operationalPoliciesJson, OPERATIONAL_POLICY_TYPE); return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies); } + /** + * Update the whole array of MicroService policies properties + * @param loopName The loop name + * @param microServicePoliciesJson The array of all MicroService policies properties + * @return The updated loop + */ public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) { List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON .fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE); return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies); } - public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties){ + /** + * Update the global properties + * @param loopName The loop name + * @param globalProperties The updated global properties + * @return The updated loop + */ + public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties) { return loopService.updateAndSaveGlobalPropertiesJson(loopName, globalProperties); } + /** + * Update one MicroService policy properties + * @param loopName The loop name + * @param newMicroservicePolicy The new MicroService policy properties + * @return The updated MicroService policy + */ public MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) { return loopService.updateMicroservicePolicy(loopName, newMicroservicePolicy); } + /** + * Get the SVG representation of the loop + * @param loopName The loop name + * @return The SVG representation + */ public String getSVGRepresentation(String loopName) { return loopService.getClosedLoopModelSVG(loopName); diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index 051ab6ed6..b4995734b 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -25,13 +25,15 @@ package org.onap.clamp.loop; import java.util.List; import java.util.Set; -import javax.persistence.EntityNotFoundException; import com.google.gson.JsonObject; -import org.onap.clamp.policy.microservice.MicroservicePolicyService; -import org.onap.clamp.policy.operational.OperationalPolicyService; + +import javax.persistence.EntityNotFoundException; + import org.onap.clamp.policy.microservice.MicroServicePolicy; +import org.onap.clamp.policy.microservice.MicroservicePolicyService; import org.onap.clamp.policy.operational.OperationalPolicy; +import org.onap.clamp.policy.operational.OperationalPolicyService; import org.springframework.stereotype.Service; @Service @@ -41,6 +43,9 @@ public class LoopService { private final MicroservicePolicyService microservicePolicyService; private final OperationalPolicyService operationalPolicyService; + /** + * Constructor. + */ public LoopService(LoopsRepository loopsRepository, MicroservicePolicyService microservicePolicyService, OperationalPolicyService operationalPolicyService) { @@ -57,7 +62,7 @@ public class LoopService { return loopsRepository.getAllLoopNames(); } - Loop getLoop(String loopName){ + Loop getLoop(String loopName) { return loopsRepository .findById(loopName) .orElse(null); @@ -87,7 +92,7 @@ public class LoopService { } MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) { - Loop loop = findClosedLoopByName(loopName); + Loop loop = findClosedLoopByName(loopName); MicroServicePolicy newPolicies = microservicePolicyService .getAndUpdateMicroServicePolicy(loop, newMicroservicePolicy); return newPolicies; diff --git a/src/main/java/org/onap/clamp/loop/log/LoopLog.java b/src/main/java/org/onap/clamp/loop/log/LoopLog.java index 7b7fe1b1c..0c51c0c1f 100644 --- a/src/main/java/org/onap/clamp/loop/log/LoopLog.java +++ b/src/main/java/org/onap/clamp/loop/log/LoopLog.java @@ -43,7 +43,6 @@ import javax.persistence.Table; import org.onap.clamp.loop.Loop; /** - * * This class holds the logs created by the Clamp Backend. The Instant is always * rounded to the nearest second as the nano seconds can't be stored in the * database. The logs can be therefore exposed to the UI or the client doing @@ -54,7 +53,7 @@ import org.onap.clamp.loop.Loop; @Table(name = "loop_logs") public class LoopLog implements Serializable { /** - * + * The serial version ID. */ private static final long serialVersionUID = 1988276670074437631L; @@ -130,18 +129,23 @@ public class LoopLog implements Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } LoopLog other = (LoopLog) obj; if (id == null) { - if (other.id != null) + if (other.id != null) { return false; - } else if (!id.equals(other.id)) + } + } else if (!id.equals(other.id)) { return false; + } return true; } diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java index c104b13e0..683881bfa 100644 --- a/src/main/java/org/onap/clamp/policy/Policy.java +++ b/src/main/java/org/onap/clamp/policy/Policy.java @@ -31,6 +31,15 @@ public interface Policy { JsonObject getJsonRepresentation(); + /** + * Generate the policy name. + * @param policyType The policy type + * @param serviceName The service name + * @param serviceVersion The service version + * @param resourceName The resource name + * @param blueprintFilename The blueprint file name + * @return The generated policy name + */ static String generatePolicyName(String policyType, String serviceName, String serviceVersion, String resourceName, String blueprintFilename) { StringBuilder buffer = new StringBuilder(policyType).append("_").append(serviceName).append("_v") diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index 857a3d747..3962a3d4e 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -50,7 +50,7 @@ import org.onap.clamp.policy.Policy; @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) }) public class MicroServicePolicy implements Serializable, Policy { /** - * + * The serial version ID. */ private static final long serialVersionUID = 6271238288583332616L; @@ -83,6 +83,13 @@ public class MicroServicePolicy implements Serializable, Policy { // serialization } + /** + * The constructor. + * @param name The name of the MicroService + * @param policyTosca The policy Tosca of the MicroService + * @param shared The flag indicate whether the MicroService is shared + * @param usedByLoops The list of loops that uses this MicroService + */ public MicroServicePolicy(String name, String policyTosca, Boolean shared, Set<Loop> usedByLoops) { this.name = name; this.policyTosca = policyTosca; @@ -92,6 +99,14 @@ public class MicroServicePolicy implements Serializable, Policy { this.usedByLoops = usedByLoops; } + /** + * The constructor. + * @param name The name of the MicroService + * @param policyTosca The policy Tosca of the MicroService + * @param shared The flag indicate whether the MicroService is shared + * @param jsonRepresentation The UI representation in json format + * @param usedByLoops The list of loops that uses this MicroService + */ public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation, Set<Loop> usedByLoops) { this.name = name; @@ -157,18 +172,23 @@ public class MicroServicePolicy implements Serializable, Policy { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } MicroServicePolicy other = (MicroServicePolicy) obj; if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } return true; } diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java b/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java index ee9ba5370..f473d160f 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java @@ -57,6 +57,12 @@ public class MicroservicePolicyService implements PolicyService<MicroServicePoli return repository.existsById(policyName); } + /** + * Get and update the MicroService policy properties. + * @param loop The loop + * @param policy The new MicroService policy + * @return The updated MicroService policy + */ @Transactional public MicroServicePolicy getAndUpdateMicroServicePolicy(Loop loop, MicroServicePolicy policy) { return repository.findById(policy.getName()).map(p -> updateMicroservicePolicyProperties(p, policy, loop)) diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java index 033b53972..c1e075daa 100644 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java @@ -38,16 +38,16 @@ import javax.persistence.Table; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; +import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.Loop; import org.onap.clamp.policy.Policy; -import org.onap.clamp.dao.model.jsontype.StringJsonUserType; @Entity @Table(name = "operational_policies") @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) }) public class OperationalPolicy implements Serializable, Policy { /** - * + * The serial version ID. */ private static final long serialVersionUID = 6117076450841538255L; @@ -69,6 +69,12 @@ public class OperationalPolicy implements Serializable, Policy { //Serialization } + /** + * The constructor. + * @param name The name of the operational policy + * @param loop The loop that uses this operational policy + * @param configurationsJson The operational policy property in the format of json + */ public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson) { this.name = name; this.loop = loop; @@ -83,7 +89,7 @@ public class OperationalPolicy implements Serializable, Policy { this.loop = loopName; } - public Loop getLoop(){ + public Loop getLoop() { return loop; } @@ -110,18 +116,23 @@ public class OperationalPolicy implements Serializable, Policy { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } OperationalPolicy other = (OperationalPolicy) obj; if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } return true; } diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java index b24a2db11..95f4f7be8 100644 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java @@ -27,8 +27,8 @@ import com.google.gson.JsonObject; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.onap.clamp.policy.PolicyService; import org.onap.clamp.loop.Loop; +import org.onap.clamp.policy.PolicyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/onap/clamp/util/PrincipalUtils.java b/src/main/java/org/onap/clamp/util/PrincipalUtils.java index ec089834d..d6b20f30b 100644 --- a/src/main/java/org/onap/clamp/util/PrincipalUtils.java +++ b/src/main/java/org/onap/clamp/util/PrincipalUtils.java @@ -40,7 +40,7 @@ public class PrincipalUtils { /** * Get the Full name. * - * @return + * @return The user name */ public static String getUserName() { String name = userNameHandler.retrieveUserName(securityContext); @@ -53,7 +53,7 @@ public class PrincipalUtils { /** * Get the userId from AAF/CSP. * - * @return + * @return The user ID */ public static String getUserId() { return getUserName(); @@ -62,7 +62,7 @@ public class PrincipalUtils { /** * Get the principal name. * - * @return + * @return The principal name */ public static String getPrincipalName() { String principal = ((UserDetails)securityContext.getAuthentication().getPrincipal()).getUsername(); @@ -72,6 +72,7 @@ public class PrincipalUtils { } return name; } + public static void setSecurityContext(SecurityContext securityContext) { PrincipalUtils.securityContext = securityContext; } |