summaryrefslogtreecommitdiffstats
path: root/adapters/mso-catalog-db-adapter
diff options
context:
space:
mode:
authorMunir Ahmad <munir.ahmad@bell.ca>2018-03-02 19:50:18 -0500
committerSeshu Kumar M <seshu.kumar.m@huawei.com>2018-03-06 14:47:33 +0000
commit78e5db7fa6a022e8dd319334ff40bbf045b5b66b (patch)
treea93fc57cc71e881da211c53c19b040c4f836fb4e /adapters/mso-catalog-db-adapter
parent2c3be92eccd45ebad09d4fea7245f11a3c14f583 (diff)
Make use of try with resources
Change-Id: If230b8249d482f7784f885fb4348943c755477cc Issue-ID: SO-437 Signed-off-by: Munir Ahmad <munir.ahmad@bell.ca>
Diffstat (limited to 'adapters/mso-catalog-db-adapter')
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java124
1 files changed, 62 insertions, 62 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java
index 8cdeaaa9e1..cd6522b487 100644
--- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java
@@ -428,45 +428,46 @@ public class CatalogDbAdapterRest {
QueryVfModule qryResp;
int respStatus = HttpStatus.SC_OK;
List<VfModuleCustomization> ret = null;
- CatalogDatabase db = CatalogDatabase.getInstance();
-
- try{
- if(vfModuleModelName != null && !"".equals(vfModuleModelName)){
- LOGGER.debug ("Query vfModules by vfModuleModuleName: " + vfModuleModelName);
- VfModuleCustomization vfModule = db.getVfModuleCustomizationByModelName(vfModuleModelName);
- if(vfModule != null){
- ret = new ArrayList<>(1);
- ret.add(vfModule);
- }
- }else{
- throw(new Exception("Incoming parameter is null or blank"));
- }
- if(ret == null || ret.isEmpty()){
- LOGGER.debug ("vfModules not found");
- respStatus = HttpStatus.SC_NOT_FOUND;
- qryResp = new QueryVfModule();
- }else{
- LOGGER.debug ("vfModules found");
- qryResp = new QueryVfModule(ret);
- LOGGER.debug ("vfModules query Results is: "+ qryResp);
- LOGGER.debug ("vfModules tojsonstring is: "+ qryResp.JSON2(false, false));
- }
- LOGGER.debug ("Query vfModules exit");
- return Response
- .status(respStatus)
- .entity(qryResp.JSON2(false, false))
- .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .build();
- }catch(Exception e){
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleModelName, "", "queryVfModules", MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ", e);
- CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
- return Response
- .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
- .entity(new GenericEntity<CatalogQueryException>(excResp) {})
- .build();
- }finally {
- db.close();
- }
+
+ try (CatalogDatabase db = CatalogDatabase.getInstance()) {
+ if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
+ LOGGER.debug("Query vfModules by vfModuleModuleName: " + vfModuleModelName);
+ VfModuleCustomization vfModule = db.getVfModuleCustomizationByModelName(vfModuleModelName);
+ if (vfModule != null) {
+ ret = new ArrayList<>(1);
+ ret.add(vfModule);
+ }
+ } else {
+ throw (new Exception("Incoming parameter is null or blank"));
+ }
+ if (ret == null || ret.isEmpty()) {
+ LOGGER.debug("vfModules not found");
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ qryResp = new QueryVfModule();
+ } else {
+ LOGGER.debug("vfModules found");
+ qryResp = new QueryVfModule(ret);
+ LOGGER.debug("vfModules query Results is: " + qryResp);
+ LOGGER.debug("vfModules tojsonstring is: " + qryResp.JSON2(false, false));
+ }
+ LOGGER.debug("Query vfModules exit");
+ return Response
+ .status(respStatus)
+ .entity(qryResp.JSON2(false, false))
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .build();
+ } catch (Exception e) {
+ LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleModelName, "", "queryVfModules",
+ MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ",
+ e);
+ CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
+ CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
+ return Response
+ .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
+ .entity(new GenericEntity<CatalogQueryException>(excResp) {
+ })
+ .build();
+ }
}
/**
@@ -482,37 +483,36 @@ public class CatalogDbAdapterRest {
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response ServiceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
int respStatus = HttpStatus.SC_OK;
- CatalogDatabase db = CatalogDatabase.getInstance();
String entity = "";
- try{
- if(smUuid != null && !"".equals(smUuid)){
- LOGGER.debug ("Query Csar by service model uuid: " + smUuid);
+ try (CatalogDatabase db = CatalogDatabase.getInstance()) {
+ if (smUuid != null && !"".equals(smUuid)) {
+ LOGGER.debug("Query Csar by service model uuid: " + smUuid);
ToscaCsar toscaCsar = db.getToscaCsarByServiceModelUUID(smUuid);
- if(toscaCsar != null){
+ if (toscaCsar != null) {
QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
entity = serviceCsar.JSON2(false, false);
- }
- else{
+ } else {
respStatus = HttpStatus.SC_NOT_FOUND;
}
- }else{
- throw(new Exception("Incoming parameter is null or blank"));
- }
- LOGGER.debug ("Query Csar exit");
+ } else {
+ throw (new Exception("Incoming parameter is null or blank"));
+ }
+ LOGGER.debug("Query Csar exit");
return Response
- .status(respStatus)
- .entity(entity)
- .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .build();
- }catch(Exception e){
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, smUuid, "", "ServiceToscaCsar", MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query csar by service model uuid: ", e);
- CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
+ .status(respStatus)
+ .entity(entity)
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .build();
+ } catch (Exception e) {
+ LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, smUuid, "", "ServiceToscaCsar",
+ MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query csar by service model uuid: ", e);
+ CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
+ CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
return Response
- .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
- .entity(new GenericEntity<CatalogQueryException>(excResp) {})
- .build();
- }finally {
- db.close();
+ .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
+ .entity(new GenericEntity<CatalogQueryException>(excResp) {
+ })
+ .build();
}
}
}