Sonar-Critical: Use Dedicated Exception 93/44293/2
authorAS00465059 <AS00465059@techmahindra.com>
Tue, 24 Apr 2018 10:46:23 +0000 (16:16 +0530)
committerAS00465059 <AS00465059@techmahindra.com>
Tue, 24 Apr 2018 10:46:23 +0000 (16:16 +0530)
File: VfModuleCustomizationToVduMapper.java

Line: L56 L79 L88 L112 L127 L141

Sonar Link:
https://sonar.onap.org/project/issues?assignees=as00465059&id=org.onap.so%3Aso&open=AWJqzmfZRGy6eclHEzWx&resolved=false&severities=CRITICAL

Change-Id: I4fd2494ee4d883910cc1d78785665d3f0c5fdd92
Issue-ID: SO-590
Signed-off-by: AS00465059 <AS00465059@techmahindra.com>
adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vdu/mapper/VfModuleCustomizationToVduMapper.java

index 22d988f..b04f3c3 100644 (file)
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP - SO\r
- * ================================================================================\r
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.\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
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.openecomp.mso.adapters.vdu.mapper;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.openecomp.mso.adapters.vdu.VduArtifact;\r
-import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;\r
-import org.openecomp.mso.adapters.vdu.VduModelInfo;\r
-import org.openecomp.mso.db.catalog.CatalogDatabase;\r
-import org.openecomp.mso.db.catalog.beans.HeatEnvironment;\r
-import org.openecomp.mso.db.catalog.beans.HeatFiles;\r
-import org.openecomp.mso.db.catalog.beans.HeatTemplate;\r
-import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;\r
-import org.openecomp.mso.logger.MsoLogger;\r
-import org.springframework.stereotype.Component;\r
-\r
-@Component\r
-public class VfModuleCustomizationToVduMapper {\r
-\r
-       private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);\r
-\r
-       public VduModelInfo mapVfModuleCustomizationToVdu(VfModuleCustomization vfModuleCustom) throws Exception {\r
-               CatalogDatabase db = CatalogDatabase.getInstance();\r
-               VduModelInfo vduModel = new VduModelInfo();\r
-               vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUuid());\r
-               try {\r
-                       // Map the cloud templates, attached files, and environment file\r
-                       mapCloudTemplates(\r
-                                       db.getHeatTemplateByArtifactUuid(vfModuleCustom.getVfModule().getHeatTemplateArtifactUUId()),\r
-                                       vduModel);\r
-                       mapCloudFiles(vfModuleCustom, vduModel);\r
-                       mapEnvironment(db.getHeatEnvironmentByArtifactUuid(vfModuleCustom.getHeatEnvironmentArtifactUuid()),\r
-                                       vduModel);\r
-               } catch (Exception e) {\r
-                       LOGGER.debug("unhandled exception in mapVfModuleCustomizationToVdu", e);\r
-                       throw new Exception("Exception during mapVfModuleCustomizationToVdu " + e.getMessage());\r
-               } finally {\r
-                       // Make sure DB session is closed\r
-                       db.close();\r
-               }\r
-\r
-               return vduModel;\r
-       }\r
-\r
-       public VduModelInfo mapVfModuleCustVolumeToVdu(VfModuleCustomization vfModuleCustom) throws Exception {\r
-               CatalogDatabase db = CatalogDatabase.getInstance();\r
-               VduModelInfo vduModel = new VduModelInfo();\r
-               vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUuid());\r
-               try {\r
-                       // Map the cloud templates, attached files, and environment file\r
-                       mapCloudTemplates(\r
-                                       db.getHeatTemplateByArtifactUuid(vfModuleCustom.getVfModule().getVolHeatTemplateArtifactUUId()),\r
-                                       vduModel);\r
-                       mapCloudFiles(vfModuleCustom, vduModel);\r
-                       mapEnvironment(db.getHeatEnvironmentByArtifactUuid(vfModuleCustom.getVolEnvironmentArtifactUuid()),\r
-                                       vduModel);\r
-               } catch (Exception e) {\r
-                       LOGGER.debug("unhandled exception in mapVfModuleCustVolumeToVdu", e);\r
-                       throw new Exception("Exception during mapVfModuleCustVolumeToVdu " + e.getMessage());\r
-               } finally {\r
-                       // Make sure DB session is closed\r
-                       db.close();\r
-               }\r
-\r
-               return vduModel;\r
-       }\r
-\r
-       private void mapCloudTemplates(HeatTemplate heatTemplate, VduModelInfo vduModel) throws Exception {\r
-               // TODO: These catalog objects will be refactored to be\r
-               // non-Heat-specific\r
-               CatalogDatabase db = CatalogDatabase.getInstance();\r
-               try {\r
-                       List<VduArtifact> vduArtifacts = vduModel.getArtifacts();\r
-\r
-                       // Main template. Also set the VDU timeout based on the main\r
-                       // template.\r
-                       vduArtifacts.add(mapHeatTemplateToVduArtifact(heatTemplate, ArtifactType.MAIN_TEMPLATE));\r
-                       vduModel.setTimeoutMinutes(heatTemplate.getTimeoutMinutes());\r
-                       \r
-                       // Nested templates\r
-                       Map<String,Object> nestedTemplates = db.getNestedTemplates(heatTemplate.getArtifactUuid());\r
-                       if (nestedTemplates != null) {\r
-                               for (String name : nestedTemplates.keySet()) {\r
-                                       String body = (String) nestedTemplates.get(name);\r
-                                       VduArtifact vduArtifact = new VduArtifact(name, body.getBytes(), ArtifactType.NESTED_TEMPLATE);\r
-                                       vduArtifacts.add(vduArtifact);\r
-                               }\r
-                       }\r
-                       \r
-               } catch (Exception e) {\r
-                       LOGGER.debug("unhandled exception in mapCloudTemplates", e);\r
-                       throw new Exception("Exception during mapCloudTemplates " + e.getMessage());\r
-               } finally {\r
-                       // Make sure DB session is closed\r
-                       db.close();\r
-               }\r
-       }\r
-\r
-       private VduArtifact mapHeatTemplateToVduArtifact(HeatTemplate heatTemplate, ArtifactType artifactType) {\r
-               VduArtifact vduArtifact = new VduArtifact();\r
-               vduArtifact.setName(heatTemplate.getTemplateName());\r
-               vduArtifact.setContent(heatTemplate.getHeatTemplate().getBytes());\r
-               vduArtifact.setType(artifactType);\r
-               return vduArtifact;\r
-       }\r
-\r
-       private void mapCloudFiles(VfModuleCustomization vfModuleCustom, VduModelInfo vduModel) throws Exception {\r
-               // TODO: These catalog objects will be refactored to be\r
-               // non-Heat-specific\r
-               CatalogDatabase db = CatalogDatabase.getInstance();\r
-\r
-               try{\r
-                       Map <String, HeatFiles> heatFiles = db.getHeatFilesForVfModule(vfModuleCustom.getVfModuleModelUuid());\r
-                       if (heatFiles != null) {\r
-                               for (HeatFiles heatFile: heatFiles.values()) {\r
-                                       mapCloudFileToVduArtifact(heatFile, ArtifactType.TEXT_FILE);\r
-                               }\r
-                       }\r
-               } catch (Exception e) {\r
-                       LOGGER.debug("unhandled exception in mapCloudFiles", e);\r
-                       throw new Exception("Exception during mapCloudFiles " + e.getMessage());\r
-               } finally {\r
-                       // Make sure DB session is closed\r
-                       db.close();\r
-               }\r
-               \r
-       }\r
-\r
-       private VduArtifact mapCloudFileToVduArtifact(HeatFiles heatFile, ArtifactType artifactType) {\r
-               VduArtifact vduArtifact = new VduArtifact();\r
-               vduArtifact.setName(heatFile.getFileName());\r
-               vduArtifact.setContent(heatFile.getFileBody().getBytes());\r
-               vduArtifact.setType(artifactType);\r
-               return vduArtifact;\r
-       }\r
-\r
-       private void mapEnvironment(HeatEnvironment heatEnvironment, VduModelInfo vduModel) {\r
-               // TODO: These catalog objects will be refactored to be\r
-               // non-Heat-specific\r
-               if (heatEnvironment != null) {\r
-                       List<VduArtifact> vduArtifacts = vduModel.getArtifacts();\r
-                       vduArtifacts.add(mapEnvironmentFileToVduArtifact(heatEnvironment));\r
-               }\r
-       }\r
-\r
-       private VduArtifact mapEnvironmentFileToVduArtifact(HeatEnvironment heatEnv) {\r
-               VduArtifact vduArtifact = new VduArtifact();\r
-               vduArtifact.setName(heatEnv.getName());\r
-               vduArtifact.setContent(heatEnv.getEnvironment().getBytes());\r
-               vduArtifact.setType(ArtifactType.ENVIRONMENT);\r
-               return vduArtifact;\r
-       }\r
-\r
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.vdu.mapper;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.openecomp.mso.adapters.vdu.VduArtifact;
+import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
+import org.openecomp.mso.adapters.vdu.VduModelInfo;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
+import org.openecomp.mso.db.catalog.beans.HeatFiles;
+import org.openecomp.mso.db.catalog.beans.HeatTemplate;
+import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
+import org.openecomp.mso.logger.MsoLogger;
+import org.springframework.stereotype.Component;
+
+@Component
+public class VfModuleCustomizationToVduMapper {
+
+       private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+
+       public VduModelInfo mapVfModuleCustomizationToVdu(VfModuleCustomization vfModuleCustom) throws SQLException {
+               CatalogDatabase db = CatalogDatabase.getInstance();
+               VduModelInfo vduModel = new VduModelInfo();
+               vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUuid());
+               try {
+                       // Map the cloud templates, attached files, and environment file
+                       mapCloudTemplates(
+                                       db.getHeatTemplateByArtifactUuid(vfModuleCustom.getVfModule().getHeatTemplateArtifactUUId()),
+                                       vduModel);
+                       mapCloudFiles(vfModuleCustom, vduModel);
+                       mapEnvironment(db.getHeatEnvironmentByArtifactUuid(vfModuleCustom.getHeatEnvironmentArtifactUuid()),
+                                       vduModel);
+               } catch (SQLException e) {
+                       LOGGER.debug("unhandled exception in mapVfModuleCustomizationToVdu", e);
+                       throw new SQLException("Exception during mapVfModuleCustomizationToVdu " + e.getMessage());
+               } finally {
+                       // Make sure DB session is closed
+                       db.close();
+               }
+
+               return vduModel;
+       }
+
+       public VduModelInfo mapVfModuleCustVolumeToVdu(VfModuleCustomization vfModuleCustom) throws SQLException {
+               CatalogDatabase db = CatalogDatabase.getInstance();
+               VduModelInfo vduModel = new VduModelInfo();
+               vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUuid());
+               try {
+                       // Map the cloud templates, attached files, and environment file
+                       mapCloudTemplates(
+                                       db.getHeatTemplateByArtifactUuid(vfModuleCustom.getVfModule().getVolHeatTemplateArtifactUUId()),
+                                       vduModel);
+                       mapCloudFiles(vfModuleCustom, vduModel);
+                       mapEnvironment(db.getHeatEnvironmentByArtifactUuid(vfModuleCustom.getVolEnvironmentArtifactUuid()),
+                                       vduModel);
+               } catch (SQLException e) {
+                       LOGGER.debug("unhandled exception in mapVfModuleCustVolumeToVdu", e);
+                       throw new SQLException("Exception during mapVfModuleCustVolumeToVdu " + e.getMessage());
+               } finally {
+                       // Make sure DB session is closed
+                       db.close();
+               }
+
+               return vduModel;
+       }
+
+       private void mapCloudTemplates(HeatTemplate heatTemplate, VduModelInfo vduModel) throws SQLException {
+               // TODO: These catalog objects will be refactored to be
+               // non-Heat-specific
+               CatalogDatabase db = CatalogDatabase.getInstance();
+               try {
+                       List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
+
+                       // Main template. Also set the VDU timeout based on the main
+                       // template.
+                       vduArtifacts.add(mapHeatTemplateToVduArtifact(heatTemplate, ArtifactType.MAIN_TEMPLATE));
+                       vduModel.setTimeoutMinutes(heatTemplate.getTimeoutMinutes());
+                       
+                       // Nested templates
+                       Map<String,Object> nestedTemplates = db.getNestedTemplates(heatTemplate.getArtifactUuid());
+                       if (nestedTemplates != null) {
+                               for (String name : nestedTemplates.keySet()) {
+                                       String body = (String) nestedTemplates.get(name);
+                                       VduArtifact vduArtifact = new VduArtifact(name, body.getBytes(), ArtifactType.NESTED_TEMPLATE);
+                                       vduArtifacts.add(vduArtifact);
+                               }
+                       }
+                       
+               } catch (IllegalArgumentException e) {
+                       LOGGER.debug("unhandled exception in mapCloudTemplates", e);
+                       throw new IllegalArgumentException("Exception during mapCloudTemplates " + e.getMessage());
+               } finally {
+                       // Make sure DB session is closed
+                       db.close();
+               }
+       }
+
+       private VduArtifact mapHeatTemplateToVduArtifact(HeatTemplate heatTemplate, ArtifactType artifactType) {
+               VduArtifact vduArtifact = new VduArtifact();
+               vduArtifact.setName(heatTemplate.getTemplateName());
+               vduArtifact.setContent(heatTemplate.getHeatTemplate().getBytes());
+               vduArtifact.setType(artifactType);
+               return vduArtifact;
+       }
+
+       private void mapCloudFiles(VfModuleCustomization vfModuleCustom, VduModelInfo vduModel) throws SQLException {
+               // TODO: These catalog objects will be refactored to be
+               // non-Heat-specific
+               CatalogDatabase db = CatalogDatabase.getInstance();
+
+               try{
+                       Map <String, HeatFiles> heatFiles = db.getHeatFilesForVfModule(vfModuleCustom.getVfModuleModelUuid());
+                       if (heatFiles != null) {
+                               for (HeatFiles heatFile: heatFiles.values()) {
+                                       mapCloudFileToVduArtifact(heatFile, ArtifactType.TEXT_FILE);
+                               }
+                       }
+               } catch (IllegalArgumentException e) {
+                       LOGGER.debug("unhandled exception in mapCloudFiles", e);
+                       throw new IllegalArgumentException("Exception during mapCloudFiles " + e.getMessage());
+               } finally {
+                       // Make sure DB session is closed
+                       db.close();
+               }
+               
+       }
+
+       private VduArtifact mapCloudFileToVduArtifact(HeatFiles heatFile, ArtifactType artifactType) {
+               VduArtifact vduArtifact = new VduArtifact();
+               vduArtifact.setName(heatFile.getFileName());
+               vduArtifact.setContent(heatFile.getFileBody().getBytes());
+               vduArtifact.setType(artifactType);
+               return vduArtifact;
+       }
+
+       private void mapEnvironment(HeatEnvironment heatEnvironment, VduModelInfo vduModel) {
+               // TODO: These catalog objects will be refactored to be
+               // non-Heat-specific
+               if (heatEnvironment != null) {
+                       List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
+                       vduArtifacts.add(mapEnvironmentFileToVduArtifact(heatEnvironment));
+               }
+       }
+
+       private VduArtifact mapEnvironmentFileToVduArtifact(HeatEnvironment heatEnv) {
+               VduArtifact vduArtifact = new VduArtifact();
+               vduArtifact.setName(heatEnv.getName());
+               vduArtifact.setContent(heatEnv.getEnvironment().getBytes());
+               vduArtifact.setType(ArtifactType.ENVIRONMENT);
+               return vduArtifact;
+       }
+
 }
\ No newline at end of file