From f1692af8bcc02c6a7335078160463025b85eba68 Mon Sep 17 00:00:00 2001 From: xuegao Date: Wed, 22 Apr 2020 13:54:24 +0200 Subject: Remove bugs and vulnerabilities Remove bugs and vulnerabilities based on the sonar report Issue-ID: CLAMP-841 Change-Id: I49d0eeeedf69a0cbe3adf49cf115ab25aec7adfd Signed-off-by: xuegao --- .../onap/clamp/loop/template/LoopElementModel.java | 4 +- .../OperationalPolicyRepresentationBuilder.java | 98 ++++++++++++---------- .../ManageDictionaries/ManageDictionaries.js | 14 ++-- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java index 4a46a954..35fdf43c 100644 --- a/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java +++ b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java @@ -75,8 +75,8 @@ public class LoopElementModel extends AuditEntity implements Serializable { @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml") private String blueprint; - public static String MICRO_SERVICE_TYPE = "MICRO_SERVICE_TYPE"; - public static String OPERATIONAL_POLICY_TYPE = "OPERATIONAL_POLICY_TYPE"; + public static final String MICRO_SERVICE_TYPE = "MICRO_SERVICE_TYPE"; + public static final String OPERATIONAL_POLICY_TYPE = "OPERATIONAL_POLICY_TYPE"; /** * The type of element. */ diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java index 57d13ef1..674db229 100644 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java @@ -45,9 +45,19 @@ public class OperationalPolicyRepresentationBuilder { EELFManager.getInstance().getLogger(OperationalPolicyRepresentationBuilder.class); public static final String PROPERTIES = "properties"; + public static final String ITEMS = "items"; + public static final String ANY_OF = "anyOf"; + public static final String TITLE = "title"; + public static final String RECIPE = "recipe"; + public static final String DEFAULT = "default"; + public static final String STRING = "string"; public static final String TYPE = "type"; public static final String TYPE_LIST = "list"; + private OperationalPolicyRepresentationBuilder() { + throw new IllegalStateException("This is Utility class, not supposed to be initiated."); + } + /** * This method generates the operational policy json representation that will be * used by ui for rendering. It uses the model (VF and VFModule) defined in the @@ -65,21 +75,21 @@ public class OperationalPolicyRepresentationBuilder { ResourceFileUtil .getResourceAsString("clds/json-schema/operational_policies/operational_policy.json"), JsonObject.class); - jsonSchema.get("properties").getAsJsonObject() - .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies") - .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("target") - .getAsJsonObject().get("anyOf").getAsJsonArray().addAll(createAnyOfArray(modelJson, true)); + jsonSchema.get(PROPERTIES).getAsJsonObject() + .get("operational_policy").getAsJsonObject().get(PROPERTIES).getAsJsonObject().get("policies") + .getAsJsonObject().get(ITEMS).getAsJsonObject().get(PROPERTIES).getAsJsonObject().get("target") + .getAsJsonObject().get(ANY_OF).getAsJsonArray().addAll(createAnyOfArray(modelJson, true)); // update CDS recipe and payload information to schema - JsonArray actors = jsonSchema.get("properties").getAsJsonObject() - .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies") - .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("actor") - .getAsJsonObject().get("anyOf").getAsJsonArray(); + JsonArray actors = jsonSchema.get(PROPERTIES).getAsJsonObject() + .get("operational_policy").getAsJsonObject().get(PROPERTIES).getAsJsonObject().get("policies") + .getAsJsonObject().get(ITEMS).getAsJsonObject().get(PROPERTIES).getAsJsonObject().get("actor") + .getAsJsonObject().get(ANY_OF).getAsJsonArray(); for (JsonElement actor : actors) { - if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) { - actor.getAsJsonObject().get("properties").getAsJsonObject().get("recipe").getAsJsonObject() - .get("anyOf").getAsJsonArray() + if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get(TITLE).getAsString())) { + actor.getAsJsonObject().get(PROPERTIES).getAsJsonObject().get(RECIPE).getAsJsonObject() + .get(ANY_OF).getAsJsonArray() .addAll(createAnyOfArrayForCdsRecipe(modelJson)); } } @@ -93,9 +103,9 @@ public class OperationalPolicyRepresentationBuilder { private static JsonObject createSchemaProperty(String title, String type, String defaultValue, String readOnlyFlag, String[] enumArray) { JsonObject property = new JsonObject(); - property.addProperty("title", title); - property.addProperty("type", type); - property.addProperty("default", defaultValue); + property.addProperty(TITLE, title); + property.addProperty(TYPE, type); + property.addProperty(DEFAULT, defaultValue); property.addProperty("readOnly", readOnlyFlag); if (enumArray != null) { @@ -114,15 +124,15 @@ public class OperationalPolicyRepresentationBuilder { for (Entry entry : modelVnfs.entrySet()) { JsonObject vnfOneOfSchema = new JsonObject(); - vnfOneOfSchema.addProperty("title", "VNF" + "-" + entry.getKey()); + vnfOneOfSchema.addProperty(TITLE, "VNF" + "-" + entry.getKey()); JsonObject properties = new JsonObject(); if (generateType) { - properties.add("type", createSchemaProperty("Type", "string", "VNF", "True", null)); + properties.add(TYPE, createSchemaProperty("Type", STRING, "VNF", "True", null)); } - properties.add("resourceID", createSchemaProperty("Resource ID", "string", + properties.add("resourceID", createSchemaProperty("Resource ID", STRING, modelVnfs.get(entry.getKey()).getAsJsonObject().get("name").getAsString(), "True", null)); - vnfOneOfSchema.add("properties", properties); + vnfOneOfSchema.add(PROPERTIES, properties); vnfSchemaArray.add(vnfOneOfSchema); } return vnfSchemaArray; @@ -134,39 +144,39 @@ public class OperationalPolicyRepresentationBuilder { for (Entry entry : modelVfModules.entrySet()) { JsonObject vfModuleOneOfSchema = new JsonObject(); - vfModuleOneOfSchema.addProperty("title", "VFMODULE" + "-" + entry.getKey()); + vfModuleOneOfSchema.addProperty(TITLE, "VFMODULE" + "-" + entry.getKey()); JsonObject properties = new JsonObject(); if (generateType) { - properties.add("type", createSchemaProperty("Type", "string", "VFMODULE", "True", null)); + properties.add(TYPE, createSchemaProperty("Type", STRING, "VFMODULE", "True", null)); } properties.add("resourceID", - createSchemaProperty("Resource ID", "string", + createSchemaProperty("Resource ID", STRING, modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelName").getAsString(), "True", null)); properties.add("modelInvariantId", - createSchemaProperty("Model Invariant Id (ModelInvariantUUID)", "string", + createSchemaProperty("Model Invariant Id (ModelInvariantUUID)", STRING, modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelInvariantUUID") .getAsString(), "True", null)); properties.add("modelVersionId", - createSchemaProperty("Model Version Id (ModelUUID)", "string", + createSchemaProperty("Model Version Id (ModelUUID)", STRING, modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelUUID").getAsString(), "True", null)); properties.add("modelName", - createSchemaProperty("Model Name", "string", + createSchemaProperty("Model Name", STRING, modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelName").getAsString(), "True", null)); - properties.add("modelVersion", createSchemaProperty("Model Version", "string", + properties.add("modelVersion", createSchemaProperty("Model Version", STRING, modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelVersion").getAsString(), "True", null)); properties .add("modelCustomizationId", - createSchemaProperty("Customization ID", "string", + createSchemaProperty("Customization ID", STRING, modelVfModules.get(entry.getKey()).getAsJsonObject() .get("vfModuleModelCustomizationUUID").getAsString(), "True", null)); - vfModuleOneOfSchema.add("properties", properties); + vfModuleOneOfSchema.add(PROPERTIES, properties); vfModuleOneOfSchemaArray.add(vfModuleOneOfSchema); } return vfModuleOneOfSchemaArray; @@ -202,9 +212,9 @@ public class OperationalPolicyRepresentationBuilder { JsonObject workflows = controllerProperties.getAsJsonObject("workflows"); for (Entry workflowsEntry : workflows.entrySet()) { JsonObject obj = new JsonObject(); - obj.addProperty("title", workflowsEntry.getKey()); - obj.addProperty("type", "object"); - obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(), + obj.addProperty(TITLE, workflowsEntry.getKey()); + obj.addProperty(TYPE, "object"); + obj.add(PROPERTIES, createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(), controllerProperties, workflowsEntry.getKey())); schemaArray.add(obj); } @@ -217,21 +227,21 @@ public class OperationalPolicyRepresentationBuilder { private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties, String workFlowName) { JsonObject payload = new JsonObject(); - payload.addProperty("title", "Payload"); - payload.addProperty("type", "object"); - payload.add("properties", createInputPropertiesForPayload(workFlow, + payload.addProperty(TITLE, "Payload"); + payload.addProperty(TYPE, "object"); + payload.add(PROPERTIES, createInputPropertiesForPayload(workFlow, controllerProperties)); JsonObject properties = new JsonObject(); - properties.add("recipe", createRecipeForCdsWorkflow(workFlowName)); + properties.add(RECIPE, createRecipeForCdsWorkflow(workFlowName)); properties.add("payload", payload); return properties; } private static JsonObject createRecipeForCdsWorkflow(String workflow) { JsonObject recipe = new JsonObject(); - recipe.addProperty("title", "recipe"); - recipe.addProperty("type", "string"); - recipe.addProperty("default", workflow); + recipe.addProperty(TITLE, RECIPE); + recipe.addProperty(TYPE, STRING); + recipe.addProperty(DEFAULT, workflow); JsonObject options = new JsonObject(); options.addProperty("hidden", true); recipe.add("options", options); @@ -253,18 +263,18 @@ public class OperationalPolicyRepresentationBuilder { JsonObject inputs = workFlow.getAsJsonObject("inputs"); JsonObject jsonObject = new JsonObject(); jsonObject.add("artifact_name", createSchemaProperty( - "artifact name", "string", artifactName, "True", null)); + "artifact name", STRING, artifactName, "True", null)); jsonObject.add("artifact_version", createSchemaProperty( - "artifact version", "string", artifactVersion, "True", null)); + "artifact version", STRING, artifactVersion, "True", null)); jsonObject.add("mode", createCdsInputProperty( - "mode", "string", "async" ,null)); + "mode", STRING, "async" ,null)); jsonObject.add("data", createDataProperty(inputs)); return jsonObject; } private static JsonObject createDataProperty(JsonObject inputs) { JsonObject data = new JsonObject(); - data.addProperty("title", "data"); + data.addProperty(TITLE, "data"); JsonObject dataObj = new JsonObject(); addDataFields(inputs, dataObj); data.add(PROPERTIES, dataObj); @@ -294,7 +304,7 @@ public class OperationalPolicyRepresentationBuilder { String defaultValue, JsonObject cdsProperty) { JsonObject property = new JsonObject(); - property.addProperty("title", title); + property.addProperty(TITLE, title); if (TYPE_LIST.equalsIgnoreCase(type)) { property.addProperty(TYPE, "array"); @@ -304,14 +314,14 @@ public class OperationalPolicyRepresentationBuilder { dataObject); JsonObject listProperties = new JsonObject(); listProperties.add(PROPERTIES, dataObject); - property.add("items", listProperties); + property.add(ITEMS, listProperties); } } else { property.addProperty(TYPE, type); } if (defaultValue != null) { - property.addProperty("default", defaultValue); + property.addProperty(DEFAULT, defaultValue); } return property; } diff --git a/ui-react/src/components/dialogs/ManageDictionaries/ManageDictionaries.js b/ui-react/src/components/dialogs/ManageDictionaries/ManageDictionaries.js index 2af1b7ce..538688da 100644 --- a/ui-react/src/components/dialogs/ManageDictionaries/ManageDictionaries.js +++ b/ui-react/src/components/dialogs/ManageDictionaries/ManageDictionaries.js @@ -21,7 +21,7 @@ */ -import React from 'react'; +import React, { forwardRef } from 'react'; import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; import styled from 'styled-components'; @@ -30,7 +30,6 @@ import MaterialTable, {MTableToolbar} from "material-table"; import IconButton from '@material-ui/core/IconButton'; import Tooltip from '@material-ui/core/Tooltip'; import Grid from '@material-ui/core/Grid'; -import { forwardRef } from 'react'; import AddBox from '@material-ui/icons/AddBox'; import ArrowUpward from '@material-ui/icons/ArrowUpward'; import Check from '@material-ui/icons/Check'; @@ -204,7 +203,7 @@ export default class ManageDictionaries extends React.Component { cellStyle: cellStyle, headerStyle: headerStyle }, - { + { title: "Sub-Dictionary", field: "subDictionary", editComponent: props => (
@@ -214,7 +213,7 @@ export default class ManageDictionaries extends React.Component { cellStyle: cellStyle, headerStyle: headerStyle }, - { + { title: "Updated By", field: "updatedBy", editable: 'never', cellStyle: cellStyle, headerStyle: headerStyle @@ -294,7 +293,7 @@ export default class ManageDictionaries extends React.Component { var dictionaryElements = []; if (event.target.files[0].type === 'text/csv' ) { if (event.target.files && event.target.files[0]) { - let reader = new FileReader(); + const reader = new FileReader(); reader.onload = function(e) { var dictElems = reader.result.split('\n'); var jsonObj = []; @@ -312,7 +311,6 @@ export default class ManageDictionaries extends React.Component { const mandatoryKeys = [ 'Element Short Name', 'Element Name', 'Element Type' ]; const validTypes = ['string','number','datetime','json','map']; if (!dictElems){ - text.setState({validData: false}); } else if (headers.length !== dictKeys.length){ text.setState({validImport: false}); @@ -373,7 +371,7 @@ export default class ManageDictionaries extends React.Component { } } - + render() { return ( @@ -440,7 +438,7 @@ export default class ManageDictionaries extends React.Component { new Promise((resolve, reject) => { setTimeout(() => { { - let data = this.state.dictionaryNames; + const data = this.state.dictionaryNames; const index = data.indexOf(oldData); data.splice(index, 1); this.setState({ data }, () => resolve()); -- cgit 1.2.3-korg