summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorShadi Haidar <sh1986@att.com>2018-10-21 14:51:22 -0400
committerHaidar, Shadi (sh1986) <sh1986@att.com>2018-11-07 09:25:50 -0500
commitedb7b340c2f055af88e1ff9a4c7dfc0d51ac9b77 (patch)
treed13dc8e4dad93eee71fab752b299497acfbeca1f /src/main
parente09d200eaf5a3b36652433f3b8581192d7e0b52b (diff)
xAdd application/component.
Change-Id: Ib60ef8f3e64aa03dfa49b7c542ac7bae1e25175f Issue-ID: DCAEGEN2-879 Signed-off-by: Shadi Haidar <sh1986@att.com> Signed-off-by: Haidar, Shadi (sh1986) <sh1986@att.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java42
-rw-r--r--src/main/java/org/onap/dcae/inventory/daos/DCAEServiceTypesDAO.java24
-rw-r--r--src/main/java/org/onap/dcae/inventory/daos/InventoryDAO.java4
-rw-r--r--src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java30
-rw-r--r--src/main/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java2
-rw-r--r--src/main/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java18
6 files changed, 109 insertions, 11 deletions
diff --git a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
index feafd20..13f1540 100644
--- a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
+++ b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
@@ -58,6 +58,8 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
serviceType.setTypeName(serviceTypeObject.getTypeName());
serviceType.setTypeVersion(serviceTypeObject.getTypeVersion());
serviceType.setOwner(serviceTypeObject.getOwner());
+ serviceType.setApplication(serviceTypeObject.getApplication());
+ serviceType.setComponent(serviceTypeObject.getComponent());
serviceType.setVnfTypes(serviceTypeObject.getVnfTypes());
serviceType.setServiceIds(serviceTypeObject.getServiceIds());
serviceType.setServiceLocations(serviceTypeObject.getServiceLocations());
@@ -76,7 +78,9 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
@Override
public Response dcaeServiceTypesGet(String typeName, Boolean onlyLatest, Boolean onlyActive, String vnfType,
String serviceId, String serviceLocation, String asdcServiceId,
- String asdcResourceId, Integer offset, UriInfo uriInfo, SecurityContext securityContext)
+ String asdcResourceId, Integer offset,
+ UriInfo uriInfo, SecurityContext securityContext,
+ String application, String component, String owner)
throws NotFoundException {
List<DCAEServiceTypeObject> serviceTypeObjects = new ArrayList<>();
@@ -100,7 +104,7 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
whereClauses.add(":typeName = type_name");
}
else {
- typeName = typeName.replaceAll("\\*", "%");
+ typeName = typeName.replaceAll("\\*", "%");
whereClauses.add("type_name LIKE :typeName");
}
}
@@ -116,14 +120,14 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
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")) {
@@ -132,6 +136,18 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
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");
@@ -174,6 +190,18 @@ 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);
+ }
query.bind("createdCutoff", createdCutoff);
@@ -205,14 +233,14 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
if (offsetPrev >= 0) {
navigationLinks.setPreviousLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "prev", typeName, onlyLatest,
- onlyActive, vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, offsetPrev));
+ onlyActive, vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, offsetPrev, application, component, owner));
}
Integer offsetNext = offset + PAGINATION_PAGE_SIZE;
if (offsetNext < totalCount) {
navigationLinks.setNextLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "next", typeName, onlyLatest,
- onlyActive, vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, offsetNext));
+ onlyActive, vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, offsetNext, application, component, owner));
}
response.setLinks(navigationLinks);
@@ -251,6 +279,8 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
serviceTypeObject.setTypeName(request.getTypeName());
serviceTypeObject.setTypeVersion(request.getTypeVersion());
serviceTypeObject.setOwner(request.getOwner());
+ serviceTypeObject.setApplication(request.getApplication());
+ serviceTypeObject.setComponent(request.getComponent());
serviceTypeObject.setBlueprintTemplate(request.getBlueprintTemplate());
serviceTypeObject.setVnfTypes(request.getVnfTypes());
serviceTypeObject.setServiceIds(request.getServiceIds());
diff --git a/src/main/java/org/onap/dcae/inventory/daos/DCAEServiceTypesDAO.java b/src/main/java/org/onap/dcae/inventory/daos/DCAEServiceTypesDAO.java
index aa242a4..770661c 100644
--- a/src/main/java/org/onap/dcae/inventory/daos/DCAEServiceTypesDAO.java
+++ b/src/main/java/org/onap/dcae/inventory/daos/DCAEServiceTypesDAO.java
@@ -42,6 +42,14 @@ public interface DCAEServiceTypesDAO extends InventoryDAO {
@SqlQuery("select exists (select * from information_schema.tables where table_name = \'dcae_service_types\')")
@Override
Boolean checkIfTableExists();
+
+ @SqlQuery("select exists (select * from information_schema.columns where table_name = \'dcae_service_types\' and column_name=\'application\')")
+ @Override
+ Boolean checkIfApplicationColumnExists();
+
+ @SqlQuery("select exists (select * from information_schema.columns where table_name = \'dcae_service_types\' and column_name=\'component\')")
+ @Override
+ Boolean checkIfComponentColumnExists();
/**
* Note that service_ids and service_locations are nullable fields. This might not be the right decision but because
@@ -50,20 +58,28 @@ public interface DCAEServiceTypesDAO extends InventoryDAO {
@SqlUpdate("create table dcae_service_types (type_id varchar not null, type_version integer not null, " +
"type_name varchar not null, owner varchar not null, blueprint_template text not null, " +
"vnf_types varchar[] not null, service_ids varchar[], service_locations varchar[], " +
- "asdc_service_id varchar, asdc_resource_id varchar, " +
+ "asdc_service_id varchar, asdc_resource_id varchar, application varchar, component varchar, " +
"created timestamp not null, deactivated timestamp, constraint pk_type_created primary key (type_id))")
@Override
void createTable();
+
+ @SqlUpdate("alter table dcae_service_types add column application varchar")
+ @Override
+ void updateTableToAddApplicationCol();
+
+ @SqlUpdate("alter table dcae_service_types add column component varchar")
+ @Override
+ void updateTableToAddComponentCol();
// REVIEW: asdcServiceId and asdcResourceId is implicitly part of the unique key and thus shouldn't be updated.
- @SqlUpdate("insert into dcae_service_types(type_id, type_version, type_name, owner, blueprint_template, vnf_types, " +
+ @SqlUpdate("insert into dcae_service_types(type_id, type_version, type_name, owner, application, component, blueprint_template, vnf_types, " +
"service_ids, service_locations, asdc_service_id, asdc_resource_id, created, deactivated) " +
- "values (:typeId, :typeVersion, :typeName, :owner, :blueprintTemplate, :vnfTypes, :serviceIds, " +
+ "values (:typeId, :typeVersion, :typeName, :owner, :application, :component, :blueprintTemplate, :vnfTypes, :serviceIds, " +
":serviceLocations, :asdcServiceId, :asdcResourceId, :created, null)")
void insert(@BindBean DCAEServiceTypeObject serviceObject);
@SqlUpdate("update dcae_service_types set " +
- "owner = :owner, blueprint_template = :blueprintTemplate, vnf_types = :vnfTypes, " +
+ "owner = :owner, application = :application, component = :component, blueprint_template = :blueprintTemplate, vnf_types = :vnfTypes, " +
"service_ids = :serviceIds, service_locations = :serviceLocations, created = :created, " +
"deactivated = null where type_id = :typeId")
void update(@BindBean DCAEServiceTypeObject serviceObject);
diff --git a/src/main/java/org/onap/dcae/inventory/daos/InventoryDAO.java b/src/main/java/org/onap/dcae/inventory/daos/InventoryDAO.java
index a369cb1..e678b60 100644
--- a/src/main/java/org/onap/dcae/inventory/daos/InventoryDAO.java
+++ b/src/main/java/org/onap/dcae/inventory/daos/InventoryDAO.java
@@ -25,5 +25,9 @@ package org.onap.dcae.inventory.daos;
*/
public interface InventoryDAO {
Boolean checkIfTableExists();
+ Boolean checkIfApplicationColumnExists();
+ Boolean checkIfComponentColumnExists();
void createTable();
+ void updateTableToAddApplicationCol();
+ void updateTableToAddComponentCol();
}
diff --git a/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java b/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java
index b809d2d..5bdecfe 100644
--- a/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java
+++ b/src/main/java/org/onap/dcae/inventory/daos/InventoryDAOManager.java
@@ -101,6 +101,8 @@ public final class InventoryDAOManager {
final DBI jdbi_local = factory.build(this.environment, this.configuration.getDataSourceFactory(), "dcae-database");
jdbi_local.registerArgumentFactory(new StringListArgument());
+ boolean recreateDcaeServiceTypesView = false;
+
for (Class<? extends InventoryDAO> daoClass : DAO_CLASSES) {
final InventoryDAO dao = jdbi_local.onDemand(daoClass);
@@ -110,6 +112,23 @@ public final class InventoryDAOManager {
dao.createTable();
debugLogger.info(String.format("Sql table created: %s", daoClass.getSimpleName()));
}
+ // dcae_service_types DB table has been enhanced to include 2 new columns which need to be added if they don't already exist
+ if ( daoClass.getSimpleName().equals("DCAEServiceTypesDAO") ) {
+ if (dao.checkIfApplicationColumnExists()) {
+ debugLogger.info(String.format("ApplicationColumn exists: %s", daoClass.getSimpleName()));
+ } else {
+ dao.updateTableToAddApplicationCol();
+ debugLogger.info(String.format("ApplicationColumn created: %s", daoClass.getSimpleName()+".updateTableToAddApplicationCol()" ));
+ recreateDcaeServiceTypesView = true;
+ }
+ if (dao.checkIfComponentColumnExists()) {
+ debugLogger.info(String.format("ComponentColumn exists: %s", daoClass.getSimpleName()));
+ } else {
+ dao.updateTableToAddComponentCol();;
+ debugLogger.info(String.format("ComponentColumn created: %s", daoClass.getSimpleName()+".updateTableToAddComponentCol()"));
+ recreateDcaeServiceTypesView = true;
+ }
+ }
}
// CREATE VIEWS
@@ -119,7 +138,16 @@ public final class InventoryDAOManager {
String checkQuery = String.format("select exists (select * from information_schema.tables where table_name = '%s')",
viewName);
- if (jdbiHandle.createQuery(checkQuery).map(BooleanMapper.FIRST).first()) {
+ boolean viewExists = jdbiHandle.createQuery(checkQuery).map(BooleanMapper.FIRST).first();
+
+ // if the view exists and the 2 new dcae_service_types DB table columns: application and component need to be added
+ // we need to re-create the view by deleting it first
+ if (viewExists && recreateDcaeServiceTypesView) {
+ debugLogger.info(String.format("Need to delete existing Sql view: %s", viewName));
+ jdbiHandle.execute(String.format("drop view %s ", viewName));
+ }
+
+ if (viewExists) {
debugLogger.info(String.format("Sql view exists: %s", viewName));
} else {
StringBuilder sb = new StringBuilder(String.format("create view %s as ", viewName));
diff --git a/src/main/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java b/src/main/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java
index bda4423..a7e2249 100644
--- a/src/main/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java
+++ b/src/main/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java
@@ -43,6 +43,8 @@ public class DCAEServiceTypeObjectMapper implements ResultSetMapper<DCAEServiceT
object.setTypeName(resultSet.getString("type_name"));
object.setTypeVersion(resultSet.getInt("type_version"));
object.setOwner(resultSet.getString("owner"));
+ object.setApplication(resultSet.getString("application"));
+ object.setComponent(resultSet.getString("component"));
String[] vnfTypes = (String[]) resultSet.getArray("vnf_types").getArray();
object.setVnfTypes(Arrays.asList(vnfTypes));
diff --git a/src/main/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java b/src/main/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java
index f264c99..3c86138 100644
--- a/src/main/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java
+++ b/src/main/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java
@@ -36,6 +36,8 @@ public class DCAEServiceTypeObject {
private Integer typeVersion = null;
private String blueprintTemplate = null;
private String owner = null;
+ private String application = null;
+ private String component = null;
private List<String> vnfTypes = null;
private List<String> serviceIds = null;
private List<String> serviceLocations = null;
@@ -83,6 +85,22 @@ public class DCAEServiceTypeObject {
public void setOwner(String owner) {
this.owner = owner;
}
+
+ public String getApplication() {
+ return application;
+ }
+
+ public void setApplication(String application) {
+ this.application = application;
+ }
+
+ public String getComponent() {
+ return component;
+ }
+
+ public void setComponent(String component) {
+ this.component = component;
+ }
public List<String> getVnfTypes() {
return vnfTypes;