aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java')
-rw-r--r--src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java97
1 files changed, 17 insertions, 80 deletions
diff --git a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
index 13f1540..3a08daa 100644
--- a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
+++ b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
@@ -3,6 +3,7 @@
* dcae-inventory
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 Nokia 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.
@@ -88,86 +89,15 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
DateTime createdCutoff = DateTime.now(DateTimeZone.UTC);
try (Handle jdbiHandle = InventoryDAOManager.getInstance().getHandle()) {
- StringBuilder sb = new StringBuilder("select * from ");
+ final String queryStatement = DcaeServiceTypesQueryStatement.create(typeName, onlyLatest, onlyActive,
+ vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, owner, application, component);
- if (onlyLatest) {
- // Use the view which filters types that are of only the latest versions
- sb.append("dcae_service_types_latest");
- } else {
- sb.append("dcae_service_types");
- }
-
- List<String> whereClauses = new ArrayList<>();
-
- if (typeName != null) {
- if (!typeName.contains("*")) {
- whereClauses.add(":typeName = type_name");
- }
- else {
- typeName = typeName.replaceAll("\\*", "%");
- whereClauses.add("type_name LIKE :typeName");
- }
- }
-
- if (vnfType != null) {
- whereClauses.add("lower(:vnfType) = any(lower(vnf_types\\:\\:text)\\:\\:text[])");
- }
-
- if (serviceId != null) {
- whereClauses.add("(:serviceId = any(service_ids) or service_ids = \'{}\' or service_ids is null)");
- }
-
- if (serviceLocation != null) {
- whereClauses.add("(:serviceLocation = any(service_locations) or service_locations = \'{}\' or service_locations is null)");
- }
-
- if (asdcServiceId != null) {
- if (asdcServiceId.equalsIgnoreCase("NONE")) {
- whereClauses.add("asdc_service_id is null");
- } else {
- whereClauses.add(":asdcServiceId = asdc_service_id");
- }
- }
-
- if (asdcResourceId != null) {
- if (asdcResourceId.equalsIgnoreCase("NONE")) {
- whereClauses.add("asdc_resource_id is null");
- } else {
- whereClauses.add(":asdcResourceId = asdc_resource_id");
- }
- }
-
- if (owner != null) {
- whereClauses.add(":owner = owner");
- }
-
- if (application != null) {
- whereClauses.add(":application = application");
- }
-
- if (component != null) {
- whereClauses.add(":component = component");
- }
-
- whereClauses.add("created < :createdCutoff");
-
- if (onlyActive) {
- whereClauses.add("deactivated is null");
- }
-
- if (!whereClauses.isEmpty()) {
- sb.append(" where ");
- sb.append(String.join(" and ", whereClauses));
- }
+ metricsLogger.info("Query created as: {}." + queryStatement);
- // Sort by created timestamp - always descending.
- sb.append(" order by created desc");
-
- metricsLogger.info("Query created as: {}." + sb.toString());
-
- Query<DCAEServiceTypeObject> query = jdbiHandle.createQuery(sb.toString()).map(new DCAEServiceTypeObjectMapper());
+ Query<DCAEServiceTypeObject> query = jdbiHandle.createQuery(queryStatement).map(new DCAEServiceTypeObjectMapper());
if (typeName != null) {
+ typeName = resolveTypeName(typeName);
query.bind("typeName", typeName);
}
@@ -190,15 +120,15 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
if (asdcResourceId != null && !"NONE".equalsIgnoreCase(asdcResourceId)) {
query.bind("asdcResourceId", asdcResourceId);
}
-
+
if (application != null) {
query.bind("application", application);
}
-
+
if (component != null) {
query.bind("component", component);
}
-
+
if (owner != null) {
query.bind("owner", owner);
}
@@ -246,7 +176,7 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
response.setLinks(navigationLinks);
debugLogger.debug("Response: {}." + response.toString());
-
+
return Response.ok().entity(response).build();
}
@@ -263,6 +193,13 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
return Response.ok().entity(createDCAEServiceType(serviceTypeObject, uriInfo)).build();
}
+ static String resolveTypeName(String typeName){
+ if (typeName.contains("*")) {
+ return typeName.replaceAll("\\*", "%");
+ }
+ return typeName;
+ }
+
/**
* Create a DCAE service type database object
*